render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
a41c76
From 4ad02094b6166037a04310dbf9a3eb2dcc21ca61 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <4ad02094b6166037a04310dbf9a3eb2dcc21ca61@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Tue, 4 Feb 2020 15:07:37 +0100
a41c76
Subject: [PATCH] qemu: domain: Extract code to determine topmost nodename to
a41c76
 qemuDomainDiskGetTopNodename
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
There are more places which require getting the topmost nodename to be
a41c76
passed to qemu. Separate it out into a new function.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Eric Blake <eblake@redhat.com>
a41c76
(cherry picked from commit 0b0f389335e5d11150fa60561cae960f20d5ca44)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1792195
a41c76
Message-Id: <b3c89cd0893677d101bc8f491bbd323db6133b19.1580824112.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_domain.c | 38 ++++++++++++++++++++++++++------------
a41c76
 src/qemu/qemu_domain.h |  4 ++++
a41c76
 2 files changed, 30 insertions(+), 12 deletions(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
a41c76
index e37404340f..be9de75909 100644
a41c76
--- a/src/qemu/qemu_domain.c
a41c76
+++ b/src/qemu/qemu_domain.c
a41c76
@@ -11598,6 +11598,31 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
a41c76
 }
a41c76
 
a41c76
 
a41c76
+/**
a41c76
+ * qemuDomainDiskGetTopNodename:
a41c76
+ *
a41c76
+ * @disk: disk definition object
a41c76
+ *
a41c76
+ * Returns the pointer to the node-name of the topmost layer used by @disk as
a41c76
+ * backend. Currently returns the nodename of the copy-on-read filter if enabled
a41c76
+ * or the nodename of the top image's format driver. Empty disks return NULL.
a41c76
+ * This must be used only when VIR_QEMU_CAPS_BLOCKDEV is enabled.
a41c76
+ */
a41c76
+const char *
a41c76
+qemuDomainDiskGetTopNodename(virDomainDiskDefPtr disk)
a41c76
+{
a41c76
+    qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
a41c76
+
a41c76
+    if (virStorageSourceIsEmpty(disk->src))
a41c76
+        return NULL;
a41c76
+
a41c76
+    if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON)
a41c76
+        return priv->nodeCopyOnRead;
a41c76
+
a41c76
+    return disk->src->nodeformat;
a41c76
+}
a41c76
+
a41c76
+
a41c76
 /**
a41c76
  * qemuDomainDiskGetBackendAlias:
a41c76
  * @disk: disk definition
a41c76
@@ -11617,8 +11642,6 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
a41c76
                               virQEMUCapsPtr qemuCaps,
a41c76
                               char **backendAlias)
a41c76
 {
a41c76
-    qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
a41c76
-    const char *nodename = NULL;
a41c76
     *backendAlias = NULL;
a41c76
 
a41c76
     if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
a41c76
@@ -11628,16 +11651,7 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
a41c76
         return 0;
a41c76
     }
a41c76
 
a41c76
-    if (virStorageSourceIsEmpty(disk->src))
a41c76
-        return 0;
a41c76
-
a41c76
-    if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON)
a41c76
-        nodename = priv->nodeCopyOnRead;
a41c76
-    else
a41c76
-        nodename = disk->src->nodeformat;
a41c76
-
a41c76
-    *backendAlias = g_strdup(nodename);
a41c76
-
a41c76
+    *backendAlias = g_strdup(qemuDomainDiskGetTopNodename(disk));
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
a41c76
index 60b80297fa..d1ab5da2c7 100644
a41c76
--- a/src/qemu/qemu_domain.h
a41c76
+++ b/src/qemu/qemu_domain.h
a41c76
@@ -881,6 +881,10 @@ int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
a41c76
                               virStorageSourcePtr parent);
a41c76
 char *qemuDomainStorageAlias(const char *device, int depth);
a41c76
 
a41c76
+const char *
a41c76
+qemuDomainDiskGetTopNodename(virDomainDiskDefPtr disk)
a41c76
+    ATTRIBUTE_NONNULL(1);
a41c76
+
a41c76
 int qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
a41c76
                                   virQEMUCapsPtr qemuCaps,
a41c76
                                   char **backendAlias)
a41c76
-- 
a41c76
2.25.0
a41c76