lvol: make unique_id an array
We know how big this should be so no need to dynamically allocate it. Change-Id: I00ae6cb7c7f525d946d213e0f58cc5fe05bcf932 Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/c/441128 Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
d263cba089
commit
1da6e2f5c5
@ -42,6 +42,10 @@
|
||||
/* Default size of blobstore cluster */
|
||||
#define SPDK_LVS_OPTS_CLUSTER_SZ (4 * 1024 * 1024)
|
||||
|
||||
/* UUID + '_' + blobid (20 characters for uint64_t).
|
||||
* Null terminator is already included in SPDK_UUID_STRING_LEN. */
|
||||
#define SPDK_LVOL_UNIQUE_ID_MAX (SPDK_UUID_STRING_LEN + 1 + 20)
|
||||
|
||||
struct spdk_lvs_req {
|
||||
spdk_lvs_op_complete cb_fn;
|
||||
void *cb_arg;
|
||||
@ -100,7 +104,7 @@ struct spdk_lvol {
|
||||
struct spdk_lvol_store *lvol_store;
|
||||
struct spdk_blob *blob;
|
||||
spdk_blob_id blob_id;
|
||||
char *unique_id;
|
||||
char unique_id[SPDK_LVOL_UNIQUE_ID_MAX];
|
||||
char name[SPDK_LVOL_NAME_MAX];
|
||||
struct spdk_uuid uuid;
|
||||
char uuid_str[SPDK_UUID_STRING_LEN];
|
||||
|
@ -920,7 +920,6 @@ _create_lvol_disk_unload_cb(void *cb_arg, int bdeverrno)
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&lvol->lvol_store->lvols, lvol, link);
|
||||
free(lvol->unique_id);
|
||||
free(lvol);
|
||||
}
|
||||
|
||||
@ -933,10 +932,6 @@ _create_lvol_disk(struct spdk_lvol *lvol, bool destroy)
|
||||
unsigned char *alias;
|
||||
int rc;
|
||||
|
||||
if (!lvol->unique_id) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvol->lvol_store);
|
||||
if (lvs_bdev == NULL) {
|
||||
SPDK_ERRLOG("No spdk lvs-bdev pair found for lvol %s\n", lvol->unique_id);
|
||||
@ -1234,7 +1229,6 @@ _vbdev_lvs_examine_finish(void *cb_arg, struct spdk_lvol *lvol, int lvolerrno)
|
||||
SPDK_ERRLOG("Error opening lvol %s\n", lvol->unique_id);
|
||||
TAILQ_REMOVE(&lvs->lvols, lvol, link);
|
||||
lvs->lvol_count--;
|
||||
free(lvol->unique_id);
|
||||
free(lvol);
|
||||
goto end;
|
||||
}
|
||||
|
@ -85,7 +85,6 @@ _spdk_lvs_free(struct spdk_lvol_store *lvs)
|
||||
static void
|
||||
_spdk_lvol_free(struct spdk_lvol *lvol)
|
||||
{
|
||||
free(lvol->unique_id);
|
||||
free(lvol);
|
||||
}
|
||||
|
||||
@ -163,7 +162,6 @@ _spdk_load_next_lvol(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
||||
struct spdk_blob_store *bs = lvs->blobstore;
|
||||
struct spdk_lvol *lvol, *tmp;
|
||||
spdk_blob_id blob_id;
|
||||
char uuid[SPDK_UUID_STRING_LEN];
|
||||
const char *attr;
|
||||
size_t value_len;
|
||||
int rc;
|
||||
@ -207,16 +205,12 @@ _spdk_load_next_lvol(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
||||
spdk_uuid_fmt_lower(lvol->uuid_str, sizeof(lvol->uuid_str), &lvol->uuid);
|
||||
|
||||
if (!spdk_mem_all_zero(&lvol->uuid, sizeof(lvol->uuid))) {
|
||||
lvol->unique_id = strdup(lvol->uuid_str);
|
||||
snprintf(lvol->unique_id, sizeof(lvol->unique_id), "%s", lvol->uuid_str);
|
||||
} else {
|
||||
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &lvol->lvol_store->uuid);
|
||||
lvol->unique_id = spdk_sprintf_alloc("%s_%"PRIu64, uuid, (uint64_t)blob_id);
|
||||
}
|
||||
if (!lvol->unique_id) {
|
||||
SPDK_ERRLOG("Cannot assign lvol name\n");
|
||||
free(lvol);
|
||||
req->lvserrno = -ENOMEM;
|
||||
goto invalid;
|
||||
spdk_uuid_fmt_lower(lvol->unique_id, sizeof(lvol->unique_id), &lvol->lvol_store->uuid);
|
||||
value_len = strlen(lvol->unique_id);
|
||||
snprintf(lvol->unique_id + value_len, sizeof(lvol->unique_id) - value_len, "_%"PRIu64,
|
||||
(uint64_t)blob_id);
|
||||
}
|
||||
|
||||
rc = spdk_blob_get_xattr_value(blob, "name", (const void **)&attr, &value_len);
|
||||
@ -242,7 +236,6 @@ _spdk_load_next_lvol(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
||||
invalid:
|
||||
TAILQ_FOREACH_SAFE(lvol, &lvs->lvols, link, tmp) {
|
||||
TAILQ_REMOVE(&lvs->lvols, lvol, link);
|
||||
free(lvol->unique_id);
|
||||
free(lvol);
|
||||
}
|
||||
|
||||
@ -839,7 +832,6 @@ spdk_lvs_destroy(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
|
||||
}
|
||||
|
||||
TAILQ_FOREACH_SAFE(iter_lvol, &lvs->lvols, link, tmp) {
|
||||
free(iter_lvol->unique_id);
|
||||
free(iter_lvol);
|
||||
}
|
||||
|
||||
@ -909,25 +901,6 @@ end:
|
||||
free(req);
|
||||
}
|
||||
|
||||
static void
|
||||
_spdk_lvol_destroy_cb(void *cb_arg, int lvolerrno)
|
||||
{
|
||||
struct spdk_lvol_req *req = cb_arg;
|
||||
struct spdk_lvol *lvol = req->lvol;
|
||||
struct spdk_blob_store *bs = lvol->lvol_store->blobstore;
|
||||
|
||||
if (lvolerrno < 0) {
|
||||
SPDK_ERRLOG("Could not close blob on lvol\n");
|
||||
_spdk_lvol_free(lvol);
|
||||
req->cb_fn(req->cb_arg, lvolerrno);
|
||||
free(req);
|
||||
return;
|
||||
}
|
||||
SPDK_INFOLOG(SPDK_LOG_LVOL, "Blob closed on lvol %s\n", lvol->unique_id);
|
||||
|
||||
spdk_bs_delete_blob(bs, lvol->blob_id, _spdk_lvol_delete_blob_cb, req);
|
||||
}
|
||||
|
||||
static void
|
||||
_spdk_lvol_create_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
||||
{
|
||||
@ -949,13 +922,7 @@ _spdk_lvol_create_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
||||
|
||||
TAILQ_INSERT_TAIL(&lvol->lvol_store->lvols, lvol, link);
|
||||
|
||||
lvol->unique_id = strdup(lvol->uuid_str);
|
||||
if (!lvol->unique_id) {
|
||||
SPDK_ERRLOG("Cannot alloc memory for lvol name\n");
|
||||
spdk_blob_close(blob, _spdk_lvol_destroy_cb, req);
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(lvol->unique_id, sizeof(lvol->unique_id), "%s", lvol->uuid_str);
|
||||
lvol->ref_count++;
|
||||
|
||||
assert(req->cb_fn != NULL);
|
||||
|
@ -351,7 +351,6 @@ spdk_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *c
|
||||
|
||||
TAILQ_FOREACH_SAFE(lvol, &lvs->lvols, link, tmp) {
|
||||
TAILQ_REMOVE(&lvs->lvols, lvol, link);
|
||||
free(lvol->unique_id);
|
||||
free(lvol);
|
||||
}
|
||||
g_lvol_store = NULL;
|
||||
@ -384,7 +383,6 @@ spdk_lvs_destroy(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
|
||||
spdk_bdev_alias_del(lvol->bdev, alias);
|
||||
|
||||
free(alias);
|
||||
free(lvol->unique_id);
|
||||
free(lvol);
|
||||
}
|
||||
g_lvol_store = NULL;
|
||||
@ -462,7 +460,6 @@ spdk_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_
|
||||
cb_fn(cb_arg, 0);
|
||||
|
||||
g_lvol = NULL;
|
||||
free(lvol->unique_id);
|
||||
free(lvol);
|
||||
}
|
||||
|
||||
@ -617,8 +614,7 @@ _lvol_create(struct spdk_lvol_store *lvs)
|
||||
|
||||
lvol->lvol_store = lvs;
|
||||
lvol->ref_count++;
|
||||
lvol->unique_id = spdk_sprintf_alloc("%s", "UNIT_TEST_UUID");
|
||||
SPDK_CU_ASSERT_FATAL(lvol->unique_id != NULL);
|
||||
snprintf(lvol->unique_id, sizeof(lvol->unique_id), "%s", "UNIT_TEST_UUID");
|
||||
|
||||
TAILQ_INSERT_TAIL(&lvol->lvol_store->lvols, lvol, link);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user