[PATCHv6 6/8] qemu: Switch snapshot deletion to the new API functions

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

 



Use the new storage driver APIs to delete snapshot backing files in case
of failure instead of directly relying on "unlink". This will help us in
the future when we will be adding network based storage without local
representation in the host.
---

Notes:
    Version 6:
    - simplified as the storage driver now doesn't require "conn"
    
    Version 5:
    - no change, wasn't reviewed yet

 cfg.mk                 |  1 +
 src/qemu/qemu_driver.c | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 207dfeb..56d7a5b 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -764,6 +764,7 @@ sc_prohibit_cross_inclusion:
 	    cpu/ | locking/ | network/ | rpc/ | security/)		\
 	      safe="($$dir|util|conf)";;				\
 	    xenapi/ | xenxs/ ) safe="($$dir|util|conf|xen)";;		\
+	    qemu/ ) safe="($$dir|util|conf|cpu|network|locking|rpc|security|storage)";; \
 	    *) safe="($$dir|util|conf|cpu|network|locking|rpc|security)";; \
 	  esac;								\
 	  in_vc_files="^src/$$dir"					\
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index aa2e178..5199bf8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -94,6 +94,7 @@
 #include "virstring.h"
 #include "viraccessapicheck.h"
 #include "viraccessapicheckqemu.h"
+#include "storage/storage_driver.h"

 #define VIR_FROM_THIS VIR_FROM_QEMU

@@ -12648,6 +12649,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     int ret = -1;
     int fd = -1;
     bool need_unlink = false;
+    virStorageFilePtr snapfile = NULL;

     if (snap->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -12667,6 +12669,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     virStorageFileFreeMetadata(disk->backingChain);
     disk->backingChain = NULL;

+    if (!(snapfile = virStorageFileInitFromSnapshotDef(snap)))
+        goto cleanup;
+
     switch (snap->type) {
     case VIR_DOMAIN_DISK_TYPE_BLOCK:
         reuse = true;
@@ -12742,8 +12747,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     }

 cleanup:
-    if (need_unlink && unlink(source))
+    if (need_unlink && virStorageFileUnlink(snapfile))
         VIR_WARN("unable to unlink just-created %s", source);
+    virStorageFileFree(snapfile);
     VIR_FREE(device);
     VIR_FREE(source);
     VIR_FREE(persistSource);
@@ -12763,16 +12769,20 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 {
     char *source = NULL;
     char *persistSource = NULL;
+    virStorageFilePtr diskfile = NULL;
     struct stat st;

+    diskfile = virStorageFileInitFromDiskDef(disk);
+
     if (VIR_STRDUP(source, origdisk->src) < 0 ||
         (persistDisk && VIR_STRDUP(persistSource, source) < 0))
         goto cleanup;

     qemuDomainPrepareDiskChainElement(driver, vm, disk, disk->src,
                                       VIR_DISK_CHAIN_NO_ACCESS);
-    if (need_unlink && stat(disk->src, &st) == 0 &&
-        S_ISREG(st.st_mode) && unlink(disk->src) < 0)
+    if (need_unlink && diskfile &&
+        virStorageFileStat(diskfile, &st) == 0 && S_ISREG(st.st_mode) &&
+        virStorageFileUnlink(diskfile) < 0)
         VIR_WARN("Unable to remove just-created %s", disk->src);

     /* Update vm in place to match changes.  */
@@ -12790,6 +12800,7 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
     }

 cleanup:
+    virStorageFileFree(diskfile);
     VIR_FREE(source);
     VIR_FREE(persistSource);
 }
-- 
1.8.5.3

--
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]