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 exactly what this
patch 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 | 19 +++++++++++++++++--
src/qemu/qemu_driver.c | 33 ++++++++++++++++++++++++++++++---
2 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c73ddf3..2370555 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1756,10 +1756,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:
@@ -9385,6 +9387,17 @@ 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;
+ 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;
@@ -17932,9 +17945,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 b0180c9..d858131 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6607,6 +6607,7 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
virDomainHostdevDefPtr hostdev;
virDomainLeaseDefPtr lease;
virDomainControllerDefPtr controller;
+ virDomainChrDefPtr chr;
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
@@ -6682,10 +6683,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;
}
@@ -6700,6 +6714,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];
@@ -6767,6 +6782,18 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
break;
+ case VIR_DOMAIN_DEVICE_CHR:
+ if (!(chr = virDomainChrRemove(vmdef, dev->data.chr))) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("device not present in domain configuration"));
+ return -1;
+ }
+
+ virDomainChrDefFree(chr);
+ virDomainChrDefFree(dev->data.chr);
+ dev->data.chr = NULL;
+ break;
+
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("persistent detach of device is not supported"));
--
1.8.1.5