Add umount gluster storage directory when remove a node (removing the master node is to destroy the cluster) in the cluster.
Signed-off-by: Weiwei Jia <[email protected]> --- lib/backend.py | 27 +++++++++++++++++++++++++++ lib/bootstrap.py | 10 ++++++++++ lib/cmdlib/node.py | 9 +++++++++ lib/rpc_defs.py | 3 +++ lib/server/noded.py | 8 ++++++++ 5 files changed, 57 insertions(+) diff --git a/lib/backend.py b/lib/backend.py index 7063aa5..2010c99 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -3255,6 +3255,33 @@ def RemoveFileStorageDir(file_storage_dir): file_storage_dir, err) +def UmountGlusterStorageDir(gluster_storage_dir): + """Umount gluster storage directory. + + Umount it only if it's mounted. If not log an error and return. + + @type gluster_storage_dir: string + @param gluster_storage_dir: the directory we should umount + @rtype: tuple (success,) + @return: tuple of one element, C{success}, denoting + whether the operation was successful + + """ + gluster_storage_dir = _TransformFileStorageDir(gluster_storage_dir) + if os.path.exists(gluster_storage_dir): + if not os.path.isdir(gluster_storage_dir): + _Fail("Specified Storage directory '%s' is not a directory", + gluster_storage_dir) + # umount dir only if it's mounted, otherwise we want to fail the rpc call + result = utils.RunCmd(["umount", gluster_storage_dir]) + + if result.failed: + raise errors.OpPrereqError("Could not umount %s, error %s" % + (gluster_storage_dir, result.output)) + else: + _Fail("Gluster storage dir %s does not exist", gluster_storage_dir) + + def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir): """Rename the file storage directory. diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 54bd38a..cd8543b 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -773,6 +773,16 @@ def FinalizeClusterDestroy(master_uuid): if msg: logging.warning("Could not disable the master IP: %s", msg) + gluster_storage_dir = cfg.GetClusterInfo().gluster_file_storage_dir + if os.path.ismount(gluster_storage_dir): + result = runner.call_gluster_storage_dir_umount(master_name, + gluster_storage_dir) + + msg = result.fail_msg + if msg: + logging.warning("Could not umount gluster storage dir %s: %s" % + (gluster_storage_dir, msg)) + result = runner.call_node_stop_master(master_name) msg = result.fail_msg if msg: diff --git a/lib/cmdlib/node.py b/lib/cmdlib/node.py index e83049d..3944fc1 100644 --- a/lib/cmdlib/node.py +++ b/lib/cmdlib/node.py @@ -1527,6 +1527,15 @@ class LUNodeRemove(LogicalUnit): logging.info("Stopping the node daemon and removing configs from node %s", self.node.name) + gluster_storage_dir = self.cfg.GetClusterInfo().gluster_file_storage_dir + if os.path.ismount(gluster_storage_dir): + result = self.rpc.call_gluster_storage_dir_umount(self.node.name, + gluster_storage_dir) + msg = result.fail_msg + if msg: + self.LogWarning("Errors encountered on the remote node while umounting" + " the cluster: %s", msg) + modify_ssh_setup = self.cfg.GetClusterInfo().modify_ssh_setup assert locking.BGL in self.owned_locks(locking.LEVEL_CLUSTER), \ diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py index ffb5ceb..4756f74 100644 --- a/lib/rpc_defs.py +++ b/lib/rpc_defs.py @@ -582,6 +582,9 @@ CALLS = { "Whether to use the user-provided master IP address setup script"), ], None, None, "Activates master IP on a node"), + ("gluster_storage_dir_umount", SINGLE, None, constants.RPC_TMO_FAST, [ + ("gluster_storage_dir", None, "Gluster storage directory"), + ], None, None, "Umount the given gluster storage directory"), ("node_stop_master", SINGLE, None, constants.RPC_TMO_FAST, [], None, None, "Deactivates master IP and stops master daemons on a node"), ("node_deactivate_master_ip", SINGLE, None, constants.RPC_TMO_FAST, [ diff --git a/lib/server/noded.py b/lib/server/noded.py index ecc7c95..828f8c0 100644 --- a/lib/server/noded.py +++ b/lib/server/noded.py @@ -990,6 +990,14 @@ class NodeRequestHandler(http.server.HttpServerHandler): return backend.RemoveFileStorageDir(file_storage_dir) @staticmethod + def perspective_gluster_storage_dir_umount(params): + """umount the gluster storage directory. + + """ + gluster_storage_dir = params[0] + return backend.UmountGlusterStorageDir(gluster_storage_dir) + + @staticmethod def perspective_file_storage_dir_rename(params): """Rename the file storage directory. -- 1.7.10.4
