[PATCH 4/5] rbd: Add support for wiping RBD volumes using TRIM.

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

 



Using VIR_STORAGE_VOL_WIPE_ALG_TRIM a RBD volume can be trimmed down
to 0 bytes using rbd_dicard()

Effectively all the data on the volume will be lost/gone, but the volume
remains available for use afterwards.

Starting at offset 0 the storage pool will call rbd_discard() in stripe
size * count increments which is usually 4MB. Stripe size being 4MB and
count 1.

rbd_discard() is available since Ceph version Dumpling (0.67) which dates
back to August 2013.

Signed-off-by: Wido den Hollander <wido@xxxxxxxxx>
---
 src/storage/storage_backend_rbd.c | 42 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 7e669ff..8a95388 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -772,6 +772,41 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image,
 }
 
 static int
+virStorageBackendRBDVolWipeDiscard(rbd_image_t image,
+                                   char *imgname,
+                                   rbd_image_info_t info,
+                                   uint64_t stripe_count)
+{
+    int r = -1;
+    int ret = -1;
+    uint64_t offset = 0;
+    uint64_t length;
+
+    VIR_DEBUG("Wiping RBD %s volume using discard)", imgname);
+
+    while (offset < info.size) {
+        length = MIN((info.size - offset), (info.obj_size * stripe_count));
+
+        if ((r = rbd_discard(image, offset, length)) < 0) {
+            virReportSystemError(-r, _("discarding %zu bytes failed on "
+                                       "RBD image %s at offset %zu"),
+                                     length, imgname, offset);
+            goto cleanup;
+        }
+
+        VIR_DEBUG("Discarded %zu bytes of RBD image %s at offset %zu",
+                  length, imgname, offset);
+
+        offset += length;
+    }
+
+    ret = 0;
+
+ cleanup:
+    return ret;
+}
+
+static int
 virStorageBackendRBDVolWipe(virConnectPtr conn,
                             virStoragePoolObjPtr pool,
                             virStorageVolDefPtr vol,
@@ -787,7 +822,8 @@ virStorageBackendRBDVolWipe(virConnectPtr conn,
     int r = -1;
     int ret = -1;
 
-    virCheckFlags(VIR_STORAGE_VOL_WIPE_ALG_ZERO, -1);
+    virCheckFlags(VIR_STORAGE_VOL_WIPE_ALG_ZERO |
+                  VIR_STORAGE_VOL_WIPE_ALG_TRIM, -1);
 
     VIR_DEBUG("Wiping RBD image %s/%s", pool->def->source.name, vol->name);
 
@@ -823,6 +859,10 @@ virStorageBackendRBDVolWipe(virConnectPtr conn,
             r = virStorageBackendRBDVolWipeZero(image, vol->name,
                                                 info, stripe_count);
             break;
+        case VIR_STORAGE_VOL_WIPE_ALG_TRIM:
+            r = virStorageBackendRBDVolWipeDiscard(image, vol->name,
+                                                   info, stripe_count);
+            break;
         default:
             virReportError(VIR_ERR_INVALID_ARG, _("unsupported algorithm %d"),
                            algorithm);
-- 
1.9.1

--
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]