diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 164bef2b2..7798b1dad 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -1480,6 +1480,13 @@ spdk_bs_init(struct spdk_bs_dev *dev, struct spdk_bs_opts *o, SPDK_TRACELOG(SPDK_TRACE_BLOB, "Initializing blobstore on dev %p\n", dev); + if ((sizeof(struct spdk_blob_md_page) % dev->blocklen) != 0) { + SPDK_ERRLOG("unsupported dev block length of %d\n", + dev->blocklen); + cb_fn(cb_arg, NULL, -EINVAL); + return; + } + if (o) { opts = *o; } else { diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index 52eb4c1f8..00ec81d64 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -95,6 +95,12 @@ blob_init(void) init_dev(&dev); + /* should fail for an unsupported blocklen */ + dev.blocklen = 500; + spdk_bs_init(&dev, NULL, bs_op_with_handle_complete, NULL); + CU_ASSERT(g_bserrno == -EINVAL); + + init_dev(&dev); spdk_bs_init(&dev, NULL, bs_op_with_handle_complete, NULL); CU_ASSERT(g_bserrno == 0); SPDK_CU_ASSERT_FATAL(g_bs != NULL);