[PATCH v5 3/8] conf: Add virDomainDeviceTypeFlags and use it in various drivers

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

 



Declare and use virDomainDeviceDefOperationsCallbacks in test / QEMU /
LXC / libxl drivers to store detachable devices that driver support,
this would be useful in future.

Also add test driver's memballoon device detach function and QEMU
driver's char device detach function to their xmlopt.

Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
 src/conf/domain_conf.h   | 31 ++++++++++++++++++++++++++
 src/libxl/libxl_conf.c   |  3 ++-
 src/libxl/libxl_domain.c |  8 +++++++
 src/libxl/libxl_domain.h |  1 +
 src/lxc/lxc_conf.c       |  3 ++-
 src/lxc/lxc_domain.c     |  7 ++++++
 src/lxc/lxc_domain.h     |  1 +
 src/qemu/qemu_conf.c     |  2 +-
 src/qemu/qemu_domain.c   | 39 +++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h   |  6 +++++
 src/test/test_driver.c   | 47 +++++++++++++++++++++++++++++++++++++++-
 11 files changed, 144 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 14fb9777de..3bb1092b60 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -90,6 +90,37 @@ typedef enum {
     VIR_DOMAIN_DEVICE_LAST
 } virDomainDeviceType;
 
+typedef enum {
+    VIR_DOMAIN_DEVICE_FLAG_NONE = (1 << VIR_DOMAIN_DEVICE_NONE),
+    VIR_DOMAIN_DEVICE_FLAG_DISK = (1 << VIR_DOMAIN_DEVICE_DISK),
+    VIR_DOMAIN_DEVICE_FLAG_LEASE = (1 << VIR_DOMAIN_DEVICE_LEASE),
+    VIR_DOMAIN_DEVICE_FLAG_FS = (1 << VIR_DOMAIN_DEVICE_FS),
+    VIR_DOMAIN_DEVICE_FLAG_NET = (1 << VIR_DOMAIN_DEVICE_NET),
+    VIR_DOMAIN_DEVICE_FLAG_INPUT = (1 << VIR_DOMAIN_DEVICE_INPUT),
+    VIR_DOMAIN_DEVICE_FLAG_SOUND = (1 << VIR_DOMAIN_DEVICE_SOUND),
+    VIR_DOMAIN_DEVICE_FLAG_VIDEO = (1 << VIR_DOMAIN_DEVICE_VIDEO),
+    VIR_DOMAIN_DEVICE_FLAG_HOSTDEV = (1 << VIR_DOMAIN_DEVICE_HOSTDEV),
+    VIR_DOMAIN_DEVICE_FLAG_WATCHDOG = (1 << VIR_DOMAIN_DEVICE_WATCHDOG),
+    VIR_DOMAIN_DEVICE_FLAG_CONTROLLER = (1 << VIR_DOMAIN_DEVICE_CONTROLLER),
+    VIR_DOMAIN_DEVICE_FLAG_GRAPHICS = (1 << VIR_DOMAIN_DEVICE_GRAPHICS),
+    VIR_DOMAIN_DEVICE_FLAG_HUB = (1 << VIR_DOMAIN_DEVICE_HUB),
+    VIR_DOMAIN_DEVICE_FLAG_REDIRDEV = (1 << VIR_DOMAIN_DEVICE_REDIRDEV),
+    VIR_DOMAIN_DEVICE_FLAG_SMARTCARD = (1 << VIR_DOMAIN_DEVICE_SMARTCARD),
+    VIR_DOMAIN_DEVICE_FLAG_CHR = (1 << VIR_DOMAIN_DEVICE_CHR),
+    VIR_DOMAIN_DEVICE_FLAG_MEMBALLOON = (1 << VIR_DOMAIN_DEVICE_MEMBALLOON),
+    VIR_DOMAIN_DEVICE_FLAG_NVRAM = (1 << VIR_DOMAIN_DEVICE_NVRAM),
+    VIR_DOMAIN_DEVICE_FLAG_RNG = (1 << VIR_DOMAIN_DEVICE_RNG),
+    VIR_DOMAIN_DEVICE_FLAG_SHMEM = (1 << VIR_DOMAIN_DEVICE_SHMEM),
+    VIR_DOMAIN_DEVICE_FLAG_TPM = (1 << VIR_DOMAIN_DEVICE_TPM),
+    VIR_DOMAIN_DEVICE_FLAG_PANIC = (1 << VIR_DOMAIN_DEVICE_PANIC),
+    VIR_DOMAIN_DEVICE_FLAG_MEMORY = (1 << VIR_DOMAIN_DEVICE_MEMORY),
+    VIR_DOMAIN_DEVICE_FLAG_IOMMU = (1 << VIR_DOMAIN_DEVICE_IOMMU),
+    VIR_DOMAIN_DEVICE_FLAG_VSOCK = (1 << VIR_DOMAIN_DEVICE_VSOCK),
+    VIR_DOMAIN_DEVICE_FLAG_AUDIO = (1 << VIR_DOMAIN_DEVICE_AUDIO),
+
+    VIR_DOMAIN_DEVICE_FLAG_LAST = (1 << VIR_DOMAIN_DEVICE_LAST)
+} virDomainDeviceTypeFlags;
+
 struct _virDomainDeviceDef {
     int type; /* enum virDomainDeviceType */
     union {
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 032f7196c2..aaf4a134a9 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -2486,5 +2486,6 @@ libxlCreateXMLConf(libxlDriverPrivate *driver)
     return virDomainXMLOptionNew(&libxlDomainDefParserConfig,
                                  &libxlDomainXMLPrivateDataCallbacks,
                                  &libxlDriverDomainXMLNamespace,
-                                 NULL, NULL, NULL);
+                                 NULL, NULL,
+                                 &libxlDriverDeviceDefOpsCallbacks);
 }
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 577985b5ea..e20adfd846 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1599,3 +1599,11 @@ virXMLNamespace libxlDriverDomainXMLNamespace = {
     .prefix = "xen",
     .uri = "http://libvirt.org/schemas/domain/xen/1.0";,
 };
