There are more places which require getting the topmost nodename to be
passed to qemu. Separate it out into a new function.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_domain.c | 38 ++++++++++++++++++++++++++------------
src/qemu/qemu_domain.h | 4 ++++
2 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 38addc7b61..4604b6c993 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11530,6 +11530,31 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
}
+/**
+ * qemuDomainDiskGetTopNodename:
+ *
+ * @disk: disk definition object
+ *
+ * Returns the pointer to the node-name of the topmost layer used by @disk as
+ * backend. Currently returns the nodename of the copy-on-read filter if enabled
+ * or the nodename of the top image's format driver. Empty disks return NULL.
+ * This must be used only when VIR_QEMU_CAPS_BLOCKDEV is enabled.
+ */
+const char *
+qemuDomainDiskGetTopNodename(virDomainDiskDefPtr disk)
+{
+ qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
+ if (virStorageSourceIsEmpty(disk->src))
+ return NULL;
+
+ if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON)
+ return priv->nodeCopyOnRead;
+
+ return disk->src->nodeformat;
+}
+
+
/**
* qemuDomainDiskGetBackendAlias:
* @disk: disk definition
@@ -11549,8 +11574,6 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps,
char **backendAlias)
{
- qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
- const char *nodename = NULL;
*backendAlias = NULL;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
@@ -11560,16 +11583,7 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
return 0;
}
- if (virStorageSourceIsEmpty(disk->src))
- return 0;
-
- if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON)
- nodename = priv->nodeCopyOnRead;
- else
- nodename = disk->src->nodeformat;
-
- *backendAlias = g_strdup(nodename);
-
+ *backendAlias = g_strdup(qemuDomainDiskGetTopNodename(disk));
return 0;
}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 21ece23177..c8bf621c61 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -874,6 +874,10 @@ int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
virStorageSourcePtr parent);
char *qemuDomainStorageAlias(const char *device, int depth);
+const char *
+qemuDomainDiskGetTopNodename(virDomainDiskDefPtr disk)
+ ATTRIBUTE_NONNULL(1);
+
int qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps,
char **backendAlias)
--
2.24.1