]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Support deletion of volumes on gluster pools
authorPeter Krempa <pkrempa@redhat.com>
Wed, 11 Dec 2013 10:38:28 +0000 (11:38 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 16 Jan 2014 10:39:53 +0000 (11:39 +0100)
Implement the "deleteVol" storage backend function for gluster volumes.

src/storage/storage_backend_gluster.c

index 2ec2424f88f1d5bcc32180f0e3852fcdd77c89c4..c73cf8a833710c85607538826b90da34c1565197 100644 (file)
@@ -382,8 +382,72 @@ cleanup:
     return ret;
 }
 
+
+static int
+virStorageBackendGlusterVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                  virStoragePoolObjPtr pool,
+                                  virStorageVolDefPtr vol,
+                                  unsigned int flags)
+{
+    virStorageBackendGlusterStatePtr state = NULL;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    switch ((virStorageVolType) vol->type) {
+    case VIR_STORAGE_VOL_FILE:
+    case VIR_STORAGE_VOL_DIR:
+    case VIR_STORAGE_VOL_BLOCK:
+    case VIR_STORAGE_VOL_LAST:
+        virReportError(VIR_ERR_NO_SUPPORT,
+                       _("removing of '%s' volumes is not supported "
+                         "by the gluster backend: %s"),
+                       virStorageVolTypeToString(vol->type),
+                       vol->target.path);
+        goto cleanup;
+        break;
+
+    case VIR_STORAGE_VOL_NETWORK:
+        if (!(state = virStorageBackendGlusterOpen(pool)))
+            goto cleanup;
+
+        if (glfs_unlink(state->vol, vol->name) < 0) {
+            if (errno != ENOENT) {
+                virReportSystemError(errno,
+                                     _("cannot remove gluster volume file '%s'"),
+                                     vol->target.path);
+                goto cleanup;
+            }
+        }
+        break;
+
+    case VIR_STORAGE_VOL_NETDIR:
+        if (!(state = virStorageBackendGlusterOpen(pool)))
+            goto cleanup;
+
+        if (glfs_rmdir(state->vol, vol->target.path) < 0) {
+            if (errno != ENOENT) {
+                virReportSystemError(errno,
+                                     _("cannot remove gluster volume dir '%s'"),
+                                     vol->target.path);
+                goto cleanup;
+            }
+        }
+        break;
+    }
+
+    ret = 0;
+
+cleanup:
+    virStorageBackendGlusterClose(state);
+    return ret;
+}
+
+
 virStorageBackend virStorageBackendGluster = {
     .type = VIR_STORAGE_POOL_GLUSTER,
 
     .refreshPool = virStorageBackendGlusterRefreshPool,
+
+    .deleteVol = virStorageBackendGlusterVolDelete,
 };