blobstore: silence false error message if device is too small

It is not an error if bdev is smaller than cluster size so convert this
error to infolog. This fixes false error message dring examine process.

To return proper error message when creating blobstore using RPC the
_spdk_bs_alloc was adjusted to return errocode that is propagated up and
converted to "No space left on device".

Fixes #316

Change-Id: Ic9803720a55125fcfa34263346f2d9e1aae03a53
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/420054
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Pawel Wodkowski 2018-07-20 19:38:18 +02:00 committed by Ben Walker
parent fbf057386d
commit 22637292ac
3 changed files with 26 additions and 22 deletions

View File

@ -2422,8 +2422,8 @@ _spdk_bs_opts_verify(struct spdk_bs_opts *opts)
return 0; return 0;
} }
static struct spdk_blob_store * static int
_spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts) _spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts, struct spdk_blob_store **_bs)
{ {
struct spdk_blob_store *bs; struct spdk_blob_store *bs;
uint64_t dev_size; uint64_t dev_size;
@ -2432,19 +2432,19 @@ _spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts)
dev_size = dev->blocklen * dev->blockcnt; dev_size = dev->blocklen * dev->blockcnt;
if (dev_size < opts->cluster_sz) { if (dev_size < opts->cluster_sz) {
/* Device size cannot be smaller than cluster size of blobstore */ /* Device size cannot be smaller than cluster size of blobstore */
SPDK_ERRLOG("Device size %" PRIu64 " is smaller than cluster size %" PRIu32 "\n", SPDK_INFOLOG(SPDK_LOG_BLOB, "Device size %" PRIu64 " is smaller than cluster size %" PRIu32 "\n",
dev_size, opts->cluster_sz); dev_size, opts->cluster_sz);
return NULL; return -ENOSPC;
} }
if (opts->cluster_sz < SPDK_BS_PAGE_SIZE) { if (opts->cluster_sz < SPDK_BS_PAGE_SIZE) {
/* Cluster size cannot be smaller than page size */ /* Cluster size cannot be smaller than page size */
SPDK_ERRLOG("Cluster size %" PRIu32 " is smaller than page size %d\n", SPDK_ERRLOG("Cluster size %" PRIu32 " is smaller than page size %d\n",
opts->cluster_sz, SPDK_BS_PAGE_SIZE); opts->cluster_sz, SPDK_BS_PAGE_SIZE);
return NULL; return -EINVAL;
} }
bs = calloc(1, sizeof(struct spdk_blob_store)); bs = calloc(1, sizeof(struct spdk_blob_store));
if (!bs) { if (!bs) {
return NULL; return -ENOMEM;
} }
TAILQ_INIT(&bs->blobs); TAILQ_INIT(&bs->blobs);
@ -2464,7 +2464,7 @@ _spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts)
bs->used_clusters = spdk_bit_array_create(bs->total_clusters); bs->used_clusters = spdk_bit_array_create(bs->total_clusters);
if (bs->used_clusters == NULL) { if (bs->used_clusters == NULL) {
free(bs); free(bs);
return NULL; return -ENOMEM;
} }
bs->max_channel_ops = opts->max_channel_ops; bs->max_channel_ops = opts->max_channel_ops;
@ -2487,10 +2487,12 @@ _spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts)
spdk_bit_array_free(&bs->used_md_pages); spdk_bit_array_free(&bs->used_md_pages);
spdk_bit_array_free(&bs->used_clusters); spdk_bit_array_free(&bs->used_clusters);
free(bs); free(bs);
return NULL; /* FIXME: this is a lie but don't know how to get a proper error code here */
return -ENOMEM;
} }
return bs; *_bs = bs;
return 0;
} }
/* START spdk_bs_load, spdk_bs_load_ctx will used for both load and unload. */ /* START spdk_bs_load, spdk_bs_load_ctx will used for both load and unload. */
@ -3122,6 +3124,7 @@ spdk_bs_load(struct spdk_bs_dev *dev, struct spdk_bs_opts *o,
spdk_bs_sequence_t *seq; spdk_bs_sequence_t *seq;
struct spdk_bs_load_ctx *ctx; struct spdk_bs_load_ctx *ctx;
struct spdk_bs_opts opts = {}; struct spdk_bs_opts opts = {};
int err;
SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Loading blobstore from dev %p\n", dev); SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Loading blobstore from dev %p\n", dev);
@ -3144,10 +3147,10 @@ spdk_bs_load(struct spdk_bs_dev *dev, struct spdk_bs_opts *o,
return; return;
} }
bs = _spdk_bs_alloc(dev, &opts); err = _spdk_bs_alloc(dev, &opts, &bs);
if (!bs) { if (err) {
dev->destroy(dev); dev->destroy(dev);
cb_fn(cb_arg, NULL, -ENOMEM); cb_fn(cb_arg, NULL, err);
return; return;
} }
@ -3405,15 +3408,16 @@ spdk_bs_dump(struct spdk_bs_dev *dev, FILE *fp, spdk_bs_dump_print_xattr print_x
spdk_bs_sequence_t *seq; spdk_bs_sequence_t *seq;
struct spdk_bs_dump_ctx *ctx; struct spdk_bs_dump_ctx *ctx;
struct spdk_bs_opts opts = {}; struct spdk_bs_opts opts = {};
int err;
SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Dumping blobstore from dev %p\n", dev); SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Dumping blobstore from dev %p\n", dev);
spdk_bs_opts_init(&opts); spdk_bs_opts_init(&opts);
bs = _spdk_bs_alloc(dev, &opts); err = _spdk_bs_alloc(dev, &opts, &bs);
if (!bs) { if (err) {
dev->destroy(dev); dev->destroy(dev);
cb_fn(cb_arg, -ENOMEM); cb_fn(cb_arg, err);
return; return;
} }
@ -3525,10 +3529,10 @@ spdk_bs_init(struct spdk_bs_dev *dev, struct spdk_bs_opts *o,
return; return;
} }
bs = _spdk_bs_alloc(dev, &opts); rc = _spdk_bs_alloc(dev, &opts, &bs);
if (!bs) { if (rc) {
dev->destroy(dev); dev->destroy(dev);
cb_fn(cb_arg, NULL, -ENOMEM); cb_fn(cb_arg, NULL, rc);
return; return;
} }

