util/uuid: add API to test/set null uuid

Refactor the code to use these new functions.

Change-Id: I21ee7e9a96f30fbd60106add5e8b071e86bf93c9
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
This commit is contained in:
Artur Paszkiewicz 2022-12-02 16:22:33 +01:00 committed by David Ko
parent 52726c9b6e
commit 882ecb55a8
14 changed files with 63 additions and 16 deletions

View File

@ -67,6 +67,11 @@ New API `spdk_bdev_part_construct_ext` is added and allows the bdev's UUID to be
the existing worker and namespace association logic to access every namespace from each worker.
This replicates behavior of bdevperf application when `-C` option is provided.
### util
New APIs `spdk_uuid_is_null` and `spdk_uuid_set_null` were added to compare and
set UUID to NULL value.
## v23.01
### accel

View File

@ -86,6 +86,22 @@ int spdk_uuid_generate_sha1(struct spdk_uuid *uuid, struct spdk_uuid *ns_uuid, c
*/
void spdk_uuid_copy(struct spdk_uuid *dst, const struct spdk_uuid *src);
/**
* Compare the UUID to the NULL value (all bits equal to zero).
*
* \param uuid The UUID to test.
*
* \return true if uuid is equal to the NULL value, false if not.
*/
bool spdk_uuid_is_null(const struct spdk_uuid *uuid);
/**
* Set the value of UUID to the NULL value.
*
* \param uuid The UUID to set.
*/
void spdk_uuid_set_null(struct spdk_uuid *uuid);
#ifdef __cplusplus
}
#endif

View File

