[libvirt] [PATCH] Implement vol delete for disk pools

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

 



The patch below implements virStorageVolDelete for volumes
on a disk pool.

The only interesting thing here is that parted wants a
partition number to delete, so we need to peel off the
end of the volume's target path which will be of the form
'/dev/sda1' or similar (I assume. If not, it's still
better than having nothing implemented).

Thanks,
Cole
diff --git a/src/storage_backend_disk.c b/src/storage_backend_disk.c
index dac827b..28e0a52 100644
--- a/src/storage_backend_disk.c
+++ b/src/storage_backend_disk.c
@@ -22,11 +22,13 @@
  */
 
 #include <config.h>
+#include <string.h>
 
 #include "internal.h"
 #include "storage_backend_disk.h"
 #include "util.h"
 #include "memory.h"
+#include "c-ctype.h"
 
 enum {
     VIR_STORAGE_POOL_DISK_DOS = 0,
@@ -416,13 +418,6 @@ virStorageBackendDiskBuildPool(virConnectPtr conn,
     return 0;
 }
 
-
-static int
-virStorageBackendDiskDeleteVol(virConnectPtr conn,
-                               virStoragePoolObjPtr pool,
-                               virStorageVolDefPtr vol,
-                               unsigned int flags);
-
 static int
 virStorageBackendDiskCreateVol(virConnectPtr conn,
                                virStoragePoolObjPtr pool,
@@ -486,14 +481,41 @@ virStorageBackendDiskCreateVol(virConnectPtr conn,
 
 static int
 virStorageBackendDiskDeleteVol(virConnectPtr conn,
-                               virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
-                               virStorageVolDefPtr vol ATTRIBUTE_UNUSED,
+                               virStoragePoolObjPtr pool,
+                               virStorageVolDefPtr vol,
                                unsigned int flags ATTRIBUTE_UNUSED)
 {
-    /* delete a partition */
-    virStorageReportError(conn, VIR_ERR_NO_SUPPORT,
-                          _("Disk pools are not yet supported"));
-    return -1;
+    char *part_num = NULL;
+    int i;
+
+    /* Strip target path (ex. '/dev/sda1') of its partition number */
+    for (i = (strlen(vol->target.path)-1); i >= 0; --i) {
+        if (!c_isdigit(vol->target.path[i]))
+            break;
+        part_num = &(vol->target.path[i]);
+    }
+
+    if (!part_num) {
+        virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                              _("cannot parse partition number from target "
+                                "path '%s'"), vol->target.path);
+        return -1;
+    }
+
+    /* eg parted /dev/sda rm 2 */
+    const char *prog[] = {
+        PARTED,
+        pool->def->source.devices[0].path,
+        "rm",
+        "--script",
+        part_num,
+        NULL,
+    };
+
+    if (virRun(conn, prog, NULL) < 0)
+        return -1;
+
+    return 0;
 }
 
 
--
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]