Skip to content

Commit

Permalink
util: Added function to find specific UUID in UUID list.
Browse files Browse the repository at this point in the history
Finds a given UUID in the UUID list returned by identify UUID.

Signed-off-by: Leonardo da Cunha <leonardo.da.cunha@solidigm.com>
  • Loading branch information
lgdacunh authored and igaw committed Jan 18, 2024
1 parent 89de650 commit d1f4c66
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libnvme.map
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
LIBNVME_1_8 {
global:
nvme_uuid_find;
};

LIBNVME_1_7 {
global:
nvme_init_copy_range_f2;
Expand Down
19 changes: 19 additions & 0 deletions src/nvme/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,25 @@ int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN])
return 0;
}

int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN])
{
const unsigned char uuid_end[NVME_UUID_LEN] = {0};

if ((!uuid_list) || (!uuid)) {
errno = EINVAL;
return -1;
}

for (int i = 0; i < NVME_ID_UUID_LIST_MAX; i++) {
if (memcmp(uuid, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
return i + 1;
if (memcmp(uuid_end, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
break;
}
errno = ENOENT;
return -1;
}

#ifdef HAVE_NETDB
static bool _nvme_ipaddrs_eq(struct sockaddr *addr1, struct sockaddr *addr2)
{
Expand Down
9 changes: 9 additions & 0 deletions src/nvme/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]);
*/
int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN]);

/**
* nvme_uuid_find - Find UUID position on UUID list
* @uuid_list: UUID list returned by identify UUID
* @uuid: Binary encoded input UUID
*
* Return: The array position where given UUID is present, or -1 on failure with errno set.
*/
int nvme_uuid_find(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN]);

/**
* nvme_ipaddrs_eq - Check if 2 IP addresses are equal.
* @addr1: IP address (can be IPv4 or IPv6)
Expand Down

0 comments on commit d1f4c66

Please sign in to comment.