+
+
+virDomainDeviceDefOperationsCallbacks libxlDriverDeviceDefOpsCallbacks = {
+    .detachFlags = VIR_DOMAIN_DEVICE_FLAG_DISK |
+                   VIR_DOMAIN_DEVICE_FLAG_NET |
+                   VIR_DOMAIN_DEVICE_FLAG_HOSTDEV |
+                   VIR_DOMAIN_DEVICE_FLAG_CONTROLLER,
+};
diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h
index 981bfc2bca..1534597cd9 100644
--- a/src/libxl/libxl_domain.h
+++ b/src/libxl/libxl_domain.h
@@ -68,6 +68,7 @@ struct _libxlDomainObjPrivate {
 extern virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks;
 extern virDomainDefParserConfig libxlDomainDefParserConfig;
 extern virXMLNamespace libxlDriverDomainXMLNamespace;
+extern virDomainDeviceDefOperationsCallbacks libxlDriverDeviceDefOpsCallbacks;
 extern const struct libxl_event_hooks ev_hooks;
 
 int
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 01a159438e..49b42033d3 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -190,7 +190,8 @@ lxcDomainXMLConfInit(virLXCDriver *driver, const char *defsecmodel)
     return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
                                  &virLXCDriverPrivateDataCallbacks,
                                  &virLXCDriverDomainXMLNamespace,
-                                 NULL, NULL, NULL);
+                                 NULL, NULL,
+                                 &virLXCDriverDeviceDefOpsCallbacks);
 }
 
 
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 0920e91fd1..5c3bc89c1c 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -496,3 +496,10 @@ virLXCDomainSetRunlevel(virDomainObj *vm,
     data.st_valid = NULL;
     return ret;
 }
