]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix directory removal in filesystem storage driver
authorSascha Peilicke <saschpe@suse.de>
Wed, 11 Jul 2012 15:34:58 +0000 (16:34 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 11 Jul 2012 15:42:06 +0000 (16:42 +0100)
Fix the virStorageBackendFileSystemVolDelete method to not use
unlink() unconditionally. It must use rmdir() for volumes which
are directories. It should also raise an error if given a volume
which has the network/block type.

AUTHORS
src/storage/storage_backend_fs.c

diff --git a/AUTHORS b/AUTHORS
index 64276aaa99e4a8600d17db9a877ba3b63cdd9a23..7eaeb26d47ede3341b409dff93f6627f0f4ba577 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -247,6 +247,7 @@ Patches have also been contributed by:
   Viktor Mihajlovski   <mihajlov@linux.vnet.ibm.com>
   Thang Pham           <thang.pham@us.ibm.com>
   Eiichi Tsukata       <eiichi.tsukata.xh@hitachi.com>
+  Sascha Peilicke      <saschpe@suse.de>
 
   [....send patches to get your name here....]
 
index 4894994649e80aa25cd77c20b5891d3e1be2c956..451841bd2930988f64b6f139ff5b0f9987d43cb0 100644 (file)
@@ -1127,7 +1127,7 @@ virStorageBackendFileSystemVolBuildFrom(virConnectPtr conn,
 }
 
 /**
- * Remove a volume - just unlinks for now
+ * Remove a volume - no support for BLOCK and NETWORK yet
  */
 static int
 virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
@@ -1137,14 +1137,33 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
 {
     virCheckFlags(0, -1);
 
-    if (unlink(vol->target.path) < 0) {
-        /* Silently ignore failures where the vol has already gone away */
-        if (errno != ENOENT) {
+    switch (vol->type) {
+    case VIR_STORAGE_VOL_FILE:
+        if (unlink(vol->target.path) < 0) {
+            /* Silently ignore failures where the vol has already gone away */
+            if (errno != ENOENT) {
+                virReportSystemError(errno,
+                                     _("cannot unlink file '%s'"),
+                                     vol->target.path);
+                return -1;
+            }
+        }
+        break;
+    case VIR_STORAGE_VOL_DIR:
+        if (rmdir(vol->target.path) < 0) {
             virReportSystemError(errno,
-                                 _("cannot unlink file '%s'"),
+                                 _("cannot remove directory '%s'"),
                                  vol->target.path);
             return -1;
         }
+        break;
+    case VIR_STORAGE_VOL_BLOCK:
+    case VIR_STORAGE_VOL_NETWORK:
+    default:
+        virStorageReportError(VIR_ERR_NO_SUPPORT,
+                              _("removing block or network volumes is not supported: %s"),
+                              vol->target.path);
+        return -1;
     }
     return 0;
 }