[libvirt] [PATCH 01/11] Added public API for post-copy migration

Cristian Klein cristiklein at gmail.com
Mon Dec 1 15:59:53 UTC 2014


Signed-off-by: Cristian Klein <cristiklein at gmail.com>
---
 include/libvirt/libvirt-domain.h |  5 +++
 src/driver-hypervisor.h          |  5 +++
 src/libvirt-domain.c             | 92 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  1 +
 src/remote/remote_driver.c       |  1 +
 src/remote/remote_protocol.x     | 12 +++++-
 src/remote_protocol-structs      |  5 +++
 7 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index ae2c49c..090d97a 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -634,6 +634,8 @@ typedef enum {
     VIR_MIGRATE_ABORT_ON_ERROR    = (1 << 12), /* abort migration on I/O errors happened during migration */
     VIR_MIGRATE_AUTO_CONVERGE     = (1 << 13), /* force convergence */
     VIR_MIGRATE_RDMA_PIN_ALL      = (1 << 14), /* RDMA memory pinning */
+    VIR_MIGRATE_ENABLE_POSTCOPY   = (1 << 15), /* enable (but do not start) post-copy */
+    VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY = (1 << 16), /* start post-copy after the first pass of pre-copy */
 } virDomainMigrateFlags;
 
 
@@ -773,6 +775,9 @@ int virDomainMigrateGetMaxSpeed(virDomainPtr domain,
                                 unsigned long *bandwidth,
                                 unsigned int flags);
 
+int virDomainMigrateStartPostCopy (virDomainPtr domain,
+                                   unsigned int flags);
+
 char * virConnectGetDomainCapabilities(virConnectPtr conn,
                                        const char *emulatorbin,
                                        const char *arch,
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 9f26b13..a642dea 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -613,6 +613,10 @@ typedef int
                                     const char *dom_xml);
 
 typedef int
+(*virDrvDomainMigrateStartPostCopy)(virDomainPtr domain,
+                                    unsigned int flags);
+
+typedef int
 (*virDrvConnectIsEncrypted)(virConnectPtr conn);
 
 typedef int
