[PATCH 1/2] storage: Don't delete Ploop volumes twice

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

 



When reinitializing Ploop volumes we also went through the rutine of the
normal wipe, effectively removing the root.hds file twice.  Since we'll
hopefully add support for other formats as well, split the function with
a switch into which we can cleanly add formats in the future.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/storage/storage_backend.c | 49 ++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 4b0b19c45ca5..eff6a2f581a1 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2245,32 +2245,19 @@ virStorageBackendVolWipePloop(virStorageVolDefPtr vol)
     return ret;
 }

-int
-virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
-                              virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
-                              virStorageVolDefPtr vol,
-                              unsigned int algorithm,
-                              unsigned int flags)
+static int
+virStorageBackendVolWipeLocalDefault(virStorageVolDefPtr vol,
+                                     unsigned int algorithm)
 {
     int ret = -1, fd = -1;
     const char *alg_char = NULL;
     struct stat st;
     virCommandPtr cmd = NULL;
-    char *path = NULL;
-    char *target_path = vol->target.path;
-
-    virCheckFlags(0, -1);

     VIR_DEBUG("Wiping volume with path '%s' and algorithm %u",
               vol->target.path, algorithm);

-    if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
-        if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
-            goto cleanup;
-        target_path = path;
-    }
-
-    fd = open(target_path, O_RDWR);
+    fd = open(vol->target.path, O_RDWR);
     if (fd == -1) {
         virReportSystemError(errno,
                              _("Failed to open storage volume with path '%s'"),
@@ -2327,7 +2314,7 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (algorithm != VIR_STORAGE_VOL_WIPE_ALG_ZERO) {
         cmd = virCommandNew(SCRUB);
         virCommandAddArgList(cmd, "-f", "-p", alg_char,
-                             target_path, NULL);
+                             vol->target.path, NULL);

         if (virCommandRun(cmd, NULL) < 0)
             goto cleanup;
@@ -2346,17 +2333,35 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
             goto cleanup;
     }

-    if (vol->target.format == VIR_STORAGE_FILE_PLOOP)
-        ret = virStorageBackendVolWipePloop(vol);
-
  cleanup:
     virCommandFree(cmd);
-    VIR_FREE(path);
     VIR_FORCE_CLOSE(fd);
     return ret;
 }


+int
+virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
+                              virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+                              virStorageVolDefPtr vol,
+                              unsigned int algorithm,
+                              unsigned int flags)
+{
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    VIR_DEBUG("Wiping volume with path '%s'", vol->target.path);
+
+    if (vol->target.format == VIR_STORAGE_FILE_PLOOP)
+        ret = virStorageBackendVolWipePloop(vol);
+    else
+        ret = virStorageBackendVolWipeLocalDefault(vol, algorithm);
+
+    return ret;
+}
+
+
 #ifdef GLUSTER_CLI
 int
 virStorageBackendFindGlusterPoolSources(const char *host,
-- 
2.9.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]