@ -7427,7 +7427,7 @@ bdev_register(struct spdk_bdev *bdev)
/* UUID may be specified by the user or defined by bdev itself.
* Otherwise it will be generated here, so this field will never be empty. */
if (spdk_mem_all_zero(&bdev->uuid, sizeof(bdev->uuid))) {
if (spdk_uuid_is_null(&bdev->uuid)) {
spdk_uuid_generate(&bdev->uuid);
}

View File

@ -255,11 +255,11 @@ load_next_lvol(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
if (rc != 0 || value_len != SPDK_UUID_STRING_LEN || attr[SPDK_UUID_STRING_LEN - 1] != '\0' ||
spdk_uuid_parse(&lvol->uuid, attr) != 0) {
SPDK_INFOLOG(lvol, "Missing or corrupt lvol uuid\n");
memset(&lvol->uuid, 0, sizeof(lvol->uuid));
spdk_uuid_set_null(&lvol->uuid);
}
spdk_uuid_fmt_lower(lvol->uuid_str, sizeof(lvol->uuid_str), &lvol->uuid);
if (!spdk_mem_all_zero(&lvol->uuid, sizeof(lvol->uuid))) {
if (!spdk_uuid_is_null(&lvol->uuid)) {
snprintf(lvol->unique_id, sizeof(lvol->unique_id), "%s", lvol->uuid_str);
} else {
spdk_uuid_fmt_lower(lvol->unique_id, sizeof(lvol->unique_id), &lvol->lvol_store->uuid);

View File

@ -544,7 +544,7 @@ nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w,
spdk_json_write_named_string_fmt(w, "eui64", "%016"PRIX64, from_be64(&ns_opts.eui64));
}
if (!spdk_mem_all_zero(&ns_opts.uuid, sizeof(ns_opts.uuid))) {
if (!spdk_uuid_is_null(&ns_opts.uuid)) {
spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &ns_opts.uuid);
spdk_json_write_named_string(w, "uuid", uuid_str);
}

View File

@ -259,7 +259,7 @@ dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct spdk_nvmf_subsystem *s
json_write_hex_str(w, ns_opts.eui64, sizeof(ns_opts.eui64));
}
if (!spdk_mem_all_zero(&ns_opts.uuid, sizeof(ns_opts.uuid))) {
if (!spdk_uuid_is_null(&ns_opts.uuid)) {
char uuid_str[SPDK_UUID_STRING_LEN];
spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &ns_opts.uuid);
@ -1221,7 +1221,7 @@ nvmf_rpc_ns_paused(struct spdk_nvmf_subsystem *subsystem,
SPDK_STATIC_ASSERT(sizeof(ns_opts.eui64) == sizeof(ctx->ns_params.eui64), "size mismatch");
memcpy(ns_opts.eui64, ctx->ns_params.eui64, sizeof(ns_opts.eui64));
if (!spdk_mem_all_zero(&ctx->ns_params.uuid, sizeof(ctx->ns_params.uuid))) {
if (!spdk_uuid_is_null(&ctx->ns_params.uuid)) {
ns_opts.uuid = ctx->ns_params.uuid;
}

View File

@ -1529,7 +1529,7 @@ spdk_nvmf_ns_opts_get_defaults(struct spdk_nvmf_ns_opts *opts, size_t opts_size)
memset(opts->eui64, 0, sizeof(opts->eui64));
}
if (FIELD_OK(uuid)) {
memset(&opts->uuid, 0, sizeof(opts->uuid));
spdk_uuid_set_null(&opts->uuid);
}
SET_FIELD(anagrpid, 0);
@ -1558,7 +1558,7 @@ nvmf_ns_opts_copy(struct spdk_nvmf_ns_opts *opts,
memcpy(opts->eui64, user_opts->eui64, sizeof(opts->eui64));
}
if (FIELD_OK(uuid)) {
memcpy(&opts->uuid, &user_opts->uuid, sizeof(opts->uuid));
spdk_uuid_copy(&opts->uuid, &user_opts->uuid);
}
SET_FIELD(anagrpid);
@ -1686,7 +1686,7 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
/* Cache the zcopy capability of the bdev device */
ns->zcopy = spdk_bdev_io_type_supported(ns->bdev, SPDK_BDEV_IO_TYPE_ZCOPY);
if (spdk_mem_all_zero(&opts.uuid, sizeof(opts.uuid))) {
if (spdk_uuid_is_null(&opts.uuid)) {
opts.uuid = *spdk_bdev_get_uuid(ns->bdev);
}

View File

@ -621,7 +621,7 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params,
return;
}
if (spdk_mem_all_zero(&params->uuid, sizeof(params->uuid))) {
if (spdk_uuid_is_null(&params->uuid)) {
spdk_uuid_generate(&params->uuid);
}

View File

@ -155,6 +155,8 @@
spdk_uuid_generate;
spdk_uuid_generate_sha1;
spdk_uuid_copy;
spdk_uuid_is_null;
spdk_uuid_set_null;
# public functions in fd_group.h
spdk_fd_group_create;

View File

@ -52,6 +52,18 @@ spdk_uuid_copy(struct spdk_uuid *dst, const struct spdk_uuid *src)
uuid_copy((void *)dst, (void *)src);
}
bool
spdk_uuid_is_null(const struct spdk_uuid *uuid)
{
return uuid_is_null((void *)uuid);
}
void
spdk_uuid_set_null(struct spdk_uuid *uuid)
{
uuid_clear((void *)uuid);
}
#else
#include <uuid.h>
@ -108,6 +120,18 @@ spdk_uuid_copy(struct spdk_uuid *dst, const struct spdk_uuid *src)
memcpy(dst, src, sizeof(*dst));
}
bool
spdk_uuid_is_null(const struct spdk_uuid *uuid)
{
return uuid_is_nil((const uuid_t *)uuid, NULL);
}
void
spdk_uuid_set_null(struct spdk_uuid *uuid)
{
uuid_create_nil((uuid_t *)uuid, NULL);
}
#endif
int

View File

@ -93,7 +93,7 @@ rpc_bdev_ftl_create(struct spdk_jsonrpc_request *request,
goto out;
}
if (spdk_mem_all_zero(&conf.uuid, sizeof(conf.uuid))) {
if (spdk_uuid_is_null(&conf.uuid)) {
conf.mode |= SPDK_FTL_MODE_CREATE;
}

View File

@ -737,7 +737,7 @@ create_malloc_disk(struct spdk_bdev **bdev, const struct malloc_bdev_opts *opts)
mdisk->disk.optimal_io_boundary = opts->optimal_io_boundary;
mdisk->disk.split_on_optimal_io_boundary = true;
}
if (!spdk_mem_all_zero(&opts->uuid, sizeof(opts->uuid))) {
if (!spdk_uuid_is_null(&opts->uuid)) {
spdk_uuid_copy(&mdisk->disk.uuid, &opts->uuid);
}

View File

@ -5943,7 +5943,7 @@ bdev_register_uuid_alias(void)
bdev = allocate_bdev("bdev0");
/* Make sure an UUID was generated */
CU_ASSERT_FALSE(spdk_mem_all_zero(&bdev->uuid, sizeof(bdev->uuid)));
CU_ASSERT_FALSE(spdk_uuid_is_null(&bdev->uuid));
/* Check that an UUID alias was registered */
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &bdev->uuid);

View File

@ -1361,7 +1361,7 @@ test_reservation_write_exclusive(void)
SPDK_CU_ASSERT_FATAL(rc == 0);
/* Unregister Host C */
memset(&g_ns_info.reg_hostid[2], 0, sizeof(struct spdk_uuid));
spdk_uuid_set_null(&g_ns_info.reg_hostid[2]);
/* Test Case: Read and Write commands from non-registrant Host C */
cmd.nvme_cmd.opc = SPDK_NVME_OPC_WRITE;
@ -1430,7 +1430,7 @@ _test_reservation_write_exclusive_regs_only_and_all_regs(enum spdk_nvme_reservat
SPDK_CU_ASSERT_FATAL(rc == 0);
/* Unregister Host C */
memset(&g_ns_info.reg_hostid[2], 0, sizeof(struct spdk_uuid));
spdk_uuid_set_null(&g_ns_info.reg_hostid[2]);
/* Test Case: Read and Write commands from non-registrant Host C */
cmd.nvme_cmd.opc = SPDK_NVME_OPC_READ;
@ -1472,7 +1472,7 @@ _test_reservation_exclusive_access_regs_only_and_all_regs(enum spdk_nvme_reserva
SPDK_CU_ASSERT_FATAL(rc == 0);
/* Unregister Host B */
memset(&g_ns_info.reg_hostid[1], 0, sizeof(struct spdk_uuid));
spdk_uuid_set_null(&g_ns_info.reg_hostid[1]);
/* Test Case: Issue a Read command from Host B */
cmd.nvme_cmd.opc = SPDK_NVME_OPC_READ;