diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 44ef86333..011995aa9 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -4972,6 +4972,14 @@ spdk_blob_resize(struct spdk_blob *blob, uint64_t sz, spdk_blob_op_complete cb_f /* START spdk_bs_delete_blob */ +static void +_spdk_bs_delete_ebusy_close_cpl(void *cb_arg, int bserrno) +{ + spdk_bs_sequence_t *seq = cb_arg; + + spdk_bs_sequence_finish(seq, -EBUSY); +} + static void _spdk_bs_delete_close_cpl(void *cb_arg, int bserrno) { @@ -5030,6 +5038,21 @@ _spdk_bs_delete_open_cpl(void *cb_arg, struct spdk_blob *blob, int bserrno) return; } + /* Check if this is a snapshot with clones */ + TAILQ_FOREACH(snapshot, &blob->bs->snapshots, link) { + if (snapshot->id == blob->id) { + break; + } + } + if (snapshot != NULL) { + /* If snapshot have clones, we cannot remove it */ + if (!TAILQ_EMPTY(&snapshot->clones)) { + SPDK_ERRLOG("Cannot remove snapshot with clones\n"); + spdk_blob_close(blob, _spdk_bs_delete_ebusy_close_cpl, seq); + return; + } + } + bserrno = _spdk_bs_blob_list_remove(blob); if (bserrno != 0) { SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Remove blob #%" PRIu64 " from a list\n", blob->id); @@ -5067,27 +5090,11 @@ spdk_bs_delete_blob(struct spdk_blob_store *bs, spdk_blob_id blobid, { struct spdk_bs_cpl cpl; spdk_bs_sequence_t *seq; - struct spdk_blob_list *snapshot_entry = NULL; SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Deleting blob %lu\n", blobid); assert(spdk_get_thread() == bs->md_thread); - /* Check if this is a snapshot with clones */ - TAILQ_FOREACH(snapshot_entry, &bs->snapshots, link) { - if (snapshot_entry->id == blobid) { - break; - } - } - if (snapshot_entry != NULL) { - /* If snapshot have clones, we cannot remove it */ - if (!TAILQ_EMPTY(&snapshot_entry->clones)) { - SPDK_ERRLOG("Cannot remove snapshot with clones\n"); - cb_fn(cb_arg, -EBUSY); - return; - } - } - cpl.type = SPDK_BS_CPL_TYPE_BLOB_BASIC; cpl.u.blob_basic.cb_fn = cb_fn; cpl.u.blob_basic.cb_arg = cb_arg;