View File

@ -145,7 +145,7 @@ if __name__ == "__main__":
def construct_malloc_bdev(args): def construct_malloc_bdev(args):
num_blocks = (args.total_size * 1024 * 1024) // args.block_size num_blocks = (args.total_size * 1024 * 1024) // args.block_size
print(rpc.bdev.construct_malloc_bdev(args.client, print(rpc.bdev.construct_malloc_bdev(args.client,
num_blocks=num_blocks, num_blocks=int(num_blocks),
block_size=args.block_size, block_size=args.block_size,
name=args.name, name=args.name,
uuid=args.uuid)) uuid=args.uuid))
@ -155,7 +155,7 @@ if __name__ == "__main__":
p.add_argument('-b', '--name', help="Name of the bdev") p.add_argument('-b', '--name', help="Name of the bdev")
p.add_argument('-u', '--uuid', help="UUID of the bdev") p.add_argument('-u', '--uuid', help="UUID of the bdev")
p.add_argument( p.add_argument(
'total_size', help='Size of malloc bdev in MB (int > 0)', type=int) 'total_size', help='Size of malloc bdev in MB (float > 0)', type=float)
p.add_argument('block_size', help='Block size for this bdev', type=int) p.add_argument('block_size', help='Block size for this bdev', type=int)
p.set_defaults(func=construct_malloc_bdev) p.set_defaults(func=construct_malloc_bdev)

View File

@ -2488,7 +2488,7 @@ bs_cluster_sz(void)
/* Initialize a new blob store */ /* Initialize a new blob store */
spdk_bs_init(dev, &opts, bs_op_with_handle_complete, NULL); spdk_bs_init(dev, &opts, bs_op_with_handle_complete, NULL);
CU_ASSERT(g_bserrno == -ENOMEM); CU_ASSERT(g_bserrno == -EINVAL);
SPDK_CU_ASSERT_FATAL(g_bs == NULL); SPDK_CU_ASSERT_FATAL(g_bs == NULL);
/* Set cluster size to twice the default */ /* Set cluster size to twice the default */