diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 62998fa6a..da215ad5d 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -2320,6 +2320,12 @@ spdk_bs_unload(struct spdk_blob_store *bs, spdk_bs_op_complete cb_fn, void *cb_a SPDK_DEBUGLOG(SPDK_TRACE_BLOB, "Syncing blobstore\n"); + if (!TAILQ_EMPTY(&bs->blobs)) { + SPDK_ERRLOG("Blobstore still has open blobs\n"); + cb_fn(cb_arg, -EBUSY); + return; + } + ctx = calloc(1, sizeof(*ctx)); if (!ctx) { cb_fn(cb_arg, -ENOMEM); @@ -2347,8 +2353,6 @@ spdk_bs_unload(struct spdk_blob_store *bs, spdk_bs_op_complete cb_fn, void *cb_a return; } - assert(TAILQ_EMPTY(&bs->blobs)); - /* Read super block */ spdk_bs_sequence_read(seq, ctx->super, _spdk_bs_page_to_lba(bs, 0), _spdk_bs_byte_to_lba(bs, sizeof(*ctx->super)), diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index 5c3aa937d..562af8119 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -1112,12 +1112,41 @@ static void bs_unload(void) { struct spdk_bs_dev *dev; + struct spdk_blob_store *bs; + spdk_blob_id blobid; + struct spdk_blob *blob; dev = init_dev(); spdk_bs_init(dev, NULL, bs_op_with_handle_complete, NULL); CU_ASSERT(g_bserrno == 0); SPDK_CU_ASSERT_FATAL(g_bs != NULL); + bs = g_bs; + + /* Create a blob and open it. */ + g_bserrno = -1; + spdk_bs_md_create_blob(bs, blob_op_with_id_complete, NULL); + CU_ASSERT(g_bserrno == 0); + CU_ASSERT(g_blobid > 0); + blobid = g_blobid; + + g_bserrno = -1; + spdk_bs_md_open_blob(bs, blobid, blob_op_with_handle_complete, NULL); + CU_ASSERT(g_bserrno == 0); + CU_ASSERT(g_blob != NULL); + blob = g_blob; + + /* Try to unload blobstore, should fail with open blob */ + g_bserrno = -1; + spdk_bs_unload(bs, bs_op_complete, NULL); + CU_ASSERT(g_bserrno == -EBUSY); + SPDK_CU_ASSERT_FATAL(g_bs != NULL); + + /* Close the blob, then successfully unload blobstore */ + g_bserrno = -1; + spdk_bs_md_close_blob(&blob, blob_op_complete, NULL); + CU_ASSERT(g_bserrno == 0); + CU_ASSERT(blob == NULL); g_bserrno = -1; spdk_bs_unload(g_bs, bs_op_complete, NULL);