提交 34872ca4 编写于 作者: W Wido den Hollander 提交者: John Ferlan

rbd: Add support for wiping RBD volumes using TRIM.

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: NWido den Hollander <wido@widodh.nl>
上级 63cdc92f
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册