]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: driver: Split out access to VIR_DOMAIN_BLOCK_COPY_REUSE_EXT
authorPeter Krempa <pkrempa@redhat.com>
Tue, 11 Jul 2017 06:20:55 +0000 (08:20 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 20 Jul 2017 08:07:48 +0000 (10:07 +0200)
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

index 8d261b7257ef06c02c61369031728bd702df14e5..eb02bb3633e091945613540ec9a7fcbb200848ed 100644 (file)
@@ -16708,6 +16708,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 |
@@ -16768,8 +16769,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 "
@@ -16790,15 +16790,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"),
@@ -16815,7 +16814,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
@@ -16828,7 +16827,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);