[PATCH 04/12] qemu_process: introduce qemuProcessPrepareDomain

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_migration.c |   4 ++
 src/qemu/qemu_process.c   | 159 +++++++++++++++++++++++++++-------------------
 src/qemu/qemu_process.h   |   6 ++
 3 files changed, 102 insertions(+), 67 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 38fa81c..0b1d37b 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3475,6 +3475,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,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 958fae3..df44fad 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4735,6 +4735,95 @@ qemuProcessSetupIOThreads(virDomainObjPtr vm)
 }
 
 
+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 (qemuAssignDeviceAliases(vm->def, priv->qemuCaps) < 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;
+
+    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);
+    }
+
+    /* "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;
+    }
+
+    /* 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;
+    }
+
+    /*
+     * 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:
+    virObjectUnref(caps);
+    return ret;
+}
+
+
 /**
  * qemuProcessLaunch:
  *
@@ -4766,7 +4855,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;
@@ -4831,15 +4919,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]);
@@ -4891,37 +4970,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;
@@ -4941,18 +4989,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,
@@ -4968,19 +5004,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");
 
     /*
@@ -5273,7 +5296,6 @@ qemuProcessLaunch(virConnectPtr conn,
     virObjectUnref(cfg);
     virObjectUnref(caps);
     VIR_FREE(nicindexes);
-    VIR_FREE(nodeset);
     return ret;
 }
 
@@ -5366,6 +5388,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)
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index c21ed1c..ef5afa8 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -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,
-- 
2.7.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]