From 1683a0b8150d5adcf64580a4d85120eb3e61cff4 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Tue, 14 Feb 2012 20:55:51 +0100 Subject: [PATCH] dom0/qvm-block: detect 'connecting' devices as 'connected' This is needed to not allow connecting the same backend to more than one VMs at the same time. --- dom0/qvm-core/qubesutils.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/dom0/qvm-core/qubesutils.py b/dom0/qvm-core/qubesutils.py index 5d65cff6..b8dd8d62 100644 --- a/dom0/qvm-core/qubesutils.py +++ b/dom0/qvm-core/qubesutils.py @@ -214,13 +214,21 @@ def block_check_attached(backend_vm, device, backend_xid = None): device_majorminor = block_name_to_majorminor(device) for vm_xid in vm_list: for devid in xs.ls('', '/local/domain/%d/backend/vbd/%s' % (backend_xid, vm_xid)): + (tmp_major, tmp_minor) = (0, 0) phys_device = xs.read('', '/local/domain/%d/backend/vbd/%s/%s/physical-device' % (backend_xid, vm_xid, devid)) - if phys_device is None or not phys_device.find(':'): - # Skip not-phy devices - continue - (tmp_major, tmp_minor) = phys_device.split(":") - tmp_major = int(tmp_major, 16) - tmp_minor = int(tmp_minor, 16) + if phys_device and phys_device.find(':'): + (tmp_major, tmp_minor) = phys_device.split(":") + tmp_major = int(tmp_major, 16) + tmp_minor = int(tmp_minor, 16) + else: + # perhaps not ready yet - check params + dev_params = xs.read('', '/local/domain/%d/backend/vbd/%s/%s/params' % (backend_xid, vm_xid, devid)) + if not dev_params or not dev_params.startswith('/dev/'): + # Skip not-phy devices + continue + else: + (tmp_major, tmp_minor) = block_name_to_majorminor(dev_params.lstrip('/dev/')) + if (tmp_major, tmp_minor) == device_majorminor: vm_name = xl_ctx.domid_to_name(int(vm_xid)) frontend = block_devid_to_name(int(devid))