]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_process: introduce qemuProcessPrepareDomain
authorPavel Hrdina <phrdina@redhat.com>
Tue, 15 Mar 2016 12:00:59 +0000 (13:00 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 22 Mar 2016 14:15:48 +0000 (15:15 +0100)
Move all code that modifies only live XML to this function.  The new
VIR_QEMU_PROCESS_START_PRETEND flag will be used by qemuXMLToNative and
qemuxml2argvtest later in order to reuse the same code as
qemuProcessStart uses.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_migration.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index 12d4ad381911430e0309ad09d5f6a179364981d2..93b0fe6051f098b5eadfa2031ed54d0dfee81772 100644 (file)
@@ -3590,6 +3590,10 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
         goto stopjob;
     dataFD[0] = -1; /* the FD is now owned by incoming */
 
+    if (qemuProcessPrepareDomain(dconn, driver, vm,
+                                 VIR_QEMU_PROCESS_START_AUTODESTROY) < 0)
+        goto stopjob;
+
     rv = qemuProcessLaunch(dconn, driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
                            incoming, NULL,
                            VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_START,
index c6bb223080a405c51ab8db097abbcdcab520c124..bcc75dfb899f880aa42b96804c5b9b0c0c6f5888 100644 (file)
@@ -4784,6 +4784,108 @@ qemuProcessSetupIOThreads(virDomainObjPtr vm)
 }
 
 
+/**
+ * qemuProcessPrepareDomain
+ *
+ * This function groups all code that modifies only live XML of a domain which
+ * is about to start and it's the only place to do those modifications.
+ *
+ * Flag VIR_QEMU_PROCESS_START_PRETEND tells, that we don't want to actually
+ * start the domain but create a valid qemu command.  If some code shouldn't be
+ * executed in this case, make sure to check this flag.
+ *
+ * TODO: move all XML modification from qemuBuildCommandLine into this function
+ */
+int
+qemuProcessPrepareDomain(virConnectPtr conn,
+                         virQEMUDriverPtr driver,
+                         virDomainObjPtr vm,
+                         unsigned int flags)
+{
+    int ret = -1;
+    size_t i;
+    char *nodeset = NULL;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virCapsPtr caps;
+
+    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    if (!(flags & VIR_QEMU_PROCESS_START_PRETEND)) {
+        /* If you are using a SecurityDriver with dynamic labelling,
+           then generate a security label for isolation */
+        VIR_DEBUG("Generating domain security label (if required)");
+        if (virSecurityManagerGenLabel(driver->securityManager, vm->def) < 0) {
+            virDomainAuditSecurityLabel(vm, false);
+            goto cleanup;
+        }
+        virDomainAuditSecurityLabel(vm, true);
+
+        /* Get the advisory nodeset from numad if 'placement' of
+         * either <vcpu> or <numatune> is 'auto'.
+         */
+        if (virDomainDefNeedsPlacementAdvice(vm->def)) {
+            nodeset = virNumaGetAutoPlacementAdvice(virDomainDefGetVcpus(vm->def),
+                                                    virDomainDefGetMemoryActual(vm->def));
+            if (!nodeset)
+                goto cleanup;
+
+            VIR_DEBUG("Nodeset returned from numad: %s", nodeset);
+
+            if (virBitmapParse(nodeset, 0, &priv->autoNodeset,
+                               VIR_DOMAIN_CPUMASK_LEN) < 0)
+                goto cleanup;
+
+            if (!(priv->autoCpuset = virCapabilitiesGetCpusForNodemask(caps,
+                                                                       priv->autoNodeset)))
+                goto cleanup;
+        }
+    }
+
+    if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0)
+        goto cleanup;
+
+    /* "volume" type disk's source must be translated before
+     * cgroup and security setting.
+     */
+    for (i = 0; i < vm->def->ndisks; i++) {
+        if (virStorageTranslateDiskSourcePool(conn, vm->def->disks[i]) < 0)
+            goto cleanup;
+    }
+
+    if (VIR_ALLOC(priv->monConfig) < 0)
+        goto cleanup;
+
+    VIR_DEBUG("Preparing monitor state");
+    if (qemuProcessPrepareMonitorChr(priv->monConfig, priv->libDir) < 0)
+        goto cleanup;
+
+    priv->monJSON = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MONITOR_JSON);
+    priv->monError = false;
+    priv->monStart = 0;
+    priv->gotShutdown = false;
+
+    /*
+     * Normally PCI addresses are assigned in the virDomainCreate
+     * or virDomainDefine methods. We might still need to assign
+     * some here to cope with the question of upgrades. Regardless
+     * we also need to populate the PCI address set cache for later
+     * use in hotplug
+     */
+    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
+        VIR_DEBUG("Assigning domain PCI addresses");
+        if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps, vm)) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(nodeset);
+    virObjectUnref(caps);
+    return ret;
+}
+
+
 /**
  * qemuProcessLaunch:
  *
@@ -4815,7 +4917,6 @@ qemuProcessLaunch(virConnectPtr conn,
     virCommandPtr cmd = NULL;
     struct qemuProcessHookData hookData;
     size_t i;
-    char *nodeset = NULL;
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
     unsigned int hostdev_flags = 0;
@@ -4880,15 +4981,6 @@ qemuProcessLaunch(virConnectPtr conn,
     if (virSecurityManagerCheckAllLabel(driver->securityManager, vm->def) < 0)
         goto cleanup;
 
-    /* If you are using a SecurityDriver with dynamic labelling,
-       then generate a security label for isolation */
-    VIR_DEBUG("Generating domain security label (if required)");
-    if (virSecurityManagerGenLabel(driver->securityManager, vm->def) < 0) {
-        virDomainAuditSecurityLabel(vm, false);
-        goto cleanup;
-    }
-    virDomainAuditSecurityLabel(vm, true);
-
     if (vm->def->mem.nhugepages) {
         for (i = 0; i < cfg->nhugetlbfs; i++) {
             char *hugepagePath = qemuGetHugepagePath(&cfg->hugetlbfs[i]);
@@ -4940,37 +5032,6 @@ qemuProcessLaunch(virConnectPtr conn,
         }
     }
 
-    if (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 0)
-        goto cleanup;
-
-    /* Get the advisory nodeset from numad if 'placement' of
-     * either <vcpu> or <numatune> is 'auto'.
-     */
-    if (virDomainDefNeedsPlacementAdvice(vm->def)) {
-        nodeset = virNumaGetAutoPlacementAdvice(virDomainDefGetVcpus(vm->def),
-                                                virDomainDefGetMemoryActual(vm->def));
-        if (!nodeset)
-            goto cleanup;
-
-        VIR_DEBUG("Nodeset returned from numad: %s", nodeset);
-
-        if (virBitmapParse(nodeset, 0, &priv->autoNodeset,
-                           VIR_DOMAIN_CPUMASK_LEN) < 0)
-            goto cleanup;
-
-        if (!(priv->autoCpuset = virCapabilitiesGetCpusForNodemask(caps,
-                                                                   priv->autoNodeset)))
-            goto cleanup;
-    }
-
-    /* "volume" type disk's source must be translated before
-     * cgroup and security setting.
-     */
-    for (i = 0; i < vm->def->ndisks; i++) {
-        if (virStorageTranslateDiskSourcePool(conn, vm->def->disks[i]) < 0)
-            goto cleanup;
-    }
-
     if (qemuDomainCheckDiskPresence(driver, vm,
                                     flags & VIR_QEMU_PROCESS_START_COLD) < 0)
         goto cleanup;
@@ -4990,18 +5051,6 @@ qemuProcessLaunch(virConnectPtr conn,
                                   vm->def->id) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC(priv->monConfig) < 0)
