[PATCH 1/4] qemu: implement older APIs by forwarding to flags version

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

 



Centralize device modification in the more flexible APIs, to allow
future honoring of additional flags.  Explicitly reject the
VIR_DOMAIN_DEVICE_MODIFY_FORCE flag on attach/detach.

* src/qemu/qemu_driver.c (qemudDomainAttachDevice)
(qemudDomainAttachDeviceFlags): Swap bodies, and rename...
(qemuDomainAttachDevice, qemuDomainAttachDeviceFlags): to this.
(qemudDomainDetachDevice, qemudDomainDetachDeviceFlags):
Likewise.
---
 src/qemu/qemu_driver.c |   72 +++++++++++++++++++++++++++--------------------
 1 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c1a44c9..ca06dd6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3776,8 +3776,9 @@ cleanup:
 }


-static int qemudDomainAttachDevice(virDomainPtr dom,
-                                   const char *xml)
+static int
+qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
+                            unsigned int flags)
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
@@ -3786,6 +3787,14 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
     virCgroupPtr cgroup = NULL;
     int ret = -1;

+    virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
+                  VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
+    if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
+        qemuReportError(VIR_ERR_OPERATION_INVALID,
+                        "%s", _("cannot modify the persistent configuration of a domain"));
+        return -1;
+    }
+
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
     if (!vm) {
@@ -3933,22 +3942,17 @@ cleanup:
     return ret;
 }

-static int qemudDomainAttachDeviceFlags(virDomainPtr dom,
-                                        const char *xml,
-                                        unsigned int flags) {
-    if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        "%s", _("cannot modify the persistent configuration of a domain"));
-        return -1;
-    }
-
-    return qemudDomainAttachDevice(dom, xml);
+static int
+qemuDomainAttachDevice(virDomainPtr dom, const char *xml)
+{
+    return qemuDomainAttachDeviceFlags(dom, xml,
+                                       VIR_DOMAIN_DEVICE_MODIFY_LIVE);
 }


-static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
-                                       const char *xml,
-                                       unsigned int flags)
+static int
+qemuDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
+                            unsigned int flags)
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
@@ -4068,14 +4072,25 @@ cleanup:
 }


-static int qemudDomainDetachDevice(virDomainPtr dom,
-                                   const char *xml) {
+static int
+qemuDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
+                            unsigned int flags)
+{
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
     virBitmapPtr qemuCaps = NULL;
     virDomainDeviceDefPtr dev = NULL;
     int ret = -1;

+    virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
+                  VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
+    if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
+        qemuReportError(VIR_ERR_OPERATION_INVALID,
+                        "%s", _("cannot modify the persistent configuration of a domain"));
+        return -1;
+    }
+
+
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
     if (!vm) {
@@ -4154,16 +4169,11 @@ cleanup:
     return ret;
 }

-static int qemudDomainDetachDeviceFlags(virDomainPtr dom,
-                                        const char *xml,
-                                        unsigned int flags) {
-    if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        "%s", _("cannot modify the persistent configuration of a domain"));
-        return -1;
-    }
-
-    return qemudDomainDetachDevice(dom, xml);
+static int
+qemuDomainDetachDevice(virDomainPtr dom, const char *xml)
+{
+    return qemuDomainDetachDeviceFlags(dom, xml,
+                                       VIR_DOMAIN_DEVICE_MODIFY_LIVE);
 }

 static int qemudDomainGetAutostart(virDomainPtr dom,
@@ -6965,10 +6975,10 @@ static virDriver qemuDriver = {
     qemudDomainStartWithFlags, /* domainCreateWithFlags */
     qemudDomainDefine, /* domainDefineXML */
     qemudDomainUndefine, /* domainUndefine */
-    qemudDomainAttachDevice, /* domainAttachDevice */
-    qemudDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
-    qemudDomainDetachDevice, /* domainDetachDevice */
-    qemudDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+    qemuDomainAttachDevice, /* domainAttachDevice */
+    qemuDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
+    qemuDomainDetachDevice, /* domainDetachDevice */
+    qemuDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
     qemuDomainUpdateDeviceFlags, /* domainUpdateDeviceFlags */
     qemudDomainGetAutostart, /* domainGetAutostart */
     qemudDomainSetAutostart, /* domainSetAutostart */
-- 
1.7.4.2

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