[PATCH 1/6] storage: Move virStorageBackendDiskDeleteVol

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

 



Move the API to before virStorageBackendDiskCreateVol in order to be
able to call the DeleteVol API when virStorageBackendDiskReadPartitions
fails so that we don't by chance leave a partition on the disk.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_backend_disk.c | 137 +++++++++++++++++++------------------
 1 file changed, 69 insertions(+), 68 deletions(-)

diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 3f97fd9..60f8393 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -640,6 +640,75 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool,
 
 
 static int
+virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
+                               virStoragePoolObjPtr pool,
+                               virStorageVolDefPtr vol,
+                               unsigned int flags)
+{
+    char *part_num = NULL;
+    char *devpath = NULL;
+    char *dev_name, *srcname;
+    virCommandPtr cmd = NULL;
+    bool isDevMapperDevice;
+    int rc = -1;
+
+    virCheckFlags(0, -1);
+
+    if (virFileResolveLink(vol->target.path, &devpath) < 0) {
+        virReportSystemError(errno,
+                             _("Couldn't read volume target path '%s'"),
+                             vol->target.path);
+        goto cleanup;
+    }
+
+    dev_name = last_component(devpath);
+    srcname = last_component(pool->def->source.devices[0].path);
+    VIR_DEBUG("dev_name=%s, srcname=%s", dev_name, srcname);
+
+    isDevMapperDevice = virIsDevMapperDevice(devpath);
+
+    if (!isDevMapperDevice && !STRPREFIX(dev_name, srcname)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Volume path '%s' did not start with parent "
+                         "pool source device name."), dev_name);
+        goto cleanup;
+    }
+
+    if (!isDevMapperDevice) {
+        part_num = dev_name + strlen(srcname);
+
+        if (*part_num == 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("cannot parse partition number from target "
+                             "'%s'"), dev_name);
+            goto cleanup;
+        }
+
+        /* eg parted /dev/sda rm 2 */
+        cmd = virCommandNewArgList(PARTED,
+                                   pool->def->source.devices[0].path,
+                                   "rm",
+                                   "--script",
+                                   part_num,
+                                   NULL);
+        if (virCommandRun(cmd, NULL) < 0)
+            goto cleanup;
+    } else {
+        cmd = virCommandNewArgList(DMSETUP, "remove", "--force", devpath, NULL);
+
+        if (virCommandRun(cmd, NULL) < 0)
+            goto cleanup;
+    }
+
+    rc = 0;
+ cleanup:
+    VIR_FREE(devpath);
+    virCommandFree(cmd);
+    return rc;
+}
+
+
+static int
 virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                                virStoragePoolObjPtr pool,
                                virStorageVolDefPtr vol)
@@ -714,74 +783,6 @@ virStorageBackendDiskBuildVolFrom(virConnectPtr conn,
     return build_func(conn, pool, vol, inputvol, flags);
 }
 
-static int
-virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
-                               virStoragePoolObjPtr pool,
-                               virStorageVolDefPtr vol,
-                               unsigned int flags)
-{
-    char *part_num = NULL;
-    char *devpath = NULL;
-    char *dev_name, *srcname;
-    virCommandPtr cmd = NULL;
-    bool isDevMapperDevice;
-    int rc = -1;
-
-    virCheckFlags(0, -1);
-
-    if (virFileResolveLink(vol->target.path, &devpath) < 0) {
-        virReportSystemError(errno,
-                             _("Couldn't read volume target path '%s'"),
-                             vol->target.path);
-        goto cleanup;
-    }
-
-    dev_name = last_component(devpath);
-    srcname = last_component(pool->def->source.devices[0].path);
-    VIR_DEBUG("dev_name=%s, srcname=%s", dev_name, srcname);
-
-    isDevMapperDevice = virIsDevMapperDevice(devpath);
-
-    if (!isDevMapperDevice && !STRPREFIX(dev_name, srcname)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Volume path '%s' did not start with parent "
-                         "pool source device name."), dev_name);
-        goto cleanup;
-    }
-
-    if (!isDevMapperDevice) {
-        part_num = dev_name + strlen(srcname);
-
-        if (*part_num == 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("cannot parse partition number from target "
-                             "'%s'"), dev_name);
-            goto cleanup;
-        }
-
-        /* eg parted /dev/sda rm 2 */
-        cmd = virCommandNewArgList(PARTED,
-                                   pool->def->source.devices[0].path,
-                                   "rm",
-                                   "--script",
-                                   part_num,
-                                   NULL);
-        if (virCommandRun(cmd, NULL) < 0)
-            goto cleanup;
-    } else {
-        cmd = virCommandNewArgList(DMSETUP, "remove", "--force", devpath, NULL);
-
-        if (virCommandRun(cmd, NULL) < 0)
-            goto cleanup;
-    }
-
-    rc = 0;
- cleanup:
-    VIR_FREE(devpath);
-    virCommandFree(cmd);
-    return rc;
-}
-
 
 virStorageBackend virStorageBackendDisk = {
     .type = VIR_STORAGE_POOL_DISK,
-- 
2.1.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]