render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From e32ede7d892db2b5903039e43bed2d490120625a Mon Sep 17 00:00:00 2001
Message-Id: <e32ede7d892db2b5903039e43bed2d490120625a.1377873637.git.jdenemar@redhat.com>
From: Guannan Ren <gren@redhat.com>
Date: Thu, 8 Aug 2013 16:07:26 +0800
Subject: [PATCH] qemu: refactor qemuDomainCheckDiskPresence for only disk
 presence check

Resovles:https://bugzilla.redhat.com/show_bug.cgi?id=910171
(cherry picked from commit e2ccc96cf0ea53aa6198efdfba79996c360567d7)

Refactor this function to make it focus on disk presence checking,
including diskchain checking, and not only for CDROM and Floppy.
This change is good for the following patches.
---
 src/qemu/qemu_domain.c | 98 +++++++++++++++++++++++++++++---------------------
 1 file changed, 58 insertions(+), 40 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index dc72722..13303da 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2067,6 +2067,61 @@ cleanup:
     virObjectUnref(cfg);
 }
 
+static int
+qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
+                                 virDomainObjPtr vm,
+                                 virDomainDiskDefPtr disk,
+                                 bool cold_boot)
+{
+    char uuid[VIR_UUID_STRING_BUFLEN];
+    virDomainEventPtr event = NULL;
+    int startupPolicy = disk->startupPolicy;
+
+    virUUIDFormat(vm->def->uuid, uuid);
+
+    switch ((enum virDomainStartupPolicy) startupPolicy) {
+        case VIR_DOMAIN_STARTUP_POLICY_OPTIONAL:
+            break;
+
+        case VIR_DOMAIN_STARTUP_POLICY_MANDATORY:
+            virReportSystemError(errno,
+                                 _("cannot access file '%s'"),
+                                 disk->src);
+            goto error;
+            break;
+
+        case VIR_DOMAIN_STARTUP_POLICY_REQUISITE:
+            if (cold_boot) {
+                virReportSystemError(errno,
+                                     _("cannot access file '%s'"),
+                                     disk->src);
+                goto error;
+            }
+            break;
+
+        case VIR_DOMAIN_STARTUP_POLICY_DEFAULT:
+        case VIR_DOMAIN_STARTUP_POLICY_LAST:
+            /* this should never happen */
+            break;
+    }
+
+    VIR_DEBUG("Dropping disk '%s' on domain '%s' (UUID '%s') "
+              "due to inaccessible source '%s'",
+              disk->dst, vm->def->name, uuid, disk->src);
+
+    event = virDomainEventDiskChangeNewFromObj(vm, disk->src, NULL, disk->info.alias,
+                                               VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START);
+    if (event)
+        qemuDomainEventQueue(driver, event);
+
+    VIR_FREE(disk->src);
+
+    return 0;
+
+error:
+    return -1;
+}
+
 int
 qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
                             virDomainObjPtr vm,
@@ -2075,12 +2130,8 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
     int ret = -1;
     size_t i;
     virDomainDiskDefPtr disk;
-    char uuid[VIR_UUID_STRING_BUFLEN];
-    virDomainEventPtr event = NULL;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 
-    virUUIDFormat(vm->def->uuid, uuid);
-
     for (i = 0; i < vm->def->ndisks; i++) {
         disk = vm->def->disks[i];
 
@@ -2094,42 +2145,9 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
             continue;
         }
 
-        switch ((enum virDomainStartupPolicy) disk->startupPolicy) {
-            case VIR_DOMAIN_STARTUP_POLICY_OPTIONAL:
-                break;
-
-            case VIR_DOMAIN_STARTUP_POLICY_MANDATORY:
-                virReportSystemError(errno,
-                                     _("cannot access file '%s'"),
-                                     disk->src);
-                goto cleanup;
-                break;
-
-            case VIR_DOMAIN_STARTUP_POLICY_REQUISITE:
-                if (cold_boot) {
-                    virReportSystemError(errno,
-                                         _("cannot access file '%s'"),
-                                         disk->src);
-                    goto cleanup;
-                }
-                break;
-
-            case VIR_DOMAIN_STARTUP_POLICY_DEFAULT:
-            case VIR_DOMAIN_STARTUP_POLICY_LAST:
-                /* this should never happen */
-                break;
-        }
-
-        VIR_DEBUG("Dropping disk '%s' on domain '%s' (UUID '%s') "
-                  "due to inaccessible source '%s'",
-                  disk->dst, vm->def->name, uuid, disk->src);
-
-        event = virDomainEventDiskChangeNewFromObj(vm, disk->src, NULL, disk->info.alias,
-                                                   VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START);
-        if (event)
-            qemuDomainEventQueue(driver, event);
-
-        VIR_FREE(disk->src);
+        if (qemuDomainCheckDiskStartupPolicy(driver, vm, disk,
+                                             cold_boot) < 0)
+            goto cleanup;
     }
 
     ret = 0;
-- 
1.8.3.2