From b571e7bad046394df9e6ff426f78b16003a9f856 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 14 May 2018 07:28:05 +0200 Subject: [PATCH] qemu: Assign managed PR path when preparing storage source Rather than always checking which path to use pre-assign it when preparing storage source. This reduces the need to pass 'vm' around too much. For later use the path can be retrieved from the status XML. Signed-off-by: Peter Krempa --- src/qemu/qemu_command.c | 18 +++++------------- src/qemu/qemu_command.h | 3 +-- src/qemu/qemu_domain.c | 35 ++++++++++++++++++++++------------- src/qemu/qemu_domain.h | 3 +-- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 2 +- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 53de109a20..353e0af3d7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9717,7 +9717,6 @@ qemuBuildPanicCommandLine(virCommandPtr cmd, /** * qemuBuildPRManagerInfoProps: - * @vm: domain object * @disk: disk definition * @propsret: Returns JSON object containing properties of the pr-manager-helper object * @aliasret: alias of the pr-manager-helper object @@ -9728,12 +9727,10 @@ qemuBuildPanicCommandLine(virCommandPtr cmd, * -1 on failure (with error message set). */ int -qemuBuildPRManagerInfoProps(virDomainObjPtr vm, - const virDomainDiskDef *disk, +qemuBuildPRManagerInfoProps(const virDomainDiskDef *disk, virJSONValuePtr *propsret, char **aliasret) { - char *socketPath = NULL; char *alias = NULL; int ret = -1; @@ -9743,9 +9740,6 @@ qemuBuildPRManagerInfoProps(virDomainObjPtr vm, if (!disk->src->pr) return 0; - if (!(socketPath = qemuDomainGetPRSocketPath(vm, disk->src->pr))) - return ret; - if (virStoragePRDefIsManaged(disk->src->pr)) { if (VIR_STRDUP(alias, qemuDomainGetManagedPRAlias()) < 0) goto cleanup; @@ -9755,7 +9749,7 @@ qemuBuildPRManagerInfoProps(virDomainObjPtr vm, } if (virJSONValueObjectCreate(propsret, - "s:path", socketPath, + "s:path", disk->src->pr->path, NULL) < 0) goto cleanup; @@ -9763,14 +9757,12 @@ qemuBuildPRManagerInfoProps(virDomainObjPtr vm, ret = 0; cleanup: VIR_FREE(alias); - VIR_FREE(socketPath); return ret; } static int -qemuBuildMasterPRCommandLine(virDomainObjPtr vm, - virCommandPtr cmd, +qemuBuildMasterPRCommandLine(virCommandPtr cmd, const virDomainDef *def) { size_t i; @@ -9790,7 +9782,7 @@ qemuBuildMasterPRCommandLine(virDomainObjPtr vm, managedAdded = true; } - if (qemuBuildPRManagerInfoProps(vm, disk, &props, &alias) < 0) + if (qemuBuildPRManagerInfoProps(disk, &props, &alias) < 0) goto cleanup; if (!props) @@ -9984,7 +9976,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, if (qemuBuildMasterKeyCommandLine(cmd, priv) < 0) goto error; - if (qemuBuildMasterPRCommandLine(vm, cmd, def) < 0) + if (qemuBuildMasterPRCommandLine(cmd, def) < 0) goto error; if (enableFips) diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index da1fe679fe..621592cd79 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -55,8 +55,7 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver, int **nicindexes); /* Generate the object properties for pr-manager */ -int qemuBuildPRManagerInfoProps(virDomainObjPtr vm, - const virDomainDiskDef *disk, +int qemuBuildPRManagerInfoProps(const virDomainDiskDef *disk, virJSONValuePtr *propsret, char **alias); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7e37d778f8..cf9280958d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11930,6 +11930,22 @@ qemuDomainPrepareDiskCachemode(virDomainDiskDefPtr disk) } +static int +qemuDomainPrepareStorageSourcePR(virStorageSourcePtr src, + qemuDomainObjPrivatePtr priv) +{ + if (!src->pr) + return 0; + + if (virStoragePRDefIsManaged(src->pr)) { + if (!(src->pr->path = qemuDomainGetManagedPRSocketPath(priv))) + return -1; + } + + return 0; +} + + int qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk, qemuDomainObjPrivatePtr priv, @@ -11946,6 +11962,9 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk, if (qemuDomainPrepareDiskSourceChain(disk, NULL, cfg, priv->qemuCaps) < 0) return -1; + if (qemuDomainPrepareStorageSourcePR(disk->src, priv) < 0) + return -1; + return 0; } @@ -12051,22 +12070,12 @@ qemuProcessEventFree(struct qemuProcessEvent *event) char * -qemuDomainGetPRSocketPath(virDomainObjPtr vm, - virStoragePRDefPtr pr) +qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv) { - qemuDomainObjPrivatePtr priv = vm->privateData; - const char *defaultAlias = NULL; char *ret = NULL; - if (!pr) - return NULL; - - if (virStoragePRDefIsManaged(pr)) { - defaultAlias = qemuDomainGetManagedPRAlias(); - ignore_value(virAsprintf(&ret, "%s/%s.sock", priv->libDir, defaultAlias)); - } else { - ignore_value(VIR_STRDUP(ret, pr->path)); - } + ignore_value(virAsprintf(&ret, "%s/%s.sock", priv->libDir, + qemuDomainGetManagedPRAlias())); return ret; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 09969f606a..40d1d095a3 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1006,7 +1006,6 @@ qemuDomainDiskCachemodeFlags(int cachemode, bool *direct, bool *noflush); -char * qemuDomainGetPRSocketPath(virDomainObjPtr vm, - virStoragePRDefPtr pr); +char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv); #endif /* __QEMU_DOMAIN_H__ */ diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index fbbb7d1917..08b0406700 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -401,7 +401,7 @@ qemuMaybeBuildPRManagerInfoProps(virDomainObjPtr vm, return 0; } - return qemuBuildPRManagerInfoProps(vm, disk, propsret, aliasret); + return qemuBuildPRManagerInfoProps(disk, propsret, aliasret); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a280784764..42b91b39ac 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2659,7 +2659,7 @@ qemuProcessStartPRDaemon(virDomainObjPtr vm, if ((pidfd = virPidFileAcquirePath(pidfile, false, -1)) < 0) goto cleanup; - if (!(socketPath = qemuDomainGetPRSocketPath(vm, disk->src->pr))) + if (!(socketPath = qemuDomainGetManagedPRSocketPath(priv))) goto cleanup; /* Remove stale socket */ -- GitLab