-        goto cleanup;
-
-    VIR_DEBUG("Preparing monitor state");
-    if (qemuProcessPrepareMonitorChr(priv->monConfig, priv->libDir) < 0)
-        goto cleanup;
-
-    priv->monJSON = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MONITOR_JSON);
-    priv->monError = false;
-    priv->monStart = 0;
-    priv->gotShutdown = false;
-
     VIR_FREE(priv->pidfile);
     if (!(priv->pidfile = virPidFileBuildPath(cfg->stateDir, vm->def->name))) {
         virReportSystemError(errno,
@@ -5017,19 +5066,6 @@ qemuProcessLaunch(virConnectPtr conn,
         goto cleanup;
     }
 
-    /*
-     * Normally PCI addresses are assigned in the virDomainCreate
-     * or virDomainDefine methods. We might still need to assign
-     * some here to cope with the question of upgrades. Regardless
-     * we also need to populate the PCI address set cache for later
-     * use in hotplug
-     */
-    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
-        VIR_DEBUG("Assigning domain PCI addresses");
-        if ((qemuDomainAssignAddresses(vm->def, priv->qemuCaps, vm)) < 0)
-            goto cleanup;
-    }
-
     VIR_DEBUG("Checking for any possible (non-fatal) issues");
 
     /*
@@ -5322,7 +5358,6 @@ qemuProcessLaunch(virConnectPtr conn,
     virObjectUnref(cfg);
     virObjectUnref(caps);
     VIR_FREE(nicindexes);
-    VIR_FREE(nodeset);
     return ret;
 }
 
@@ -5415,6 +5450,9 @@ qemuProcessStart(virConnectPtr conn,
             goto stop;
     }
 
+    if (qemuProcessPrepareDomain(conn, driver, vm, flags) < 0)
+        goto stop;
+
     if ((rv = qemuProcessLaunch(conn, driver, vm, asyncJob, incoming,
                                 snapshot, vmop, flags)) < 0) {
         if (rv == -2)
index c21ed1c81567d9848db8ed4f1b274e72953017df..ef5afa8eb541d317856d1981fde8ce76b4b68475 100644 (file)
@@ -67,6 +67,7 @@ typedef enum {
     VIR_QEMU_PROCESS_START_COLD         = 1 << 0,
     VIR_QEMU_PROCESS_START_PAUSED       = 1 << 1,
     VIR_QEMU_PROCESS_START_AUTODESTROY  = 1 << 2,
+    VIR_QEMU_PROCESS_START_PRETEND      = 1 << 3,
 } qemuProcessStartFlags;
 
 int qemuProcessStart(virConnectPtr conn,
@@ -92,6 +93,11 @@ int qemuProcessInit(virQEMUDriverPtr driver,
                     bool migration,
                     bool snap);
 
+int qemuProcessPrepareDomain(virConnectPtr conn,
+                             virQEMUDriverPtr driver,
+                             virDomainObjPtr vm,
+                             unsigned int flags);
+
 int qemuProcessLaunch(virConnectPtr conn,
                       virQEMUDriverPtr driver,
                       virDomainObjPtr vm,