mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
qemu: Store and parse disk authentication and encryption secret alias
Rather than trying to figure out which alias was used, store it in the status XML. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
04c890cc8b
commit
f95baa3813
@ -1991,20 +1991,84 @@ qemuDomainObjPrivateFree(void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuStorageSourcePrivateDataAssignSecinfo(qemuDomainSecretInfoPtr *secinfo,
|
||||||
|
char **alias)
|
||||||
|
{
|
||||||
|
if (!*alias)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!*secinfo) {
|
||||||
|
if (VIR_ALLOC(*secinfo) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
(*secinfo)->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*secinfo)->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
|
||||||
|
VIR_STEAL_PTR((*secinfo)->s.aes.alias, *alias);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
|
qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
|
||||||
virStorageSourcePtr src)
|
virStorageSourcePtr src)
|
||||||
{
|
{
|
||||||
|
qemuDomainStorageSourcePrivatePtr priv;
|
||||||
|
char *authalias = NULL;
|
||||||
|
char *encalias = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
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)
|
if (src->pr)
|
||||||
src->pr->mgralias = virXPathString("string(./reservations/@mgralias)", ctxt);
|
src->pr->mgralias = virXPathString("string(./reservations/@mgralias)", ctxt);
|
||||||
|
|
||||||
if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
|
authalias = virXPathString("string(./objects/secret[@type='auth']/@alias)", ctxt);
|
||||||
return -1;
|
encalias = virXPathString("string(./objects/secret[@type='encryption']/@alias)", ctxt);
|
||||||
|
|
||||||
return 0;
|
if (authalias || encalias) {
|
||||||
|
if (!src->privateData &&
|
||||||
|
!(src->privateData = qemuDomainStorageSourcePrivateNew()))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
priv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
|
||||||
|
|
||||||
|
if (qemuStorageSourcePrivateDataAssignSecinfo(&priv->secinfo, &authalias) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (qemuStorageSourcePrivateDataAssignSecinfo(&priv->encinfo, &encalias) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(authalias);
|
||||||
|
VIR_FREE(encalias);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
qemuStorageSourcePrivateDataFormatSecinfo(virBufferPtr buf,
|
||||||
|
qemuDomainSecretInfoPtr secinfo,
|
||||||
|
const char *type)
|
||||||
|
{
|
||||||
|
if (!secinfo ||
|
||||||
|
secinfo->type != VIR_DOMAIN_SECRET_INFO_TYPE_AES ||
|
||||||
|
!secinfo->s.aes.alias)
|
||||||
|
return;
|
||||||
|
|
||||||
|
virBufferAsprintf(buf, "<secret type='%s' alias='%s'/>\n",
|
||||||
|
type, secinfo->s.aes.alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2012,6 +2076,10 @@ static int
|
|||||||
qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
|
qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
|
||||||
virBufferPtr buf)
|
virBufferPtr buf)
|
||||||
{
|
{
|
||||||
|
virBuffer tmp = VIR_BUFFER_INITIALIZER;
|
||||||
|
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
if (src->nodestorage || src->nodeformat) {
|
if (src->nodestorage || src->nodeformat) {
|
||||||
virBufferAddLit(buf, "<nodenames>\n");
|
virBufferAddLit(buf, "<nodenames>\n");
|
||||||
virBufferAdjustIndent(buf, 2);
|
virBufferAdjustIndent(buf, 2);
|
||||||
@ -2025,9 +2093,23 @@ qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
|
|||||||
virBufferAsprintf(buf, "<reservations mgralias='%s'/>\n", src->pr->mgralias);
|
virBufferAsprintf(buf, "<reservations mgralias='%s'/>\n", src->pr->mgralias);
|
||||||
|
|
||||||
if (virStorageSourcePrivateDataFormatRelPath(src, buf) < 0)
|
if (virStorageSourcePrivateDataFormatRelPath(src, buf) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
return 0;
|
virBufferSetChildIndent(&tmp, buf);
|
||||||
|
|
||||||
|
if (srcPriv) {
|
||||||
|
qemuStorageSourcePrivateDataFormatSecinfo(&tmp, srcPriv->secinfo, "auth");
|
||||||
|
qemuStorageSourcePrivateDataFormatSecinfo(&tmp, srcPriv->encinfo, "encryption");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virXMLFormatElement(buf, "objects", NULL, &tmp) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virBufferFreeAndReset(&tmp);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -319,6 +319,10 @@
|
|||||||
</nodenames>
|
</nodenames>
|
||||||
<reservations mgralias='test-alias'/>
|
<reservations mgralias='test-alias'/>
|
||||||
<relPath>base.qcow2</relPath>
|
<relPath>base.qcow2</relPath>
|
||||||
|
<objects>
|
||||||
|
<secret type='auth' alias='test-auth-alias'/>
|
||||||
|
<secret type='encryption' alias='test-encryption-alias'/>
|
||||||
|
</objects>
|
||||||
</privateData>
|
</privateData>
|
||||||
</source>
|
</source>
|
||||||
<backingStore/>
|
<backingStore/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user