File libvirt-qemu-Make-qemuMigrationIsAllowed-more-reusable.patch of Package libvirt

From b1eab9954b06955ed9dd13d1bfaa89462ecf2bf6 Mon Sep 17 00:00:00 2001
Message-Id: <b1eab9954b06955ed9dd13d1bfaa89462ecf2bf6.1373885147.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 4 Jul 2013 11:50:20 +0200
Subject: [PATCH] qemu: Make qemuMigrationIsAllowed more reusable

https://bugzilla.redhat.com/show_bug.cgi?id=972675

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.
(cherry picked from commit e5d3ab5e218b4e7a19a59ec1f250dbff315cce5a)

Conflicts:
	src/qemu/qemu_migration.c - qemu driver structure renamed
---
 src/qemu/qemu_migration.c | 35 +++++++++++++++++++++--------------
 src/qemu/qemu_migration.h |  2 ++
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index e8a2623..e0a4743 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -801,9 +801,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(struct qemud_driver *driver, virDomainObjPtr vm,
-                       virDomainDefPtr def)
+                       virDomainDefPtr def, bool remote)
 {
     int nsnapshots;
     bool forbid;
@@ -815,16 +815,24 @@ qemuMigrationIsAllowed(struct qemud_driver *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;
         }
 
@@ -845,8 +853,7 @@ qemuMigrationIsAllowed(struct qemud_driver *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;
     }
 
@@ -1213,7 +1220,7 @@ char *qemuMigrationBegin(struct qemud_driver *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))
@@ -1308,7 +1315,7 @@ qemuMigrationPrepareAny(struct qemud_driver *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. */
@@ -2765,7 +2772,7 @@ qemuMigrationPerformJob(struct qemud_driver *driver,
         goto endjob;
     }
 
-    if (!qemuMigrationIsAllowed(driver, vm, NULL))
+    if (!qemuMigrationIsAllowed(driver, vm, NULL, true))
         goto endjob;
 
     if (!(flags & VIR_MIGRATE_UNSAFE) && !qemuMigrationIsSafe(vm->def))
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 7a2269a..2390e04 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -144,6 +144,8 @@ int qemuMigrationConfirm(struct qemud_driver *driver,
                          unsigned int flags,
                          int retcode);
 
+bool qemuMigrationIsAllowed(struct qemud_driver *driver, virDomainObjPtr vm,
+                            virDomainDefPtr def, bool remote);
 
 int qemuMigrationToFile(struct qemud_driver *driver, virDomainObjPtr vm,
                         int fd, off_t offset, const char *path,
-- 
1.8.3.2

openSUSE Build Service is sponsored by