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 63f4daf..dcf4740 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1760,10 +1760,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:
@@ -9040,6 +9042,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;
@@ -17354,9 +17370,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 d5d7de3..1900c4a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6027,6 +6027,7 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
     virDomainHostdevDefPtr hostdev;
     virDomainLeaseDefPtr lease;
     virDomainControllerDefPtr controller;
+    virDomainChrDefPtr chr;
 
     switch (dev->type) {
     case VIR_DOMAIN_DEVICE_DISK:
@@ -6108,10 +6109,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;
 }
@@ -6126,6 +6140,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];
 
@@ -6193,6 +6208,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.1.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to