[libvirt] [PATCH 05/12] qemu_process: introduce qemuProcessPrepareHost

Pavel Hrdina phrdina at redhat.com
Tue Mar 15 13:16:01 UTC 2016


Move all code that modifies host system to this function.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/qemu/qemu_migration.c |   3 +
 src/qemu/qemu_process.c   | 191 +++++++++++++++++++++++++---------------------
 src/qemu/qemu_process.h   |   4 +
 3 files changed, 113 insertions(+), 85 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 0b1d37b..f204855 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3479,6 +3479,9 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
                                  VIR_QEMU_PROCESS_START_AUTODESTROY) < 0)
         goto stopjob;
 
+    if (qemuProcessPrepareHost(driver, vm, !!incoming) < 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 df44fad..32efafb 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4396,8 +4396,6 @@ qemuProcessInit(virQEMUDriverPtr driver,
     if (virDomainObjSetDefTransient(caps, driver->xmlopt, vm, true) < 0)
         goto stop;
 
-    if (qemuPrepareNVRAM(cfg, vm, migration) < 0)
-        goto stop;
 
     vm->def->id = qemuDriverAllocateID(driver);
     qemuDomainSetFakeReboot(driver, vm, false);
@@ -4824,6 +4822,109 @@ qemuProcessPrepareDomain(virConnectPtr conn,
 }
 
 
+int
+qemuProcessPrepareHost(virQEMUDriverPtr driver,
+                       virDomainObjPtr vm,
+                       bool incoming)
+{
+    int ret = -1;
+    unsigned int hostdev_flags = 0;
+    size_t i;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+
+    if (qemuPrepareNVRAM(cfg, vm, incoming) < 0)
+        goto cleanup;
+
+    /* network devices must be "prepared" before hostdevs, because
+     * setting up a network device might create a new hostdev that
+     * will need to be setup.
+     */
+    VIR_DEBUG("Preparing network devices");
+    if (qemuProcessNetworkPrepareDevices(vm->def) < 0)
+        goto cleanup;
+
+    /* Must be run before security labelling */
+    VIR_DEBUG("Preparing host devices");
+    if (!cfg->relaxedACS)
+        hostdev_flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
+    if (!incoming)
+        hostdev_flags |= VIR_HOSTDEV_COLD_BOOT;
+    if (qemuHostdevPrepareDomainDevices(driver, vm->def, priv->qemuCaps,
+                                        hostdev_flags) < 0)
+        goto cleanup;
+
+    VIR_DEBUG("Preparing chr devices");
+    if (virDomainChrDefForeach(vm->def,
+                               true,
+                               qemuProcessPrepareChardevDevice,
+                               NULL) < 0)
+        goto cleanup;
+
+    if (vm->def->mem.nhugepages) {
+        for (i = 0; i < cfg->nhugetlbfs; i++) {
+            char *hugepagePath = qemuGetHugepagePath(&cfg->hugetlbfs[i]);
+
+            if (!hugepagePath)
+                goto cleanup;
+
+            if (virSecurityManagerSetHugepages(driver->securityManager,
+                                               vm->def, hugepagePath) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               "%s", _("Unable to set huge path in security driver"));
+                VIR_FREE(hugepagePath);
+                goto cleanup;
+            }
+            VIR_FREE(hugepagePath);
+        }
+    }
+
+    /* Ensure no historical cgroup for this VM is lying around bogus
+     * settings */
+    VIR_DEBUG("Ensuring no historical cgroup is lying around");
+    qemuRemoveCgroup(vm);
+
+    VIR_DEBUG("Setting up ports for graphics");
+    if (qemuProcessSetupGraphics(driver, vm) < 0)
+        goto cleanup;
+
+    if (virFileMakePath(cfg->logDir) < 0) {
+        virReportSystemError(errno,
+                             _("cannot create log directory %s"),
+                             cfg->logDir);
+        goto cleanup;
+    }
+
+    VIR_FREE(priv->pidfile);
+    if (!(priv->pidfile = virPidFileBuildPath(cfg->stateDir, vm->def->name))) {
+        virReportSystemError(errno,
+                             "%s", _("Failed to build pidfile path."));
+        goto cleanup;
+    }
+
+    if (unlink(priv->pidfile) < 0 &&
+        errno != ENOENT) {
+        virReportSystemError(errno,
+                             _("Cannot remove stale PID file %s"),
+                             priv->pidfile);
+        goto cleanup;
+    }
+
+    /*
+     * Create all per-domain directories in order to make sure domain
+     * with any possible seclabels can access it.
+     */
+    if (qemuProcessMakeDir(driver, vm, priv->libDir) < 0 ||
+        qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    virObjectUnref(cfg);
+    return ret;
+}
+
+
 /**
  * qemuProcessLaunch:
  *
@@ -4857,7 +4958,6 @@ qemuProcessLaunch(virConnectPtr conn,
     size_t i;
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
-    unsigned int hostdev_flags = 0;
     size_t nnicindexes = 0;
     int *nicindexes = NULL;
     bool check_shmem = false;
@@ -4890,69 +4990,10 @@ qemuProcessLaunch(virConnectPtr conn,
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;
 
-    /* network devices must be "prepared" before hostdevs, because
-     * setting up a network device might create a new hostdev that
-     * will need to be setup.
-     */
-    VIR_DEBUG("Preparing network devices");
-    if (qemuProcessNetworkPrepareDevices(vm->def) < 0)
-        goto cleanup;
-
-    /* Must be run before security labelling */
-    VIR_DEBUG("Preparing host devices");
-    if (!cfg->relaxedACS)
-        hostdev_flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
-    if (!incoming)
-        hostdev_flags |= VIR_HOSTDEV_COLD_BOOT;
-    if (qemuHostdevPrepareDomainDevices(driver, vm->def, priv->qemuCaps,
-                                        hostdev_flags) < 0)
-        goto cleanup;
-
-    VIR_DEBUG("Preparing chr devices");
-    if (virDomainChrDefForeach(vm->def,
-                               true,
-                               qemuProcessPrepareChardevDevice,
-                               NULL) < 0)
-        goto cleanup;
-
     VIR_DEBUG("Checking domain and device security labels");
     if (virSecurityManagerCheckAllLabel(driver->securityManager, vm->def) < 0)
         goto cleanup;
 
-    if (vm->def->mem.nhugepages) {
-        for (i = 0; i < cfg->nhugetlbfs; i++) {
-            char *hugepagePath = qemuGetHugepagePath(&cfg->hugetlbfs[i]);
-
-            if (!hugepagePath)
-                goto cleanup;
-
-            if (virSecurityManagerSetHugepages(driver->securityManager,
-                                               vm->def, hugepagePath) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               "%s", _("Unable to set huge path in security driver"));
-                VIR_FREE(hugepagePath);
-                goto cleanup;
-            }
-            VIR_FREE(hugepagePath);
-        }
-    }
-
-    /* Ensure no historical cgroup for this VM is lying around bogus
-     * settings */
-    VIR_DEBUG("Ensuring no historical cgroup is lying around");
-    qemuRemoveCgroup(vm);
-
-    VIR_DEBUG("Setting up ports for graphics");
-    if (qemuProcessSetupGraphics(driver, vm) < 0)
-        goto cleanup;
-
-    if (virFileMakePath(cfg->logDir) < 0) {
-        virReportSystemError(errno,
-                             _("cannot create log directory %s"),
-                             cfg->logDir);
-        goto cleanup;
-    }
-
     VIR_DEBUG("Creating domain log file");
     if (!(logCtxt = qemuDomainLogContextNew(driver, vm,
                                             QEMU_DOMAIN_LOG_CONTEXT_MODE_START)))
@@ -4989,21 +5030,6 @@ qemuProcessLaunch(virConnectPtr conn,
                                   vm->def->id) < 0)
         goto cleanup;
 
