render / rpms / libvirt

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