[PATCH 3/6] domain_conf: Add helpers to verify if device configuration is valid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds helpers that validate domain's device configuration.
This will be needed later on to verify devices being hot-plugged to
guests. If the guest has no USB bus, then it's not valid to plug a USB
device to that guest.
---
 src/conf/domain_conf.c   |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |    5 +++++
 src/libvirt_private.syms |    2 ++
 3 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9afae87..6c7242e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13258,6 +13258,49 @@ error:
     return NULL;
 }

+bool
+virDomainDefHasUSB(virDomainDefPtr def)
+{
+    int i;
+
+    for (i = 0; i < def->ncontrollers; i++) {
+        if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
+            def->controllers[i]->model != VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE)
+            return true;
+    }
+
+    return false;
+}
+
+int
+virDomainDefCompatibleDevice(virDomainDefPtr def,
+                             virDomainDeviceDefPtr dev)
+{
+    int t = dev->type;
+    if (!virDomainDefHasUSB(def) &&
+        ((t == VIR_DOMAIN_DEVICE_DISK &&
+          dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_USB) ||
+         (t == VIR_DOMAIN_DEVICE_CONTROLLER &&
+          dev->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) ||
+         (t == VIR_DOMAIN_DEVICE_INPUT &&
+          dev->data.input->type == VIR_DOMAIN_INPUT_BUS_USB) ||
+         (t == VIR_DOMAIN_DEVICE_HOSTDEV &&
+          dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+          dev->data.hostdev->source.subsys.type ==
+          VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) ||
+         (t == VIR_DOMAIN_DEVICE_HUB &&
+          dev->data.hub->type == VIR_DOMAIN_HUB_TYPE_USB) ||
+         (t == VIR_DOMAIN_DEVICE_REDIRDEV &&
+          dev->data.redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB))) {
+        virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                             _("Device configuration is not compatible: "
+                               "Domain has no USB bus support"));
+        return -1;
+    }
+
+    return 0;
+}
+
 int virDomainSaveXML(const char *configDir,
                      virDomainDefPtr def,
                      const char *xml)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5c06f88..36b2220 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1970,6 +1970,11 @@ int virDomainDefFormatInternal(virDomainDefPtr def,
                                unsigned int flags,
                                virBufferPtr buf);

+bool virDomainDefHasUSB(virDomainDefPtr def);
+
+int virDomainDefCompatibleDevice(virDomainDefPtr def,
+                                 virDomainDeviceDefPtr dev);
+
 int virDomainCpuSetParse(const char *str,
                          char sep,
                          char *cpuset,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6625fc6..2bd9116 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -278,9 +278,11 @@ virDomainDefAddImplicitControllers;
 virDomainDefCheckABIStability;
 virDomainDefClearDeviceAliases;
 virDomainDefClearPCIAddresses;
+virDomainDefCompatibleDevice;
 virDomainDefFormat;
 virDomainDefFormatInternal;
 virDomainDefFree;
+virDomainDefHasUSB;
 virDomainDefParseFile;
 virDomainDefParseNode;
 virDomainDefParseString;
-- 
1.7.8.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]