[PATCH 4/8] qemu: a code movement

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

 



Move implementation of qemuDomainAttachDeviceDiskLive after
qemuDomainDetachDiskDevice for later usage.

Signed-off-by: Wang Rui <moon.wangrui@xxxxxxxxxx>
Signed-off-by: Zhou Yimin <zhouyimin@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 173 ++++++++++++++++++++++++------------------------
 1 file changed, 86 insertions(+), 87 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 919a061..2f84949 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -729,93 +729,6 @@ qemuDomainAttachUSBMassstorageDevice(virConnectPtr conn,
 }
 
 
-int
-qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
-                               virQEMUDriverPtr driver,
-                               virDomainObjPtr vm,
-                               virDomainDeviceDefPtr dev)
-{
-    virDomainDiskDefPtr disk = dev->data.disk;
-    virDomainDiskDefPtr orig_disk = NULL;
-    int ret = -1;
-    const char *driverName = virDomainDiskGetDriver(disk);
-    const char *src = virDomainDiskGetSource(disk);
-
-    if (driverName && !STREQ(driverName, "qemu")) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unsupported driver name '%s' for disk '%s'"),
-                       driverName, src);
-        goto end;
-    }
-
-    if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
-        goto end;
-
-    if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
-        goto end;
-
-    if (qemuSetUnprivSGIO(dev) < 0)
-        goto end;
-
-    if (qemuDomainDetermineDiskChain(driver, vm, disk, false, true) < 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'. "
-                             "cdrom and floppy device hotplug isn't supported "
-                             "by libvirt"),
-                           virDomainDiskBusTypeToString(disk->bus),
-                           disk->dst);
-            goto end;
-        }
-
-        if (qemuDomainChangeEjectableMedia(driver, conn, vm, orig_disk,
-                                           disk->src, false) < 0)
-            goto end;
-
-        disk->src = NULL;
-        ret = 0;
-        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;
-    }
-
- end:
-    if (ret != 0)
-        ignore_value(qemuRemoveSharedDevice(driver, dev, vm->def->name));
-    return ret;
-}
-
-
 /* XXX conn required for network -> bridge resolution */
 int qemuDomainAttachNetDevice(virConnectPtr conn,
                               virQEMUDriverPtr driver,
@@ -3078,6 +2991,92 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver,
     return ret;
 }
 
+int
+qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
+                               virQEMUDriverPtr driver,
+                               virDomainObjPtr vm,
+                               virDomainDeviceDefPtr dev)
+{
+    virDomainDiskDefPtr disk = dev->data.disk;
+    virDomainDiskDefPtr orig_disk = NULL;
+    int ret = -1;
+    const char *driverName = virDomainDiskGetDriver(disk);
+    const char *src = virDomainDiskGetSource(disk);
+
+    if (driverName && !STREQ(driverName, "qemu")) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unsupported driver name '%s' for disk '%s'"),
+                       driverName, src);
+        goto end;
+    }
+
+    if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
+        goto end;
+
+    if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
+        goto end;
+
+    if (qemuSetUnprivSGIO(dev) < 0)
+        goto end;
+
+    if (qemuDomainDetermineDiskChain(driver, vm, disk, false, true) < 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'. "
+                             "cdrom and floppy device hotplug isn't supported "
+                             "by libvirt"),
+                           virDomainDiskBusTypeToString(disk->bus),
+                           disk->dst);
+            goto end;
+        }
+
+        if (qemuDomainChangeEjectableMedia(driver, conn, vm, orig_disk,
+                                           disk->src, false) < 0)
+            goto end;
+
+        disk->src = NULL;
+        ret = 0;
+        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;
+    }
+
+ end:
+    if (ret != 0)
+        ignore_value(qemuRemoveSharedDevice(driver, dev, vm->def->name));
+    return ret;
+}
+
 static int
 qemuFindDisk(virDomainDefPtr def, const char *dst)
 {
-- 
1.7.12.4


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