util/uuid: use libc uuid functions on freebsd

Remove libuuid usage on FreeBSD and add dedicated implementation of
spdk_uuid API using functions from the standard library.

Fixes: #2878
Change-Id: Ie49ccb2842acad6064bffd789e4f64b7365b6e5c
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16558
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Artur Paszkiewicz 2023-01-26 14:04:08 +01:00 committed by Tomasz Zawadzki
parent 96073478de
commit 19572e5b20
5 changed files with 71 additions and 9 deletions

View File

@ -13,7 +13,10 @@ C_SRCS = base64.c bit_array.c cpuset.c crc16.c crc32.c crc32c.c crc32_ieee.c \
dif.c fd.c file.c hexlify.c iov.c math.c pipe.c strerror_tls.c string.c uuid.c \
fd_group.c xor.c zipf.c
LIBNAME = util
ifneq ($(OS),FreeBSD)
LOCAL_SYS_LIBS = -luuid
endif
ifeq ($(CONFIG_ISAL), y)
LOCAL_SYS_LIBS += -L$(ISAL_DIR)/.libs -lisal

View File

@ -5,6 +5,8 @@
#include "spdk/uuid.h"
#ifndef __FreeBSD__
#include <uuid/uuid.h>
SPDK_STATIC_ASSERT(sizeof(struct spdk_uuid) == sizeof(uuid_t), "Size mismatch");
@ -43,3 +45,61 @@ spdk_uuid_copy(struct spdk_uuid *dst, const struct spdk_uuid *src)
{
uuid_copy((void *)dst, (void *)src);
}
#else
#include <uuid.h>
SPDK_STATIC_ASSERT(sizeof(struct spdk_uuid) == sizeof(uuid_t), "Size mismatch");
int
spdk_uuid_parse(struct spdk_uuid *uuid, const char *uuid_str)
{
uint32_t status;
uuid_from_string(uuid_str, (uuid_t *)uuid, &status);
return status == 0 ? 0 : -EINVAL;
}
int
spdk_uuid_fmt_lower(char *uuid_str, size_t uuid_str_size, const struct spdk_uuid *uuid)
{
uint32_t status;
char *str;
if (uuid_str_size < SPDK_UUID_STRING_LEN) {
return -EINVAL;
}
uuid_to_string((const uuid_t *)uuid, &str, &status);
if (status == uuid_s_no_memory) {
return -ENOMEM;
}
snprintf(uuid_str, uuid_str_size, "%s", str);
free(str);
return 0;
}
int
spdk_uuid_compare(const struct spdk_uuid *u1, const struct spdk_uuid *u2)
{
return uuid_compare((const uuid_t *)u1, (const uuid_t *)u2, NULL);
}
void
spdk_uuid_generate(struct spdk_uuid *uuid)
{
uuid_create((uuid_t *)uuid, NULL);
}
void
spdk_uuid_copy(struct spdk_uuid *dst, const struct spdk_uuid *src)
{
memcpy(dst, src, sizeof(*dst));
}
#endif

View File

@ -338,7 +338,9 @@ CFLAGS += $(COMMON_CFLAGS) -Wno-pointer-sign -Wstrict-prototypes -Wold-style-d
CXXFLAGS += $(COMMON_CFLAGS) -std=c++11
SYS_LIBS += -lrt
ifneq ($(OS),FreeBSD)
SYS_LIBS += -luuid
endif
SYS_LIBS += -lssl
SYS_LIBS += -lcrypto
SYS_LIBS += -lm

View File

@ -4,15 +4,13 @@
# All rights reserved.
#
# Minimal install
pkg install -y gmake cunit openssl git bash misc/e2fsprogs-libuuid python \
ncurses ninja meson
pkg install -y gmake cunit openssl git bash python ncurses ninja meson
pkg install -g -y "py*-pyelftools-*" "py*-pandas"
# Additional dependencies for ISA-L used in compression
pkg install -y autoconf automake libtool help2man
if [[ $INSTALL_DEV_TOOLS == "true" ]]; then
# Tools for developers
pkg install -y devel/astyle bash \
misc/e2fsprogs-libuuid sysutils/sg3_utils nasm \
pkg install -y devel/astyle bash sysutils/sg3_utils nasm \
bash-completion ruby devel/ruby-gems
pkg install -g -y "py*-pycodestyle"
# ruby and ruby-gems are not preinstalled on FreeBSD but are needed to

View File

@ -11,7 +11,6 @@
#include "spdk/bdev_module.h"
#include "nvmf/subsystem.c"
#include <uuid/uuid.h>
SPDK_LOG_REGISTER_COMPONENT(nvmf)
@ -1593,7 +1592,7 @@ test_nvmf_valid_nqn(void)
struct spdk_uuid s_uuid = {};
spdk_uuid_generate(&s_uuid);
uuid_unparse((void *)&s_uuid, uuid);
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
/* discovery nqn */
snprintf(nqn, sizeof(nqn), "%s", SPDK_NVMF_DISCOVERY_NQN);
@ -1659,13 +1658,13 @@ test_nvmf_ns_reservation_restore(void)
/* Generate and prepare uuids, make sure bdev and info uuid are the same */
spdk_uuid_generate(&s_uuid);
uuid_unparse((void *)&s_uuid, uuid);
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
snprintf(info.holder_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
snprintf(info.bdev_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
snprintf(info.registrants[0].host_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
spdk_uuid_copy(&bdev.uuid, &s_uuid);
spdk_uuid_generate(&s_uuid);
uuid_unparse((void *)&s_uuid, uuid);
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
snprintf(info.registrants[1].host_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
/* info->rkey not exist in registrants */
@ -1695,7 +1694,7 @@ test_nvmf_ns_reservation_restore(void)
/* Existing bdev UUID is different with configuration */
spdk_uuid_generate(&s_uuid);
uuid_unparse((void *)&s_uuid, uuid);
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
snprintf(info.bdev_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
spdk_uuid_generate(&s_uuid);
spdk_uuid_copy(&bdev.uuid, &s_uuid);