From 856612876d2de8f25db872b9ddb3750efd17c361 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Mon, 2 Nov 2015 13:39:28 +0100 Subject: [PATCH] qemu: Introduce qemuProcessMakeDir qemuProcessMakeDir is used for creating a per-domain directory in a given parent directory. Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 59 +++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index e148286f2d..021912e36a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4448,6 +4448,34 @@ qemuProcessSetupBalloon(virQEMUDriverPtr driver, } +static int +qemuProcessMakeDir(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *parentDir) +{ + char *path = NULL; + int ret = -1; + + if (virAsprintf(&path, "%s/domain-%s", parentDir, vm->def->name) < 0) + goto cleanup; + + if (virFileMakePathWithMode(path, 0750) < 0) { + virReportSystemError(errno, _("Cannot create directory '%s'"), path); + goto cleanup; + } + + if (virSecurityManagerDomainSetDirLabel(driver->securityManager, + vm->def, path) < 0) + goto cleanup; + + ret = 0; + + cleanup: + VIR_FREE(path); + return ret; +} + + int qemuProcessStart(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -4475,7 +4503,6 @@ int qemuProcessStart(virConnectPtr conn, unsigned int hostdev_flags = 0; size_t nnicindexes = 0; int *nicindexes = NULL; - char *tmppath = NULL; qemuProcessIncomingDefPtr incoming = NULL; VIR_DEBUG("vm=%p name=%s id=%d asyncJob=%d migrateFrom=%s migrateFd=%d " @@ -4755,35 +4782,10 @@ int qemuProcessStart(virConnectPtr conn, * Create all per-domain directories in order to make sure domain * with any possible seclabels can access it. */ - if (virAsprintf(&tmppath, "%s/domain-%s", cfg->libDir, vm->def->name) < 0) + if (qemuProcessMakeDir(driver, vm, cfg->libDir) < 0 || + qemuProcessMakeDir(driver, vm, cfg->channelTargetDir) < 0) goto error; - if (virFileMakePathWithMode(tmppath, 0750) < 0) { - virReportSystemError(errno, _("Cannot create directory '%s'"), tmppath); - goto error; - } - - if (virSecurityManagerDomainSetDirLabel(driver->securityManager, - vm->def, tmppath) < 0) - goto error; - - VIR_FREE(tmppath); - - if (virAsprintf(&tmppath, "%s/domain-%s", - cfg->channelTargetDir, vm->def->name) < 0) - goto error; - - if (virFileMakePathWithMode(tmppath, 0750) < 0) { - virReportSystemError(errno, _("Cannot create directory '%s'"), tmppath); - goto error; - } - - if (virSecurityManagerDomainSetDirLabel(driver->securityManager, - vm->def, tmppath) < 0) - goto error; - - VIR_FREE(tmppath); - /* now that we know it is about to start call the hook if present */ if (qemuProcessStartHook(driver, vm, VIR_HOOK_QEMU_OP_START, @@ -5059,7 +5061,6 @@ int qemuProcessStart(virConnectPtr conn, virObjectUnref(caps); VIR_FREE(nicindexes); VIR_FREE(nodeset); - VIR_FREE(tmppath); qemuProcessIncomingDefFree(incoming); return ret; -- GitLab