From 9d17cbdd23d4938a9b67926332f9b4145b841fb7 Mon Sep 17 00:00:00 2001 From: Piotr Pelplinski Date: Thu, 26 Oct 2017 10:31:16 +0200 Subject: [PATCH] blob: fix bug when specifing cluster size < 4096 Signed-off-by: Piotr Pelplinski Change-Id: I59cbef4ce1bfe8af113c66c2c9cb9f208440c0aa Reviewed-on: https://review.gerrithub.io/383887 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- lib/blob/blobstore.c | 6 ++++++ test/unit/lib/blob/blob.c/blob_ut.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index da215ad5db..c1c6c7e251 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -1408,6 +1408,12 @@ _spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts) opts->cluster_sz); return NULL; } + if (opts->cluster_sz < SPDK_BS_PAGE_SIZE) { + /* Cluster size cannot be smaller than page size */ + SPDK_ERRLOG("Cluster size %d is smaller than page size %d\n", + opts->cluster_sz, SPDK_BS_PAGE_SIZE); + return NULL; + } bs = calloc(1, sizeof(struct spdk_blob_store)); if (!bs) { return NULL; diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index 562af81191..54f8efe8e5 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -1188,6 +1188,19 @@ bs_cluster_sz(void) CU_ASSERT(g_bserrno == -ENOMEM); SPDK_CU_ASSERT_FATAL(g_bs == NULL); + /* + * Set cluster size to lower than page size, + * to work it is required to be at least twice the blobstore page size. + */ + dev = init_dev(); + spdk_bs_opts_init(&opts); + opts.cluster_sz = SPDK_BS_PAGE_SIZE - 1; + + /* Initialize a new blob store */ + spdk_bs_init(dev, &opts, bs_op_with_handle_complete, NULL); + CU_ASSERT(g_bserrno == -ENOMEM); + SPDK_CU_ASSERT_FATAL(g_bs == NULL); + /* Set cluster size to twice the default */ dev = init_dev(); spdk_bs_opts_init(&opts);