lvol: verify lvol name rework

This commit moves the name verification function out of the
spdk_lvol_create.

Also changes return value from -EINVAL to -EEXIST when name
already exists in lvol store, as more informative. It implies
that spdk_lvol_create also returns -EEXIST error code for
this case.

Change-Id: Ie0f642b316ba8c5cc42657334d35e539be56e830
Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
Reviewed-on: https://review.gerrithub.io/406745
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Tomasz Kulasek 2018-04-06 12:20:32 +02:00 committed by Jim Harris
parent 3eb5130de6
commit f0aacaf6ae
2 changed files with 28 additions and 14 deletions

View File

@ -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));

View File

@ -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);