VirtualMachine: Refresh LVM cache before creating PV

When *lvmetad* is in use, it will cache volume group metadata from
previous runs of `mkvm` that used the same block device and prevent new
physical volumes from being created on it. Running `pvscan` alone does
not refresh the cache unless it is told to do so with the `--cache`
argument.
master
Dustin 2015-07-11 17:55:44 -05:00
parent e28238dc33
commit ef6b3ba8e8
2 changed files with 7 additions and 5 deletions

View File

@ -135,9 +135,12 @@ def partition_gpt(blockdev, partitions):
raise DiskError('Failed to partition disk: {}'.format(msg))
def pvscan():
def pvscan(dev=None):
cmd = ['pvscan']
if dev:
cmd += ('--cache', dev)
try:
output = subprocess.check_output(['pvscan'], stderr=subprocess.STDOUT)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
if output:
log.debug('pvscan:\n{}'.format(output.decode().rstrip()))
except subprocess.CalledProcessError as e:

View File

@ -372,8 +372,7 @@ class VirtualMachine(object):
storage.partition_gpt(self._disk.blockdev, self.partitions)
def _partition_lvm(self):
blockdev = self._disk.blockdev
storage.pvscan()
storage.pvscan(self._disk.blockdev)
pvs = []
if self.partitions:
partitions = self._disk.partitions
@ -381,7 +380,7 @@ class VirtualMachine(object):
if part.get('type') == 0x8e00:
pvs.append(partitions[idx])
else:
pvs.append(blockdev)
pvs.append(self._disk.blockdev)
storage.create_lvm_pv(*pvs)
storage.create_lvm_vg(self.vg_name, *pvs)
for vol in self.volumes: