[libvirt] [PATCH v2 17/39] qemuMigrationSrcIsSafe: Rework slightly

Michal Privoznik posted 39 patches 6 years, 4 months ago
There is a newer version of this series
[libvirt] [PATCH v2 17/39] qemuMigrationSrcIsSafe: Rework slightly
Posted by Michal Privoznik 6 years, 4 months ago
There are going to be more disk types that are considered unsafe
with respect to migration. Therefore, move the error reporting
call outside of if() body and rework if-else combo to switch().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_migration.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index a98ec2d55a..693240ed3d 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1239,6 +1239,8 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def,
     for (i = 0; i < def->ndisks; i++) {
         virDomainDiskDefPtr disk = def->disks[i];
         const char *src = virDomainDiskGetSource(disk);
+        int actualType = virStorageSourceGetActualType(disk->src);
+        bool unsafe = false;
 
         /* Disks without any source (i.e. floppies and CD-ROMs)
          * OR readonly are safe. */
@@ -1252,21 +1254,34 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def,
             continue;
 
         /* However, disks on local FS (e.g. ext4) are not safe. */
-        if (virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_FILE) {
+        switch ((virStorageType) actualType) {
+        case VIR_STORAGE_TYPE_FILE:
             if ((rc = virFileIsSharedFS(src)) < 0) {
                 return false;
             } else if (rc == 0) {
-                virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s",
-                               _("Migration without shared storage is unsafe"));
-                return false;
+                unsafe = true;
             }
             if ((rc = virStorageFileIsClusterFS(src)) < 0)
                 return false;
             else if (rc == 1)
                 continue;
-        } else if (virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_NETWORK) {
+            break;
+        case VIR_STORAGE_TYPE_NETWORK:
             /* But network disks are safe again. */
             continue;
+
+        case VIR_STORAGE_TYPE_NONE:
+        case VIR_STORAGE_TYPE_BLOCK:
+        case VIR_STORAGE_TYPE_DIR:
+        case VIR_STORAGE_TYPE_VOLUME:
+        case VIR_STORAGE_TYPE_LAST:
+            break;
+        }
+
+        if (unsafe) {
+            virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s",
+                           _("Migration without shared storage is unsafe"));
+            return false;
         }
 
         /* Our code elsewhere guarantees shared disks are either readonly (in
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list