render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From b2d5a99d66da041feddf6498d90cb12e44702b28 Mon Sep 17 00:00:00 2001
Message-Id: <b2d5a99d66da041feddf6498d90cb12e44702b28@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:55:29 +0100
Subject: [PATCH] qemu: snapshot: Use new APIs to detect presence of existing
 storage files

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

Use the new storage driver based "stat" api to detect exiting files just
as we did with local files.

(cherry picked from commit 7183d7d2e80b45ef0b9c3d352f0e3faf63c301a4)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_driver.c | 58 ++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a91b06d..86f2775 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12245,7 +12245,6 @@ qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr
 }
 
 
-
 static int
 qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
                                       virDomainDiskDefPtr disk,
@@ -12253,7 +12252,8 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
                                       bool active,
                                       bool reuse)
 {
-    int actualType;
+    virStorageFilePtr snapfile = NULL;
+    int ret = -1;
     struct stat st;
 
     if (qemuTranslateSnapshotDiskSourcePool(conn, snapdisk) < 0)
@@ -12276,40 +12276,34 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
             return -1;
     }
 
-    actualType = virDomainSnapshotDiskGetActualType(snapdisk);
+    if (!(snapfile = virStorageFileInitFromSnapshotDef(snapdisk)))
+        return -1;
 
-    switch ((enum virDomainDiskType) actualType) {
-    case VIR_DOMAIN_DISK_TYPE_BLOCK:
-    case VIR_DOMAIN_DISK_TYPE_FILE:
-        if (stat(snapdisk->file, &st) < 0) {
-            if (errno != ENOENT) {
-                virReportSystemError(errno,
-                                     _("unable to stat for disk %s: %s"),
-                                     snapdisk->name, snapdisk->file);
-                return -1;
-            } else if (reuse) {
-                virReportSystemError(errno,
-                                     _("missing existing file for disk %s: %s"),
-                                     snapdisk->name, snapdisk->file);
-                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->file);
-            return -1;
+    if (virStorageFileStat(snapfile, &st) < 0) {
+        if (errno != ENOENT) {
+            virReportSystemError(errno,
+                                 _("unable to stat for disk %s: %s"),
+                                 snapdisk->name, snapdisk->file);
+            goto cleanup;
+        } else if (reuse) {
+            virReportSystemError(errno,
+                                 _("missing existing file for disk %s: %s"),
+                                 snapdisk->name, snapdisk->file);
+            goto cleanup;
         }
-        break;
-
-    case VIR_DOMAIN_DISK_TYPE_NETWORK:
-    case VIR_DOMAIN_DISK_TYPE_DIR:
-    case VIR_DOMAIN_DISK_TYPE_VOLUME:
-    case VIR_DOMAIN_DISK_TYPE_LAST:
-        break;
+    } 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->file);
+        goto cleanup;
     }
 
-    return 0;
+    ret = 0;
+
+cleanup:
+    virStorageFileFree(snapfile);
+    return ret;
 }
 
 
-- 
1.9.0