]> xenbits.xensource.com Git - libvirt.git/commitdiff
rbd: Add support for wiping RBD volumes using TRIM.
authorWido den Hollander <wido@widodh.nl>
Wed, 27 Jan 2016 10:20:08 +0000 (11:20 +0100)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 29 Jan 2016 16:11:32 +0000 (11:11 -0500)
Using VIR_STORAGE_VOL_WIPE_ALG_TRIM a RBD volume can be trimmed down
to 0 bytes using rbd_discard()

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@widodh.nl>
src/storage/storage_backend_rbd.c

index 8a3efe9f9d969ece37898f44ae4b40295a30fb72..58090cb8fb6aeceefad9454a43808cf3d061564b 100644 (file)
@@ -771,6 +771,41 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image,
     return ret;
 }
 
+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,
@@ -822,6 +857,10 @@ virStorageBackendRBDVolWipe(virConnectPtr conn,
     case VIR_STORAGE_VOL_WIPE_ALG_ZERO:
         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;
     case VIR_STORAGE_VOL_WIPE_ALG_NNSA:
     case VIR_STORAGE_VOL_WIPE_ALG_DOD:
@@ -831,7 +870,6 @@ virStorageBackendRBDVolWipe(virConnectPtr conn,
     case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7:
     case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33:
     case VIR_STORAGE_VOL_WIPE_ALG_RANDOM:
-    case VIR_STORAGE_VOL_WIPE_ALG_TRIM:
     case VIR_STORAGE_VOL_WIPE_ALG_LAST:
         virReportError(VIR_ERR_INVALID_ARG, _("unsupported algorithm %d"),
                        algorithm);