Blame SOURCES/libvirt-qemu-snapshot-Use-new-APIs-to-detect-presence-of-existing-storage-files.patch

c401cc
From b2d5a99d66da041feddf6498d90cb12e44702b28 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <b2d5a99d66da041feddf6498d90cb12e44702b28@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:55:29 +0100
c401cc
Subject: [PATCH] qemu: snapshot: Use new APIs to detect presence of existing
c401cc
 storage files
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
Use the new storage driver based "stat" api to detect exiting files just
c401cc
as we did with local files.
c401cc
c401cc
(cherry picked from commit 7183d7d2e80b45ef0b9c3d352f0e3faf63c301a4)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/qemu/qemu_driver.c | 58 ++++++++++++++++++++++----------------------------
c401cc
 1 file changed, 26 insertions(+), 32 deletions(-)
c401cc
c401cc
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
c401cc
index a91b06d..86f2775 100644
c401cc
--- a/src/qemu/qemu_driver.c
c401cc
+++ b/src/qemu/qemu_driver.c
c401cc
@@ -12245,7 +12245,6 @@ qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr
c401cc
 }
c401cc
 
c401cc
 
c401cc
-
c401cc
 static int
c401cc
 qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
c401cc
                                       virDomainDiskDefPtr disk,
c401cc
@@ -12253,7 +12252,8 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
c401cc
                                       bool active,
c401cc
                                       bool reuse)
c401cc
 {
c401cc
-    int actualType;
c401cc
+    virStorageFilePtr snapfile = NULL;
c401cc
+    int ret = -1;
c401cc
     struct stat st;
c401cc
 
c401cc
     if (qemuTranslateSnapshotDiskSourcePool(conn, snapdisk) < 0)
c401cc
@@ -12276,40 +12276,34 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
c401cc
             return -1;
c401cc
     }
c401cc
 
c401cc
-    actualType = virDomainSnapshotDiskGetActualType(snapdisk);
c401cc
+    if (!(snapfile = virStorageFileInitFromSnapshotDef(snapdisk)))
c401cc
+        return -1;
c401cc
 
c401cc
-    switch ((enum virDomainDiskType) actualType) {
c401cc
-    case VIR_DOMAIN_DISK_TYPE_BLOCK:
c401cc
-    case VIR_DOMAIN_DISK_TYPE_FILE:
c401cc
-        if (stat(snapdisk->file, &st) < 0) {
c401cc
-            if (errno != ENOENT) {
c401cc
-                virReportSystemError(errno,
c401cc
-                                     _("unable to stat for disk %s: %s"),
c401cc
-                                     snapdisk->name, snapdisk->file);
c401cc
-                return -1;
c401cc
-            } else if (reuse) {
c401cc
-                virReportSystemError(errno,
c401cc
-                                     _("missing existing file for disk %s: %s"),
c401cc
-                                     snapdisk->name, snapdisk->file);
c401cc
-                return -1;
c401cc
-            }
c401cc
-        } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
c401cc
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c401cc
-                           _("external snapshot file for disk %s already "
c401cc
-                             "exists and is not a block device: %s"),
c401cc
-                           snapdisk->name, snapdisk->file);
c401cc
-            return -1;
c401cc
+    if (virStorageFileStat(snapfile, &st) < 0) {
c401cc
+        if (errno != ENOENT) {
c401cc
+            virReportSystemError(errno,
c401cc
+                                 _("unable to stat for disk %s: %s"),
c401cc
+                                 snapdisk->name, snapdisk->file);
c401cc
+            goto cleanup;
c401cc
+        } else if (reuse) {
c401cc
+            virReportSystemError(errno,
c401cc
+                                 _("missing existing file for disk %s: %s"),
c401cc
+                                 snapdisk->name, snapdisk->file);
c401cc
+            goto cleanup;
c401cc
         }
c401cc
-        break;
c401cc
-
c401cc
-    case VIR_DOMAIN_DISK_TYPE_NETWORK:
c401cc
-    case VIR_DOMAIN_DISK_TYPE_DIR:
c401cc
-    case VIR_DOMAIN_DISK_TYPE_VOLUME:
c401cc
-    case VIR_DOMAIN_DISK_TYPE_LAST:
c401cc
-        break;
c401cc
+    } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
c401cc
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c401cc
+                       _("external snapshot file for disk %s already "
c401cc
+                         "exists and is not a block device: %s"),
c401cc
+                       snapdisk->name, snapdisk->file);
c401cc
+        goto cleanup;
c401cc
     }
c401cc
 
c401cc
-    return 0;
c401cc
+    ret = 0;
c401cc
+
c401cc
+cleanup:
c401cc
+    virStorageFileFree(snapfile);
c401cc
+    return ret;
c401cc
 }
c401cc
 
c401cc
 
c401cc
-- 
c401cc
1.9.0
c401cc