提交 8bebb2b7 编写于 作者: P Peter Krempa

util: storage: Store PR manager alias in the definition

Rather than always re-generating the alias store it in the definition
and in the status XML.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
上级 26c72a76
...@@ -9719,7 +9719,6 @@ qemuBuildPanicCommandLine(virCommandPtr cmd, ...@@ -9719,7 +9719,6 @@ qemuBuildPanicCommandLine(virCommandPtr cmd,
* qemuBuildPRManagerInfoProps: * qemuBuildPRManagerInfoProps:
* @disk: disk definition * @disk: disk definition
* @propsret: Returns JSON object containing properties of the pr-manager-helper object * @propsret: Returns JSON object containing properties of the pr-manager-helper object
* @aliasret: alias of the pr-manager-helper object
* *
* Build the JSON properties for the pr-manager object. * Build the JSON properties for the pr-manager object.
* *
...@@ -9728,32 +9727,19 @@ qemuBuildPanicCommandLine(virCommandPtr cmd, ...@@ -9728,32 +9727,19 @@ qemuBuildPanicCommandLine(virCommandPtr cmd,
*/ */
int int
qemuBuildPRManagerInfoProps(const virDomainDiskDef *disk, qemuBuildPRManagerInfoProps(const virDomainDiskDef *disk,
virJSONValuePtr *propsret, virJSONValuePtr *propsret)
char **aliasret)
{ {
char *alias = NULL;
int ret = -1; int ret = -1;
*propsret = NULL; *propsret = NULL;
*aliasret = NULL;
if (virStoragePRDefIsManaged(disk->src->pr)) {
if (VIR_STRDUP(alias, qemuDomainGetManagedPRAlias()) < 0)
goto cleanup;
} else {
if (!(alias = qemuDomainGetUnmanagedPRAlias(disk->info.alias)))
goto cleanup;
}
if (virJSONValueObjectCreate(propsret, if (virJSONValueObjectCreate(propsret,
"s:path", disk->src->pr->path, "s:path", disk->src->pr->path,
NULL) < 0) NULL) < 0)
goto cleanup; goto cleanup;
VIR_STEAL_PTR(*aliasret, alias);
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(alias);
return ret; return ret;
} }
...@@ -9765,7 +9751,6 @@ qemuBuildMasterPRCommandLine(virCommandPtr cmd, ...@@ -9765,7 +9751,6 @@ qemuBuildMasterPRCommandLine(virCommandPtr cmd,
size_t i; size_t i;
bool managedAdded = false; bool managedAdded = false;
virJSONValuePtr props = NULL; virJSONValuePtr props = NULL;
char *alias = NULL;
char *tmp = NULL; char *tmp = NULL;
int ret = -1; int ret = -1;
...@@ -9782,14 +9767,13 @@ qemuBuildMasterPRCommandLine(virCommandPtr cmd, ...@@ -9782,14 +9767,13 @@ qemuBuildMasterPRCommandLine(virCommandPtr cmd,
managedAdded = true; managedAdded = true;
} }
if (qemuBuildPRManagerInfoProps(disk, &props, &alias) < 0) if (qemuBuildPRManagerInfoProps(disk, &props) < 0)
goto cleanup; goto cleanup;
if (!(tmp = virQEMUBuildObjectCommandlineFromJSON("pr-manager-helper", if (!(tmp = virQEMUBuildObjectCommandlineFromJSON("pr-manager-helper",
alias, disk->src->pr->mgralias,
props))) props)))
goto cleanup; goto cleanup;
VIR_FREE(alias);
virJSONValueFree(props); virJSONValueFree(props);
props = NULL; props = NULL;
...@@ -9799,7 +9783,6 @@ qemuBuildMasterPRCommandLine(virCommandPtr cmd, ...@@ -9799,7 +9783,6 @@ qemuBuildMasterPRCommandLine(virCommandPtr cmd,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(alias);
virJSONValueFree(props); virJSONValueFree(props);
return ret; return ret;
} }
......
...@@ -56,8 +56,7 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver, ...@@ -56,8 +56,7 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
/* Generate the object properties for pr-manager */ /* Generate the object properties for pr-manager */
int qemuBuildPRManagerInfoProps(const virDomainDiskDef *disk, int qemuBuildPRManagerInfoProps(const virDomainDiskDef *disk,
virJSONValuePtr *propsret, virJSONValuePtr *propsret);
char **alias);
/* Generate the object properties for a secret */ /* Generate the object properties for a secret */
int qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo, int qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
......
...@@ -1941,6 +1941,9 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt, ...@@ -1941,6 +1941,9 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
src->nodestorage = virXPathString("string(./nodenames/nodename[@type='storage']/@name)", ctxt); src->nodestorage = virXPathString("string(./nodenames/nodename[@type='storage']/@name)", ctxt);
src->nodeformat = virXPathString("string(./nodenames/nodename[@type='format']/@name)", ctxt); src->nodeformat = virXPathString("string(./nodenames/nodename[@type='format']/@name)", ctxt);
if (src->pr)
src->pr->mgralias = virXPathString("string(./reservations/@mgralias)", ctxt);
if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0) if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
return -1; return -1;
...@@ -1961,6 +1964,9 @@ qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src, ...@@ -1961,6 +1964,9 @@ qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
virBufferAddLit(buf, "</nodenames>\n"); virBufferAddLit(buf, "</nodenames>\n");
} }
if (src->pr)
virBufferAsprintf(buf, "<reservations mgralias='%s'/>\n", src->pr->mgralias);
if (virStorageSourcePrivateDataFormatRelPath(src, buf) < 0) if (virStorageSourcePrivateDataFormatRelPath(src, buf) < 0)
return -1; return -1;
...@@ -11932,7 +11938,8 @@ qemuDomainPrepareDiskCachemode(virDomainDiskDefPtr disk) ...@@ -11932,7 +11938,8 @@ qemuDomainPrepareDiskCachemode(virDomainDiskDefPtr disk)
static int static int
qemuDomainPrepareStorageSourcePR(virStorageSourcePtr src, qemuDomainPrepareStorageSourcePR(virStorageSourcePtr src,
qemuDomainObjPrivatePtr priv) qemuDomainObjPrivatePtr priv,
const char *parentalias)
{ {
if (!src->pr) if (!src->pr)
return 0; return 0;
...@@ -11940,6 +11947,11 @@ qemuDomainPrepareStorageSourcePR(virStorageSourcePtr src, ...@@ -11940,6 +11947,11 @@ qemuDomainPrepareStorageSourcePR(virStorageSourcePtr src,
if (virStoragePRDefIsManaged(src->pr)) { if (virStoragePRDefIsManaged(src->pr)) {
if (!(src->pr->path = qemuDomainGetManagedPRSocketPath(priv))) if (!(src->pr->path = qemuDomainGetManagedPRSocketPath(priv)))
return -1; return -1;
if (VIR_STRDUP(src->pr->mgralias, qemuDomainGetManagedPRAlias()) < 0)
return -1;
} else {
if (!(src->pr->mgralias = qemuDomainGetUnmanagedPRAlias(parentalias)))
return -1;
} }
return 0; return 0;
...@@ -11962,7 +11974,7 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk, ...@@ -11962,7 +11974,7 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
if (qemuDomainPrepareDiskSourceChain(disk, NULL, cfg, priv->qemuCaps) < 0) if (qemuDomainPrepareDiskSourceChain(disk, NULL, cfg, priv->qemuCaps) < 0)
return -1; return -1;
if (qemuDomainPrepareStorageSourcePR(disk->src, priv) < 0) if (qemuDomainPrepareStorageSourcePR(disk->src, priv, disk->info.alias) < 0)
return -1; return -1;
return 0; return 0;
......
...@@ -387,13 +387,11 @@ qemuDomainMaybeStartPRDaemon(virDomainObjPtr vm, ...@@ -387,13 +387,11 @@ qemuDomainMaybeStartPRDaemon(virDomainObjPtr vm,
static int static int
qemuMaybeBuildPRManagerInfoProps(virDomainObjPtr vm, qemuMaybeBuildPRManagerInfoProps(virDomainObjPtr vm,
const virDomainDiskDef *disk, const virDomainDiskDef *disk,
virJSONValuePtr *propsret, virJSONValuePtr *propsret)
char **aliasret)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
*propsret = NULL; *propsret = NULL;
*aliasret = NULL;
if (!disk->src->pr) if (!disk->src->pr)
return 0; return 0;
...@@ -404,7 +402,7 @@ qemuMaybeBuildPRManagerInfoProps(virDomainObjPtr vm, ...@@ -404,7 +402,7 @@ qemuMaybeBuildPRManagerInfoProps(virDomainObjPtr vm,
return 0; return 0;
} }
return qemuBuildPRManagerInfoProps(disk, propsret, aliasret); return qemuBuildPRManagerInfoProps(disk, propsret);
} }
...@@ -425,7 +423,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ...@@ -425,7 +423,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
char *devstr = NULL; char *devstr = NULL;
char *drivestr = NULL; char *drivestr = NULL;
char *drivealias = NULL; char *drivealias = NULL;
char *prmgrAlias = NULL;
bool driveAdded = false; bool driveAdded = false;
bool secobjAdded = false; bool secobjAdded = false;
bool encobjAdded = false; bool encobjAdded = false;
...@@ -462,7 +459,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ...@@ -462,7 +459,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0) if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0)
goto error; goto error;
if (qemuMaybeBuildPRManagerInfoProps(vm, disk, &prmgrProps, &prmgrAlias) < 0) if (qemuMaybeBuildPRManagerInfoProps(vm, disk, &prmgrProps) < 0)
goto error; goto error;
/* Start daemon only after prmgrProps is built. Otherwise /* Start daemon only after prmgrProps is built. Otherwise
...@@ -511,7 +508,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ...@@ -511,7 +508,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
} }
if (prmgrProps) { if (prmgrProps) {
rv = qemuMonitorAddObject(priv->mon, "pr-manager-helper", prmgrAlias, rv = qemuMonitorAddObject(priv->mon, "pr-manager-helper",
disk->src->pr->mgralias,
prmgrProps); prmgrProps);
prmgrProps = NULL; /* qemuMonitorAddObject consumes */ prmgrProps = NULL; /* qemuMonitorAddObject consumes */
if (rv < 0) if (rv < 0)
...@@ -541,7 +539,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ...@@ -541,7 +539,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
virJSONValueFree(encobjProps); virJSONValueFree(encobjProps);
virJSONValueFree(secobjProps); virJSONValueFree(secobjProps);
qemuDomainSecretDiskDestroy(disk); qemuDomainSecretDiskDestroy(disk);
VIR_FREE(prmgrAlias);
VIR_FREE(drivealias); VIR_FREE(drivealias);
VIR_FREE(drivestr); VIR_FREE(drivestr);
VIR_FREE(devstr); VIR_FREE(devstr);
...@@ -559,7 +556,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ...@@ -559,7 +556,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
if (encobjAdded) if (encobjAdded)
ignore_value(qemuMonitorDelObject(priv->mon, encinfo->s.aes.alias)); ignore_value(qemuMonitorDelObject(priv->mon, encinfo->s.aes.alias));
if (prmgrAdded) if (prmgrAdded)
ignore_value(qemuMonitorDelObject(priv->mon, prmgrAlias)); ignore_value(qemuMonitorDelObject(priv->mon, disk->src->pr->mgralias));
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
ret = -2; ret = -2;
virErrorRestore(&orig_err); virErrorRestore(&orig_err);
...@@ -3832,22 +3829,18 @@ static bool qemuIsMultiFunctionDevice(virDomainDefPtr def, ...@@ -3832,22 +3829,18 @@ static bool qemuIsMultiFunctionDevice(virDomainDefPtr def,
static int static int
qemuDomainDiskNeedRemovePR(virDomainObjPtr vm, qemuDomainDiskNeedRemovePR(virDomainObjPtr vm,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
char **aliasret,
bool *stopDaemon) bool *stopDaemon)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
size_t i; size_t i;
*aliasret = NULL;
*stopDaemon = false; *stopDaemon = false;
if (!disk->src->pr) if (!disk->src->pr)
return 0; return 0;
if (!virStoragePRDefIsManaged(disk->src->pr)) { if (!virStoragePRDefIsManaged(disk->src->pr))
*aliasret = qemuDomainGetUnmanagedPRAlias(disk->info.alias); return 0;
return *aliasret ? 0 : -1;
}
for (i = 0; i < vm->def->ndisks; i++) { for (i = 0; i < vm->def->ndisks; i++) {
const virDomainDiskDef *domainDisk = vm->def->disks[i]; const virDomainDiskDef *domainDisk = vm->def->disks[i];
...@@ -3862,9 +3855,6 @@ qemuDomainDiskNeedRemovePR(virDomainObjPtr vm, ...@@ -3862,9 +3855,6 @@ qemuDomainDiskNeedRemovePR(virDomainObjPtr vm,
if (i != vm->def->ndisks) if (i != vm->def->ndisks)
return 0; return 0;
if (VIR_STRDUP(*aliasret, qemuDomainGetManagedPRAlias()) < 0)
return -1;
if (priv->prDaemonRunning) if (priv->prDaemonRunning)
*stopDaemon = true; *stopDaemon = true;
...@@ -3885,7 +3875,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, ...@@ -3885,7 +3875,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
char *drivestr; char *drivestr;
char *objAlias = NULL; char *objAlias = NULL;
char *encAlias = NULL; char *encAlias = NULL;
char *prmgrAlias = NULL;
bool stopPRDaemon = false; bool stopPRDaemon = false;
VIR_DEBUG("Removing disk %s from domain %p %s", VIR_DEBUG("Removing disk %s from domain %p %s",
...@@ -3924,7 +3913,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, ...@@ -3924,7 +3913,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
} }
} }
if (qemuDomainDiskNeedRemovePR(vm, disk, &prmgrAlias, &stopPRDaemon) < 0) if (qemuDomainDiskNeedRemovePR(vm, disk, &stopPRDaemon) < 0)
return -1; return -1;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
...@@ -3943,9 +3932,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, ...@@ -3943,9 +3932,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
VIR_FREE(encAlias); VIR_FREE(encAlias);
/* If it fails, then so be it - it was a best shot */ /* If it fails, then so be it - it was a best shot */
if (prmgrAlias) if (disk->src->pr)
ignore_value(qemuMonitorDelObject(priv->mon, prmgrAlias)); ignore_value(qemuMonitorDelObject(priv->mon, disk->src->pr->mgralias));
VIR_FREE(prmgrAlias);
if (disk->src->haveTLS) if (disk->src->haveTLS)
ignore_value(qemuMonitorDelObject(priv->mon, disk->src->tlsAlias)); ignore_value(qemuMonitorDelObject(priv->mon, disk->src->tlsAlias));
......
...@@ -1899,6 +1899,7 @@ virStoragePRDefFree(virStoragePRDefPtr prd) ...@@ -1899,6 +1899,7 @@ virStoragePRDefFree(virStoragePRDefPtr prd)
return; return;
VIR_FREE(prd->path); VIR_FREE(prd->path);
VIR_FREE(prd->mgralias);
VIR_FREE(prd); VIR_FREE(prd);
} }
......
...@@ -221,6 +221,9 @@ typedef virStoragePRDef *virStoragePRDefPtr; ...@@ -221,6 +221,9 @@ typedef virStoragePRDef *virStoragePRDefPtr;
struct _virStoragePRDef { struct _virStoragePRDef {
int managed; /* enum virTristateBool */ int managed; /* enum virTristateBool */
char *path; char *path;
/* manager object alias */
char *mgralias;
}; };
typedef struct _virStorageDriverData virStorageDriverData; typedef struct _virStorageDriverData virStorageDriverData;
......
...@@ -308,11 +308,15 @@ ...@@ -308,11 +308,15 @@
<backingStore type='file' index='1'> <backingStore type='file' index='1'>
<format type='qcow2'/> <format type='qcow2'/>
<source file='/var/lib/libvirt/images/base.qcow2'> <source file='/var/lib/libvirt/images/base.qcow2'>
<reservations managed='yes'>
<source type='unix' path='/somepath/ux.sck' mode='client'/>
</reservations>
<privateData> <privateData>
<nodenames> <nodenames>
<nodename type='storage' name='test-storage'/> <nodename type='storage' name='test-storage'/>
<nodename type='format' name='test-format'/> <nodename type='format' name='test-format'/>
</nodenames> </nodenames>
<reservations mgralias='test-alias'/>
<relPath>base.qcow2</relPath> <relPath>base.qcow2</relPath>
</privateData> </privateData>
</source> </source>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册