render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c401cc
From 52badc03dfe80a80996d6dfb98ba18d65333f346 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <52badc03dfe80a80996d6dfb98ba18d65333f346@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:55:28 +0100
c401cc
Subject: [PATCH] qemu: Switch snapshot deletion to the new API functions
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
Use the new storage driver APIs to delete snapshot backing files in case
c401cc
of failure instead of directly relying on "unlink". This will help us in
c401cc
the future when we will be adding network based storage without local
c401cc
representation in the host.
c401cc
c401cc
(cherry picked from commit 8f4091d6771069324e60c8708881b76de8a8ab8a)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 cfg.mk                 |  1 +
c401cc
 src/qemu/qemu_driver.c | 17 ++++++++++++++---
c401cc
 2 files changed, 15 insertions(+), 3 deletions(-)
c401cc
c401cc
diff --git a/cfg.mk b/cfg.mk
c401cc
index f2cd411..cfbdc30 100644
c401cc
--- a/cfg.mk
c401cc
+++ b/cfg.mk
c401cc
@@ -749,6 +749,7 @@ sc_prohibit_cross_inclusion:
c401cc
 	    cpu/ | locking/ | network/ | rpc/ | security/)		\
c401cc
 	      safe="($$dir|util|conf)";;				\
c401cc
 	    xenapi/ | xenxs/ ) safe="($$dir|util|conf|xen)";;		\
c401cc
+	    qemu/ ) safe="($$dir|util|conf|cpu|network|locking|rpc|security|storage)";; \
c401cc
 	    *) safe="($$dir|util|conf|cpu|network|locking|rpc|security)";; \
c401cc
 	  esac;								\
c401cc
 	  in_vc_files="^src/$$dir"					\
c401cc
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
c401cc
index a1145a2..a91b06d 100644
c401cc
--- a/src/qemu/qemu_driver.c
c401cc
+++ b/src/qemu/qemu_driver.c
c401cc
@@ -94,6 +94,7 @@
c401cc
 #include "virstring.h"
c401cc
 #include "viraccessapicheck.h"
c401cc
 #include "viraccessapicheckqemu.h"
c401cc
+#include "storage/storage_driver.h"
c401cc
 
c401cc
 #define VIR_FROM_THIS VIR_FROM_QEMU
c401cc
 
c401cc
@@ -12521,6 +12522,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
c401cc
     int ret = -1;
c401cc
     int fd = -1;
c401cc
     bool need_unlink = false;
c401cc
+    virStorageFilePtr snapfile = NULL;
c401cc
 
c401cc
     if (snap->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
c401cc
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
c401cc
@@ -12540,6 +12542,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
c401cc
     virStorageFileFreeMetadata(disk->backingChain);
c401cc
     disk->backingChain = NULL;
c401cc
 
c401cc
+    if (!(snapfile = virStorageFileInitFromSnapshotDef(snap)))
c401cc
+        goto cleanup;
c401cc
+
c401cc
     switch (snap->type) {
c401cc
     case VIR_DOMAIN_DISK_TYPE_BLOCK:
c401cc
         reuse = true;
c401cc
@@ -12615,8 +12620,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
c401cc
     }
c401cc
 
c401cc
 cleanup:
c401cc
-    if (need_unlink && unlink(source))
c401cc
+    if (need_unlink && virStorageFileUnlink(snapfile))
c401cc
         VIR_WARN("unable to unlink just-created %s", source);
c401cc
+    virStorageFileFree(snapfile);
c401cc
     VIR_FREE(device);
c401cc
     VIR_FREE(source);
c401cc
     VIR_FREE(persistSource);
c401cc
@@ -12636,16 +12642,20 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
c401cc
 {
c401cc
     char *source = NULL;
c401cc
     char *persistSource = NULL;
c401cc
+    virStorageFilePtr diskfile = NULL;
c401cc
     struct stat st;
c401cc
 
c401cc
+    diskfile = virStorageFileInitFromDiskDef(disk);
c401cc
+
c401cc
     if (VIR_STRDUP(source, origdisk->src) < 0 ||
c401cc
         (persistDisk && VIR_STRDUP(persistSource, source) < 0))
c401cc
         goto cleanup;
c401cc
 
c401cc
     qemuDomainPrepareDiskChainElement(driver, vm, disk, disk->src,
c401cc
                                       VIR_DISK_CHAIN_NO_ACCESS);
c401cc
-    if (need_unlink && stat(disk->src, &st) == 0 &&
c401cc
-        S_ISREG(st.st_mode) && unlink(disk->src) < 0)
c401cc
+    if (need_unlink && diskfile &&
c401cc
+        virStorageFileStat(diskfile, &st) == 0 && S_ISREG(st.st_mode) &&
c401cc
+        virStorageFileUnlink(diskfile) < 0)
c401cc
         VIR_WARN("Unable to remove just-created %s", disk->src);
c401cc
 
c401cc
     /* Update vm in place to match changes.  */
c401cc
@@ -12663,6 +12673,7 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
c401cc
     }
c401cc
 
c401cc
 cleanup:
c401cc
+    virStorageFileFree(diskfile);
c401cc
     VIR_FREE(source);
c401cc
     VIR_FREE(persistSource);
c401cc
 }
c401cc
-- 
c401cc
1.9.0
c401cc