Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for DRBD >= 8.4. #1496

Merged
merged 1 commit into from Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 47 additions & 22 deletions lib/storage/drbd.py
Expand Up @@ -315,6 +315,13 @@ def _GetShowInfo(self, minor):
"""
return self._show_info_cls.GetDevInfo(self._GetShowData(minor))

@staticmethod
def _NeedsLocalSyncerParams():
# For DRBD >= 8.4, syncer init must be done after local, not in net.
info = DRBD8.GetProcInfo()
version = info.GetVersion()
return version["k_minor"] >= 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally checking that version["k_major"] == 8 would make the code more robust.


def _MatchesLocal(self, info):
"""Test if our local config matches with an existing device.

Expand Down Expand Up @@ -397,6 +404,20 @@ def _AssembleLocal(self, minor, backend, meta, size):
base.ThrowError("drbd%d: can't attach local disk: %s",
minor, result.output)

def _WaitForMinorSyncParams():
"""Call _SetMinorSyncParams and raise RetryAgain on errors.
"""
if self._SetMinorSyncParams(minor, self.params):
raise utils.RetryAgain()

if self._NeedsLocalSyncerParams():
# Retry because disk config for DRBD resource may be still uninitialized.
try:
utils.Retry(_WaitForMinorSyncParams, 1.0, 5.0)
except utils.RetryTimeout as e:
base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
(minor, utils.CommaJoin(e.args[0])))

def _AssembleNet(self, minor, net_info, dual_pri=False, hmac=None,
secret=None):
"""Configure the network part of the device.
Expand Down Expand Up @@ -432,21 +453,24 @@ def _AssembleNet(self, minor, net_info, dual_pri=False, hmac=None,
# sync speed only after setting up both sides can race with DRBD
# connecting, hence we set it here before telling DRBD anything
# about its peer.
sync_errors = self._SetMinorSyncParams(minor, self.params)
if sync_errors:
base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
(minor, utils.CommaJoin(sync_errors)))

if not self._NeedsLocalSyncerParams():
sync_errors = self._SetMinorSyncParams(minor, self.params)
if sync_errors:
base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
(minor, utils.CommaJoin(sync_errors)))

family = self._GetNetFamily(minor, lhost, rhost)

cmd = self._cmd_gen.GenNetInitCmd(minor, family, lhost, lport,
cmds = self._cmd_gen.GenNetInitCmds(minor, family, lhost, lport,
rhost, rport, protocol,
dual_pri, hmac, secret, self.params)

result = utils.RunCmd(cmd)
if result.failed:
base.ThrowError("drbd%d: can't setup network: %s - %s",
minor, result.fail_reason, result.output)
for cmd in cmds:
result = utils.RunCmd(cmd)
if result.failed:
base.ThrowError("drbd%d: can't setup network: %s - %s",
minor, result.fail_reason, result.output)

def _CheckNetworkConfig():
info = self._GetShowInfo(minor)
Expand All @@ -463,19 +487,20 @@ def _CheckNetworkConfig():
base.ThrowError("drbd%d: timeout while configuring network", minor)

# Once the assembly is over, try to set the synchronization parameters
try:
# The minor may not have been set yet, requiring us to set it at least
# temporarily
old_minor = self.minor
self._SetFromMinor(minor)
sync_errors = self.SetSyncParams(self.params)
if sync_errors:
base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
(self.minor, utils.CommaJoin(sync_errors)))
finally:
# Undo the change, regardless of whether it will have to be done again
# soon
self._SetFromMinor(old_minor)
if not self._NeedsLocalSyncerParams():
try:
# The minor may not have been set yet, requiring us to set it at least
# temporarily
old_minor = self.minor
self._SetFromMinor(minor)
sync_errors = self.SetSyncParams(self.params)
if sync_errors:
base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
(self.minor, utils.CommaJoin(sync_errors)))
finally:
# Undo the change, regardless of whether it will have to be done again
# soon
self._SetFromMinor(old_minor)

@staticmethod
def _GetNetFamily(minor, lhost, rhost):
Expand Down
17 changes: 12 additions & 5 deletions lib/storage/drbd_cmdgen.py
Expand Up @@ -56,7 +56,7 @@ def GenInitMetaCmd(self, minor, meta_dev):
def GenLocalInitCmds(self, minor, data_dev, meta_dev, size_mb, params):
raise NotImplementedError

def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol,
dual_pri, hmac, secret, params):
raise NotImplementedError

Expand Down Expand Up @@ -138,7 +138,7 @@ def GenLocalInitCmds(self, minor, data_dev, meta_dev, size_mb, params):

return [args]

def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol,
dual_pri, hmac, secret, params):
args = ["drbdsetup", self._DevPath(minor), "net",
"%s:%s:%s" % (family, lhost, lport),
Expand All @@ -155,7 +155,7 @@ def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
if params[constants.LDP_NET_CUSTOM]:
args.extend(shlex.split(params[constants.LDP_NET_CUSTOM]))

return args
return [args]

def GenSyncParamsCmd(self, minor, params):
args = ["drbdsetup", self._DevPath(minor), "syncer"]
Expand Down Expand Up @@ -345,8 +345,14 @@ def GenLocalInitCmds(self, minor, data_dev, meta_dev, size_mb, params):

return cmds

def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol,
dual_pri, hmac, secret, params):
cmds = []

cmds.append(["drbdsetup", "new-resource", self._GetResource(minor)])
cmds.append(["drbdsetup", "new-minor", self._GetResource(minor),
str(minor), "0"])

args = ["drbdsetup", "connect", self._GetResource(minor),
"%s:%s:%s" % (family, lhost, lport),
"%s:%s:%s" % (family, rhost, rport),
Expand All @@ -362,7 +368,8 @@ def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
if params[constants.LDP_NET_CUSTOM]:
args.extend(shlex.split(params[constants.LDP_NET_CUSTOM]))

return args
cmds.append(args)
return cmds

def GenSyncParamsCmd(self, minor, params):
args = ["drbdsetup", "disk-options", minor]
Expand Down