From 6c3c6db9e84ae4e7d5ed0cb4e86f374df28be18f Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Mon, 17 Aug 2009 13:02:14 +0200 Subject: [PATCH] =?UTF-8?q?storage:=20Add=20operation=20for=20=E2=80=9Cvgr?= =?UTF-8?q?educe=20--removemissing=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/constants.py | 4 ++++ lib/storage.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/constants.py b/lib/constants.py index 175782f79..03ed03dd1 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -199,6 +199,9 @@ SF_FREE = "free" SF_USED = "used" SF_ALLOCATABLE = "allocatable" +# Storage operations +SO_FIX_CONSISTENCY = "fix-consistency" + # Available fields per storage type VALID_STORAGE_FIELDS = { ST_FILE: frozenset([SF_NAME, SF_USED, SF_FREE]), @@ -211,6 +214,7 @@ MODIFIABLE_STORAGE_FIELDS = { } VALID_STORAGE_OPERATIONS = { + ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]), } # Local disk status diff --git a/lib/storage.py b/lib/storage.py index 19563bf62..e589dd8db 100644 --- a/lib/storage.py +++ b/lib/storage.py @@ -374,6 +374,39 @@ class LvmVgStorage(_LvmBase): (constants.SF_SIZE, "vg_size", _ParseSize), ] + def _RemoveMissing(self, name): + """Runs "vgreduce --removemissing" on a volume group. + + @type name: string + @param name: Volume group name + + """ + # Ignoring vgreduce exit code. Older versions exit with an error even tough + # the VG is already consistent. This was fixed in later versions, but we + # cannot depend on it. + result = utils.RunCmd(["vgreduce", "--removemissing", name]) + + # Keep output in case something went wrong + vgreduce_output = result.output + + result = utils.RunCmd(["vgs", "--noheadings", "--nosuffix", name]) + if result.failed: + raise errors.StorageError(("Volume group '%s' still not consistent," + " 'vgreduce' output: %r," + " 'vgs' output: %r") % + (name, vgreduce_output, result.output)) + + def Execute(self, name, op): + """Executes an operation on a virtual volume. + + See L{_Base.Execute}. + + """ + if op == constants.SO_FIX_CONSISTENCY: + return self._RemoveMissing(name) + + return _LvmBase.Execute(self, name, op) + # Lookup table for storage types _STORAGE_TYPES = { -- GitLab