[PATCH 5/5] qemu: blockcopy: Refactor logic checking the target storage file

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

 



Use virStorageSource accessors to check the file and call
virStorageFileAccess before even attempting to stat the target. This
will be helpful once we try to add network destinations for block copy,
since there will be no need to stat them.
---
 src/qemu/qemu_driver.c | 53 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5beb14e64..f93c5cb21 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16693,36 +16693,49 @@ qemuDomainBlockCopyValidateMirror(virStorageSourcePtr mirror,
     int desttype = virStorageSourceGetActualType(mirror);
     struct stat st;

-    if (stat(mirror->path, &st) < 0) {
+    if (virStorageFileAccess(mirror, F_OK) < 0) {
         if (errno != ENOENT) {
-            virReportSystemError(errno, _("unable to stat for disk %s: %s"),
-                                 dst, mirror->path);
+            virReportSystemError(errno, "%s",
+                                 _("unable to verify existance of "
+                                   "block copy target"));
             return -1;
-        } else if (*reuse || desttype == VIR_STORAGE_TYPE_BLOCK) {
+        }
+
+        if (*reuse || desttype == VIR_STORAGE_TYPE_BLOCK) {
             virReportSystemError(errno,
                                  _("missing destination file for disk %s: %s"),
                                  dst, mirror->path);
             return -1;
         }
-    } else if (!S_ISBLK(st.st_mode)) {
-        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"),
-                           dst, mirror->path);
+    } else {
+        if (virStorageFileStat(mirror, &st) < 0) {
+            virReportSystemError(errno,
+                                 _("unable to stat block copy target '%s'"),
+                                 mirror->path);
             return -1;
         }
-        if (desttype == VIR_STORAGE_TYPE_BLOCK) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("blockdev flag requested for disk %s, but file "
-                             "'%s' is not a block device"),
-                           dst, mirror->path);
-            return -1;
+
+        if (S_ISBLK(st.st_mode)) {
+            /* if the target is a block device, assume that we are reusing it,
+             * so there are no attempts to create it */
+            *reuse = true;
+        } else {
+            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"),
+                               dst, mirror->path);
+                return -1;
+            }
+
+            if (desttype == VIR_STORAGE_TYPE_BLOCK) {
+                virReportError(VIR_ERR_INVALID_ARG,
+                               _("blockdev flag requested for disk %s, but file "
+                                 "'%s' is not a block device"),
+                               dst, mirror->path);
+                return -1;
+            }
         }
-    } else {
-        /* if the target is a block device, assume that we are reusing it, so
-         * there are no attempts to create it */
-        *reuse = true;
     }

     return 0;
-- 
2.12.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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