[PATCH] qemu: Support attaching controller device persistently

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

 



src/conf/domain_conf.*: (Introduce virDomainControllerFind)
src/libvirt_private.syms: (Add virDomainControllerFind to private symbol)
src/qemu/qemu_driver.c: (Use of virDomainControllerFind)
src/qemu/qemu_driver.c: (Support attaching controller device persistently)
---
 src/conf/domain_conf.c   |   17 +++++++++++++++++
 src/conf/domain_conf.h   |    2 +-
 src/libvirt_private.syms |    1 +
 src/qemu/qemu_driver.c   |   17 +++++++++++++++++
 src/qemu/qemu_hotplug.c  |   14 +++++---------
 5 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4651765..f2e8271 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7520,6 +7520,23 @@ void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
     def->ncontrollers++;
 }
 
+bool
+virDomainControllerFind(virDomainDefPtr def,
+                        virDomainControllerDefPtr controller)
+{
+    int i;
+    bool found = false;
+
+    for (i = 0 ; i < def->ncontrollers ; i++) {
+        if ((def->controllers[i]->type == controller->type) &&
+            (def->controllers[i]->idx == controller->idx)) {
+            found = true;
+            break;
+        }
+    }
+
+    return found;
+}
 
 int virDomainLeaseIndex(virDomainDefPtr def,
                         virDomainLeaseDefPtr lease)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3712785..f7e7dca 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2036,7 +2036,7 @@ int virDomainControllerInsert(virDomainDefPtr def,
                               virDomainControllerDefPtr controller);
 void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
                                          virDomainControllerDefPtr controller);
-
+bool virDomainControllerFind(virDomainDefPtr def, virDomainControllerDefPtr controller);
 
 int virDomainLeaseIndex(virDomainDefPtr def,
                         virDomainLeaseDefPtr lease);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2fe5068..a75086b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -263,6 +263,7 @@ virDomainClockOffsetTypeFromString;
 virDomainClockOffsetTypeToString;
 virDomainConfigFile;
 virDomainControllerDefFree;
+virDomainControllerFind;
 virDomainControllerInsert;
 virDomainControllerInsertPreAlloced;
 virDomainControllerModelSCSITypeFromString;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2177c30..5713650 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5529,6 +5529,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
     virDomainNetDefPtr net;
     virDomainHostdevDefPtr hostdev;
     virDomainLeaseDefPtr lease;
+    virDomainControllerDefPtr controller;
 
     switch (dev->type) {
     case VIR_DOMAIN_DEVICE_DISK:
@@ -5600,6 +5601,22 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
         dev->data.lease = NULL;
         break;
 
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+        controller = dev->data.controller;
+        if (virDomainControllerFind(vmdef, controller)) {
+            qemuReportError(VIR_ERR_INVALID_ARG,
+                            _("Target already exists"));
+            return -1;
+        }
+
+        if (virDomainControllerInsert(vmdef, controller) < 0)
+            return -1;
+        dev->data.controller = NULL;
+
+        if (qemuDomainAssignAddresses(vmdef) < 0)
+            return -1;
+        break;
+
     default:
          qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                          _("persistent attach of device is not supported"));
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index c2fa75b..a9d9ff9 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -308,21 +308,17 @@ int qemuDomainAttachPciControllerDevice(struct qemud_driver *driver,
                                         virDomainObjPtr vm,
                                         virDomainControllerDefPtr controller)
 {
-    int i;
     int ret = -1;
     const char* type = virDomainControllerTypeToString(controller->type);
     char *devstr = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     bool releaseaddr = false;
 
-    for (i = 0 ; i < vm->def->ncontrollers ; i++) {
-        if ((vm->def->controllers[i]->type == controller->type) &&
-            (vm->def->controllers[i]->idx == controller->idx)) {
-            qemuReportError(VIR_ERR_OPERATION_FAILED,
-                            _("target %s:%d already exists"),
-                            type, controller->idx);
-            return -1;
-        }
+    if (virDomainControllerFind(vm->def, controller)) {
+        qemuReportError(VIR_ERR_OPERATION_FAILED,
+                        _("target %s:%d already exists"),
+                        type, controller->idx);
+        return -1;
     }
 
     if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
-- 
1.7.7.3

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