Track kernel/initrd/dtb in 'path in use by' UI

This commit is contained in:
Cole Robinson 2014-01-14 16:32:05 -05:00
parent 6dd41e6944
commit 765b1ed7d6
4 changed files with 75 additions and 23 deletions

View File

@ -39,6 +39,20 @@
</devices>
</domain>
<domain type='test'>
<name>test-arm-kernel</name>
<memory>8388608</memory>
<currentMemory>2097152</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch="i686">hvm</type>
<kernel>/dev/default-pool/test-arm-kernel</kernel>
<initrd>/dev/default-pool/test-arm-initrd</initrd>
<dtb>/dev/default-pool/test-arm-dtb</dtb>
<cmdline>console=ttyAMA0 rw root=/dev/vda3</cmdline>
</os>
</domain>
<domain type='test'>
<name>test-many-devices</name>
@ -544,13 +558,13 @@ test-many-devices, like an alternate RNG.
<domain type='test'>
<name>test_xenpv_kernel</name>
<name>test-xenpv-kernel</name>
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
<os>
<type>xen</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
<cmdline>method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os</cmdline>
</os>
<memory>430080</memory>
<vcpu>2</vcpu>
@ -1320,6 +1334,33 @@ ba</description>
<path>/dev/default-pool/backing.img</path>
</backingStore>
</volume>
<!-- fake arm media -->
<volume>
<name>test-arm-kernel</name>
<capacity>1000000</capacity>
<allocation>50000</allocation>
<target>
<format type='raw'/>
</target>
</volume>
<volume>
<name>test-arm-initrd</name>
<capacity>1000000</capacity>
<allocation>50000</allocation>
<target>
<format type='raw'/>
</target>
</volume>
<volume>
<name>test-arm-dtb</name>
<capacity>1000000</capacity>
<allocation>50000</allocation>
<target>
<format type='raw'/>
</target>
</volume>
</pool>

View File

@ -1,6 +1,5 @@
<domain type="test">
<name>test_xenpv_kernel</name>
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
<name>xenpv-kernel</name>
<os>
<type>xen</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>

View File

@ -1,6 +1,5 @@
<domain type="test">
<name>test_xenpv_kernel</name>
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
<name>xenpv-kernel</name>
<os>
<type>xen</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>

View File

@ -331,37 +331,50 @@ class VirtualDisk(VirtualDevice):
return errdict
@staticmethod
def path_in_use_by(conn, path, check_conflict=False):
def path_in_use_by(conn, path, shareable=False, read_only=False):
"""
Return a list of VM names that are using the passed path.
@param conn: virConnect to check VMs
@param path: Path to check for
@param check_conflict: Only return names that are truly conflicting:
this will omit guests that are using the disk with the
'shareable' flag, and possible other heuristics
@param shareable: Path we are checking is marked shareable, so
don't warn if it conflicts with another shareable source.
@param read_only: Path we are checking is marked read_only, so
don't warn if it conflicts with another read_only source.
"""
if not path:
return
ret = []
return []
vols = []
for vol in conn.fetch_all_vols():
if path == vol.backing_store:
vols.append(vol.target_path)
ret = []
vms = conn.fetch_all_guests()
for vm in vms:
for disk in vm.get_devices("disk"):
if disk.path == path:
if check_conflict:
if disk.shareable:
continue
if vm.name not in ret:
ret.append(vm.name)
if disk.path in vols and vm.name not in ret:
if not read_only:
if path in [vm.os.kernel, vm.os.initrd, vm.os.dtb]:
ret.append(vm.name)
continue
for disk in vm.get_devices("disk"):
if disk.path in vols and vm.name not in ret:
# VM uses the path indirectly via backing store
ret.append(vm.name)
break
if disk.path != path:
continue
if shareable and disk.shareable:
continue
if read_only and disk.read_only:
continue
ret.append(vm.name)
break
return ret
@staticmethod
@ -798,9 +811,9 @@ class VirtualDisk(VirtualDevice):
if not conn:
conn = self.conn
check_conflict = self.shareable
ret = self.path_in_use_by(conn, self.path,
check_conflict=check_conflict)
shareable=self.shareable,
read_only=self.read_only)
return ret