Commit | Line | Data |
---|---|---|
72a91d74 MB |
1 | This patch adds support for newer versions of DRBD. |
2 | ||
3 | Submitted upstream: <https://github.com/ganeti/ganeti/pull/1496>. | |
4 | ||
5 | diff --git a/lib/storage/drbd.py b/lib/storage/drbd.py | |
6 | --- a/lib/storage/drbd.py | |
7 | +++ b/lib/storage/drbd.py | |
8 | @@ -315,6 +315,13 @@ class DRBD8Dev(base.BlockDev): | |
9 | """ | |
10 | return self._show_info_cls.GetDevInfo(self._GetShowData(minor)) | |
11 | ||
12 | + @staticmethod | |
13 | + def _NeedsLocalSyncerParams(): | |
14 | + # For DRBD >= 8.4, syncer init must be done after local, not in net. | |
15 | + info = DRBD8.GetProcInfo() | |
16 | + version = info.GetVersion() | |
17 | + return version["k_minor"] >= 4 | |
18 | + | |
19 | def _MatchesLocal(self, info): | |
20 | """Test if our local config matches with an existing device. | |
21 | ||
22 | @@ -397,6 +404,20 @@ class DRBD8Dev(base.BlockDev): | |
23 | base.ThrowError("drbd%d: can't attach local disk: %s", | |
24 | minor, result.output) | |
25 | ||
26 | + def _WaitForMinorSyncParams(): | |
27 | + """Call _SetMinorSyncParams and raise RetryAgain on errors. | |
28 | + """ | |
29 | + if self._SetMinorSyncParams(minor, self.params): | |
30 | + raise utils.RetryAgain() | |
31 | + | |
32 | + if self._NeedsLocalSyncerParams(): | |
33 | + # Retry because disk config for DRBD resource may be still uninitialized. | |
34 | + try: | |
35 | + utils.Retry(_WaitForMinorSyncParams, 1.0, 5.0) | |
36 | + except utils.RetryTimeout as e: | |
37 | + base.ThrowError("drbd%d: can't set the synchronization parameters: %s" % | |
38 | + (minor, utils.CommaJoin(e.args[0]))) | |
39 | + | |
40 | def _AssembleNet(self, minor, net_info, dual_pri=False, hmac=None, | |
41 | secret=None): | |
42 | """Configure the network part of the device. | |
43 | @@ -432,21 +453,24 @@ class DRBD8Dev(base.BlockDev): | |
44 | # sync speed only after setting up both sides can race with DRBD | |
45 | # connecting, hence we set it here before telling DRBD anything | |
46 | # about its peer. | |
47 | - sync_errors = self._SetMinorSyncParams(minor, self.params) | |
48 | - if sync_errors: | |
49 | - base.ThrowError("drbd%d: can't set the synchronization parameters: %s" % | |
50 | - (minor, utils.CommaJoin(sync_errors))) | |
51 | + | |
52 | + if not self._NeedsLocalSyncerParams(): | |
53 | + sync_errors = self._SetMinorSyncParams(minor, self.params) | |
54 | + if sync_errors: | |
55 | + base.ThrowError("drbd%d: can't set the synchronization parameters: %s" % | |
56 | + (minor, utils.CommaJoin(sync_errors))) | |
57 | ||
58 | family = self._GetNetFamily(minor, lhost, rhost) | |
59 | ||
60 | - cmd = self._cmd_gen.GenNetInitCmd(minor, family, lhost, lport, | |
61 | + cmds = self._cmd_gen.GenNetInitCmds(minor, family, lhost, lport, | |
62 | rhost, rport, protocol, | |
63 | dual_pri, hmac, secret, self.params) | |
64 | ||
65 | - result = utils.RunCmd(cmd) | |
66 | - if result.failed: | |
67 | - base.ThrowError("drbd%d: can't setup network: %s - %s", | |
68 | - minor, result.fail_reason, result.output) | |
69 | + for cmd in cmds: | |
70 | + result = utils.RunCmd(cmd) | |
71 | + if result.failed: | |
72 | + base.ThrowError("drbd%d: can't setup network: %s - %s", | |
73 | + minor, result.fail_reason, result.output) | |
74 | ||
75 | def _CheckNetworkConfig(): | |
76 | info = self._GetShowInfo(minor) | |
77 | @@ -463,19 +487,20 @@ class DRBD8Dev(base.BlockDev): | |
78 | base.ThrowError("drbd%d: timeout while configuring network", minor) | |
79 | ||
80 | # Once the assembly is over, try to set the synchronization parameters | |
81 | - try: | |
82 | - # The minor may not have been set yet, requiring us to set it at least | |
83 | - # temporarily | |
84 | - old_minor = self.minor | |
85 | - self._SetFromMinor(minor) | |
86 | - sync_errors = self.SetSyncParams(self.params) | |
87 | - if sync_errors: | |
88 | - base.ThrowError("drbd%d: can't set the synchronization parameters: %s" % | |
89 | - (self.minor, utils.CommaJoin(sync_errors))) | |
90 | - finally: | |
91 | - # Undo the change, regardless of whether it will have to be done again | |
92 | - # soon | |
93 | - self._SetFromMinor(old_minor) | |
94 | + if not self._NeedsLocalSyncerParams(): | |
95 | + try: | |
96 | + # The minor may not have been set yet, requiring us to set it at least | |
97 | + # temporarily | |
98 | + old_minor = self.minor | |
99 | + self._SetFromMinor(minor) | |
100 | + sync_errors = self.SetSyncParams(self.params) | |
101 | + if sync_errors: | |
102 | + base.ThrowError("drbd%d: can't set the synchronization parameters: %s" % | |
103 | + (self.minor, utils.CommaJoin(sync_errors))) | |
104 | + finally: | |
105 | + # Undo the change, regardless of whether it will have to be done again | |
106 | + # soon | |
107 | + self._SetFromMinor(old_minor) | |
108 | ||
109 | @staticmethod | |
110 | def _GetNetFamily(minor, lhost, rhost): | |
111 | diff --git a/lib/storage/drbd_cmdgen.py b/lib/storage/drbd_cmdgen.py | |
112 | --- a/lib/storage/drbd_cmdgen.py | |
113 | +++ b/lib/storage/drbd_cmdgen.py | |
114 | @@ -56,7 +56,7 @@ class BaseDRBDCmdGenerator(object): | |
115 | def GenLocalInitCmds(self, minor, data_dev, meta_dev, size_mb, params): | |
116 | raise NotImplementedError | |
117 | ||
118 | - def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol, | |
119 | + def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol, | |
120 | dual_pri, hmac, secret, params): | |
121 | raise NotImplementedError | |
122 | ||
123 | @@ -138,7 +138,7 @@ class DRBD83CmdGenerator(BaseDRBDCmdGenerator): | |
124 | ||
125 | return [args] | |
126 | ||
127 | - def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol, | |
128 | + def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol, | |
129 | dual_pri, hmac, secret, params): | |
130 | args = ["drbdsetup", self._DevPath(minor), "net", | |
131 | "%s:%s:%s" % (family, lhost, lport), | |
132 | @@ -155,7 +155,7 @@ class DRBD83CmdGenerator(BaseDRBDCmdGenerator): | |
133 | if params[constants.LDP_NET_CUSTOM]: | |
134 | args.extend(shlex.split(params[constants.LDP_NET_CUSTOM])) | |
135 | ||
136 | - return args | |
137 | + return [args] | |
138 | ||
139 | def GenSyncParamsCmd(self, minor, params): | |
140 | args = ["drbdsetup", self._DevPath(minor), "syncer"] | |
141 | @@ -345,8 +345,14 @@ class DRBD84CmdGenerator(BaseDRBDCmdGenerator): | |
142 | ||
143 | return cmds | |
144 | ||
145 | - def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol, | |
146 | + def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol, | |
147 | dual_pri, hmac, secret, params): | |
148 | + cmds = [] | |
149 | + | |
150 | + cmds.append(["drbdsetup", "new-resource", self._GetResource(minor)]) | |
151 | + cmds.append(["drbdsetup", "new-minor", self._GetResource(minor), | |
152 | + str(minor), "0"]) | |
153 | + | |
154 | args = ["drbdsetup", "connect", self._GetResource(minor), | |
155 | "%s:%s:%s" % (family, lhost, lport), | |
156 | "%s:%s:%s" % (family, rhost, rport), | |
157 | @@ -362,7 +368,8 @@ class DRBD84CmdGenerator(BaseDRBDCmdGenerator): | |
158 | if params[constants.LDP_NET_CUSTOM]: | |
159 | args.extend(shlex.split(params[constants.LDP_NET_CUSTOM])) | |
160 | ||
161 | - return args | |
162 | + cmds.append(args) | |
163 | + return cmds | |
164 | ||
165 | def GenSyncParamsCmd(self, minor, params): | |
166 | args = ["drbdsetup", "disk-options", minor] |