[libvirt] [PATCH 1/5] qemu: driver: Split out access to VIR_DOMAIN_BLOCK_COPY_REUSE_EXT

Peter Krempa pkrempa at redhat.com
Tue Jul 11 15:46:38 UTC 2017


Extract the presence of the flag into a boolean to simplify conditions
and allow further manipulation of the state of the flag.
---
 src/qemu/qemu_driver.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a7019c53c..d03a9dbc3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16709,6 +16709,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
     const char *format = NULL;
     int desttype = virStorageSourceGetActualType(mirror);
     virErrorPtr monitor_error = NULL;
+    bool reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);

     /* Preliminaries: find the disk we are editing, sanity checks */
     virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW |
@@ -16769,8 +16770,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,

     /* unless the user provides a pre-created file, shallow copy into a raw
      * file is not possible */
-    if ((flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW) &&
-        !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT) &&
+    if ((flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW) && !reuse &&
         mirror->format == VIR_STORAGE_FILE_RAW) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("shallow copy of disk '%s' into a raw file "
@@ -16791,15 +16791,14 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
             virReportSystemError(errno, _("unable to stat for disk %s: %s"),
                                  disk->dst, mirror->path);
             goto endjob;
-        } else if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT ||
-                   desttype == VIR_STORAGE_TYPE_BLOCK) {
+        } else if (reuse || desttype == VIR_STORAGE_TYPE_BLOCK) {
             virReportSystemError(errno,
                                  _("missing destination file for disk %s: %s"),
                                  disk->dst, mirror->path);
             goto endjob;
         }
     } else if (!S_ISBLK(st.st_mode)) {
-        if (st.st_size && !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
+        if (st.st_size && !reuse) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("external destination file for disk %s already "
                              "exists and is not a block device: %s"),
@@ -16816,7 +16815,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
     }

     if (!mirror->format) {
-        if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
+        if (!reuse) {
             mirror->format = disk->src->format;
         } else {
             /* If the user passed the REUSE_EXT flag, then either they
@@ -16829,7 +16828,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
     }

     /* pre-create the image file */
-    if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
+    if (!reuse) {
         int fd = qemuOpenFile(driver, vm, mirror->path,
                               O_WRONLY | O_TRUNC | O_CREAT,
                               &need_unlink, NULL);
-- 
2.12.2




More information about the libvir-list mailing list