1 This patch adds support for newer versions of DRBD.
3 Submitted upstream: <https://github.com/ganeti/ganeti/pull/1496>.
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):
10 return self._show_info_cls.GetDevInfo(self._GetShowData(minor))
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
19 def _MatchesLocal(self, info):
20 """Test if our local config matches with an existing device.
22 @@ -397,6 +404,20 @@ class DRBD8Dev(base.BlockDev):
23 base.ThrowError("drbd%d: can't attach local disk: %s",
26 + def _WaitForMinorSyncParams():
27 + """Call _SetMinorSyncParams and raise RetryAgain on errors.
29 + if self._SetMinorSyncParams(minor, self.params):
30 + raise utils.RetryAgain()
32 + if self._NeedsLocalSyncerParams():
33 + # Retry because disk config for DRBD resource may be still uninitialized.
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])))
40 def _AssembleNet(self, minor, net_info, dual_pri=False, hmac=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
47 - sync_errors = self._SetMinorSyncParams(minor, self.params)
49 - base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
50 - (minor, utils.CommaJoin(sync_errors)))
52 + if not self._NeedsLocalSyncerParams():
53 + sync_errors = self._SetMinorSyncParams(minor, self.params)
55 + base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
56 + (minor, utils.CommaJoin(sync_errors)))
58 family = self._GetNetFamily(minor, lhost, rhost)
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)
65 - result = utils.RunCmd(cmd)
67 - base.ThrowError("drbd%d: can't setup network: %s - %s",
68 - minor, result.fail_reason, result.output)
70 + result = utils.RunCmd(cmd)
72 + base.ThrowError("drbd%d: can't setup network: %s - %s",
73 + minor, result.fail_reason, result.output)
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)
80 # Once the assembly is over, try to set the synchronization parameters
82 - # The minor may not have been set yet, requiring us to set it at least
84 - old_minor = self.minor
85 - self._SetFromMinor(minor)
86 - sync_errors = self.SetSyncParams(self.params)
88 - base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
89 - (self.minor, utils.CommaJoin(sync_errors)))
91 - # Undo the change, regardless of whether it will have to be done again
93 - self._SetFromMinor(old_minor)
94 + if not self._NeedsLocalSyncerParams():
96 + # The minor may not have been set yet, requiring us to set it at least
98 + old_minor = self.minor
99 + self._SetFromMinor(minor)
100 + sync_errors = self.SetSyncParams(self.params)
102 + base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
103 + (self.minor, utils.CommaJoin(sync_errors)))
105 + # Undo the change, regardless of whether it will have to be done again
107 + self._SetFromMinor(old_minor)
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
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
123 @@ -138,7 +138,7 @@ class DRBD83CmdGenerator(BaseDRBDCmdGenerator):
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]))
139 def GenSyncParamsCmd(self, minor, params):
140 args = ["drbdsetup", self._DevPath(minor), "syncer"]
141 @@ -345,8 +345,14 @@ class DRBD84CmdGenerator(BaseDRBDCmdGenerator):
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):
150 + cmds.append(["drbdsetup", "new-resource", self._GetResource(minor)])
151 + cmds.append(["drbdsetup", "new-minor", self._GetResource(minor),
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]))
165 def GenSyncParamsCmd(self, minor, params):
166 args = ["drbdsetup", "disk-options", minor]