]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Make qemuMigrationIsAllowed more reusable
authorPeter Krempa <pkrempa@redhat.com>
Fri, 7 Dec 2012 10:59:24 +0000 (11:59 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 11 Dec 2012 18:48:37 +0000 (19:48 +0100)
This patch exports qemuMigrationIsAllowed and adds a new parameter to it
to denote if it's a remote migration or a local migration. Local
migrations are used in snapshots and saving of the machine state and
have fewer restrictions. This patch also adjusts callers of the function
and tweaks some error messages to be more universal.

src/qemu/qemu_migration.c
src/qemu/qemu_migration.h

index 8796eb651001f9588a099235396eb289677a0dc8..5dcbb07954051c574a34abf45dfed5cefffcd262 100644 (file)
@@ -1011,9 +1011,9 @@ error:
  * assume that checking on source is sufficient to prevent ever
  * talking to the destination in the first place, we are stuck with
  * the fact that older servers did not do checks on the source. */
-static bool
+bool
 qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
-                       virDomainDefPtr def)
+                       virDomainDefPtr def, bool remote)
 {
     int nsnapshots;
     bool forbid;
@@ -1025,16 +1025,24 @@ qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
                            "%s", _("domain is marked for auto destroy"));
             return false;
         }
-        if ((nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL,
-                                                      0))) {
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("cannot migrate domain with %d snapshots"),
-                           nsnapshots);
-            return false;
+
+        /* perform these checks only when migrating to remote hosts */
+        if (remote) {
+            nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0);
+            if (nsnapshots < 0)
+                return false;
+
+            if (nsnapshots > 0) {
+                virReportError(VIR_ERR_OPERATION_INVALID,
+                               _("cannot migrate domain with %d snapshots"),
+                               nsnapshots);
+                return false;
+            }
         }
+
         if (virDomainHasDiskMirror(vm)) {
             virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("cannot migrate domain with active block job"));
+                           _("domain has an active block job"));
             return false;
         }
 
@@ -1055,8 +1063,7 @@ qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
     }
     if (forbid) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("Domain with assigned non-USB host devices "
-                         "cannot be migrated"));
+                       _("domain has assigned non-USB host devices"));
         return false;
     }
 
@@ -1428,7 +1435,7 @@ char *qemuMigrationBegin(virQEMUDriverPtr driver,
     if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT)
         qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_BEGIN3);
 
-    if (!qemuMigrationIsAllowed(driver, vm, NULL))
+    if (!qemuMigrationIsAllowed(driver, vm, NULL, true))
         goto cleanup;
 
     if (!(flags & VIR_MIGRATE_UNSAFE) && !qemuMigrationIsSafe(vm->def))
@@ -1567,7 +1574,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
-    if (!qemuMigrationIsAllowed(driver, NULL, def))
+    if (!qemuMigrationIsAllowed(driver, NULL, def, true))
         goto cleanup;
 
     /* Target domain name, maybe renamed. */
@@ -3005,7 +3012,7 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
         goto endjob;
     }
 
-    if (!qemuMigrationIsAllowed(driver, vm, NULL))
+    if (!qemuMigrationIsAllowed(driver, vm, NULL, true))
         goto endjob;
 
     if (!(flags & VIR_MIGRATE_UNSAFE) && !qemuMigrationIsSafe(vm->def))
index eb30f06b2e6a3f80cebc79dd2018bd20d1ab4d58..1729d73614505ac1a3395977c5464dd1d10e5b4c 100644 (file)
@@ -147,6 +147,8 @@ int qemuMigrationConfirm(virQEMUDriverPtr driver,
                          unsigned int flags,
                          int retcode);
 
+bool qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
+                            virDomainDefPtr def, bool remote);
 
 int qemuMigrationToFile(virQEMUDriverPtr driver, virDomainObjPtr vm,
                         int fd, off_t offset, const char *path,