[PATCH 10/17] qemu: block: Absorb logic from qemuBlockReopenFormat to qemuBlockReopenAccess

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

 



Move all the logic into the new function and remove the old one.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_block.c | 60 +++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 39 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 1ef6bf98bc..2872d74fa2 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3182,22 +3182,29 @@ qemuBlockReopenFormatMon(qemuMonitor *mon,


 /**
- * qemuBlockReopenFormat:
+ * qemuBlockReopenAccess:
  * @vm: domain object
  * @src: storage source to reopen
+ * @readonly: requested readonly mode
  * @asyncJob: qemu async job type
  *
- * Invokes the 'blockdev-reopen' command on the format layer of @src. This means
- * that @src must be already properly configured for the desired outcome. The
- * nodenames of @src are used to identify the specific image in qemu.
+ * Reopen @src image to ensure that it is in @readonly. Does nothing if it is
+ * already in the requested state.
+ *
+ * Callers must use qemuBlockReopenReadWrite/qemuBlockReopenReadOnly functions.
  */
 static int
-qemuBlockReopenFormat(virDomainObj *vm,
+qemuBlockReopenAccess(virDomainObj *vm,
                       virStorageSource *src,
+                      bool readonly,
                       virDomainAsyncJob asyncJob)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
     int rc;
+    int ret = -1;
+
+    if (src->readonly == readonly)
+        return 0;

     /* If we are lacking the object here, qemu might have opened an image with
      * a node name unknown to us */
@@ -3207,48 +3214,23 @@ qemuBlockReopenFormat(virDomainObj *vm,
         return -1;
     }

+    src->readonly = readonly;
+    /* from now on all error paths must use 'goto cleanup' */
+
     if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0)
-        return -1;
+        goto cleanup;

     rc = qemuBlockReopenFormatMon(priv->mon, src);

     qemuDomainObjExitMonitor(vm);
     if (rc < 0)
-        return -1;
-
-    return 0;
-}
-
-
-/**
- * qemuBlockReopenAccess:
- * @vm: domain object
- * @src: storage source to reopen
- * @readonly: requested readonly mode
- * @asyncJob: qemu async job type
- *
- * Reopen @src image to ensure that it is in @readonly. Does nothing if it is
- * already in the requested state.
- *
- * Callers must use qemuBlockReopenReadWrite/qemuBlockReopenReadOnly functions.
- */
-
-static int
-qemuBlockReopenAccess(virDomainObj *vm,
-                      virStorageSource *src,
-                      bool readonly,
-                      virDomainAsyncJob asyncJob)
-{
-    if (src->readonly == readonly)
-        return 0;
+        goto cleanup;

-    src->readonly = readonly;
-    if (qemuBlockReopenFormat(vm, src, asyncJob) < 0) {
-        src->readonly = !readonly;
-        return -1;
-    }
+    ret = 0;

-    return 0;
+ cleanup:
+    src->readonly = !readonly;
+    return ret;
 }


-- 
2.42.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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