@@ -1396,6 +1400,7 @@ struct _virHypervisorDriver {
     virDrvConnectGetAllDomainStats connectGetAllDomainStats;
     virDrvNodeAllocPages nodeAllocPages;
     virDrvDomainGetFSInfo domainGetFSInfo;
+    virDrvDomainMigrateStartPostCopy domainMigrateStartPostCopy;
 };
 
 
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 2b0defc..f29af21 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -3500,6 +3500,9 @@ virDomainMigrateDirect(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_ENABLE_POSTCOPY Enable (but do not start) post-copy
+ *   VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY Start post-copy after the first pass
+ *                                      of pre-copy
  *
  * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
  * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
@@ -3536,6 +3539,17 @@ virDomainMigrateDirect(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * If you want to do post-copy migration, you have two choices:
+ * either use the low-level mechanism provided by libvirt, or its
+ * default policy. To use the low-level mechanism, you must first enable
+ * post-copy migration using the VIR_MIGRATE_ENABLE_POSTCOPY flag. Once
+ * migration is active, from a separate thread, you may start post-copy
+ * by calling virDomainMigrateStartPostCopy.
+ *
+ * The default post-copy policy implemented in libvirt is to start
+ * post-copy after the first pass of pre-copy. To enable this behaviour
+ * start migration with the VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY flag.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -3716,6 +3730,8 @@ virDomainMigrate(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_ENABLE_POSTCOPY Enable (but do not start) post-copy
+ *   VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY Start post-copy after the first pass of pre-copy
  *
  * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
  * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
@@ -3752,6 +3768,17 @@ virDomainMigrate(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * If you want to do post-copy migration, you have two choices:
+ * either use the low-level mechanism provided by libvirt, or its
+ * default policy. To use the low-level mechanism, you must first enable
+ * post-copy migration using the VIR_MIGRATE_ENABLE_POSTCOPY flag. Once
+ * migration is active, from a separate thread, you may start post-copy
+ * by calling virDomainMigrateStartPostCopy.
+ *
+ * The default post-copy policy implemented in libvirt is to start
+ * post-copy after the first pass of pre-copy. To enable this behaviour
+ * start migration with the VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY flag.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -4147,6 +4174,8 @@ virDomainMigrate3(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_ENABLE_POSTCOPY Enable (but do not start) post-copy
+ *   VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY Start post-copy after the first pass of pre-copy
  *
  * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
  * If the VIR_MIGRATE_PEER2PEER flag is NOT set, the duri parameter
@@ -4179,6 +4208,17 @@ virDomainMigrate3(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * If you want to do post-copy migration, you have two choices:
+ * either use the low-level mechanism provided by libvirt, or its
+ * default policy. To use the low-level mechanism, you must first enable
+ * post-copy migration using the VIR_MIGRATE_ENABLE_POSTCOPY flag. Once
+ * migration is active, from a separate thread, you may start post-copy
+ * by calling virDomainMigrateStartPostCopy.
+ *
+ * The default post-copy policy implemented in libvirt is to start
+ * post-copy after the first pass of pre-copy. To enable this behaviour
+ * start migration with the VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY flag.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -4292,6 +4332,8 @@ virDomainMigrateToURI(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_ENABLE_POSTCOPY Enable (but do not start) post-copy
+ *   VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY Start post-copy after the first pass of pre-copy
  *
  * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
  *
@@ -4334,6 +4376,17 @@ virDomainMigrateToURI(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * If you want to do post-copy migration, you have two choices:
+ * either use the low-level mechanism provided by libvirt, or its
+ * default policy. To use the low-level mechanism, you must first enable
+ * post-copy migration using the VIR_MIGRATE_ENABLE_POSTCOPY flag. Once
+ * migration is active, from a separate thread, you may start post-copy
+ * by calling virDomainMigrateStartPostCopy.
+ *
+ * The default post-copy policy implemented in libvirt is to start
+ * post-copy after the first pass of pre-copy. To enable this behaviour
+ * start migration with the VIR_MIGRATE_POSTCOPY_AFTER_PRECOPY flag.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -8932,6 +8985,45 @@ virDomainMigrateGetMaxSpeed(virDomainPtr domain,
 
 
 /**
+ * virDomainMigrateStartPostCopy:
+ * @domain: a domain object
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Starts post-copy migration. This function has to be called while
+ * migration (initially pre-copy) is in progress. The migration operation
+ * must be called with the VIR_MIGRATE_ENABLE_POSTCOPY flag.
+ *
+ * Returns 0 in case of success, -1 otherwise.
+ */
+int
+virDomainMigrateStartPostCopy(virDomainPtr domain,
+                              unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
+
+    if (conn->driver->domainMigrateStartPostCopy) {
+        if (conn->driver->domainMigrateStartPostCopy(domain, flags) < 0)
+            goto error;
+        return 0;
+    }
+
+    virReportUnsupportedError();
+ error:
+    virDispatchError(conn);
+    return -1;
+}
+
+
+/**
  * virConnectDomainEventRegisterAny:
  * @conn: pointer to the connection
  * @dom: pointer to the domain
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index e4c2df1..790f2f3 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -688,6 +688,7 @@ LIBVIRT_1.2.11 {
     global:
         virDomainFSInfoFree;
         virDomainGetFSInfo;
+        virDomainMigrateStartPostCopy;
 } LIBVIRT_1.2.9;
 
 # .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 22f0c88..001010f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8295,6 +8295,7 @@ static virHypervisorDriver hypervisor_driver = {
     .connectGetAllDomainStats = remoteConnectGetAllDomainStats, /* 1.2.8 */
     .nodeAllocPages = remoteNodeAllocPages, /* 1.2.9 */
     .domainGetFSInfo = remoteDomainGetFSInfo, /* 1.2.11 */
+    .domainMigrateStartPostCopy = remoteDomainMigrateStartPostCopy, /* 1.2.11 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index cbd3ec7..4b13a8e 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -3143,6 +3143,10 @@ struct remote_domain_get_fsinfo_ret {
     unsigned int ret;
 };
 
+struct remote_domain_migrate_start_post_copy_args {
+    remote_nonnull_domain dom;
+    unsigned int flags;
+};
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -5550,5 +5554,11 @@ enum remote_procedure {
      * @generate: none
      * @acl: domain:fs_freeze
      */
-    REMOTE_PROC_DOMAIN_GET_FSINFO = 349
+    REMOTE_PROC_DOMAIN_GET_FSINFO = 349,
+
+    /**
+     * @generate: both
+     * @acl: domain:migrate
+     */
+    REMOTE_PROC_DOMAIN_MIGRATE_START_POST_COPY = 350
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 2907fd5..c23d7c7 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2605,6 +2605,10 @@ struct remote_domain_get_fsinfo_ret {
         } info;
         u_int                      ret;
 };
+struct remote_domain_migrate_start_post_copy_args {
+        remote_nonnull_domain      dom;
+        u_int                      flags;
+};
 enum remote_procedure {
         REMOTE_PROC_CONNECT_OPEN = 1,
         REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -2955,4 +2959,5 @@ enum remote_procedure {
         REMOTE_PROC_NODE_ALLOC_PAGES = 347,
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_AGENT_LIFECYCLE = 348,
         REMOTE_PROC_DOMAIN_GET_FSINFO = 349,
+        REMOTE_PROC_DOMAIN_MIGRATE_START_POST_COPY = 350,
 };
-- 
1.9.1




More information about the libvir-list mailing list