On Wed, Jul 10, 2013 at 07:02:58PM +0200, Michal Privoznik wrote:
Since previous patches has prepared everything for us, we may now
implement live hotplug of a character device.
---
src/qemu/qemu_command.c | 38 ++++++++++++++++-
src/qemu/qemu_driver.c | 26 ++++++++++--
src/qemu/qemu_hotplug.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_hotplug.h | 6 +++
4 files changed, 173 insertions(+), 5 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 063d76b..6842cab 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -863,8 +863,41 @@ qemuAssignDeviceControllerAlias(virDomainControllerDefPtr
controller)
return virAsprintf(&controller->info.alias, "%s%d", prefix,
controller->idx);
}
+static ssize_t
+qemuGetNextChrDevIndex(virDomainDefPtr def,
+ virDomainChrDefPtr chr,
+ const char *prefix)
+{
+ virDomainChrDefPtr **arrPtr;
+ size_t *cntPtr;
+ size_t i;
+ ssize_t idx = 0;
+ const char *prefix2 = NULL;
+
+ if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE)
+ prefix2 = "serial";
+
+ virDomainChrGetDomainPtrs(def, chr, &arrPtr, &cntPtr);
+
+ for (i = 0; i < *cntPtr; i++) {
+ ssize_t thisidx;
+ if (((thisidx = qemuDomainDeviceAliasIndex(&(*arrPtr)[i]->info, prefix))
< 0) &&
+ (prefix2 &&
+ (thisidx = qemuDomainDeviceAliasIndex(&(*arrPtr)[i]->info, prefix2))
< 0)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Unable to determine device index for character
device"));
+ return -1;
+ }
+ if (thisidx >= idx)
+ idx = thisidx + 1;
+ }
+
+ return idx;
+}
+
+
int
-qemuAssignDeviceChrAlias(virDomainDefPtr def ATTRIBUTE_UNUSED,
+qemuAssignDeviceChrAlias(virDomainDefPtr def,
virDomainChrDefPtr chr,
ssize_t idx)
{
@@ -891,6 +924,9 @@ qemuAssignDeviceChrAlias(virDomainDefPtr def ATTRIBUTE_UNUSED,
return -1;
}
+ if (idx == -1 && (idx = qemuGetNextChrDevIndex(def, chr, prefix)) < 0)
+ return -1;
+
return virAsprintf(&chr->info.alias, "%s%zd", prefix, idx);
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d858131..486de4e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6387,6 +6387,13 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
dev->data.redirdev = NULL;
break;
+ case VIR_DOMAIN_DEVICE_CHR:
+ ret = qemuDomainAttachChrDevice(driver, vm,
+ dev->data.chr);
+ if (!ret)
+ dev->data.chr = NULL;
+ break;
+
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("device type '%s' cannot be attached"),
@@ -6474,6 +6481,9 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_HOSTDEV:
ret = qemuDomainDetachHostDevice(driver, vm, dev);
break;
+ case VIR_DOMAIN_DEVICE_CHR:
+ ret = qemuDomainDetachChrDevice(driver, vm, dev->data.chr);
+ break;
As with the cold-plug code, I'm not sure this is handling of the
case of adding/removing the first serial device, where you need
to update the corresponding console device in virDomainDefPtr.
Also we ought to probably forbid hotplug/unplug of a console
device with type=serial, and require they change the actual
serial device directly.
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|