[libvirt] [PATCH 04/10] qemu: snapshot: Restrict file existance check only for local storage

Peter Krempa posted 10 patches 6 years, 5 months ago
There is a newer version of this series
[libvirt] [PATCH 04/10] qemu: snapshot: Restrict file existance check only for local storage
Posted by Peter Krempa 6 years, 5 months ago
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>
---
 src/qemu/qemu_driver.c | 44 ++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 29a47af0a2..52540eb77d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15022,32 +15022,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;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/10] qemu: snapshot: Restrict file existance check only for local storage
Posted by Ján Tomko 6 years, 5 months ago
s/existance/existence/
in the commit summary

On Fri, Aug 16, 2019 at 03:54:38PM +0200, Peter Krempa wrote:
>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>
>---
> src/qemu/qemu_driver.c | 44 ++++++++++++++++++++++--------------------
> 1 file changed, 23 insertions(+), 21 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

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