[libvirt] [PATCH] storage: dir: adapts .wipeVol for ploop volumes

Olga Krishtal okrishtal at virtuozzo.com
Mon May 16 07:19:34 UTC 2016


The modification of .volWipe callback wipes ploop volume using one of
given wiping algorithm: dod, nnsa, etc.
However, in case of ploop volume we need to reinitialize root.hds and DiskDescriptor.xml.

Signed-off-by: Olga Krishtal <okrishtal at virtuozzo.com>
---
 src/storage/storage_backend.c | 58 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 6 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index d47a76a..367a887 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2295,6 +2295,45 @@ virStorageBackendWipeLocal(virStorageVolDefPtr vol,
     return ret;
 }
 
+static int
+virStorageBackendVolWipePloop(virStorageVolDefPtr vol)
+{
+    virCommandPtr cmd = NULL;
+    char *target_path = NULL;
+    char *disk_desc = NULL;
+    int ret = -1;
+
+    if (virAsprintf(&target_path, "%s/root.hds", vol->target.path) < 0)
+        goto cleanup;
+
+    if (virAsprintf(&disk_desc, "%s/DiskDescriptor.xml", vol->target.path) < 0)
+        goto cleanup;
+
+    if (virFileRemove(disk_desc, 0, 0) < 0) {
+        virReportError(errno, _("Failed to delete DiskDescriptor.xml of volume '%s'"),
+                       vol->target.path);
+        goto cleanup;
+    }
+    if (virFileRemove(target_path, 0, 0) < 0) {
+        virReportError(errno, _("failed to delete root.hds of volume '%s'"),
+                       vol->target.path);
+        goto cleanup;
+    }
+
+    cmd = virCommandNewArgList("ploop", "init", "-s", NULL);
+
+    virCommandAddArgFormat(cmd, "%lluM", VIR_DIV_UP(vol->target.capacity,
+                                                        (1024 * 1024)));
+    virCommandAddArgList(cmd, "-t", "ext4", NULL);
+    virCommandAddArgFormat(cmd, "%s/root.hds", vol->target.path);
+    ret = virCommandRun(cmd, NULL);
+
+ cleanup:
+    VIR_FREE(disk_desc);
+    VIR_FREE(target_path);
+    virCommandFree(cmd);
+    return ret;
+}
 
 int
 virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
@@ -2307,6 +2346,8 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
     const char *alg_char = NULL;
     struct stat st;
     virCommandPtr cmd = NULL;
+    char *path = NULL;
+    char *target_path = vol->target.path;
 
     virCheckFlags(0, -1);
 
@@ -2314,12 +2355,12 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
               vol->target.path, algorithm);
 
     if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("wiping for ploop volumes is not supported"));
-        goto cleanup;
+        if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
+            goto cleanup;
+        target_path = path;
     }
 
-    fd = open(vol->target.path, O_RDWR);
+    fd = open(target_path, O_RDWR);
     if (fd == -1) {
         virReportSystemError(errno,
                              _("Failed to open storage volume with path '%s'"),
@@ -2376,13 +2417,12 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (algorithm != VIR_STORAGE_VOL_WIPE_ALG_ZERO) {
         cmd = virCommandNew(SCRUB);
         virCommandAddArgList(cmd, "-f", "-p", alg_char,
-                             vol->target.path, NULL);
+                             target_path, NULL);
 
         if (virCommandRun(cmd, NULL) < 0)
             goto cleanup;
 
         ret = 0;
-        goto cleanup;
     } else {
         if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)) {
             ret = virStorageBackendVolZeroSparseFileLocal(vol, st.st_size, fd);
@@ -2392,10 +2432,16 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
                                              vol->target.allocation,
                                              st.st_blksize);
         }
+        if (ret < 0)
+            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;
 }
-- 
1.8.3.1




More information about the libvir-list mailing list