[PATCH v2 2/8] qemu: Implement chardev hotplug on config level

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

 



There are two levels on which a device may be hotplugged: config
and live. The config level requires just an insert or remove from
internal domain definition structure, which is what this patch
exactly does. There is currently no implementation for a chardev
update action, as there's not much to be updated. But more
importantly, the only thing that can be updated is path or socket
address by which chardevs are distinguished. So the update action
is currently not supported.
---
 src/conf/domain_conf.c | 22 ++++++++++++++++++++--
 src/qemu/qemu_driver.c | 33 ++++++++++++++++++++++++++++++---
 2 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 37f0ce9..582eade 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1755,10 +1755,12 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
     case VIR_DOMAIN_DEVICE_RNG:
         virDomainRNGDefFree(def->data.rng);
         break;
+    case VIR_DOMAIN_DEVICE_CHR:
+        virDomainChrDefFree(def->data.chr);
+        break;
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_FS:
     case VIR_DOMAIN_DEVICE_SMARTCARD:
-    case VIR_DOMAIN_DEVICE_CHR:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
     case VIR_DOMAIN_DEVICE_NVRAM:
     case VIR_DOMAIN_DEVICE_LAST:
@@ -9433,6 +9435,20 @@ virDomainDeviceDefParse(const char *xmlStr,
         dev->type = VIR_DOMAIN_DEVICE_RNG;
         if (!(dev->data.rng = virDomainRNGDefParseXML(node, ctxt, flags)))
             goto error;
+    } else if (xmlStrEqual(node->name, BAD_CAST "channel") ||
+               xmlStrEqual(node->name, BAD_CAST "console") ||
+               xmlStrEqual(node->name, BAD_CAST "parallel") ||
+               xmlStrEqual(node->name, BAD_CAST "serial")) {
+        dev->type = VIR_DOMAIN_DEVICE_CHR;
+        /* In case of serial chardev we want to parse <source> as it is the only
+         * thing distinguishing two serial chardevs */
+        flags &= ~VIR_DOMAIN_XML_INACTIVE;
+        if (!(dev->data.chr = virDomainChrDefParseXML(ctxt,
+                                                      node,
+                                                      def->seclabels,
+                                                      def->nseclabels,
+                                                      flags)))
+            goto error;
     } else {
         virReportError(VIR_ERR_XML_ERROR, "%s", _("unknown device type"));
         goto error;
@@ -17823,9 +17839,11 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
     case VIR_DOMAIN_DEVICE_RNG:
         rc = virDomainRNGDefFormat(&buf, src->data.rng, flags);
         break;
+    case VIR_DOMAIN_DEVICE_CHR:
+        rc = virDomainChrDefFormat(&buf, src->data.chr, flags);
+        break;
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_SMARTCARD:
-    case VIR_DOMAIN_DEVICE_CHR:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
     case VIR_DOMAIN_DEVICE_NVRAM:
     case VIR_DOMAIN_DEVICE_LAST:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index db56823..9ce186e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6110,6 +6110,7 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
     virDomainHostdevDefPtr hostdev;
     virDomainLeaseDefPtr lease;
     virDomainControllerDefPtr controller;
+    virDomainChrDefPtr chr;
 
     switch (dev->type) {
     case VIR_DOMAIN_DEVICE_DISK:
@@ -6191,10 +6192,23 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
             return -1;
         break;
 
+    case VIR_DOMAIN_DEVICE_CHR:
+        chr = dev->data.chr;
+        if (virDomainChrFind(vmdef, chr)) {
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                           _("chardev already exists"));
+            return -1;
+        }
+
+        if (virDomainChrInsert(vmdef, chr) < 0)
+            return -1;
+        dev->data.chr = NULL;
+        break;
+
     default:
-         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                        _("persistent attach of device is not supported"));
-         return -1;
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("persistent attach of device is not supported"));
+        return -1;
     }
     return 0;
 }
@@ -6209,6 +6223,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
     virDomainHostdevDefPtr hostdev, det_hostdev;
     virDomainLeaseDefPtr lease, det_lease;
     virDomainControllerDefPtr cont, det_cont;
+    virDomainChrDefPtr chr;
     int idx;
     char mac[VIR_MAC_STRING_BUFLEN];
 
@@ -6276,6 +6291,18 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
 
         break;
 
+    case VIR_DOMAIN_DEVICE_CHR:
+        chr = dev->data.chr;
+        if (virDomainChrRemove(vmdef, chr) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("device not present in domain configuration"));
+            return -1;
+        }
+
+        virDomainChrDefFree(chr);
+        dev->data.chr = NULL;
+        break;
+
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("persistent detach of device is not supported"));
-- 
1.8.2.1

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