From 981a96931ce5ed5f67e0c4cdc3b0e2c0a71e2b24 Mon Sep 17 00:00:00 2001 From: Dmitry Savitskiy Date: Wed, 24 Jul 2024 23:40:34 +0400 Subject: [PATCH] blobstore: allow to disable cluster release on unmap Signed-off-by: Dmitry Savitskiy --- include/spdk/blob.h | 8 ++++++++ lib/blob/blobstore.c | 28 +++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/spdk/blob.h b/include/spdk/blob.h index 134a11577bc..2b6f49ac046 100644 --- a/include/spdk/blob.h +++ b/include/spdk/blob.h @@ -1312,6 +1312,14 @@ int spdk_blob_get_cluster_bitmap(struct spdk_blob *blob, spdk_blob_cluster_bitmap_complete cb_fn, void *cb_arg); +/** + * Enables or disables globally cluster release on unmap. + * + * \param is_enabled If true, cluster release on unmap is enabled. + */ +void +spdk_blob_enable_cluster_unmap(bool is_enabled); + #ifdef __cplusplus } #endif diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 1f7a971e8d5..8190e18c301 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -25,6 +25,8 @@ #define BLOB_CRC32C_INITIAL 0xffffffffUL +static bool g_cluster_unmap_enabled = true; + static int bs_register_md_thread(struct spdk_blob_store *bs); static int bs_unregister_md_thread(struct spdk_blob_store *bs); static void blob_close_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno); @@ -3292,7 +3294,7 @@ blob_request_submit_op_single(struct spdk_io_channel *_ch, struct spdk_blob *blo /* if aligned with cluster release cluster */ if (spdk_blob_is_thin_provisioned(blob) && is_allocated && - bs_io_units_per_cluster(blob) == length) { + bs_io_units_per_cluster(blob) == length && g_cluster_unmap_enabled) { struct spdk_bs_channel *bs_channel = spdk_io_channel_get_ctx(_ch); uint32_t cluster_start_page; uint32_t cluster_number; @@ -3337,6 +3339,24 @@ blob_request_submit_op_single(struct spdk_io_channel *_ch, struct spdk_blob *blo cpl.u.blob_basic.cb_arg = ctx; } + + /* OLD + spdk_bs_batch_t *batch; + + batch = bs_batch_open(_ch, &cpl, blob); + if (!batch) { + cb_fn(cb_arg, -ENOMEM); + return; + } + + if (is_allocated) { + bs_batch_unmap_dev(batch, lba, lba_count); + } + + bs_batch_close(batch); + break; + */ + batch = bs_batch_open(_ch, &cpl, blob); if (!batch) { free(ctx); @@ -10570,5 +10590,11 @@ spdk_blob_is_degraded(const struct spdk_blob *blob) return blob->back_bs_dev->is_degraded(blob->back_bs_dev); } +void +spdk_blob_enable_cluster_unmap(bool is_enabled) +{ + g_cluster_unmap_enabled = is_enabled; +} + SPDK_LOG_REGISTER_COMPONENT(blob) SPDK_LOG_REGISTER_COMPONENT(blob_esnap)