Blame SOURCES/libvirt-qemu-block-Extract-calls-of-qemuBlockGetNamedNodeData-into-a-helper-function.patch

d76c62
From 70cf28f452df43cec98387b3039c3b8c5dda10d4 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <70cf28f452df43cec98387b3039c3b8c5dda10d4@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Tue, 4 Feb 2020 15:08:16 +0100
d76c62
Subject: [PATCH] qemu: block: Extract calls of qemuBlockGetNamedNodeData into
d76c62
 a helper function
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Create a wrapper for qemuBlockGetNamedNodeData named
d76c62
qemuBlockGetNamedNodeData. The purpose of the wrapper is to integrate
d76c62
the monitor handling functionality and in the future possible
d76c62
qemuCaps-based flags.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 5ddfac11698ec230626e12d077206210424c9bb2)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
d76c62
Message-Id: <5527853a9417cf84812cadb842b934ff67de1ea4.1580824112.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/qemu/qemu_backup.c |  5 +----
d76c62
 src/qemu/qemu_block.c  | 20 ++++++++++++++++++++
d76c62
 src/qemu/qemu_block.h  |  4 ++++
d76c62
 src/qemu/qemu_driver.c | 16 ++++------------
d76c62
 4 files changed, 29 insertions(+), 16 deletions(-)
d76c62
d76c62
diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
d76c62
index 23518a5d40..8b1e9a7e19 100644
d76c62
--- a/src/qemu/qemu_backup.c
d76c62
+++ b/src/qemu/qemu_backup.c
d76c62
@@ -830,10 +830,7 @@ qemuBackupBegin(virDomainObjPtr vm,
d76c62
             goto endjob;
d76c62
     }
d76c62
 
d76c62
-    if (qemuDomainObjEnterMonitorAsync(priv->driver, vm, QEMU_ASYNC_JOB_BACKUP) < 0)
d76c62
-        goto endjob;
d76c62
-    blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
d76c62
-    if (qemuDomainObjExitMonitor(priv->driver, vm) < 0 || !blockNamedNodeData)
d76c62
+    if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_BACKUP)))
d76c62
         goto endjob;
d76c62
 
d76c62
     if ((ndd = qemuBackupDiskPrepareData(vm, def, incremental, blockNamedNodeData,
d76c62
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
d76c62
index 22f03da485..13e240fdac 100644
d76c62
--- a/src/qemu/qemu_block.c
d76c62
+++ b/src/qemu/qemu_block.c
d76c62
@@ -2670,3 +2670,23 @@ qemuBlockNamedNodeDataGetBitmapByName(virHashTablePtr blockNamedNodeData,
d76c62
 
d76c62
     return NULL;
d76c62
 }
d76c62
+
d76c62
+
d76c62
+virHashTablePtr
d76c62
+qemuBlockGetNamedNodeData(virDomainObjPtr vm,
d76c62
+                          qemuDomainAsyncJob asyncJob)
d76c62
+{
d76c62
+    qemuDomainObjPrivatePtr priv = vm->privateData;
d76c62
+    virQEMUDriverPtr driver = priv->driver;
d76c62
+    g_autoptr(virHashTable) blockNamedNodeData = NULL;
d76c62
+
d76c62
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
d76c62
+        return NULL;
d76c62
+
d76c62
+    blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
d76c62
+
d76c62
+    if (qemuDomainObjExitMonitor(driver, vm) < 0 || !blockNamedNodeData)
d76c62
+        return NULL;
d76c62
+
d76c62
+    return g_steal_pointer(&blockNamedNodeData);
d76c62
+}
d76c62
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
d76c62
index 1a38e0eccf..68646cbf2e 100644
d76c62
--- a/src/qemu/qemu_block.h
d76c62
+++ b/src/qemu/qemu_block.h
d76c62
@@ -208,3 +208,7 @@ qemuBlockNamedNodeDataBitmapPtr
d76c62
 qemuBlockNamedNodeDataGetBitmapByName(virHashTablePtr blockNamedNodeData,
d76c62
                                       virStorageSourcePtr src,
d76c62
                                       const char *bitmap);
d76c62
+
d76c62
+virHashTablePtr
d76c62
+qemuBlockGetNamedNodeData(virDomainObjPtr vm,
d76c62
+                          qemuDomainAsyncJob asyncJob);
d76c62
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
d76c62
index e19e1da0bb..f7ad2dca28 100644
d76c62
--- a/src/qemu/qemu_driver.c
d76c62
+++ b/src/qemu/qemu_driver.c
d76c62
@@ -15622,15 +15622,9 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
d76c62
     if (!(actions = virJSONValueNewArray()))
d76c62
         return -1;
d76c62
 
d76c62
-    if (blockdev) {
d76c62
-        if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
d76c62
-            return -1;
d76c62
-
d76c62
-        blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
d76c62
-
d76c62
-        if (qemuDomainObjExitMonitor(driver, vm) < 0 || !blockNamedNodeData)
d76c62
-            return -1;
d76c62
-    }
d76c62
+    if (blockdev &&
d76c62
+        !(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, asyncJob)))
d76c62
+        return -1;
d76c62
 
d76c62
     /* prepare a list of objects to use in the vm definition so that we don't
d76c62
      * have to roll back later */
d76c62
@@ -18334,9 +18328,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
d76c62
                                                                           priv->qemuCaps)))
d76c62
                 goto endjob;
d76c62
         } else {
d76c62
-            qemuDomainObjEnterMonitor(driver, vm);
d76c62
-            blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
d76c62
-            if (qemuDomainObjExitMonitor(driver, vm) < 0 || !blockNamedNodeData)
d76c62
+            if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_NONE)))
d76c62
                 goto endjob;
d76c62
 
d76c62
             if (qemuBlockStorageSourceCreateDetectSize(blockNamedNodeData,
d76c62
-- 
d76c62
2.25.0
d76c62