]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemuDomainChangeDiskLive: rework slightly
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 15 Sep 2015 12:37:21 +0000 (14:37 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Sep 2015 13:51:18 +0000 (15:51 +0200)
Firstly, our coding guidelines suggest using 'cleanup' label
instead of 'end'. Then, @ret should be set to value representing
success as the last statement before the 'cleanup' label.
And while I am at this function, lets enumerate all the possible
enum items (virDomainDiskDevice) and avoid using 'default' in
switch(). Pooh. Also, nothing bad happens if we look up the disk
to change in the domain upfront. In fact, it's going to be
helpful later when we want to keep some old values for performing
a rollback.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_driver.c

index 7e15af013320fa6bf26627e78c8e84b5f7f8ad7c..4debaa46d77a73c56b9fe1ff7d8f415551060235 100644 (file)
@@ -7907,48 +7907,54 @@ qemuDomainChangeDiskLive(virConnectPtr conn,
     int ret = -1;
 
     if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
-        goto end;
+        goto cleanup;
 
     if (qemuDomainDetermineDiskChain(driver, vm, disk, false, true) < 0)
-        goto end;
+        goto cleanup;
 
-    switch (disk->device) {
+    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 cleanup;
+    }
+
+    switch ((virDomainDiskDevice) 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 (!virDomainDiskDiffersSourceOnly(disk, orig_disk))
-            goto end;
+            goto cleanup;
 
         /* Add the new disk src into shared disk hash table */
         if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
-            goto end;
+            goto cleanup;
 
         if (qemuDomainChangeEjectableMedia(driver, conn, vm,
-                                           orig_disk, dev->data.disk->src, force) < 0) {
-            ignore_value(qemuRemoveSharedDisk(driver, dev->data.disk, vm->def->name));
-            goto end;
+                                           orig_disk, disk->src, force) < 0) {
+            ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
+            goto cleanup;
         }
 
-        dev->data.disk->src = NULL;
-        ret = 0;
+        disk->src = NULL;
         break;
 
-    default:
+    case VIR_DOMAIN_DISK_DEVICE_DISK:
+    case VIR_DOMAIN_DISK_DEVICE_LUN:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("disk bus '%s' cannot be updated."),
                        virDomainDiskBusTypeToString(disk->bus));
+        goto cleanup;
+        break;
+
+    case VIR_DOMAIN_DISK_DEVICE_LAST:
+        /* nada */
         break;
     }
 
- end:
+    ret = 0;
+ cleanup:
     return ret;
 }