]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: snapshot: Restrict file existence check only for local storage
authorPeter Krempa <pkrempa@redhat.com>
Mon, 12 Aug 2019 11:48:51 +0000 (13:48 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Aug 2019 11:49:17 +0000 (13:49 +0200)
Soon we'll allow more protocols and storage types with snapshots where
we in some cases can't check whether the storage already exists.
Restrict the sanity checks whether the destination images exist or not
for local storage where it's easy. For any other case we will fail
later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c

index ac235c9cc6f6ddc5dd2fcee5023f82055088a78b..31202cf7f6b12d7d5689d405948c01ceba2683f6 100644 (file)
@@ -15008,32 +15008,34 @@ qemuDomainSnapshotPrepareDiskExternal(virDomainDiskDefPtr disk,
             return -1;
     }
 
-    if (virStorageFileInit(snapdisk->src) < 0)
-        return -1;
+    if (virStorageSourceIsLocalStorage(snapdisk->src)) {
+        if (virStorageFileInit(snapdisk->src) < 0)
+            return -1;
 
-    rc = virStorageFileStat(snapdisk->src, &st);
-    err = errno;
+        rc = virStorageFileStat(snapdisk->src, &st);
+        err = errno;
 
-    virStorageFileDeinit(snapdisk->src);
+        virStorageFileDeinit(snapdisk->src);
 
-    if (rc < 0) {
-        if (err != ENOENT) {
-            virReportSystemError(err,
-                                 _("unable to stat for disk %s: %s"),
-                                 snapdisk->name, snapdisk->src->path);
-            return -1;
-        } else if (reuse) {
-            virReportSystemError(err,
-                                 _("missing existing file for disk %s: %s"),
-                                 snapdisk->name, snapdisk->src->path);
+        if (rc < 0) {
+            if (err != ENOENT) {
+                virReportSystemError(err,
+                                     _("unable to stat for disk %s: %s"),
+                                     snapdisk->name, snapdisk->src->path);
+                return -1;
+            } else if (reuse) {
+                virReportSystemError(err,
+                                     _("missing existing file for disk %s: %s"),
+                                     snapdisk->name, snapdisk->src->path);
+                return -1;
+            }
+        } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("external snapshot file for disk %s already "
+                             "exists and is not a block device: %s"),
+                           snapdisk->name, snapdisk->src->path);
             return -1;
         }
-    } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("external snapshot file for disk %s already "
-                         "exists and is not a block device: %s"),
-                       snapdisk->name, snapdisk->src->path);
-        return -1;
     }
 
     return 0;