]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Introduce qemuProcessIncomingDef
authorJiri Denemark <jdenemar@redhat.com>
Fri, 6 Nov 2015 17:41:37 +0000 (18:41 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 19 Nov 2015 08:41:23 +0000 (09:41 +0100)
Incoming migration may require quite a few parameters (URI, fd, path) to
be considered while starting QEMU and we will soon add another one.
Let's group all of them in a single struct.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index fdd640d8de5482b4c2c02b8886e2ed4d6b9f5313..9de7f66ac8c76fbadffad0a7017aa8c44f4ea201 100644 (file)
@@ -4156,6 +4156,52 @@ qemuLogOperation(virDomainObjPtr vm,
     goto cleanup;
 }
 
+
+void
+qemuProcessIncomingDefFree(qemuProcessIncomingDefPtr inc)
+{
+    if (!inc)
+        return;
+
+    VIR_FREE(inc->launchURI);
+    VIR_FREE(inc);
+}
+
+
+/*
+ * This function does not copy @path, the caller is responsible for keeping
+ * the @path pointer valid during the lifetime of the allocated
+ * qemuProcessIncomingDef structure.
+ */
+qemuProcessIncomingDefPtr
+qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps,
+                          const char *migrateFrom,
+                          int fd,
+                          const char *path)
+{
+    qemuProcessIncomingDefPtr inc = NULL;
+
+    if (qemuMigrationCheckIncoming(qemuCaps, migrateFrom) < 0)
+        return NULL;
+
+    if (VIR_ALLOC(inc) < 0)
+        return NULL;
+
+    inc->launchURI = qemuMigrationIncomingURI(migrateFrom, fd);
+    if (!inc->launchURI)
+        goto error;
+
+    inc->fd = fd;
+    inc->path = path;
+
+    return inc;
+
+ error:
+    qemuProcessIncomingDefFree(inc);
+    return NULL;
+}
+
+
 int qemuProcessStart(virConnectPtr conn,
                      virQEMUDriverPtr driver,
                      virDomainObjPtr vm,
@@ -4185,7 +4231,7 @@ int qemuProcessStart(virConnectPtr conn,
     size_t nnicindexes = 0;
     int *nicindexes = NULL;
     char *tmppath = NULL;
-    char *migrateURI = NULL;
+    qemuProcessIncomingDefPtr incoming = NULL;
 
     VIR_DEBUG("vm=%p name=%s id=%d asyncJob=%d migrateFrom=%s stdin_fd=%d "
               "stdin_path=%s snapshot=%p vmop=%d flags=0x%x",
@@ -4514,25 +4560,25 @@ int qemuProcessStart(virConnectPtr conn,
     }
 
     if (migrateFrom) {
-        if (qemuMigrationCheckIncoming(priv->qemuCaps, migrateFrom) < 0)
-            goto error;
-
-        if (!(migrateURI = qemuMigrationIncomingURI(migrateFrom, stdin_fd)))
+        incoming = qemuProcessIncomingDefNew(priv->qemuCaps, migrateFrom,
+                                             stdin_fd, stdin_path);
+        if (!incoming)
             goto error;
     }
 
     VIR_DEBUG("Building emulator command line");
     if (!(cmd = qemuBuildCommandLine(conn, driver, vm->def, priv->monConfig,
                                      priv->monJSON, priv->qemuCaps,
-                                     migrateURI, snapshot, vmop,
+                                     incoming ? incoming->launchURI : NULL,
+                                     snapshot, vmop,
                                      &buildCommandLineCallbacks, false,
                                      qemuCheckFips(),
                                      priv->autoNodeset,
                                      &nnicindexes, &nicindexes)))
         goto error;
 
-    if (migrateFrom && stdin_fd != -1)
-        virCommandPassFD(cmd, stdin_fd, 0);
+    if (incoming && incoming->fd != -1)
+        virCommandPassFD(cmd, incoming->fd, 0);
 
     /*
      * Create all per-domain directories in order to make sure domain
@@ -4731,7 +4777,7 @@ int qemuProcessStart(virConnectPtr conn,
         goto error;
     VIR_DEBUG("Handshake complete, child running");
 
-    if (migrateFrom)
+    if (incoming)
         flags |= VIR_QEMU_PROCESS_START_PAUSED;
 
     if (rv == -1) /* The VM failed to start; tear filters before taps */
@@ -4852,7 +4898,7 @@ int qemuProcessStart(virConnectPtr conn,
     /* Since CPUs were not started yet, the balloon could not return the memory
      * to the host and thus cur_balloon needs to be updated so that GetXMLdesc
      * and friends return the correct size in case they can't grab the job */
-    if (!migrateFrom && !snapshot &&
+    if (!incoming && !snapshot &&
         qemuProcessRefreshBalloonState(driver, vm, asyncJob) < 0)
         goto error;
 
@@ -4873,7 +4919,7 @@ int qemuProcessStart(virConnectPtr conn,
         }
     } else {
         virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
-                             migrateFrom ?
+                             incoming ?
                              VIR_DOMAIN_PAUSED_MIGRATION :
                              VIR_DOMAIN_PAUSED_USER);
     }
@@ -4905,7 +4951,7 @@ int qemuProcessStart(virConnectPtr conn,
 
     /* Keep watching qemu log for errors during incoming migration, otherwise
      * unset reporting errors from qemu log. */
-    if (!migrateFrom)
+    if (!incoming)
         qemuMonitorSetDomainLog(priv->mon, -1);
 
     ret = 0;
@@ -4918,7 +4964,7 @@ int qemuProcessStart(virConnectPtr conn,
     VIR_FREE(nicindexes);
     VIR_FREE(nodeset);
     VIR_FREE(tmppath);
-    VIR_FREE(migrateURI);
+    qemuProcessIncomingDefFree(incoming);
     return ret;
 
  error:
index d40f68d3a9d10643481536f2aa999643dc182844..7eee2b2c79793ff8f24dd20d72de872f5ff3c07a 100644 (file)
@@ -44,6 +44,20 @@ void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver);
 
 int qemuProcessAssignPCIAddresses(virDomainDefPtr def);
 
+typedef struct _qemuProcessIncomingDef qemuProcessIncomingDef;
+typedef qemuProcessIncomingDef *qemuProcessIncomingDefPtr;
+struct _qemuProcessIncomingDef {
+    char *launchURI; /* used as a parameter for -incoming command line option */
+    int fd; /* for fd:N URI */
+    const char *path; /* path associated with fd */
+};
+
+qemuProcessIncomingDefPtr qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps,
+                                                    const char *migrateFrom,
+                                                    int fd,
+                                                    const char *path);
+void qemuProcessIncomingDefFree(qemuProcessIncomingDefPtr inc);
+
 typedef enum {
     VIR_QEMU_PROCESS_START_COLD         = 1 << 0,
     VIR_QEMU_PROCESS_START_PAUSED       = 1 << 1,