diff --git a/lib/lvol/lvol.c b/lib/lvol/lvol.c index e30f3a9f3..23a7ade9e 100644 --- a/lib/lvol/lvol.c +++ b/lib/lvol/lvol.c @@ -1015,24 +1015,18 @@ spdk_lvol_get_xattr_value(void *xattr_ctx, const char *name, } } -int -spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz, - bool thin_provision, spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg) +static int +_spdk_lvs_verify_lvol_name(struct spdk_lvol_store *lvs, const char *name) { - struct spdk_lvol_with_handle_req *req; - struct spdk_blob_store *bs; - struct spdk_lvol *lvol, *tmp; - struct spdk_blob_opts opts; - uint64_t num_clusters; - char *xattr_names[] = {LVOL_NAME, "uuid"}; + struct spdk_lvol *tmp; if (lvs == NULL) { SPDK_ERRLOG("lvol store does not exist\n"); return -ENODEV; } - if (name == NULL || strnlen(name, SPDK_LVS_NAME_MAX) == 0) { - SPDK_ERRLOG("No name specified.\n"); + if (name == NULL || strnlen(name, SPDK_LVOL_NAME_MAX) == 0) { + SPDK_INFOLOG(SPDK_LOG_LVOL, "lvol name not provided.\n"); return -EINVAL; } @@ -1044,10 +1038,30 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz, TAILQ_FOREACH(tmp, &lvs->lvols, link) { if (!strncmp(name, tmp->name, SPDK_LVOL_NAME_MAX)) { SPDK_ERRLOG("lvol with name %s already exists\n", name); - return -EINVAL; + return -EEXIST; } } + return 0; +} + +int +spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz, + bool thin_provision, spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg) +{ + struct spdk_lvol_with_handle_req *req; + struct spdk_blob_store *bs; + struct spdk_lvol *lvol; + struct spdk_blob_opts opts; + uint64_t num_clusters; + char *xattr_names[] = {LVOL_NAME, "uuid"}; + int rc; + + rc = _spdk_lvs_verify_lvol_name(lvs, name); + if (rc < 0) { + return rc; + } + bs = lvs->blobstore; req = calloc(1, sizeof(*req)); diff --git a/test/unit/lib/lvol/lvol.c/lvol_ut.c b/test/unit/lib/lvol/lvol.c/lvol_ut.c index 21c5c10af..1d370aed5 100644 --- a/test/unit/lib/lvol/lvol.c/lvol_ut.c +++ b/test/unit/lib/lvol/lvol.c/lvol_ut.c @@ -1324,7 +1324,7 @@ lvol_names(void) lvol = g_lvol; rc = spdk_lvol_create(lvs, "lvol", 1, false, lvol_op_with_handle_complete, NULL); - CU_ASSERT(rc == -EINVAL); + CU_ASSERT(rc == -EEXIST); g_lvserrno = -1; rc = spdk_lvol_create(lvs, "lvol2", 1, false, lvol_op_with_handle_complete, NULL); @@ -1395,7 +1395,7 @@ lvol_rename(void) g_lvserrno = -1; g_lvol = NULL; rc = spdk_lvol_create(lvs, "lvol", 1, false, lvol_op_with_handle_complete, NULL); - CU_ASSERT(rc == -EINVAL); + CU_ASSERT(rc == -EEXIST); CU_ASSERT(g_lvserrno == -1); SPDK_CU_ASSERT_FATAL(g_lvol == NULL);