[PATCH 1/4] Refine parameter `attach' of qemuDomainModifyDevicePersistent

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

 



This patch renames parameter `attach' to `action', and adds two
macros for it. Then we can easily add more macros in the furture
if needed.
---
 src/qemu/qemu_driver.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 840d76d..f33882a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4237,9 +4237,15 @@ static int qemuDomainDetachDevicePersistent(virDomainDefPtr vmdef,
     return 0;
 }
 
+/* XXX: better names are requested */
+#define ATTACH_DEVICE 0        /* Attach device persistently, device must not
+                                * exist before attach. */
+#define DETACH_DEVICE 1        /* Detach device persistently, device must exist
+                                * before detach. */
+
 static int qemuDomainModifyDevicePersistent(virDomainPtr dom,
                                         const char *xml,
-                                        unsigned int attach, unsigned int flags)
+                                        unsigned int action, unsigned int flags)
 {
     struct qemud_driver *driver;
     virDomainDeviceDefPtr device;
@@ -4295,10 +4301,15 @@ static int qemuDomainModifyDevicePersistent(virDomainPtr dom,
     if (!device)
         goto endjob;
 
-    if (attach)
+    if (action == ATTACH_DEVICE)
         ret = qemuDomainAttachDevicePersistent(vmdef, device);
-    else
+    else if (action == DETACH_DEVICE)
         ret = qemuDomainDetachDevicePersistent(vmdef, device);
+    else {
+        qemuReportError(VIR_ERR_INVALID_ARG, "%s %d",
+                        _("Unknown action"), action);
+        ret = -1;
+    }
 
     if (!ret) /* save the result */
         ret = virDomainSaveConfig(driver->configDir, vmdef);
@@ -4320,7 +4331,7 @@ static int qemudDomainAttachDeviceFlags(virDomainPtr dom,
                                         unsigned int flags)
 {
     if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)
-        return qemuDomainModifyDevicePersistent(dom, xml, 1, flags);
+        return qemuDomainModifyDevicePersistent(dom, xml, ATTACH_DEVICE, flags);
 
     if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE)
         return qemudDomainAttachDevice(dom, xml);
@@ -4546,7 +4557,7 @@ static int qemudDomainDetachDeviceFlags(virDomainPtr dom,
                                         unsigned int flags) {
 
     if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)
-        return qemuDomainModifyDevicePersistent(dom, xml, 0, flags);
+        return qemuDomainModifyDevicePersistent(dom, xml, DETACH_DEVICE, flags);
 
     if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE)
         return qemudDomainDetachDevice(dom, xml);
-- 
1.7.3.1


-- 
Thanks,
Hu Tao

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