+
+
+virDomainDeviceDefOperationsCallbacks virLXCDriverDeviceDefOpsCallbacks = {
+    .detachFlags = VIR_DOMAIN_DEVICE_FLAG_DISK |
+                   VIR_DOMAIN_DEVICE_FLAG_NET |
+                   VIR_DOMAIN_DEVICE_FLAG_HOSTDEV,
+};
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h
index 766837bdf1..2bdd67886e 100644
--- a/src/lxc/lxc_domain.h
+++ b/src/lxc/lxc_domain.h
@@ -92,6 +92,7 @@ struct _virLXCDomainObjPrivate {
 extern virXMLNamespace virLXCDriverDomainXMLNamespace;
 extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
 extern virDomainDefParserConfig virLXCDriverDomainDefParserConfig;
+extern virDomainDeviceDefOperationsCallbacks virLXCDriverDeviceDefOpsCallbacks;
 
 int
 virLXCDomainObjBeginJob(virLXCDriver *driver,
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 8b2926f766..aad361034a 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1297,7 +1297,7 @@ virQEMUDriverCreateXMLConf(virQEMUDriver *driver,
                                  &virQEMUDriverDomainXMLNamespace,
                                  &virQEMUDriverDomainABIStability,
                                  &virQEMUDriverDomainSaveCookie,
-                                 NULL);
+                                 &virQEMUDriverDeviceDefOpsCallbacks);
 }
 
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 14b585c6e9..bbf9804f09 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -29,6 +29,7 @@
 #include "qemu_process.h"
 #include "qemu_capabilities.h"
 #include "qemu_hostdev.h"
+#include "qemu_hotplug.h"
 #include "qemu_migration.h"
 #include "qemu_migration_params.h"
 #include "qemu_security.h"
@@ -11563,6 +11564,24 @@ qemuDomainDeviceBackendChardevForeachOne(virDomainDeviceDef *dev,
     return 0;
 }
 
+
+int
+qemuDomainDetachDeviceChrConfig(virDomainDef *vmdef,
+                                virDomainDeviceDef *dev,
+                                unsigned int flags)
+{
+    virDomainChrDef *chr;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!(chr = qemuDomainChrRemove(vmdef, dev->data.chr)))
+        return -1;
+
+    virDomainChrDefFree(chr);
+
+    return 0;
+}
+
 struct qemuDomainDeviceBackendChardevIterData {
     qemuDomainDeviceBackendChardevForeachCallback cb;
     void *cbdata;
@@ -11605,3 +11624,23 @@ qemuDomainDeviceBackendChardevForeach(virDomainDef *def,
                                            DOMAIN_DEVICE_ITERATE_MISSING_INFO,
                                            &data);
 }
+
+
+virDomainDeviceDefOperationsCallbacks virQEMUDriverDeviceDefOpsCallbacks = {
+    .detachChr = qemuDomainDetachDeviceChrConfig,
+    .detachFlags = VIR_DOMAIN_DEVICE_FLAG_DISK |
+                   VIR_DOMAIN_DEVICE_FLAG_NET |
+                   VIR_DOMAIN_DEVICE_FLAG_SOUND |
+                   VIR_DOMAIN_DEVICE_FLAG_HOSTDEV |
+                   VIR_DOMAIN_DEVICE_FLAG_LEASE |
+                   VIR_DOMAIN_DEVICE_FLAG_CONTROLLER |
+                   VIR_DOMAIN_DEVICE_FLAG_CHR |
+                   VIR_DOMAIN_DEVICE_FLAG_FS |
+                   VIR_DOMAIN_DEVICE_FLAG_RNG |
+                   VIR_DOMAIN_DEVICE_FLAG_MEMORY |
+                   VIR_DOMAIN_DEVICE_FLAG_REDIRDEV |
+                   VIR_DOMAIN_DEVICE_FLAG_SHMEM |
+                   VIR_DOMAIN_DEVICE_FLAG_WATCHDOG |
+                   VIR_DOMAIN_DEVICE_FLAG_INPUT |
+                   VIR_DOMAIN_DEVICE_FLAG_VSOCK,
+};
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 78474b3f73..79c0fcfe33 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -723,6 +723,7 @@ void qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *priv);
 extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
 extern virXMLNamespace virQEMUDriverDomainXMLNamespace;
 extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
