[PATCH 08/19] qemu: block: Extract calls of qemuBlockGetNamedNodeData into a helper function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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 8bb845298b..47f0754a1a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15642,15 +15642,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 */
@@ -18354,9 +18348,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.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux