From 84b5ac7dac529782ac59518facb80540f215d5f9 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Thu, 9 May 2019 12:08:23 +0200 Subject: [PATCH] blobstore: Enable/disable snapshot deletion with CFLAGS Snapshot delete functionality is targeted for .1 release and therefore should not be enabled by default. Use export CFLAGS=-DSPDK_ENABLE_SNAPSHOT_DELETION to enable this functionality. Signed-off-by: Maciej Szwed Change-Id: I2d966b62cd5d7eaf8134962d1a833542edfe2d9f Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458466 Reviewed-by: Tomasz Zawadzki Reviewed-by: Ben Walker Reviewed-by: Darek Stojaczyk Tested-by: SPDK CI Jenkins --- lib/blob/blobstore.c | 11 +++++++++++ test/unit/lib/blob/blob.c/blob_ut.c | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 99f32e27a..547bf78c4 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -49,6 +49,12 @@ #define BLOB_CRC32C_INITIAL 0xffffffffUL +#ifdef SPDK_ENABLE_SNAPSHOT_DELETION +bool g_delete_snapshot_enabled = true; +#else +bool g_delete_snapshot_enabled = false; +#endif + static int spdk_bs_register_md_thread(struct spdk_blob_store *bs); static int spdk_bs_unregister_md_thread(struct spdk_blob_store *bs); static void _spdk_blob_close_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno); @@ -5507,6 +5513,11 @@ _spdk_bs_is_blob_deletable(struct spdk_blob *blob, bool *update_clone) /* Check if this is a snapshot with clones */ snapshot_entry = _spdk_bs_get_snapshot_entry(blob->bs, blob->id); if (snapshot_entry != NULL) { + if (snapshot_entry->clone_count > 0 && !g_delete_snapshot_enabled) { + SPDK_ERRLOG("Cannot remove snapshot with clones\n"); + return -EBUSY; + } + if (snapshot_entry->clone_count > 1) { SPDK_ERRLOG("Cannot remove snapshot with more than one clone\n"); return -EBUSY; diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index 632fed372..3a0924b7c 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -45,6 +45,8 @@ #include "blob/zeroes.c" #include "blob/blob_bs_dev.c" +extern bool g_delete_snapshot_enabled; + struct spdk_blob_store *g_bs; spdk_blob_id g_blobid; struct spdk_blob *g_blob; @@ -5435,7 +5437,13 @@ _blob_inflate_rw(bool decouple_parent) /* Try to delete base snapshot */ spdk_bs_delete_blob(bs, snapshotid, blob_op_complete, NULL); poll_threads(); - CU_ASSERT(g_bserrno == 0); + + if (g_delete_snapshot_enabled) { + CU_ASSERT(g_bserrno == 0); + } else { + CU_ASSERT(decouple_parent || g_bserrno == 0); + CU_ASSERT(!decouple_parent || g_bserrno != 0); + } /* Reopen blob after snapshot deletion */ spdk_bs_open_blob(bs, blobid, blob_op_with_handle_complete, NULL); @@ -5854,6 +5862,10 @@ blob_relations2(void) size_t count; spdk_blob_id ids[10] = {}; + if (!g_delete_snapshot_enabled) { + return; + } + dev = init_dev(); spdk_bs_opts_init(&bs_opts); snprintf(bs_opts.bstype.bstype, sizeof(bs_opts.bstype.bstype), "TESTTYPE");