提交 eee85c23 编写于 作者: P Peter Krempa

qemu: command: Refactor qemuBuildStorageSourceChainAttachPrepareBlockdevInternal

Extract the loop and supporting infrastructure to the caller as only one
of the two callers actually cares about looping and rename the helper to
qemuBuildStorageSourceChainAttachPrepareBlockdevOne.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 a7643da8
......@@ -10720,33 +10720,23 @@ qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk,
}
static qemuBlockStorageSourceChainDataPtr
qemuBuildStorageSourceChainAttachPrepareBlockdevInternal(virStorageSourcePtr top,
virQEMUCapsPtr qemuCaps,
bool onlyTop)
static int
qemuBuildStorageSourceChainAttachPrepareBlockdevOne(qemuBlockStorageSourceChainData *data,
virStorageSourcePtr src,
virQEMUCapsPtr qemuCaps)
{
VIR_AUTOPTR(qemuBlockStorageSourceAttachData) elem = NULL;
VIR_AUTOPTR(qemuBlockStorageSourceChainData) data = NULL;
virStorageSourcePtr n;
if (VIR_ALLOC(data) < 0)
return NULL;
for (n = top; virStorageSourceIsBacking(n); n = n->backingStore) {
if (!(elem = qemuBlockStorageSourceAttachPrepareBlockdev(n, true)))
return NULL;
if (qemuBuildStorageSourceAttachPrepareCommon(n, elem, qemuCaps) < 0)
return NULL;
if (!(elem = qemuBlockStorageSourceAttachPrepareBlockdev(src, true)))
return -1;
if (VIR_APPEND_ELEMENT(data->srcdata, data->nsrcdata, elem) < 0)
return NULL;
if (qemuBuildStorageSourceAttachPrepareCommon(src, elem, qemuCaps) < 0)
return -1;
if (onlyTop)
break;
}
if (VIR_APPEND_ELEMENT(data->srcdata, data->nsrcdata, elem) < 0)
return -1;
VIR_RETURN_PTR(data);
return 0;
}
......@@ -10762,8 +10752,18 @@ qemuBlockStorageSourceChainDataPtr
qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSourcePtr top,
virQEMUCapsPtr qemuCaps)
{
return qemuBuildStorageSourceChainAttachPrepareBlockdevInternal(top, qemuCaps,
false);
VIR_AUTOPTR(qemuBlockStorageSourceChainData) data = NULL;
virStorageSourcePtr n;
if (VIR_ALLOC(data) < 0)
return NULL;
for (n = top; virStorageSourceIsBacking(n); n = n->backingStore) {
if (qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, n, qemuCaps) < 0)
return NULL;
}
VIR_RETURN_PTR(data);
}
......@@ -10779,6 +10779,13 @@ qemuBlockStorageSourceChainDataPtr
qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSourcePtr top,
virQEMUCapsPtr qemuCaps)
{
return qemuBuildStorageSourceChainAttachPrepareBlockdevInternal(top, qemuCaps,
true);
VIR_AUTOPTR(qemuBlockStorageSourceChainData) data = NULL;
if (VIR_ALLOC(data) < 0)
return NULL;
if (qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, top, qemuCaps) < 0)
return NULL;
VIR_RETURN_PTR(data);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册