-    VIR_FREE(priv->pidfile);
-    if (!(priv->pidfile = virPidFileBuildPath(cfg->stateDir, vm->def->name))) {
-        virReportSystemError(errno,
-                             "%s", _("Failed to build pidfile path."));
-        goto cleanup;
-    }
-
-    if (unlink(priv->pidfile) < 0 &&
-        errno != ENOENT) {
-        virReportSystemError(errno,
-                             _("Cannot remove stale PID file %s"),
-                             priv->pidfile);
-        goto cleanup;
-    }
-
     VIR_DEBUG("Checking for any possible (non-fatal) issues");
 
     /*
@@ -5066,14 +5092,6 @@ qemuProcessLaunch(virConnectPtr conn,
     if (incoming && incoming->fd != -1)
         virCommandPassFD(cmd, incoming->fd, 0);
 
-    /*
-     * Create all per-domain directories in order to make sure domain
-     * with any possible seclabels can access it.
-     */
-    if (qemuProcessMakeDir(driver, vm, priv->libDir) < 0 ||
-        qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0)
-        goto cleanup;
-
     /* now that we know it is about to start call the hook if present */
     if (qemuProcessStartHook(driver, vm,
                              VIR_HOOK_QEMU_OP_START,
@@ -5391,6 +5409,9 @@ qemuProcessStart(virConnectPtr conn,
     if (qemuProcessPrepareDomain(conn, driver, vm, flags) < 0)
         goto stop;
 
+    if (qemuProcessPrepareHost(driver, vm, !!incoming) < 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 ef5afa8..049c097 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -98,6 +98,10 @@ int qemuProcessPrepareDomain(virConnectPtr conn,
                              virDomainObjPtr vm,
                              unsigned int flags);
 
+int qemuProcessPrepareHost(virQEMUDriverPtr driver,
+                           virDomainObjPtr vm,
+                           bool incoming);
+
 int qemuProcessLaunch(virConnectPtr conn,
                       virQEMUDriverPtr driver,
                       virDomainObjPtr vm,
-- 
2.7.2




More information about the libvir-list mailing list