qemuBuildStorageSourceChainAttachPrepareBlockdev prepares the full
backing chain for attachment via blockdev. For snapshots we'll need to
prepare one image only as it needs to be plugged on top of the existing
chain.
This patch introduces qemuBuildStorageSourceChainAttachPrepareBlockdevTop
which prepares only @top similarly to the original function by splitting
out the functionality into an internal function so that the API does not
change.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 51 +++++++++++++++++++++++++++++++++--------
src/qemu/qemu_command.h | 3 +++
2 files changed, 44 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index eefec98022..476e710257 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -11159,16 +11159,10 @@
qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk,
}
-/**
- * qemuBuildStorageSourceChainAttachPrepareBlockdev:
- * @top: storage source chain
- * @qemuCaps: qemu capabilities object
- *
- * Prepares qemuBlockStorageSourceChainDataPtr for attaching @top via -blockdev.
- */
-qemuBlockStorageSourceChainDataPtr
-qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSourcePtr top,
- virQEMUCapsPtr qemuCaps)
+static qemuBlockStorageSourceChainDataPtr
+qemuBuildStorageSourceChainAttachPrepareBlockdevInternal(virStorageSourcePtr top,
+ virQEMUCapsPtr qemuCaps,
+ bool onlyTop)
{
VIR_AUTOPTR(qemuBlockStorageSourceAttachData) elem = NULL;
VIR_AUTOPTR(qemuBlockStorageSourceChainData) data = NULL;
@@ -11186,7 +11180,44 @@
qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSourcePtr top,
if (VIR_APPEND_ELEMENT(data->srcdata, data->nsrcdata, elem) < 0)
return NULL;
+
+ if (onlyTop)
+ break;
}
VIR_RETURN_PTR(data);
}
+
+
+/**
+ * qemuBuildStorageSourceChainAttachPrepareBlockdev:
+ * @top: storage source chain
+ * @qemuCaps: qemu capabilities object
+ *
+ * Prepares qemuBlockStorageSourceChainDataPtr for attaching the chain of images
+ * starting at @top via -blockdev.
+ */
+qemuBlockStorageSourceChainDataPtr
+qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSourcePtr top,
+ virQEMUCapsPtr qemuCaps)
+{
+ return qemuBuildStorageSourceChainAttachPrepareBlockdevInternal(top, qemuCaps,
+ false);
+}
+
+
+/**
+ * qemuBuildStorageSourceChainAttachPrepareBlockdevTop:
+ * @top: storage source chain
+ * @qemuCaps: qemu capabilities object
+ *
+ * Prepares qemuBlockStorageSourceChainDataPtr for attaching of @top image only
+ * via -blockdev.
+ */
+qemuBlockStorageSourceChainDataPtr
+qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSourcePtr top,
+ virQEMUCapsPtr qemuCaps)
+{
+ return qemuBuildStorageSourceChainAttachPrepareBlockdevInternal(top, qemuCaps,
+ true);
+}
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 8695832c16..7e2dc5a60a 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -117,6 +117,9 @@ qemuBlockStorageSourceChainDataPtr
qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSourcePtr top,
virQEMUCapsPtr qemuCaps);
+qemuBlockStorageSourceChainDataPtr
+qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSourcePtr top,
+ virQEMUCapsPtr qemuCaps);
char
*qemuBuildDiskDeviceStr(const virDomainDef *def,
--
2.21.0