+ def _RemoveMissing(self, name, _runcmd_fn=utils.RunCmd):
+ """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 = _runcmd_fn([self.VGREDUCE_COMMAND, "--removemissing", name])
+
+ # Keep output in case something went wrong
+ vgreduce_output = result.output
+
+ # work around newer LVM version
+ if ("Wrote out consistent volume group" not in vgreduce_output or
+ "vgreduce --removemissing --force" in vgreduce_output):
+ # we need to re-run with --force
+ result = _runcmd_fn([self.VGREDUCE_COMMAND, "--removemissing",
+ "--force", name])
+ vgreduce_output += "\n" + result.output
+
+ result = _runcmd_fn([self.LIST_COMMAND, "--noheadings",
+ "--nosuffix", name])
+ # we also need to check the output
+ if result.failed or "Couldn't find device with uuid" in result.output:
+ 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)
+