+extern virDomainDeviceDefOperationsCallbacks virQEMUDriverDeviceDefOpsCallbacks;
 extern virDomainABIStability virQEMUDriverDomainABIStability;
 extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie;
 
@@ -1058,3 +1059,8 @@ int
 qemuDomainDeviceBackendChardevForeach(virDomainDef *def,
                                       qemuDomainDeviceBackendChardevForeachCallback cb,
                                       void *opaque);
+
+int
+qemuDomainDetachDeviceChrConfig(virDomainDef *vmdef,
+                                virDomainDeviceDef *dev,
+                                unsigned int flags);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e4eb0e87d2..2380c37ddb 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -431,6 +431,31 @@ testDomainObjPrivateFree(void *data)
 }
 
 
+static int
+testDomainDetachMemballoonDevice(virDomainDef *vmdef,
+                                 virDomainDeviceDef *dev G_GNUC_UNUSED,
+                                 unsigned int flags)
+{
+    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("detach memballon device on running domain "
+                       "is not supported"));
+        return -1;
+    }
+
+    if (!vmdef->memballoon) {
+        virReportError(VIR_ERR_DEVICE_MISSING, "%s",
+                       _("no memballoon device was found"));
+        return -1;
+    }
+
+    virDomainMemballoonDefFree(vmdef->memballoon);
+    vmdef->memballoon = NULL;
+
+    return 0;
+}
+
+
 static testDriver *
 testDriverNew(void)
 {
@@ -454,6 +479,26 @@ testDriverNew(void)
         .alloc = testDomainObjPrivateAlloc,
         .free = testDomainObjPrivateFree,
     };
+    virDomainDeviceDefOperationsCallbacks deviceOps = {
+        .detachMemballoon = testDomainDetachMemballoonDevice,
+        .detachFlags = VIR_DOMAIN_DEVICE_FLAG_DISK |
+                       VIR_DOMAIN_DEVICE_FLAG_NET |
+                       VIR_DOMAIN_DEVICE_FLAG_SOUND |
+                       VIR_DOMAIN_DEVICE_FLAG_HOSTDEV |
+                       VIR_DOMAIN_DEVICE_FLAG_LEASE |
+                       VIR_DOMAIN_DEVICE_FLAG_CONTROLLER |
+                       VIR_DOMAIN_DEVICE_FLAG_CHR |
+                       VIR_DOMAIN_DEVICE_FLAG_FS |
+                       VIR_DOMAIN_DEVICE_FLAG_RNG |
+                       VIR_DOMAIN_DEVICE_FLAG_MEMORY |
+                       VIR_DOMAIN_DEVICE_FLAG_REDIRDEV |
+                       VIR_DOMAIN_DEVICE_FLAG_SHMEM |
+                       VIR_DOMAIN_DEVICE_FLAG_WATCHDOG |
+                       VIR_DOMAIN_DEVICE_FLAG_INPUT |
+                       VIR_DOMAIN_DEVICE_FLAG_VSOCK |
+                       VIR_DOMAIN_DEVICE_FLAG_TPM |
+                       VIR_DOMAIN_DEVICE_FLAG_MEMBALLOON,
+    };
     testDriver *ret;
 
     if (testDriverInitialize() < 0)
@@ -463,7 +508,7 @@ testDriverNew(void)
         return NULL;
 
     if (!(ret->xmlopt = virDomainXMLOptionNew(&config, &privatecb, &ns,
-                                              NULL, NULL, NULL)) ||
+                                              NULL, NULL, &deviceOps)) ||
         !(ret->eventState = virObjectEventStateNew()) ||
         !(ret->ifaces = virInterfaceObjListNew()) ||
         !(ret->domains = virDomainObjListNew()) ||
-- 
2.35.1




[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]

  Powered by Linux