---
src/qemu/qemu_driver.c | 114 --------------------------------------
src/qemu/qemu_hotplug.c | 142 ++++++++++++++++++++++++++++++++++++++++++++----
src/qemu/qemu_hotplug.h | 16 ++----
3 files changed, 134 insertions(+), 138 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2daafa8..c926fba 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6270,120 +6270,6 @@ qemuDomainUndefine(virDomainPtr dom)
}
static int
-qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDeviceDefPtr dev)
-{
- virDomainDiskDefPtr disk = dev->data.disk;
- virDomainDiskDefPtr orig_disk = NULL;
- virDomainDeviceDefPtr dev_copy = NULL;
- virDomainDiskDefPtr tmp = NULL;
- virCgroupPtr cgroup = NULL;
- virCapsPtr caps = NULL;
- int ret = -1;
-
- if (disk->driverName != NULL && !STREQ(disk->driverName,
"qemu")) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unsupported driver name '%s' for disk
'%s'"),
- disk->driverName, disk->src);
- goto end;
- }
-
- if (qemuTranslateDiskSourcePool(conn, disk) < 0)
- goto end;
-
- if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
- goto end;
-
- if (qemuSetUnprivSGIO(dev) < 0)
- goto end;
-
- if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
- goto end;
-
- if (qemuSetupDiskCgroup(vm, disk) < 0)
- goto end;
-
- switch (disk->device) {
- case VIR_DOMAIN_DISK_DEVICE_CDROM:
- case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
- if (!(orig_disk = virDomainDiskFindByBusAndDst(vm->def,
- disk->bus, disk->dst))) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("No device with bus '%s' and target
'%s'"),
- virDomainDiskBusTypeToString(disk->bus),
- disk->dst);
- goto end;
- }
-
- if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
- goto end;
-
- tmp = dev->data.disk;
- dev->data.disk = orig_disk;
-
- if (!(dev_copy = virDomainDeviceDefCopy(dev, vm->def,
- caps, driver->xmlopt))) {
- dev->data.disk = tmp;
- goto end;
- }
- dev->data.disk = tmp;
-
- ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, false);
- /* 'disk' must not be accessed now - it has been free'd.
- * 'orig_disk' now points to the new disk, while 'dev_copy'
- * now points to the old disk */
-
- /* Need to remove the shared disk entry for the original disk src
- * if the operation is either ejecting or updating.
- */
- if (ret == 0)
- ignore_value(qemuRemoveSharedDevice(driver, dev_copy,
- vm->def->name));
- break;
- case VIR_DOMAIN_DISK_DEVICE_DISK:
- case VIR_DOMAIN_DISK_DEVICE_LUN:
- if (disk->bus == VIR_DOMAIN_DISK_BUS_USB) {
- if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("disk device='lun' is not supported for usb
bus"));
- break;
- }
- ret = qemuDomainAttachUsbMassstorageDevice(conn, driver, vm,
- disk);
- } else if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
- ret = qemuDomainAttachVirtioDiskDevice(conn, driver, vm, disk);
- } else if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
- ret = qemuDomainAttachSCSIDisk(conn, driver, vm, disk);
- } else {
- virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
- _("disk bus '%s' cannot be hotplugged."),
- virDomainDiskBusTypeToString(disk->bus));
- }
- break;
- default:
- virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
- _("disk device type '%s' cannot be
hotplugged"),
- virDomainDiskDeviceTypeToString(disk->device));
- break;
- }
-
- if (ret != 0 && cgroup) {
- if (qemuTeardownDiskCgroup(vm, disk) < 0)
- VIR_WARN("Failed to teardown cgroup for disk path %s",
- NULLSTR(disk->src));
- }
-
-end:
- if (ret != 0)
- ignore_value(qemuRemoveSharedDevice(driver, dev, vm->def->name));
- virObjectUnref(caps);
- virDomainDeviceDefFree(dev_copy);
- return ret;
-}
-
-static int
qemuDomainAttachDeviceControllerLive(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDeviceDefPtr dev)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 032de69..0f5622d 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -217,10 +217,11 @@ cleanup:
return ret;
}
-int qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDiskDefPtr disk)
+static int
+qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
+ virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDiskDefPtr disk)
{
size_t i;
int ret = -1;
@@ -450,10 +451,11 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver,
}
-int qemuDomainAttachSCSIDisk(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDiskDefPtr disk)
+static int
+qemuDomainAttachSCSIDisk(virConnectPtr conn,
+ virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDiskDefPtr disk)
{
size_t i;
qemuDomainObjPrivatePtr priv = vm->privateData;
@@ -573,10 +575,11 @@ error:
}
-int qemuDomainAttachUsbMassstorageDevice(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDiskDefPtr disk)
+static int
+qemuDomainAttachUsbMassstorageDevice(virConnectPtr conn,
+ virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDiskDefPtr disk)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
size_t i;
@@ -665,6 +668,121 @@ error:
}
+int
+qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
+ virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDeviceDefPtr dev)
+{
+ virDomainDiskDefPtr disk = dev->data.disk;
+ virDomainDiskDefPtr orig_disk = NULL;
+ virDomainDeviceDefPtr dev_copy = NULL;
+ virDomainDiskDefPtr tmp = NULL;
+ virCgroupPtr cgroup = NULL;
+ virCapsPtr caps = NULL;
+ int ret = -1;
+
+ if (disk->driverName != NULL && !STREQ(disk->driverName,
"qemu")) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported driver name '%s' for disk
'%s'"),
+ disk->driverName, disk->src);
+ goto end;
+ }
+
+ if (qemuTranslateDiskSourcePool(conn, disk) < 0)
+ goto end;
+
+ if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
+ goto end;
+
+ if (qemuSetUnprivSGIO(dev) < 0)
+ goto end;
+
+ if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
+ goto end;
+
+ if (qemuSetupDiskCgroup(vm, disk) < 0)
+ goto end;
+
+ switch (disk->device) {
+ case VIR_DOMAIN_DISK_DEVICE_CDROM:
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ if (!(orig_disk = virDomainDiskFindByBusAndDst(vm->def,
+ disk->bus, disk->dst))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("No device with bus '%s' and target
'%s'"),
+ virDomainDiskBusTypeToString(disk->bus),
+ disk->dst);
+ goto end;
+ }
+
+ if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+ goto end;
+
+ tmp = dev->data.disk;
+ dev->data.disk = orig_disk;
+
+ if (!(dev_copy = virDomainDeviceDefCopy(dev, vm->def,
+ caps, driver->xmlopt))) {
+ dev->data.disk = tmp;
+ goto end;
+ }
+ dev->data.disk = tmp;
+
+ ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, false);
+ /* 'disk' must not be accessed now - it has been free'd.
+ * 'orig_disk' now points to the new disk, while 'dev_copy'
+ * now points to the old disk */
+
+ /* Need to remove the shared disk entry for the original disk src
+ * if the operation is either ejecting or updating.
+ */
+ if (ret == 0)
+ ignore_value(qemuRemoveSharedDevice(driver, dev_copy,
+ vm->def->name));
+ break;
+ case VIR_DOMAIN_DISK_DEVICE_DISK:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ if (disk->bus == VIR_DOMAIN_DISK_BUS_USB) {
+ if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("disk device='lun' is not supported for usb
bus"));
+ break;
+ }
+ ret = qemuDomainAttachUsbMassstorageDevice(conn, driver, vm,
+ disk);
+ } else if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
+ ret = qemuDomainAttachVirtioDiskDevice(conn, driver, vm, disk);
+ } else if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
+ ret = qemuDomainAttachSCSIDisk(conn, driver, vm, disk);
+ } else {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("disk bus '%s' cannot be hotplugged."),
+ virDomainDiskBusTypeToString(disk->bus));
+ }
+ break;
+ default:
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("disk device type '%s' cannot be
hotplugged"),
+ virDomainDiskDeviceTypeToString(disk->device));
+ break;
+ }
+
+ if (ret != 0 && cgroup) {
+ if (qemuTeardownDiskCgroup(vm, disk) < 0)
+ VIR_WARN("Failed to teardown cgroup for disk path %s",
+ NULLSTR(disk->src));
+ }
+
+end:
+ if (ret != 0)
+ ignore_value(qemuRemoveSharedDevice(driver, dev, vm->def->name));
+ virObjectUnref(caps);
+ virDomainDeviceDefFree(dev_copy);
+ return ret;
+}
+
+
/* XXX conn required for network -> bridge resolution */
int qemuDomainAttachNetDevice(virConnectPtr conn,
virQEMUDriverPtr driver,
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 6fa1f33..80f6e4b 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -36,21 +36,13 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
int qemuDomainCheckEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm,
enum qemuDomainAsyncJob asyncJob);
-int qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDiskDefPtr disk);
int qemuDomainAttachPciControllerDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainControllerDefPtr controller);
-int qemuDomainAttachSCSIDisk(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDiskDefPtr disk);
-int qemuDomainAttachUsbMassstorageDevice(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDiskDefPtr disk);
+int qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
+ virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDeviceDefPtr dev);
int qemuDomainAttachNetDevice(virConnectPtr conn,
virQEMUDriverPtr driver,
virDomainObjPtr vm,
--
1.8.3.2