render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 70cf28f452df43cec98387b3039c3b8c5dda10d4 Mon Sep 17 00:00:00 2001
Message-Id: <70cf28f452df43cec98387b3039c3b8c5dda10d4@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 4 Feb 2020 15:08:16 +0100
Subject: [PATCH] qemu: block: Extract calls of qemuBlockGetNamedNodeData into
 a helper function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Create a wrapper for qemuBlockGetNamedNodeData named
qemuBlockGetNamedNodeData. The purpose of the wrapper is to integrate
the monitor handling functionality and in the future possible
qemuCaps-based flags.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 5ddfac11698ec230626e12d077206210424c9bb2)

https://bugzilla.redhat.com/show_bug.cgi?id=1207659
Message-Id: <5527853a9417cf84812cadb842b934ff67de1ea4.1580824112.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_backup.c |  5 +----
 src/qemu/qemu_block.c  | 20 ++++++++++++++++++++
 src/qemu/qemu_block.h  |  4 ++++
 src/qemu/qemu_driver.c | 16 ++++------------
 4 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
index 23518a5d40..8b1e9a7e19 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -830,10 +830,7 @@ qemuBackupBegin(virDomainObjPtr vm,
             goto endjob;
     }
 
-    if (qemuDomainObjEnterMonitorAsync(priv->driver, vm, QEMU_ASYNC_JOB_BACKUP) < 0)
-        goto endjob;
-    blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
-    if (qemuDomainObjExitMonitor(priv->driver, vm) < 0 || !blockNamedNodeData)
+    if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_BACKUP)))
         goto endjob;
 
     if ((ndd = qemuBackupDiskPrepareData(vm, def, incremental, blockNamedNodeData,
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 22f03da485..13e240fdac 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -2670,3 +2670,23 @@ qemuBlockNamedNodeDataGetBitmapByName(virHashTablePtr blockNamedNodeData,
 
     return NULL;
 }
+
+
+virHashTablePtr
+qemuBlockGetNamedNodeData(virDomainObjPtr vm,
+                          qemuDomainAsyncJob asyncJob)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virQEMUDriverPtr driver = priv->driver;
+    g_autoptr(virHashTable) blockNamedNodeData = NULL;
+
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+        return NULL;
+
+    blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
+
+    if (qemuDomainObjExitMonitor(driver, vm) < 0 || !blockNamedNodeData)
+        return NULL;
+
+    return g_steal_pointer(&blockNamedNodeData);
+}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 1a38e0eccf..68646cbf2e 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -208,3 +208,7 @@ qemuBlockNamedNodeDataBitmapPtr
 qemuBlockNamedNodeDataGetBitmapByName(virHashTablePtr blockNamedNodeData,
                                       virStorageSourcePtr src,
                                       const char *bitmap);
+
+virHashTablePtr
+qemuBlockGetNamedNodeData(virDomainObjPtr vm,
+                          qemuDomainAsyncJob asyncJob);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e19e1da0bb..f7ad2dca28 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15622,15 +15622,9 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
     if (!(actions = virJSONValueNewArray()))
         return -1;
 
-    if (blockdev) {
-        if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-            return -1;
-
-        blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
-
-        if (qemuDomainObjExitMonitor(driver, vm) < 0 || !blockNamedNodeData)
-            return -1;
-    }
+    if (blockdev &&
+        !(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, asyncJob)))
+        return -1;
 
     /* prepare a list of objects to use in the vm definition so that we don't
      * have to roll back later */
@@ -18334,9 +18328,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
                                                                           priv->qemuCaps)))
                 goto endjob;
         } else {
-            qemuDomainObjEnterMonitor(driver, vm);
-            blockNamedNodeData = qemuMonitorBlockGetNamedNodeData(priv->mon);
-            if (qemuDomainObjExitMonitor(driver, vm) < 0 || !blockNamedNodeData)
+            if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, QEMU_ASYNC_JOB_NONE)))
                 goto endjob;
 
             if (qemuBlockStorageSourceCreateDetectSize(blockNamedNodeData,
-- 
2.25.0