From 7d6161ae980d95e2ed100334d0f1557f12e961d9 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 14:06:57 +0200 Subject: [PATCH 01/14] zns: fix check for valid global context When the code was switched to use nvme_scan_topology, the introduced error check was incorrect. Fixes: 7daa1e95e61b ("plugins: replace nvme_scan with nvme_scan_topology") Signed-off-by: Daniel Wagner --- plugins/zns/zns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 8bd61faed8..3f179e993f 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -107,7 +107,7 @@ static int list(int argc, char **argv, struct command *acmd, struct table *t = table_init_with_columns(columns, ARRAY_SIZE(columns)); ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); - if (ctx) { + if (!ctx) { fprintf(stderr, "Failed to create root object\n"); return -ENOMEM; } From 9d06ccdabacf87ae481120637eda9bdf18ea64e9 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 12:26:41 +0200 Subject: [PATCH 02/14] compiler-attributes: rename header to match pattern All other files in libnvme use a dash. Rename the compiler attributes header accordingly. Signed-off-by: Daniel Wagner --- libnvme/src/nvme/accessors-fabrics.c | 2 +- libnvme/src/nvme/accessors.c | 2 +- libnvme/src/nvme/cmds.c | 2 +- .../src/nvme/{compiler_attributes.h => compiler-attributes.h} | 0 libnvme/src/nvme/fabrics.c | 2 +- libnvme/src/nvme/filters.c | 2 +- libnvme/src/nvme/ioctl.c | 2 +- libnvme/src/nvme/lib.c | 2 +- libnvme/src/nvme/linux.c | 2 +- libnvme/src/nvme/log.c | 2 +- libnvme/src/nvme/mi-mctp.c | 2 +- libnvme/src/nvme/mi.c | 2 +- libnvme/src/nvme/nbft.c | 2 +- libnvme/src/nvme/tree.c | 2 +- libnvme/src/nvme/util.c | 2 +- libnvme/tools/generator/generate-accessors.md | 2 +- libnvme/tools/generator/generate-accessors.py | 2 +- 17 files changed, 16 insertions(+), 16 deletions(-) rename libnvme/src/nvme/{compiler_attributes.h => compiler-attributes.h} (100%) diff --git a/libnvme/src/nvme/accessors-fabrics.c b/libnvme/src/nvme/accessors-fabrics.c index e442ce6950..12ad9b71ff 100644 --- a/libnvme/src/nvme/accessors-fabrics.c +++ b/libnvme/src/nvme/accessors-fabrics.c @@ -22,7 +22,7 @@ #include "accessors-fabrics.h" #include "private-fabrics.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" /**************************************************************************** * Accessors for: struct libnvmf_discovery_args diff --git a/libnvme/src/nvme/accessors.c b/libnvme/src/nvme/accessors.c index d844e72b4a..20b645984c 100644 --- a/libnvme/src/nvme/accessors.c +++ b/libnvme/src/nvme/accessors.c @@ -22,7 +22,7 @@ #include "accessors.h" #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" /**************************************************************************** * Accessors for: struct libnvme_path diff --git a/libnvme/src/nvme/cmds.c b/libnvme/src/nvme/cmds.c index 30720d36fe..39b921b9b4 100644 --- a/libnvme/src/nvme/cmds.c +++ b/libnvme/src/nvme/cmds.c @@ -14,7 +14,7 @@ #include "cleanup.h" #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" static bool force_4k; diff --git a/libnvme/src/nvme/compiler_attributes.h b/libnvme/src/nvme/compiler-attributes.h similarity index 100% rename from libnvme/src/nvme/compiler_attributes.h rename to libnvme/src/nvme/compiler-attributes.h diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index 815cc1f880..9228d75626 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -37,7 +37,7 @@ #include "cleanup.h" #include "private.h" #include "private-fabrics.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" const char *nvmf_dev = "/dev/nvme-fabrics"; diff --git a/libnvme/src/nvme/filters.c b/libnvme/src/nvme/filters.c index f18a6e3e1c..59c807bea7 100644 --- a/libnvme/src/nvme/filters.c +++ b/libnvme/src/nvme/filters.c @@ -13,7 +13,7 @@ #include #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" __public int libnvme_filter_namespace(const struct dirent *d) { diff --git a/libnvme/src/nvme/ioctl.c b/libnvme/src/nvme/ioctl.c index 53ee19ac91..2fcd868019 100644 --- a/libnvme/src/nvme/ioctl.c +++ b/libnvme/src/nvme/ioctl.c @@ -23,7 +23,7 @@ #include #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" static int nvme_verify_chr(struct libnvme_transport_handle *hdl) { diff --git a/libnvme/src/nvme/lib.c b/libnvme/src/nvme/lib.c index 47089f5c99..4203e2754e 100644 --- a/libnvme/src/nvme/lib.c +++ b/libnvme/src/nvme/lib.c @@ -17,7 +17,7 @@ #include "cleanup.h" #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" static bool libnvme_mi_probe_enabled_default(void) { diff --git a/libnvme/src/nvme/linux.c b/libnvme/src/nvme/linux.c index 809c4a49fb..61a3052b8a 100644 --- a/libnvme/src/nvme/linux.c +++ b/libnvme/src/nvme/linux.c @@ -50,7 +50,7 @@ #include "base64.h" #include "cleanup.h" #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" #define NVMF_HOSTID_SIZE 37 diff --git a/libnvme/src/nvme/log.c b/libnvme/src/nvme/log.c index 159e0d1aa0..3d025cd8f0 100644 --- a/libnvme/src/nvme/log.c +++ b/libnvme/src/nvme/log.c @@ -20,7 +20,7 @@ #include "cleanup.h" #define LOG_FUNCNAME 1 #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" #ifndef LOG_CLOCK #define LOG_CLOCK CLOCK_MONOTONIC diff --git a/libnvme/src/nvme/mi-mctp.c b/libnvme/src/nvme/mi-mctp.c index 1e1554e1cb..476b97e0c9 100644 --- a/libnvme/src/nvme/mi-mctp.c +++ b/libnvme/src/nvme/mi-mctp.c @@ -39,7 +39,7 @@ #include #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" #if !defined(AF_MCTP) diff --git a/libnvme/src/nvme/mi.c b/libnvme/src/nvme/mi.c index da8486448f..df54c20502 100644 --- a/libnvme/src/nvme/mi.c +++ b/libnvme/src/nvme/mi.c @@ -20,7 +20,7 @@ #include #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" #define NUM_ENABLES (256u) diff --git a/libnvme/src/nvme/nbft.c b/libnvme/src/nvme/nbft.c index 852d8c4db6..5caf15755d 100644 --- a/libnvme/src/nvme/nbft.c +++ b/libnvme/src/nvme/nbft.c @@ -17,7 +17,7 @@ #include #include "private.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" #define MIN(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index ab1e4b5e1b..23206b7295 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -30,7 +30,7 @@ #include "cleanup.h" #include "private.h" #include "util.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" /** * struct candidate_args - Used to look for a controller matching these parameters diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index 1f412f58c9..37b8a0cf1b 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -30,7 +30,7 @@ #include "cleanup.h" #include "private.h" #include "util.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" /* The bionic libc implementation doesn't define LINE_MAX */ #ifndef LINE_MAX diff --git a/libnvme/tools/generator/generate-accessors.md b/libnvme/tools/generator/generate-accessors.md index 42702d9a12..2dc1fc16bf 100644 --- a/libnvme/tools/generator/generate-accessors.md +++ b/libnvme/tools/generator/generate-accessors.md @@ -210,7 +210,7 @@ const char *car_get_vin(const struct car *p); #include "accessors.h" #include "person.h" -#include "compiler_attributes.h" +#include "compiler-attributes.h" /**************************************************************************** * Accessors for: struct person diff --git a/libnvme/tools/generator/generate-accessors.py b/libnvme/tools/generator/generate-accessors.py index 7e6ce48a13..cdd78af57a 100755 --- a/libnvme/tools/generator/generate-accessors.py +++ b/libnvme/tools/generator/generate-accessors.py @@ -655,7 +655,7 @@ def main(): ) for fname in files_to_include: f.write(f'#include "{fname}"\n') - f.write('#include "compiler_attributes.h"\n') + f.write('#include "compiler-attributes.h"\n') f.write('\n') f.write(''.join(src_parts)) From a8c9b33d7ffb618f825d346ad02b9700a1f2abf1 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 10:04:18 +0200 Subject: [PATCH 03/14] cleanup: move optional cleanups to C files The cleanup helpers for addrinfo and uri depend on features that are not always available, such as network support or fabrics. Therefore, they cannot be part of the generic cleanup header file. Also, they are only used in a single location each. Move them to the C files that use them. Signed-off-by: Daniel Wagner --- libnvme/src/nvme/cleanup.h | 14 -------------- libnvme/src/nvme/fabrics.c | 7 +++++++ libnvme/src/nvme/linux.c | 1 + libnvme/src/nvme/util.c | 4 ++++ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libnvme/src/nvme/cleanup.h b/libnvme/src/nvme/cleanup.h index c8fbe3f50c..8d602de4a6 100644 --- a/libnvme/src/nvme/cleanup.h +++ b/libnvme/src/nvme/cleanup.h @@ -3,14 +3,10 @@ #define __CLEANUP_H #include -#include #include #include #include -#include -#include - #include "fabrics.h" #define __cleanup(fn) __attribute__((cleanup(fn))) @@ -44,14 +40,4 @@ static inline void cleanup_fd(int *fd) } #define __cleanup_fd __cleanup(cleanup_fd) -static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *, freeaddrinfo) -#define __cleanup_addrinfo __cleanup(cleanup_addrinfo) - -static inline void free_uri(struct libnvme_fabrics_uri **uri) -{ - if (*uri) - libnvmf_free_uri(*uri); -} -#define __cleanup_uri __cleanup(free_uri) - #endif diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index 9228d75626..2ab71186ee 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -41,6 +41,13 @@ const char *nvmf_dev = "/dev/nvme-fabrics"; +static inline void free_uri(struct libnvme_fabrics_uri **uri) +{ + if (*uri) + libnvmf_free_uri(*uri); +} +#define __cleanup_uri __cleanup(free_uri) + /** * strchomp() - Strip trailing spaces * @str: String to strip diff --git a/libnvme/src/nvme/linux.c b/libnvme/src/nvme/linux.c index 61a3052b8a..7fa7e6c01f 100644 --- a/libnvme/src/nvme/linux.c +++ b/libnvme/src/nvme/linux.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index 37b8a0cf1b..fe8790302d 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -453,6 +453,10 @@ __public const char *libnvme_strerror(int errnum) } #ifdef HAVE_NETDB +static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *, + freeaddrinfo) +#define __cleanup_addrinfo __cleanup(cleanup_addrinfo) + int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, char **hostname) { From 6ea4083f1806301650406270d7b13ec59e8f89c7 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 12:22:35 +0200 Subject: [PATCH 04/14] cleanup: move POSIX API cleanup helpers into a separate file The main cleanup header file should only include generic headers to simplify porting. Signed-off-by: Daniel Wagner --- libnvme/src/nvme/cleanup-linux.h | 28 ++++++++++++++++++++++++++++ libnvme/src/nvme/cleanup.h | 18 ------------------ libnvme/src/nvme/fabrics.c | 1 + libnvme/src/nvme/lib.c | 1 + libnvme/src/nvme/linux.c | 1 + libnvme/src/nvme/tree.c | 1 + libnvme/src/nvme/util.c | 1 + 7 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 libnvme/src/nvme/cleanup-linux.h diff --git a/libnvme/src/nvme/cleanup-linux.h b/libnvme/src/nvme/cleanup-linux.h new file mode 100644 index 0000000000..fab5796edd --- /dev/null +++ b/libnvme/src/nvme/cleanup-linux.h @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * This file is part of libnvme. + * Copyright (c) 2026 SUSE Software Solutions + * + * Authors: Daniel Wagner + */ + +#pragma once + +#include +#include +#include + +#include "cleanup.h" + +static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose) +#define __cleanup_file __cleanup(cleanup_file) + +static inline DEFINE_CLEANUP_FUNC(cleanup_dir, DIR *, closedir) +#define __cleanup_dir __cleanup(cleanup_dir) + +static inline void cleanup_fd(int *fd) +{ + if (*fd >= 0) + close(*fd); +} +#define __cleanup_fd __cleanup(cleanup_fd) diff --git a/libnvme/src/nvme/cleanup.h b/libnvme/src/nvme/cleanup.h index 8d602de4a6..5c7c550e24 100644 --- a/libnvme/src/nvme/cleanup.h +++ b/libnvme/src/nvme/cleanup.h @@ -2,12 +2,7 @@ #ifndef __CLEANUP_H #define __CLEANUP_H -#include -#include #include -#include - -#include "fabrics.h" #define __cleanup(fn) __attribute__((cleanup(fn))) @@ -27,17 +22,4 @@ static inline void freep(void *p) } #define __cleanup_free __cleanup(freep) -static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose) -#define __cleanup_file __cleanup(cleanup_file) - -static inline DEFINE_CLEANUP_FUNC(cleanup_dir, DIR *, closedir) -#define __cleanup_dir __cleanup(cleanup_dir) - -static inline void cleanup_fd(int *fd) -{ - if (*fd >= 0) - close(*fd); -} -#define __cleanup_fd __cleanup(cleanup_fd) - #endif diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index 2ab71186ee..e121bbb65a 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -35,6 +35,7 @@ #include #include "cleanup.h" +#include "cleanup-linux.h" #include "private.h" #include "private-fabrics.h" #include "compiler-attributes.h" diff --git a/libnvme/src/nvme/lib.c b/libnvme/src/nvme/lib.c index 4203e2754e..adbd16b5b7 100644 --- a/libnvme/src/nvme/lib.c +++ b/libnvme/src/nvme/lib.c @@ -16,6 +16,7 @@ #include #include "cleanup.h" +#include "cleanup-linux.h" #include "private.h" #include "compiler-attributes.h" diff --git a/libnvme/src/nvme/linux.c b/libnvme/src/nvme/linux.c index 7fa7e6c01f..fe37ea21d3 100644 --- a/libnvme/src/nvme/linux.c +++ b/libnvme/src/nvme/linux.c @@ -50,6 +50,7 @@ #include "crc32.h" #include "base64.h" #include "cleanup.h" +#include "cleanup-linux.h" #include "private.h" #include "compiler-attributes.h" diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 23206b7295..5a4a94ab83 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -28,6 +28,7 @@ #include #include "cleanup.h" +#include "cleanup-linux.h" #include "private.h" #include "util.h" #include "compiler-attributes.h" diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index fe8790302d..9289b33cca 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -28,6 +28,7 @@ #include #include "cleanup.h" +#include "cleanup-linux.h" #include "private.h" #include "util.h" #include "compiler-attributes.h" From 7ed392fed4b6e20ee5ce7880ddbb8d7d3575e68b Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 10:52:32 +0200 Subject: [PATCH 05/14] uring: move no-uring implementation into C file Keep header files readable by avoiding static inline dummy function implementations. Signed-off-by: Daniel Wagner --- libnvme/src/meson.build | 2 ++ libnvme/src/nvme/no-uring.c | 39 +++++++++++++++++++++++++++++++++++++ libnvme/src/nvme/private.h | 30 ---------------------------- 3 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 libnvme/src/nvme/no-uring.c diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index 5e7ec5b33c..fd5d9364d1 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -56,6 +56,8 @@ endif if liburing_dep.found() sources += 'nvme/uring.c' +else + sources += 'nvme/no-uring.c' endif if host_system != 'windows' diff --git a/libnvme/src/nvme/no-uring.c b/libnvme/src/nvme/no-uring.c new file mode 100644 index 0000000000..abaadd7afa --- /dev/null +++ b/libnvme/src/nvme/no-uring.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * This file is part of libnvme. + * Copyright (c) 2026 SUSE Software Solutions + * + * Authors: Daniel Wagner + */ + + +#include + +#include + +#include "private.h" + +int libnvme_open_uring(struct libnvme_global_ctx *ctx) +{ + return -ENOTSUP; +} +void libnvme_close_uring(struct libnvme_global_ctx *ctx) +{ +} + +int __libnvme_transport_handle_open_uring(struct libnvme_transport_handle *hdl) +{ + hdl->ctx->uring_state = LIBNVME_IO_URING_STATE_NOT_AVAILABLE; + return -ENOTSUP; +} + +int libnvme_submit_admin_passthru_async(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) +{ + return -ENOTSUP; +} + +int libnvme_wait_complete_passthru(struct libnvme_transport_handle *hdl) +{ + return -ENOTSUP; +} diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index eaf20eb2a9..e4b3df2485 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -7,7 +7,6 @@ */ #pragma once -#include #include #include @@ -743,39 +742,10 @@ void libnvme_ns_release_transport_handle(libnvme_ns_t n); int libnvme_mi_admin_admin_passthru(struct libnvme_transport_handle *hdl, struct libnvme_passthru_cmd *cmd); -#ifdef CONFIG_LIBURING int libnvme_open_uring(struct libnvme_global_ctx *ctx); void libnvme_close_uring(struct libnvme_global_ctx *ctx); int __libnvme_transport_handle_open_uring(struct libnvme_transport_handle *hdl); int libnvme_submit_admin_passthru_async(struct libnvme_transport_handle *hdl, struct libnvme_passthru_cmd *cmd); int libnvme_wait_complete_passthru(struct libnvme_transport_handle *hdl); -#else -static inline int -libnvme_open_uring(struct libnvme_global_ctx *ctx) -{ - return -ENOTSUP; -} -static inline void -libnvme_close_uring(struct libnvme_global_ctx *ctx) -{ -} -static inline int -__libnvme_transport_handle_open_uring(struct libnvme_transport_handle *hdl) -{ - hdl->ctx->uring_state = LIBNVME_IO_URING_STATE_NOT_AVAILABLE; - return -ENOTSUP; -} -static inline int -libnvme_submit_admin_passthru_async(struct libnvme_transport_handle *hdl, - struct libnvme_passthru_cmd *cmd) -{ - return -ENOTSUP; -} -static inline int -libnvme_wait_complete_passthru(struct libnvme_transport_handle *hdl) -{ - return -ENOTSUP; -} -#endif From b0cf18ca18ccfb4392ba89f73f334ec8ea808b02 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 11:11:18 +0200 Subject: [PATCH 06/14] private: make fabrics parts optional in global context As a first step, mark all fabrics-related parts of the global context as optional. Once all fabrics-related functions are clearly identified, they can be moved to the appropriate location. Signed-off-by: Daniel Wagner --- libnvme/src/nvme/lib.c | 10 +++++++++- libnvme/src/nvme/private.h | 3 ++- libnvme/src/nvme/tree.c | 20 ++++++++++++++++---- libnvme/src/nvme/util.c | 7 +++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/libnvme/src/nvme/lib.c b/libnvme/src/nvme/lib.c index adbd16b5b7..a81283d8ee 100644 --- a/libnvme/src/nvme/lib.c +++ b/libnvme/src/nvme/lib.c @@ -11,6 +11,12 @@ #include #include +#ifdef CONFIG_FABRICS +#include + +#include +#endif + #include #include @@ -72,10 +78,12 @@ __public void libnvme_free_global_ctx(struct libnvme_global_ctx *ctx) if (!ctx) return; +#ifdef CONFIG_FABRICS freeifaddrs(ctx->ifaddrs_cache); /* NULL-safe */ ctx->ifaddrs_cache = NULL; - free(ctx->options); +#endif + libnvme_for_each_host_safe(ctx, h, _h) __libnvme_free_host(h); libnvme_mi_for_each_endpoint_safe(ctx, ep, tmp) diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index e4b3df2485..c451dbfb7e 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -7,7 +7,6 @@ */ #pragma once -#include #include #include @@ -295,8 +294,10 @@ struct libnvme_global_ctx { bool ioctl_probing; bool create_only; bool dry_run; +#ifdef CONFIG_FABRICS struct libnvme_fabric_options *options; struct ifaddrs *ifaddrs_cache; /* init with libnvme_getifaddrs() */ +#endif enum libnvme_io_uring_state uring_state; #ifdef CONFIG_LIBURING diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 5a4a94ab83..2e712f7074 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -17,11 +16,16 @@ #include #include -#include -#include #include #include +#ifdef CONFIG_FABRICS +#include +#include + +#include +#endif + #include #include @@ -1067,18 +1071,21 @@ __public void libnvme_free_ctrl(libnvme_ctrl_t c) static bool traddr_is_hostname(const char *transport, const char *traddr) { - char addrstr[NVMF_TRADDR_SIZE]; if (!traddr || !transport) return false; if (!strcmp(traddr, "none")) return false; +#ifdef CONFIG_FABRICS + char addrstr[NVMF_TRADDR_SIZE]; + if (strcmp(transport, "tcp") && strcmp(transport, "rdma")) return false; if (inet_pton(AF_INET, traddr, addrstr) > 0 || inet_pton(AF_INET6, traddr, addrstr) > 0) return false; +#endif return true; } @@ -1157,6 +1164,7 @@ __public int libnvme_create_ctrl(struct libnvme_global_ctx *ctx, return _libnvme_create_ctrl(ctx, &fctx, cp); } +#ifdef CONFIG_FABRICS /** * _tcp_ctrl_match_host_traddr_no_src_addr() - Match host_traddr w/o src_addr * @c: An existing controller instance @@ -1383,6 +1391,7 @@ static bool _tcp_match_ctrl(struct libnvme_ctrl *c, return true; } +#endif /** * _match_ctrl() - Check if controller matches candidate (non TCP transport) @@ -1425,6 +1434,7 @@ static bool _match_ctrl(struct libnvme_ctrl *c, return true; } + /** * _candidate_init() - Init candidate and get the matching function * @@ -1469,6 +1479,7 @@ static ctrl_match_t _candidate_init(struct libnvme_global_ctx *ctx, candidate->well_known_nqn = true; } +#ifdef CONFIG_FABRICS if (streq0(fctx->transport, "tcp")) { candidate->iface_list = libnvme_getifaddrs(ctx); /* TCP only */ candidate->addreq = libnvme_ipaddrs_eq; @@ -1479,6 +1490,7 @@ static ctrl_match_t _candidate_init(struct libnvme_global_ctx *ctx, candidate->addreq = libnvme_ipaddrs_eq; return _match_ctrl; } +#endif /* All other transport types */ candidate->addreq = streqcase0; diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index 9289b33cca..2166e2cba6 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -16,6 +16,11 @@ #include #include +#if defined(HAVE_NETDB) || defined(CONFIG_FABRICS) +#include +#include +#endif + #include #include #include @@ -981,6 +986,7 @@ void *__libnvme_realloc(void *p, size_t len) return result; } +#ifdef CONFIG_FABRICS const struct ifaddrs *libnvme_getifaddrs(struct libnvme_global_ctx *ctx) { if (!ctx->ifaddrs_cache) { @@ -992,6 +998,7 @@ const struct ifaddrs *libnvme_getifaddrs(struct libnvme_global_ctx *ctx) return ctx->ifaddrs_cache; } +#endif /* This used instead of basename() due to behavioral differences between * the POSIX and the GNU version. This is the glibc implementation. From ccb12c1ba0b318e8fe0b00a9611ea2ebf4915d1f Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 11:53:40 +0200 Subject: [PATCH 07/14] mi: make management interface support optional The MI code depends on Linux-specific interfaces (networking), which makes porting to other platforms more difficult. Make it optional. This also helps reduce the footprint for minimal setups. Signed-off-by: Daniel Wagner --- libnvme/examples/meson.build | 68 ++++++++++--------- libnvme/src/meson.build | 34 +++++++--- libnvme/src/nvme/lib.c | 5 ++ libnvme/src/nvme/mi-mctp.c | 2 + libnvme/src/nvme/mi.c | 1 + libnvme/src/nvme/no-mi.c | 37 +++++++++++ libnvme/src/nvme/private-mi.h | 122 ++++++++++++++++++++++++++++++++++ libnvme/src/nvme/private.h | 110 +----------------------------- libnvme/test/mi-mctp.c | 1 + libnvme/test/mi.c | 1 + meson.build | 4 +- meson_options.txt | 6 ++ scripts/build.sh | 1 + 13 files changed, 240 insertions(+), 152 deletions(-) create mode 100644 libnvme/src/nvme/no-mi.c create mode 100644 libnvme/src/nvme/private-mi.h diff --git a/libnvme/examples/meson.build b/libnvme/examples/meson.build index 31db6a7e17..40da11edbb 100644 --- a/libnvme/examples/meson.build +++ b/libnvme/examples/meson.build @@ -47,46 +47,48 @@ if want_fabrics ) endif -executable( - 'mi-mctp', - ['mi-mctp.c'], - dependencies: [ - config_dep, - ccan_dep, - libnvme_dep, - ], -) - -executable( - 'mi-mctp-csi-test', - ['mi-mctp-csi-test.c'], - dependencies: [ - config_dep, - ccan_dep, - libnvme_dep, - threads_dep, - ], -) +if want_mi + executable( + 'mi-mctp', + ['mi-mctp.c'], + dependencies: [ + config_dep, + ccan_dep, + libnvme_dep, + ], + ) -executable( - 'mi-mctp-ae', - ['mi-mctp-ae.c'], - dependencies: [ - config_dep, - ccan_dep, - libnvme_dep, - ], -) + executable( + 'mi-mctp-csi-test', + ['mi-mctp-csi-test.c'], + dependencies: [ + config_dep, + ccan_dep, + libnvme_dep, + threads_dep, + ], + ) -if libdbus_dep.found() executable( - 'mi-conf', - ['mi-conf.c'], + 'mi-mctp-ae', + ['mi-mctp-ae.c'], dependencies: [ config_dep, ccan_dep, libnvme_dep, - libdbus_dep, ], ) + + if libdbus_dep.found() + executable( + 'mi-conf', + ['mi-conf.c'], + dependencies: [ + config_dep, + ccan_dep, + libnvme_dep, + libdbus_dep, + ], + ) + endif endif diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index fd5d9364d1..2815d2ffee 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -19,8 +19,6 @@ else 'nvme/lib.c', 'nvme/linux.c', 'nvme/log.c', - 'nvme/mi-mctp.c', - 'nvme/mi.c', 'nvme/sysfs.c', 'nvme/tree.c', 'nvme/util.c', @@ -34,8 +32,6 @@ headers = [ 'nvme/lib-types.h', 'nvme/lib.h', 'nvme/linux.h', - 'nvme/mi-types.h', - 'nvme/mi.h', 'nvme/tree.h', 'nvme/types.h', 'nvme/util.h', @@ -54,6 +50,21 @@ if want_fabrics ] endif +if want_mi + sources += [ + 'nvme/mi-mctp.c', + 'nvme/mi.c', + ] + headers += [ + 'nvme/mi-types.h', + 'nvme/mi.h', + ] +else + sources += [ + 'nvme/no-mi.c' + ] +endif + if liburing_dep.found() sources += 'nvme/uring.c' else @@ -158,14 +169,17 @@ libnvme_test_dep = declare_dependency( ) mode = 'rw-r--r--' -install_headers( - [ - 'libnvme-mi.h', - ], - install_mode: mode, -) install_headers( headers, subdir: 'nvme', install_mode: mode, ) +if want_mi + install_headers( + [ + 'libnvme-mi.h', + ], + install_mode: mode, + ) +endif + diff --git a/libnvme/src/nvme/lib.c b/libnvme/src/nvme/lib.c index a81283d8ee..bfec5713a0 100644 --- a/libnvme/src/nvme/lib.c +++ b/libnvme/src/nvme/lib.c @@ -24,6 +24,7 @@ #include "cleanup.h" #include "cleanup-linux.h" #include "private.h" +#include "private-mi.h" #include "compiler-attributes.h" static bool libnvme_mi_probe_enabled_default(void) @@ -73,7 +74,9 @@ __public struct libnvme_global_ctx *libnvme_create_global_ctx(FILE *fp, int log_ __public void libnvme_free_global_ctx(struct libnvme_global_ctx *ctx) { struct libnvme_host *h, *_h; +#ifdef CONFIG_MI libnvme_mi_ep_t ep, tmp; +#endif if (!ctx) return; @@ -86,8 +89,10 @@ __public void libnvme_free_global_ctx(struct libnvme_global_ctx *ctx) libnvme_for_each_host_safe(ctx, h, _h) __libnvme_free_host(h); +#ifdef CONFIG_MI libnvme_mi_for_each_endpoint_safe(ctx, ep, tmp) libnvme_mi_close(ep); +#endif free(ctx->config_file); free(ctx->application); libnvme_close_uring(ctx); diff --git a/libnvme/src/nvme/mi-mctp.c b/libnvme/src/nvme/mi-mctp.c index 476b97e0c9..dad699e844 100644 --- a/libnvme/src/nvme/mi-mctp.c +++ b/libnvme/src/nvme/mi-mctp.c @@ -27,6 +27,8 @@ #include +#include "private-mi.h" + #ifdef CONFIG_DBUS #include diff --git a/libnvme/src/nvme/mi.c b/libnvme/src/nvme/mi.c index df54c20502..be0c555608 100644 --- a/libnvme/src/nvme/mi.c +++ b/libnvme/src/nvme/mi.c @@ -20,6 +20,7 @@ #include #include "private.h" +#include "private-mi.h" #include "compiler-attributes.h" #define NUM_ENABLES (256u) diff --git a/libnvme/src/nvme/no-mi.c b/libnvme/src/nvme/no-mi.c new file mode 100644 index 0000000000..954303fbfd --- /dev/null +++ b/libnvme/src/nvme/no-mi.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * This file is part of libnvme. + * Copyright (c) 2026 SUSE Software Solutions + * + * Authors: Daniel Wagner + */ + +#include + +#include + +const char *libnvme_mi_status_to_string(int status) +{ + return "MI support disabled"; +} + +int __libnvme_transport_handle_open_mi(struct libnvme_transport_handle *hdl, + const char *devname) +{ + return -ENOTSUP; +} + +int __libnvme_transport_handle_init_mi(struct libnvme_transport_handle *hdl) +{ + return -ENOTSUP; +} + +void __libnvme_transport_handle_close_mi(struct libnvme_transport_handle *hdl) +{ +} + +int libnvme_mi_admin_admin_passthru(struct libnvme_transport_handle *hdl, + struct libnvme_passthru_cmd *cmd) +{ + return -ENOTSUP; +} diff --git a/libnvme/src/nvme/private-mi.h b/libnvme/src/nvme/private-mi.h new file mode 100644 index 0000000000..d814df4fe3 --- /dev/null +++ b/libnvme/src/nvme/private-mi.h @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * This file is part of libnvme. + * Copyright (c) 2021 Code Construct Pty Ltd + * + * Authors: Jeremy Kerr + */ + +#pragma once + +#include +#include +#include +#include + +#include + +#include + +#include + +/* internal transport API */ +struct libnvme_mi_req { + struct nvme_mi_msg_hdr *hdr; + size_t hdr_len; + void *data; + size_t data_len; + __u32 mic; +}; + +struct libnvme_mi_resp { + struct nvme_mi_msg_hdr *hdr; + size_t hdr_len; + void *data; + size_t data_len; + __u32 mic; +}; + +struct libnvme_mi_aem_ctx { + struct nvme_mi_aem_occ_list_hdr *occ_header; + struct nvme_mi_aem_occ_data *list_start; + struct nvme_mi_aem_occ_data *list_current; + int list_current_index; + struct libnvme_mi_aem_config callbacks; + int last_generation_num; + struct libnvme_mi_event event; +}; + +struct libnvme_mi_ep { + struct libnvme_global_ctx *ctx; + const struct libnvme_mi_transport *transport; + void *transport_data; + struct list_node root_entry; + struct list_head controllers; + bool quirks_probed; + bool controllers_scanned; + unsigned int timeout; + unsigned int mprt_max; + unsigned long quirks; + + __u8 csi; + + /* inter-command delay, for LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME */ + unsigned int inter_command_us; + struct timespec last_resp_time; + bool last_resp_time_valid; + + struct libnvme_mi_aem_ctx *aem_ctx; +}; + +struct libnvme_mi_transport { + const char *name; + bool mic_enabled; + int (*submit)(struct libnvme_mi_ep *ep, + struct libnvme_mi_req *req, + struct libnvme_mi_resp *resp); + void (*close)(struct libnvme_mi_ep *ep); + int (*desc_ep)(struct libnvme_mi_ep *ep, char *buf, size_t len); + int (*check_timeout)(struct libnvme_mi_ep *ep, unsigned int timeout); + int (*aem_fd)(struct libnvme_mi_ep *ep); + int (*aem_read)(struct libnvme_mi_ep *ep, + struct libnvme_mi_resp *resp); + int (*aem_purge)(struct libnvme_mi_ep *ep); +}; + +struct libnvme_mi_ep *libnvme_mi_init_ep(struct libnvme_global_ctx *ctx); +void libnvme_mi_ep_probe(struct libnvme_mi_ep *ep); + +/* for tests, we need to calculate the correct MICs */ +__u32 libnvme_mi_crc32_update(__u32 crc, void *data, size_t len); + +/* we have a facility to mock MCTP socket operations in the mi-mctp transport, + * using this ops type. This should only be used for test, and isn't exposed + * in the shared lib */; +struct mctp_ioc_tag_ctl; +struct __mi_mctp_socket_ops { + int (*msg_socket)(void); + int (*aem_socket)(__u8 eid, unsigned int network); + ssize_t (*sendmsg)(int, const struct msghdr *, int); + ssize_t (*recvmsg)(int, struct msghdr *, int); + int (*poll)(struct pollfd *, nfds_t, int); + int (*ioctl_tag)(int, unsigned long, struct mctp_ioc_tag_ctl *); +}; +void __libnvme_mi_mctp_set_ops(const struct __mi_mctp_socket_ops *newops); + +/* quirks */ + +/* Set a minimum time between receiving a response from one command and + * sending the next request. Some devices may ignore new commands sent too soon + * after the previous request, so manually insert a delay + */ +#define LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME (1 << 0) + +/* Some devices may not support using CSI 1. Attempting to set an + * endpoint to use this with these devices should return an error + */ +#define LIBNVME_QUIRK_CSI_1_NOT_SUPPORTED (1 << 1) + +int __libnvme_transport_handle_open_mi(struct libnvme_transport_handle *hdl, + const char *devname); +int __libnvme_transport_handle_init_mi(struct libnvme_transport_handle *hdl); +void __libnvme_transport_handle_close_mi(struct libnvme_transport_handle *hdl); diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index c451dbfb7e..231241fdae 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -7,17 +7,13 @@ */ #pragma once -#include - #include -#include #include #include #include #include -#include const char *libnvme_subsys_sysfs_dir(void); const char *libnvme_ctrl_sysfs_dir(void); @@ -118,10 +114,12 @@ struct libnvme_transport_handle { bool ioctl_io64; bool uring_enabled; +#ifdef CONFIG_MI /* mi */ struct libnvme_mi_ep *ep; __u16 id; struct list_node ep_entry; +#endif struct libnvme_log *log; }; @@ -381,10 +379,6 @@ struct libnvme_transport_handle *__libnvme_open(struct libnvme_global_ctx *ctx, const char *name); struct libnvme_transport_handle *__libnvme_create_transport_handle( struct libnvme_global_ctx *ctx); -int __libnvme_transport_handle_open_mi(struct libnvme_transport_handle *hdl, - const char *devname); -int __libnvme_transport_handle_init_mi(struct libnvme_transport_handle *hdl); -void __libnvme_transport_handle_close_mi(struct libnvme_transport_handle *hdl); int _libnvme_create_ctrl(struct libnvme_global_ctx *ctx, struct libnvmf_context *fctx, @@ -420,106 +414,6 @@ __libnvme_msg(struct libnvme_global_ctx *ctx, int level, #define libnvme_msg(ctx, level, format, ...) \ __libnvme_msg(ctx, level, __libnvme_log_func, format, ##__VA_ARGS__) -/* mi internal headers */ - -/* internal transport API */ -struct libnvme_mi_req { - struct nvme_mi_msg_hdr *hdr; - size_t hdr_len; - void *data; - size_t data_len; - __u32 mic; -}; - -struct libnvme_mi_resp { - struct nvme_mi_msg_hdr *hdr; - size_t hdr_len; - void *data; - size_t data_len; - __u32 mic; -}; - -struct libnvme_mi_ep; -struct libnvme_mi_transport { - const char *name; - bool mic_enabled; - int (*submit)(struct libnvme_mi_ep *ep, - struct libnvme_mi_req *req, - struct libnvme_mi_resp *resp); - void (*close)(struct libnvme_mi_ep *ep); - int (*desc_ep)(struct libnvme_mi_ep *ep, char *buf, size_t len); - int (*check_timeout)(struct libnvme_mi_ep *ep, unsigned int timeout); - int (*aem_fd)(struct libnvme_mi_ep *ep); - int (*aem_read)(struct libnvme_mi_ep *ep, - struct libnvme_mi_resp *resp); - int (*aem_purge)(struct libnvme_mi_ep *ep); -}; - -struct libnvme_mi_aem_ctx { - struct nvme_mi_aem_occ_list_hdr *occ_header; - struct nvme_mi_aem_occ_data *list_start; - struct nvme_mi_aem_occ_data *list_current; - int list_current_index; - struct libnvme_mi_aem_config callbacks; - int last_generation_num; - struct libnvme_mi_event event; -}; - -/* quirks */ - -/* Set a minimum time between receiving a response from one command and - * sending the next request. Some devices may ignore new commands sent too soon - * after the previous request, so manually insert a delay - */ -#define LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME (1 << 0) - -/* Some devices may not support using CSI 1. Attempting to set an - * endpoint to use this with these devices should return an error - */ -#define LIBNVME_QUIRK_CSI_1_NOT_SUPPORTED (1 << 1) - -struct libnvme_mi_ep { - struct libnvme_global_ctx *ctx; - const struct libnvme_mi_transport *transport; - void *transport_data; - struct list_node root_entry; - struct list_head controllers; - bool quirks_probed; - bool controllers_scanned; - unsigned int timeout; - unsigned int mprt_max; - unsigned long quirks; - - __u8 csi; - - /* inter-command delay, for LIBNVME_QUIRK_MIN_INTER_COMMAND_TIME */ - unsigned int inter_command_us; - struct timespec last_resp_time; - bool last_resp_time_valid; - - struct libnvme_mi_aem_ctx *aem_ctx; -}; - -struct libnvme_mi_ep *libnvme_mi_init_ep(struct libnvme_global_ctx *ctx); -void libnvme_mi_ep_probe(struct libnvme_mi_ep *ep); - -/* for tests, we need to calculate the correct MICs */ -__u32 libnvme_mi_crc32_update(__u32 crc, void *data, size_t len); - -/* we have a facility to mock MCTP socket operations in the mi-mctp transport, - * using this ops type. This should only be used for test, and isn't exposed - * in the shared lib */; -struct mctp_ioc_tag_ctl; -struct __mi_mctp_socket_ops { - int (*msg_socket)(void); - int (*aem_socket)(__u8 eid, unsigned int network); - ssize_t (*sendmsg)(int, const struct msghdr *, int); - ssize_t (*recvmsg)(int, struct msghdr *, int); - int (*poll)(struct pollfd *, nfds_t, int); - int (*ioctl_tag)(int, unsigned long, struct mctp_ioc_tag_ctl *); -}; -void __libnvme_mi_mctp_set_ops(const struct __mi_mctp_socket_ops *newops); - #define SECTOR_SIZE 512 #define SECTOR_SHIFT 9 diff --git a/libnvme/test/mi-mctp.c b/libnvme/test/mi-mctp.c index f88a7381f3..ca93e614d3 100644 --- a/libnvme/test/mi-mctp.c +++ b/libnvme/test/mi-mctp.c @@ -29,6 +29,7 @@ #include #include "nvme/private.h" +#include "nvme/private-mi.h" #include "utils.h" diff --git a/libnvme/test/mi.c b/libnvme/test/mi.c index 8d033cd590..26372ee8df 100644 --- a/libnvme/test/mi.c +++ b/libnvme/test/mi.c @@ -18,6 +18,7 @@ /* we define a custom transport, so need the internal headers */ #include "nvme/private.h" +#include "nvme/private-mi.h" #include "utils.h" diff --git a/meson.build b/meson.build index d04bf26c85..361e61dd6e 100644 --- a/meson.build +++ b/meson.build @@ -53,6 +53,7 @@ host_system = host_machine.system() want_nvme = get_option('nvme').disabled() == false want_libnvme = get_option('libnvme').disabled() == false want_fabrics = get_option('fabrics').disabled() == false and host_system != 'windows' +want_mi = get_option('mi').disabled() == false and host_system != 'windows' want_json_c = get_option('json-c').disabled() == false and host_system != 'windows' want_tests = get_option('tests') and host_system != 'windows' want_examples = get_option('examples') and host_system != 'windows' @@ -139,6 +140,7 @@ conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir)) conf.set('RUNDIR', '"@0@"'.format(rundir)) conf.set('CONFIG_FABRICS', want_fabrics, description: 'Is fabrics enabled') +conf.set('CONFIG_MI', want_mi, description: 'Is MI enabled') if host_system == 'windows' kernel32_dep = cc.find_library('kernel32', required: true) @@ -336,7 +338,7 @@ else endif conf.set('CONFIG_KEYUTILS', keyutils_dep.found(), description: 'Is libkeyutils available?') -if not want_fabrics or get_option('libdbus').disabled() +if not want_mi or get_option('libdbus').disabled() libdbus_dep = dependency('', required: false) else # Check for libdbus availability. Optional, only required for MCTP dbus scan diff --git a/meson_options.txt b/meson_options.txt index 88c8f364cb..2b6ccf155e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -17,6 +17,12 @@ option( value: 'enabled', description : 'NVMeoF support' ) +option( + 'mi', + type : 'feature', + value: 'enabled', + description : 'MI support' +) option( 'python', type : 'feature', diff --git a/scripts/build.sh b/scripts/build.sh index 5b06f68c37..f1fd04e005 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -236,6 +236,7 @@ config_meson_minimal_static() { -Dc_args="${cflags_str}" \ -Dc_link_args="${ldflags_str}" \ -Dfabrics=disabled \ + -Dmi=disabled \ -Djson-c=disabled \ -Dtests=false \ -Dexamples=false \ From 93653e615b960d63332ead3c82acc7123dbbd34e Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 11:57:09 +0200 Subject: [PATCH 08/14] private: remove unused ioctl.h include The ioctl APIs have been moved out of the private header. No need to include it. Signed-off-by: Daniel Wagner --- libnvme/src/nvme/private.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libnvme/src/nvme/private.h b/libnvme/src/nvme/private.h index 231241fdae..e39e90b455 100644 --- a/libnvme/src/nvme/private.h +++ b/libnvme/src/nvme/private.h @@ -7,7 +7,6 @@ */ #pragma once -#include #include #include From 60f380ace50c09f607e299611229ba283ef0755e Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 13:33:05 +0000 Subject: [PATCH 09/14] lib: define LIBNVME_LOG_* levels to replace syslog.h LOG_* constants The library uses these only for log levels, so the remaining syslog constants are unnecessary. Furthermore, removing the dependency on syslog simplifies porting the project to other operating systems. Signed-off-by: Daniel Wagner --- fabrics.c | 1 - libnvme/libnvme/nvme.i | 12 +- libnvme/libnvme/tests/test-objects.py | 2 +- libnvme/src/nvme/cmds.c | 2 +- libnvme/src/nvme/fabrics.c | 164 +++++++++++------------ libnvme/src/nvme/json.c | 10 +- libnvme/src/nvme/lib.h | 15 ++- libnvme/src/nvme/linux.c | 56 ++++---- libnvme/src/nvme/log.c | 1 - libnvme/src/nvme/mi-mctp.c | 54 ++++---- libnvme/src/nvme/mi.c | 38 +++--- libnvme/src/nvme/nbft.c | 38 +++--- libnvme/src/nvme/tree.c | 84 ++++++------ libnvme/src/nvme/util.c | 14 +- libnvme/test/config/config-dump.c | 2 +- libnvme/test/config/hostnqn-order.c | 6 +- libnvme/test/config/psk-json.c | 2 +- libnvme/test/sysfs/tree-dump.c | 2 +- libnvme/test/tree.c | 8 +- logging.c | 40 ++---- logging.h | 6 +- nvme-print-stdout.c | 2 +- nvme.c | 6 +- plugins/ocp/ocp-hardware-component-log.c | 4 +- 24 files changed, 273 insertions(+), 296 deletions(-) diff --git a/fabrics.c b/fabrics.c index 0f5591ee0c..9d194c4315 100644 --- a/fabrics.c +++ b/fabrics.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include diff --git a/libnvme/libnvme/nvme.i b/libnvme/libnvme/nvme.i index 49da2384fc..56bf04ed1b 100644 --- a/libnvme/libnvme/nvme.i +++ b/libnvme/libnvme/nvme.i @@ -508,14 +508,10 @@ struct libnvme_ns { } void log_level(const char *level) { int log_level = DEFAULT_LOGLEVEL; - if (!strcmp(level, "debug")) log_level = LOG_DEBUG; - else if (!strcmp(level, "info")) log_level = LOG_INFO; - else if (!strcmp(level, "notice")) log_level = LOG_NOTICE; - else if (!strcmp(level, "warning")) log_level = LOG_WARNING; - else if (!strcmp(level, "err")) log_level = LOG_ERR; - else if (!strcmp(level, "crit")) log_level = LOG_CRIT; - else if (!strcmp(level, "alert")) log_level = LOG_ALERT; - else if (!strcmp(level, "emerg")) log_level = LOG_EMERG; + if (!strcmp(level, "debug")) log_level = LIBNVME_LOG_DEBUG; + else if (!strcmp(level, "info")) log_level = LIBNVME_LOG_INFO; + else if (!strcmp(level, "warning")) log_level = LIBNVME_LOG_WARN; + else if (!strcmp(level, "err")) log_level = LIBNVME_LOG_ERR; libnvme_set_logging_level($self, log_level, false, false); } %pythoncode %{ diff --git a/libnvme/libnvme/tests/test-objects.py b/libnvme/libnvme/tests/test-objects.py index e13814cfb4..0aa427a29e 100644 --- a/libnvme/libnvme/tests/test-objects.py +++ b/libnvme/libnvme/tests/test-objects.py @@ -45,7 +45,7 @@ def test_refresh_topology_does_not_raise(self): def test_log_level_all_valid_levels(self): ctx = nvme.global_ctx() - for level in ('debug', 'info', 'notice', 'warning', 'err', 'crit', 'alert', 'emerg'): + for level in ('debug', 'info', 'warning', 'err'): with self.subTest(level=level): ctx.log_level(level) diff --git a/libnvme/src/nvme/cmds.c b/libnvme/src/nvme/cmds.c index 39b921b9b4..f3c378e811 100644 --- a/libnvme/src/nvme/cmds.c +++ b/libnvme/src/nvme/cmds.c @@ -296,7 +296,7 @@ __public int libnvme_get_uuid_list(struct libnvme_transport_handle *hdl, nvme_init_identify_ctrl(&cmd, &ctrl); err = libnvme_submit_admin_passthru(hdl, &cmd); if (err) { - libnvme_msg(hdl->ctx, LOG_ERR, + libnvme_msg(hdl->ctx, LIBNVME_LOG_ERR, "ERROR: nvme_identify_ctrl() failed 0x%x\n", err); return err; } diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index e121bbb65a..7c3b9c680f 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -536,7 +536,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx); stringify(tok), \ arg); \ } else { \ - libnvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -553,7 +553,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx); arg, \ allow_zero); \ } else { \ - libnvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -570,7 +570,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx); arg, \ allow_zero); \ } else { \ - libnvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -586,7 +586,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx); stringify(tok), \ arg); \ } else { \ - libnvme_msg(ctx, LOG_DEBUG, \ + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -602,7 +602,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx); stringify(tok), \ arg); \ } else { \ - libnvme_msg(ctx, LOG_NOTICE, \ + libnvme_msg(ctx, LIBNVME_LOG_WARN, \ "option \"%s\" ignored\n", \ stringify(tok)); \ ret = 0; \ @@ -639,7 +639,7 @@ static int inet6_pton(struct libnvme_global_ctx *ctx, const char *src, uint16_t __cleanup_free char *tmp = strdup(src); if (!tmp) { - libnvme_msg(ctx, LOG_ERR, "cannot copy: %s\n", src); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "cannot copy: %s\n", src); return -ENOMEM; } @@ -655,7 +655,7 @@ static int inet6_pton(struct libnvme_global_ctx *ctx, const char *src, uint16_t if (IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr) && scope) { addr6->sin6_scope_id = if_nametoindex(scope); if (addr6->sin6_scope_id == 0) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "can't find iface index for: %s (%m)\n", scope); return -EINVAL; } @@ -687,7 +687,7 @@ static int inet_pton_with_scope(struct libnvme_global_ctx *ctx, int af, unsigned long long tmp = strtoull(trsvcid, NULL, 0); port = (uint16_t)tmp; if (tmp != port) { - libnvme_msg(ctx, LOG_ERR, "trsvcid out of range: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "trsvcid out of range: %s\n", trsvcid); return -ERANGE; } @@ -708,7 +708,7 @@ static int inet_pton_with_scope(struct libnvme_global_ctx *ctx, int af, ret = inet6_pton(ctx, src, port, addr); break; default: - libnvme_msg(ctx, LOG_ERR, "unexpected address family %d\n", af); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "unexpected address family %d\n", af); } return ret; @@ -739,13 +739,13 @@ static int build_options(libnvme_host_t h, libnvme_ctrl_t c, char **argstr) int ret; if (!transport) { - libnvme_msg(ctx, LOG_ERR, "need a transport (-t) argument\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "need a transport (-t) argument\n"); return -ENVME_CONNECT_TARG; } if (strncmp(transport, "loop", 4)) { if (!libnvme_ctrl_get_traddr(c)) { - libnvme_msg(h->ctx, LOG_ERR, "need a address (-a) argument\n"); + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "need a address (-a) argument\n"); return -ENVME_CONNECT_AARG; } } @@ -775,12 +775,12 @@ static int build_options(libnvme_host_t h, libnvme_ctrl_t c, char **argstr) ctrlkey = libnvme_ctrl_get_dhchap_ctrl_key(c); if (cfg->tls && cfg->concat) { - libnvme_msg(h->ctx, LOG_ERR, "cannot specify --tls and --concat together\n"); + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "cannot specify --tls and --concat together\n"); return -ENVME_CONNECT_INVAL; } if (cfg->concat && !hostkey) { - libnvme_msg(h->ctx, LOG_ERR, "required argument [--dhchap-secret | -S] not specified with --concat\n"); + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "required argument [--dhchap-secret | -S] not specified with --concat\n"); return -ENVME_CONNECT_INVAL; } @@ -882,7 +882,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx) fd = open(nvmf_dev, O_RDONLY); if (fd < 0) { - libnvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to open %s: %s\n", nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_OPEN; } @@ -895,14 +895,14 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx) * Older Linux kernels don't allow reading from nvmf_dev * to get supported options, so use a default set */ - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "Cannot read %s, using default options\n", nvmf_dev); *ctx->options = default_supported_options; return 0; } - libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to read from %s: %s\n", nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_READ; } @@ -910,7 +910,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx) buf[len] = '\0'; options = buf; - libnvme_msg(ctx, LOG_DEBUG, "kernel supports: "); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "kernel supports: "); while ((p = strsep(&options, ",\n")) != NULL) { if (!*p) @@ -918,7 +918,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx) v = strsep(&p, "= "); if (!v) continue; - libnvme_msg(ctx, LOG_DEBUG, "%s ", v); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "%s ", v); parse_option(ctx, v, cntlid); parse_option(ctx, v, concat); @@ -951,7 +951,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx) parse_option(ctx, v, transport); parse_option(ctx, v, trsvcid); } - libnvme_msg(ctx, LOG_DEBUG, "\n"); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "\n"); return 0; } @@ -963,16 +963,16 @@ static int __nvmf_add_ctrl(struct libnvme_global_ctx *ctx, const char *argstr) fd = open(nvmf_dev, O_RDWR); if (fd < 0) { - libnvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to open %s: %s\n", nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_OPEN; } - libnvme_msg(ctx, LOG_DEBUG, "connect ctrl, '%.*s'\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "connect ctrl, '%.*s'\n", (int)strcspn(argstr,"\n"), argstr); ret = write(fd, argstr, len); if (ret != len) { - libnvme_msg(ctx, LOG_INFO, "Failed to write to %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_INFO, "Failed to write to %s: %s\n", nvmf_dev, libnvme_strerror(errno)); switch (errno) { case EALREADY: @@ -999,11 +999,11 @@ static int __nvmf_add_ctrl(struct libnvme_global_ctx *ctx, const char *argstr) memset(buf, 0x0, sizeof(buf)); len = read(fd, buf, sizeof(buf) - 1); if (len < 0) { - libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to read from %s: %s\n", nvmf_dev, libnvme_strerror(errno)); return -ENVME_CONNECT_READ; } - libnvme_msg(ctx, LOG_DEBUG, "connect ctrl, response '%.*s'\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "connect ctrl, response '%.*s'\n", (int)strcspn(buf, "\n"), buf); buf[len] = '\0'; options = buf; @@ -1014,7 +1014,7 @@ static int __nvmf_add_ctrl(struct libnvme_global_ctx *ctx, const char *argstr) return ret; } - libnvme_msg(ctx, LOG_ERR, "Failed to parse ctrl info for \"%s\"\n", argstr); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to parse ctrl info for \"%s\"\n", argstr); return -ENVME_CONNECT_PARSE; } @@ -1108,7 +1108,7 @@ __public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c, * application string. */ if (app && strcmp(app, root_app)) { - libnvme_msg(h->ctx, LOG_INFO, "skip %s, not managed by %s\n", + libnvme_msg(h->ctx, LIBNVME_LOG_INFO, "skip %s, not managed by %s\n", libnvme_subsystem_get_subsysnqn(s), root_app); return -ENVME_CONNECT_IGNORED; } @@ -1133,7 +1133,7 @@ __public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c, if (ret < 0) return ret; - libnvme_msg(h->ctx, LOG_INFO, "nvme%d: %s connected\n", ret, + libnvme_msg(h->ctx, LIBNVME_LOG_INFO, "nvme%d: %s connected\n", ret, libnvme_ctrl_get_subsysnqn(c)); return libnvme_init_ctrl(h, c, ret); } @@ -1162,7 +1162,7 @@ static void nvmf_update_tls_concat(struct nvmf_disc_log_entry *e, return; if (e->treq & NVMF_TREQ_REQUIRED) { - libnvme_msg(h->ctx, LOG_DEBUG, + libnvme_msg(h->ctx, LIBNVME_LOG_DEBUG, "setting --tls due to treq %s and sectype %s\n", libnvmf_treq_str(e->treq), libnvmf_sectype_str(e->tsas.tcp.sectype)); @@ -1172,7 +1172,7 @@ static void nvmf_update_tls_concat(struct nvmf_disc_log_entry *e, } if (e->treq & NVMF_TREQ_NOT_REQUIRED) { - libnvme_msg(h->ctx, LOG_DEBUG, + libnvme_msg(h->ctx, LIBNVME_LOG_DEBUG, "setting --concat due to treq %s and sectype %s\n", libnvmf_treq_str(e->treq), libnvmf_sectype_str(e->tsas.tcp.sectype)); @@ -1201,7 +1201,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h, fctx->trsvcid = e->trsvcid; break; default: - libnvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "skipping unsupported adrfam %d\n", e->adrfam); return -EINVAL; @@ -1213,7 +1213,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h, fctx->traddr = e->traddr; break; default: - libnvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "skipping unsupported adrfam %d\n", e->adrfam); return -EINVAL; @@ -1223,7 +1223,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h, fctx->traddr = strlen(e->traddr) ? e->traddr : NULL; break; default: - libnvme_msg(h->ctx, LOG_ERR, "skipping unsupported transport %d\n", + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "skipping unsupported transport %d\n", e->trtype); return -EINVAL; } @@ -1231,13 +1231,13 @@ static int nvmf_connect_disc_entry(libnvme_host_t h, fctx->transport = libnvmf_trtype_str(e->trtype); fctx->subsysnqn = e->subnqn; - libnvme_msg(h->ctx, LOG_DEBUG, "lookup ctrl " + libnvme_msg(h->ctx, LIBNVME_LOG_DEBUG, "lookup ctrl " "(transport: %s, traddr: %s, trsvcid %s)\n", fctx->transport, fctx->traddr, fctx->trsvcid); ret = _libnvme_create_ctrl(h->ctx, fctx, &c); if (ret) { - libnvme_msg(h->ctx, LOG_DEBUG, "skipping discovery entry, " + libnvme_msg(h->ctx, LIBNVME_LOG_DEBUG, "skipping discovery entry, " "failed to allocate %s controller with traddr %s\n", fctx->transport, fctx->traddr); return ret; @@ -1257,7 +1257,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h, strcmp(e->subnqn, NVME_DISC_SUBSYS_NAME)); break; default: - libnvme_msg(h->ctx, LOG_ERR, "unsupported subtype %d\n", + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "unsupported subtype %d\n", e->subtype); fallthrough; case NVME_NQN_NVME: @@ -1286,7 +1286,7 @@ static int nvmf_connect_disc_entry(libnvme_host_t h, if (ret == EINVAL && c->cfg.disable_sqflow) { /* disable_sqflow is unrecognized option on older kernels */ - libnvme_msg(h->ctx, LOG_INFO, "failed to connect controller, " + libnvme_msg(h->ctx, LIBNVME_LOG_INFO, "failed to connect controller, " "retry with disabling SQ flow control\n"); c->cfg.disable_sqflow = false; ret = libnvmf_add_ctrl(h, c, cfg); @@ -1323,17 +1323,17 @@ static int nvme_discovery_log(libnvme_ctrl_t ctrl, log = __libnvme_alloc(sizeof(*log)); if (!log) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "could not allocate memory for discovery log header\n"); return -ENOMEM; } - libnvme_msg(ctx, LOG_DEBUG, "%s: get header (try %d/%d)\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "%s: get header (try %d/%d)\n", name, retries, args->max_retries); nvme_init_get_log_discovery(&cmd, 0, log, DISCOVERY_HEADER_LEN); err = libnvme_get_log(hdl, &cmd, false, DISCOVERY_HEADER_LEN); if (err) { - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: discover try %d/%d failed, errno %d status 0x%x\n", name, retries, args->max_retries, errno, err); goto out_free_log; @@ -1352,12 +1352,12 @@ static int nvme_discovery_log(libnvme_ctrl_t ctrl, entries_size = sizeof(*log->entries) * numrec; log = __libnvme_alloc(sizeof(*log) + entries_size); if (!log) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "could not alloc memory for discovery log page\n"); return -ENOMEM; } - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "%s: get %" PRIu64 " records (genctr %" PRIu64 ")\n", name, numrec, genctr); @@ -1367,7 +1367,7 @@ static int nvme_discovery_log(libnvme_ctrl_t ctrl, NVME_LOG_CDW10_LSP_MASK); err = libnvme_get_log(hdl, &cmd, false, NVME_LOG_PAGE_PDU_SIZE); if (err) { - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: discover try %d/%d failed, errno %d status 0x%x\n", name, retries, args->max_retries, errno, err); goto out_free_log; @@ -1377,12 +1377,12 @@ static int nvme_discovery_log(libnvme_ctrl_t ctrl, * If the log page was read with multiple Get Log Page commands, * genctr must be checked afterwards to ensure atomicity */ - libnvme_msg(ctx, LOG_DEBUG, "%s: get header again\n", name); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "%s: get header again\n", name); nvme_init_get_log_discovery(&cmd, 0, log, DISCOVERY_HEADER_LEN); err = libnvme_get_log(hdl, &cmd, false, DISCOVERY_HEADER_LEN); if (err) { - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: discover try %d/%d failed, errno %d status 0x%x\n", name, retries, args->max_retries, errno, err); goto out_free_log; @@ -1391,10 +1391,10 @@ static int nvme_discovery_log(libnvme_ctrl_t ctrl, ++retries < args->max_retries); if (genctr != le64_to_cpu(log->genctr)) { - libnvme_msg(ctx, LOG_INFO, "%s: discover genctr mismatch\n", name); + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: discover genctr mismatch\n", name); err = -EAGAIN; } else if (numrec != le64_to_cpu(log->numrec)) { - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: numrec changed unexpectedly " "from %" PRIu64 " to %" PRIu64 "\n", name, numrec, le64_to_cpu(log->numrec)); @@ -1423,7 +1423,7 @@ static void sanitize_discovery_log_entry(struct libnvme_global_ctx *ctx, char *comma = strchr(e->traddr, ','); if (comma) { - libnvme_msg(ctx, LOG_WARNING, + libnvme_msg(ctx, LIBNVME_LOG_WARN, "invalid traddr separator ',' instead ':', fixing it"); *comma = ':'; } @@ -1595,35 +1595,35 @@ static int nvmf_dim(libnvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, int ret; if (!c->s) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "%s: failed to perform DIM. subsystem undefined.\n", c->name); return -EINVAL; } if (!c->s->h) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "%s: failed to perform DIM. host undefined.\n", c->name); return -EINVAL; } if (!c->s->h->hostid) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "%s: failed to perform DIM. hostid undefined.\n", c->name); return -EINVAL; } if (!c->s->h->hostnqn) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "%s: failed to perform DIM. hostnqn undefined.\n", c->name); return -EINVAL; } if (strcmp(c->transport, "tcp")) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "%s: DIM only supported for TCP connections.\n", c->name); return -EINVAL; @@ -1649,15 +1649,15 @@ static int nvmf_dim(libnvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, ret = get_entity_name(dim->ename, sizeof(dim->ename)); if (ret < 0) - libnvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME. %s.\n", + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: Failed to retrieve ENAME. %s.\n", c->name, libnvme_strerror(-ret)); else if (ret == 0) - libnvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME.\n", + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: Failed to retrieve ENAME.\n", c->name); ret = get_entity_version(dim->ever, sizeof(dim->ever)); if (ret <= 0) - libnvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve EVER.\n", c->name); + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: Failed to retrieve EVER.\n", c->name); die = &dim->die->extended; nvmf_fill_die(die, c->s->h, tel, trtype, adrfam, reg_addr, tsas); @@ -2019,7 +2019,7 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx, err = nvme_discovery_log(c, &args, &log); if (err) { - libnvme_msg(ctx, LOG_ERR, "failed to get discovery log: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to get discovery log: %s\n", libnvme_strerror(err)); return err; } @@ -2217,14 +2217,14 @@ static int nvmf_create_discovery_ctrl(struct libnvme_global_ctx *ctx, ret = libnvme_open(ctx, c->name, &c->hdl); if (ret) { - libnvme_msg(ctx, LOG_ERR, "failed to open %s\n", c->name); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to open %s\n", c->name); return ret; } /* Find out the name of discovery controller */ ret = libnvme_ctrl_identify(c, id); if (ret) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to identify controller, error %s\n", libnvme_strerror(-ret)); libnvme_disconnect_ctrl(c); @@ -2279,7 +2279,7 @@ int _discovery_config_json(struct libnvme_global_ctx *ctx, /* ignore if no host_traddr for fc */ if (!strcmp(nfctx.transport, "fc")) { if (!nfctx.host_traddr) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "host_traddr required for fc\n"); return 0; } @@ -2289,7 +2289,7 @@ int _discovery_config_json(struct libnvme_global_ctx *ctx, if (!strcmp(nfctx.transport, "rdma") || !strcmp(nfctx.transport, "fc")) { if (nfctx.host_iface) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "host_iface not permitted for rdma or fc\n"); return 0; } @@ -2363,7 +2363,7 @@ __public int libnvmf_discovery_config_json(struct libnvme_global_ctx *ctx, err = _discovery_config_json(ctx, fctx, h, c, connect, force); if (err) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to connect to hostnqn=%s,nqn=%s,%s\n", libnvme_host_get_hostnqn(h), libnvme_subsystem_get_name(s), @@ -2422,7 +2422,7 @@ __public int libnvmf_connect_config_json(struct libnvme_global_ctx *ctx, if (err == -ENVME_CONNECT_ALREADY) continue; - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to connect to hostnqn=%s,nqn=%s,%s\n", libnvme_host_get_hostnqn(h), libnvme_subsystem_get_name(s), @@ -2508,7 +2508,7 @@ __public int libnvmf_config_modify(struct libnvme_global_ctx *ctx, h = libnvme_lookup_host(ctx, fctx->hostnqn, fctx->hostid); if (!h) { - libnvme_msg(ctx, LOG_ERR, "Failed to lookup host '%s'\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to lookup host '%s'\n", fctx->hostnqn); return -ENODEV; } @@ -2518,14 +2518,14 @@ __public int libnvmf_config_modify(struct libnvme_global_ctx *ctx, s = libnvme_lookup_subsystem(h, NULL, fctx->subsysnqn); if (!s) { - libnvme_msg(ctx, LOG_ERR, "Failed to lookup subsystem '%s'\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to lookup subsystem '%s'\n", fctx->subsysnqn); return -ENODEV; } c = libnvme_lookup_ctrl(s, fctx, NULL); if (!c) { - libnvme_msg(ctx, LOG_ERR, "Failed to lookup controller\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to lookup controller\n"); return -ENODEV; } if (fctx->ctrlkey) @@ -2602,19 +2602,19 @@ static bool validate_uri(struct libnvme_global_ctx *ctx, struct libnvme_fabrics_uri *uri) { if (!uri) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Discovery Descriptor %d: failed to parse URI %s\n", dd->index, dd->uri); return false; } if (strcmp(uri->scheme, "nvme") != 0) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Discovery Descriptor %d: unsupported scheme '%s'\n", dd->index, uri->scheme); return false; } if (!uri->protocol || strcmp(uri->protocol, "tcp") != 0) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Discovery Descriptor %d: unsupported transport '%s'\n", dd->index, uri->protocol); return false; @@ -2669,7 +2669,7 @@ static int nbft_connect(struct libnvme_global_ctx *ctx, * our connection attempt has failed, ignore it. */ if (ss && ss->unavailable) { - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "SSNS %d reported as unavailable, skipping\n", ss->index); return 0; @@ -2699,7 +2699,7 @@ static int nbft_discovery(struct libnvme_global_ctx *ctx, ret = nvme_discovery_log(c, &args, &log); if (ret) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Discovery Descriptor %d: failed to get discovery log: %s\n", dd->index, libnvme_strerror(ret)); return ret; @@ -2758,14 +2758,14 @@ static int nbft_discovery(struct libnvme_global_ctx *ctx, defcfg); if (ret == 0) - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "Discovery Descriptor %d: connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n", dd->index, htradr); } if (ret) - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Discovery Descriptor %d: no controller found\n", dd->index); if (ret == -ENOMEM) @@ -2806,7 +2806,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx, ret = libnvmf_nbft_read_files(ctx, nbft_path, &entry); if (ret) { if (ret != -ENOENT) - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to access ACPI tables directory\n"); else ret = 0; /* nothing to connect */ @@ -2848,7 +2848,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx, /* Skip discovery NQN records */ if (strcmp((*ss)->subsys_nqn, NVME_DISC_SUBSYS_NAME) == 0) { - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "SSNS %d points to well-known discovery NQN, skipping\n", (*ss)->index); continue; @@ -2883,14 +2883,14 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx, *ss, fctx->cfg); if (rr == 0) - libnvme_msg(ctx, LOG_INFO, + libnvme_msg(ctx, LIBNVME_LOG_INFO, "SSNS %d: connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n", (*ss)->index, host_traddr); } if (rr) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "SSNS %d: no controller found\n", (*ss)->index); /* report an error */ @@ -2974,7 +2974,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx, ret = 0; if (ret) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Discovery Descriptor %d: failed to add discovery controller: %s\n", (*dd)->index, libnvme_strerror(-ret)); goto out_free; @@ -3015,14 +3015,14 @@ __public int libnvmf_discovery(struct libnvme_global_ctx *ctx, struct libnvmf_co if (!ret) { /* Check if device matches command-line options */ if (!_libnvme_ctrl_match_config(c, fctx)) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "ctrl device %s found, ignoring non matching command-line options\n", fctx->device); } if (!libnvme_ctrl_get_discovery_ctrl(c)) { libnvme_msg( - ctx, LOG_ERR, + ctx, LIBNVME_LOG_ERR, "ctrl device %s found, ignoring non discovery controller\n", fctx->device); @@ -3058,7 +3058,7 @@ __public int libnvmf_discovery(struct libnvme_global_ctx *ctx, struct libnvmf_co * No controller found, fall back to create one. * But that controller cannot be persistent. */ - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "ctrl device %s not found%s\n", fctx->device, fctx->persistent ? ", ignoring --persistent" : ""); fctx->persistent = false; @@ -3075,7 +3075,7 @@ __public int libnvmf_discovery(struct libnvme_global_ctx *ctx, struct libnvmf_co ret = nvmf_create_discovery_ctrl(ctx, fctx, h, fctx->cfg, &c); if (ret) { if (ret != -ENVME_CONNECT_IGNORED) - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to add controller, error %s\n", libnvme_strerror(-ret)); return ret; @@ -3137,7 +3137,7 @@ __public int libnvmf_connect(struct libnvme_global_ctx *ctx, struct libnvmf_cont err = libnvme_add_ctrl(fctx, h, c, fctx->cfg); if (err) { - libnvme_msg(ctx, LOG_ERR, "could not add new controller: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "could not add new controller: %s\n", libnvme_strerror(-err)); libnvme_free_ctrl(c); return err; diff --git a/libnvme/src/nvme/json.c b/libnvme/src/nvme/json.c index 70316c9ce5..416476c75c 100644 --- a/libnvme/src/nvme/json.c +++ b/libnvme/src/nvme/json.c @@ -224,7 +224,7 @@ static struct json_object *parse_json(struct libnvme_global_ctx *ctx, int fd) obj = json_tokener_parse_ex(tok, str, len); if (!obj) - libnvme_msg(ctx, LOG_DEBUG, "JSON parsing failed: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "JSON parsing failed: %s\n", json_util_get_last_err()); return obj; @@ -237,7 +237,7 @@ int json_read_config(struct libnvme_global_ctx *ctx, const char *config_file) fd = open(config_file, O_RDONLY); if (fd < 0) { - libnvme_msg(ctx, LOG_DEBUG, "Error opening %s, %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "Error opening %s, %s\n", config_file, libnvme_strerror(errno)); return fd; } @@ -246,7 +246,7 @@ int json_read_config(struct libnvme_global_ctx *ctx, const char *config_file) if (!json_root) return -EPROTO; if (!json_object_is_type(json_root, json_type_array)) { - libnvme_msg(ctx, LOG_DEBUG, "Wrong format, expected array\n"); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "Wrong format, expected array\n"); json_object_put(json_root); return -EPROTO; } @@ -431,7 +431,7 @@ int json_update_config(struct libnvme_global_ctx *ctx, int fd) JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE); if (ret < 0 || write(fd, "\n", 1) < 0) { - libnvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to write JSON config file: %s\n", ret ? json_util_get_last_err() : strerror(errno)); ret = -EIO; } @@ -657,7 +657,7 @@ int json_dump_tree(struct libnvme_global_ctx *ctx) JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE); if (ret < 0) { - libnvme_msg(ctx, LOG_ERR, "Failed to write, %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to write, %s\n", json_util_get_last_err()); ret = -EIO; } diff --git a/libnvme/src/nvme/lib.h b/libnvme/src/nvme/lib.h index bbce950ac2..8d8e506f4c 100644 --- a/libnvme/src/nvme/lib.h +++ b/libnvme/src/nvme/lib.h @@ -10,16 +10,17 @@ #include #include -#include #include -#ifndef MAX_LOGLEVEL -# define MAX_LOGLEVEL LOG_DEBUG -#endif -#ifndef DEFAULT_LOGLEVEL -# define DEFAULT_LOGLEVEL LOG_NOTICE -#endif +enum libnvme_log_level { + LIBNVME_LOG_ERR = 0, + LIBNVME_LOG_WARN = 1, + LIBNVME_LOG_INFO = 2, + LIBNVME_LOG_DEBUG = 3, +}; + +#define DEFAULT_LOGLEVEL LIBNVME_LOG_WARN /** * libnvme_create_global_ctx() - Initialize global context object diff --git a/libnvme/src/nvme/linux.c b/libnvme/src/nvme/linux.c index fe37ea21d3..7fbccb4c04 100644 --- a/libnvme/src/nvme/linux.c +++ b/libnvme/src/nvme/linux.c @@ -66,7 +66,7 @@ static int __nvme_set_attr(const char *path, const char *value) fd = open(path, O_WRONLY); if (fd < 0) { #if 0 - libnvme_msg(LOG_DEBUG, "Failed to open %s: %s\n", path, + libnvme_msg(LIBNVME_LOG_DEBUG, "Failed to open %s: %s\n", path, strerror(errno)); #endif return -errno; @@ -159,7 +159,7 @@ __public int libnvme_gen_dhchap_key(struct libnvme_global_ctx *ctx, unsigned char *key) { if (hmac != LIBNVME_HMAC_ALG_NONE) { - libnvme_msg(ctx, LOG_ERR, "HMAC transformation not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "HMAC transformation not supported; " "recompile with OpenSSL support.\n"); return -EINVAL; } @@ -171,7 +171,7 @@ __public int libnvme_gen_dhchap_key(struct libnvme_global_ctx *ctx, __public int libnvme_create_raw_secret(struct libnvme_global_ctx *ctx, const char *secret, size_t key_len, unsigned char **raw_secret) { - libnvme_msg(ctx, LOG_ERR, "NVMe TLS 2.0 is not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "NVMe TLS 2.0 is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } @@ -180,7 +180,7 @@ static int derive_retained_key(struct libnvme_global_ctx *ctx, int hmac, const char *hostnqn, unsigned char *generated, unsigned char *retained, size_t key_len) { - libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } @@ -189,7 +189,7 @@ static int derive_retained_key_compat(struct libnvme_global_ctx *ctx, int hmac, const char *hostnqn, unsigned char *generated, unsigned char *retained, size_t key_len) { - libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } @@ -200,7 +200,7 @@ static int derive_psk_digest(struct libnvme_global_ctx *ctx, unsigned char *retained, size_t key_len, char *digest, size_t digest_len) { - libnvme_msg(ctx, LOG_ERR, "NVMe TLS 2.0 is not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "NVMe TLS 2.0 is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } @@ -209,7 +209,7 @@ static int derive_tls_key(struct libnvme_global_ctx *ctx, int version, unsigned char cipher, const char *context, unsigned char *retained, unsigned char *psk, size_t key_len) { - libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } @@ -218,7 +218,7 @@ static int derive_tls_key_compat(struct libnvme_global_ctx *ctx, int version, unsigned char cipher, const char *context, unsigned char *retained, unsigned char *psk, size_t key_len) { - libnvme_msg(ctx, LOG_ERR, "NVMe TLS is not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "NVMe TLS is not supported; " "recompile with OpenSSL support.\n"); return -ENOTSUP; } @@ -827,7 +827,7 @@ __public int libnvme_create_raw_secret(struct libnvme_global_ctx *ctx, unsigned int c; if (key_len != 32 && key_len != 48 && key_len != 64) { - libnvme_msg(ctx, LOG_ERR, "Invalid key length %ld", key_len); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Invalid key length %ld", key_len); return -EINVAL; } @@ -844,7 +844,7 @@ __public int libnvme_create_raw_secret(struct libnvme_global_ctx *ctx, } if (strlen(secret) < 4) { - libnvme_msg(ctx, LOG_ERR, "Input secret too short\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Input secret too short\n"); return -EINVAL; } @@ -858,19 +858,19 @@ __public int libnvme_create_raw_secret(struct libnvme_global_ctx *ctx, for (i = 0; i < strlen(secret); i += 2) { if (sscanf(&secret[i], "%02x", &c) != 1) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Invalid secret '%s'", secret); return -EINVAL; } if (i >= key_len * 2) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Skipping excess secret bytes\n"); break; } buf[secret_len++] = (unsigned char)c; } if (secret_len != key_len) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Invalid key length (%d bytes)\n", secret_len); return -EINVAL; } @@ -1372,7 +1372,7 @@ int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, int ret; if (!hostnqn || !subsysnqn) { - libnvme_msg(h->ctx, LOG_ERR, "Invalid NQNs (%s, %s)\n", + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "Invalid NQNs (%s, %s)\n", hostnqn, subsysnqn); return -EINVAL; } @@ -1402,7 +1402,7 @@ int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, } if (libnvme_set_keyring(h->ctx, kr_id) < 0) { - libnvme_msg(h->ctx, LOG_ERR, "Failed to set keyring\n"); + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "Failed to set keyring\n"); return -errno; } @@ -1410,7 +1410,7 @@ int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, if (identity) { ret = libnvme_lookup_key(h->ctx, "psk", identity, &id); if (ret && !(ret == -ENOKEY || ret == -EKEYREVOKED)) { - libnvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "Failed to lookup key for identity %s, error %d\n", identity, ret); return ret; @@ -1421,7 +1421,7 @@ int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, ret = __nvme_import_tls_key(h->ctx, kr_id, hostnqn, subsysnqn, identity, key, &id); if (ret) { - libnvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "Failed to insert TLS KEY, error %d\n", ret); return ret; } @@ -1437,14 +1437,14 @@ int __libnvme_import_keys_from_config(libnvme_host_t h, libnvme_ctrl_t c, __public int libnvme_lookup_keyring(struct libnvme_global_ctx *ctx, const char *keyring, long *key) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } __public char *libnvme_describe_key_serial(struct libnvme_global_ctx *ctx, long key_id) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return NULL; } @@ -1452,14 +1452,14 @@ __public char *libnvme_describe_key_serial(struct libnvme_global_ctx *ctx, long __public int libnvme_lookup_key(struct libnvme_global_ctx *ctx, const char *type, const char *identity, long *key) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } __public int libnvme_set_keyring(struct libnvme_global_ctx *ctx, long key_id) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } @@ -1467,7 +1467,7 @@ __public int libnvme_set_keyring(struct libnvme_global_ctx *ctx, long key_id) __public int libnvme_read_key(struct libnvme_global_ctx *ctx, long keyring_id, long key_id, int *len, unsigned char **key) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } @@ -1476,7 +1476,7 @@ __public int libnvme_update_key(struct libnvme_global_ctx *ctx, long keyring_id, const char *key_type, const char *identity, unsigned char *key_data, int key_len, long *key) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } @@ -1484,7 +1484,7 @@ __public int libnvme_update_key(struct libnvme_global_ctx *ctx, long keyring_id, __public int libnvme_scan_tls_keys(struct libnvme_global_ctx *ctx, const char *keyring, libnvme_scan_tls_keys_cb_t cb, void *data) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } @@ -1496,7 +1496,7 @@ __public int libnvme_insert_tls_key_versioned(struct libnvme_global_ctx *ctx, unsigned char *configured_key, int key_len, long *keyp) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } @@ -1508,7 +1508,7 @@ __public int libnvme_insert_tls_key_compat(struct libnvme_global_ctx *ctx, unsigned char *configured_key, int key_len, long *keyp) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } @@ -1517,7 +1517,7 @@ __public int libnvme_revoke_tls_key(struct libnvme_global_ctx *ctx, const char *keyring, const char *key_type, const char *identity) { - libnvme_msg(ctx, LOG_ERR, "key operations not supported; " + libnvme_msg(ctx, LIBNVME_LOG_ERR, "key operations not supported; " "recompile with keyutils support.\n"); return -ENOTSUP; } @@ -1672,7 +1672,7 @@ __public int libnvme_import_tls_key_versioned(struct libnvme_global_ctx *ctx, ((uint32_t)decoded_key[decoded_len + 2] << 16) | ((uint32_t)decoded_key[decoded_len + 3] << 24); if (key_crc != crc) { - libnvme_msg(ctx, LOG_ERR, "CRC mismatch (key %08x, crc %08x)", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "CRC mismatch (key %08x, crc %08x)", key_crc, crc); return -ENOKEY; } diff --git a/libnvme/src/nvme/log.c b/libnvme/src/nvme/log.c index 3d025cd8f0..a436e005f7 100644 --- a/libnvme/src/nvme/log.c +++ b/libnvme/src/nvme/log.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/libnvme/src/nvme/mi-mctp.c b/libnvme/src/nvme/mi-mctp.c index dad699e844..d3cc7c2ae5 100644 --- a/libnvme/src/nvme/mi-mctp.c +++ b/libnvme/src/nvme/mi-mctp.c @@ -167,7 +167,7 @@ static __u8 libnvme_mi_mctp_tag_alloc(struct libnvme_mi_ep *ep) if (!logged) { /* not necessarily fatal, just means we can't handle * "more processing required" messages */ - libnvme_msg(ep->ctx, LOG_INFO, + libnvme_msg(ep->ctx, LIBNVME_LOG_INFO, "System does not support explicit tag allocation\n"); logged = true; } @@ -308,7 +308,7 @@ static int libnvme_mi_mctp_aem_read(struct libnvme_mi_ep *ep, if (!tmp) { errno_save = errno; - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Failure allocating response buffer: %m\n"); errno = errno_save; rc = -1; @@ -336,7 +336,7 @@ static int libnvme_mi_mctp_aem_read(struct libnvme_mi_ep *ep, goto out; errno_save = errno; - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Failure receiving MCTP message: %m\n"); errno = errno_save; goto out; @@ -344,13 +344,13 @@ static int libnvme_mi_mctp_aem_read(struct libnvme_mi_ep *ep, if (len == 0) { - libnvme_msg(ep->ctx, LOG_WARNING, "No data from MCTP endpoint\n"); + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "No data from MCTP endpoint\n"); errno = EIO; goto out; } if (resp_msg.msg_namelen < sizeof(src_addr)) { - libnvme_msg(ep->ctx, LOG_WARNING, "Unexpected src address length\n"); + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "Unexpected src address length\n"); errno = EIO; goto out; } @@ -369,7 +369,7 @@ static int libnvme_mi_mctp_aem_read(struct libnvme_mi_ep *ep, * plus four bytes of error data (excluding MIC). Ensure we have enough. */ if (len < 8 + sizeof(mic)) { - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Invalid MCTP response: too short (%zd bytes, needed %zd)\n", len, 8 + sizeof(mic)); errno = EPROTO; @@ -468,7 +468,7 @@ static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, len = ops.sendmsg(mctp->sd, &req_msg, 0); if (len < 0) { errno_save = errno; - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Failure sending MCTP message: %m\n"); errno = errno_save; rc = -1; @@ -480,7 +480,7 @@ static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, void *tmp = realloc(mctp->resp_buf, resp_len); if (!tmp) { errno_save = errno; - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Failure allocating response buffer: %m\n"); errno = errno_save; rc = -1; @@ -509,14 +509,14 @@ static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, if (errno == EINTR) goto retry; errno_save = errno; - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Failed polling on MCTP socket: %m"); errno = errno_save; goto out; } if (rc == 0) { - libnvme_msg(ep->ctx, LOG_DEBUG, "Timeout on MCTP socket"); + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "Timeout on MCTP socket"); errno = ETIMEDOUT; rc = -1; goto out; @@ -527,7 +527,7 @@ static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, if (len < 0) { errno_save = errno; - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Failure receiving MCTP message: %m\n"); errno = errno_save; goto out; @@ -535,7 +535,7 @@ static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, if (len == 0) { - libnvme_msg(ep->ctx, LOG_WARNING, "No data from MCTP endpoint\n"); + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "No data from MCTP endpoint\n"); errno = EIO; goto out; } @@ -548,7 +548,7 @@ static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, * plus four bytes of error data (excluding MIC). Ensure we have enough. */ if (len < 8 + sizeof(mic)) { - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Invalid MCTP response: too short (%zd bytes, needed %zd)\n", len, 8 + sizeof(mic)); errno = EPROTO; @@ -570,7 +570,7 @@ static int libnvme_mi_mctp_submit(struct libnvme_mi_ep *ep, * to keep the tag allocated and retry the recvmsg */ if (libnvme_mi_mctp_resp_is_mpr(mctp->resp_buf, len, mic, &mpr_time)) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "Received More Processing Required, waiting for response\n"); /* if the controller hasn't set MPRT, fall back to our command/ @@ -830,7 +830,7 @@ static int handle_mctp_endpoint(struct libnvme_global_ctx *ctx, const char* objp dbus_message_iter_recurse(props, &prop); if (!dbus_object_is_type(&prop, DBUS_TYPE_STRING)) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "error unmashalling object (propname)\n"); return -1; } @@ -840,7 +840,7 @@ static int handle_mctp_endpoint(struct libnvme_global_ctx *ctx, const char* objp dbus_message_iter_next(&prop); if (!dbus_object_is_type(&prop, DBUS_TYPE_VARIANT)) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "error unmashalling object (propval)\n"); return -1; } @@ -868,7 +868,7 @@ static int handle_mctp_endpoint(struct libnvme_global_ctx *ctx, const char* objp if (have_nvmemi) { if (!(have_eid && have_net)) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Missing property for %s\n", objpath); errno = ENOENT; return -1; @@ -876,7 +876,7 @@ static int handle_mctp_endpoint(struct libnvme_global_ctx *ctx, const char* objp rc = libnvme_mi_mctp_add(ctx, net, eid); if (rc < 0) { int errno_save = errno; - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Error adding net %d eid %d: %m\n", net, eid); errno = errno_save; } @@ -896,7 +896,7 @@ static int handle_mctp_obj(struct libnvme_global_ctx *ctx, DBusMessageIter *obj) DBusMessageIter intfs; if (!dbus_object_is_type(obj, DBUS_TYPE_OBJECT_PATH)) { - libnvme_msg(ctx, LOG_ERR, "error unmashalling object (path)\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "error unmashalling object (path)\n"); return -1; } @@ -905,7 +905,7 @@ static int handle_mctp_obj(struct libnvme_global_ctx *ctx, DBusMessageIter *obj) dbus_message_iter_next(obj); if (!dbus_object_is_dict(obj)) { - libnvme_msg(ctx, LOG_ERR, "error unmashalling object (intfs)\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "error unmashalling object (intfs)\n"); return -1; } @@ -919,7 +919,7 @@ static int handle_mctp_obj(struct libnvme_global_ctx *ctx, DBusMessageIter *obj) dbus_message_iter_recurse(&intfs, &intf); if (!dbus_object_is_type(&intf, DBUS_TYPE_STRING)) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "error unmashalling object (intf)\n"); return -1; } @@ -935,7 +935,7 @@ static int handle_mctp_obj(struct libnvme_global_ctx *ctx, DBusMessageIter *obj) dbus_message_iter_next(&intf); if (!dbus_object_is_dict(&intf)) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "error unmarshalling object (props)\n"); return -1; } @@ -967,7 +967,7 @@ __public struct libnvme_global_ctx *libnvme_mi_scan_mctp(void) bus = dbus_bus_get(DBUS_BUS_SYSTEM, &berr); if (!bus) { - libnvme_msg(ctx, LOG_ERR, "Failed connecting to D-Bus: %s (%s)\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed connecting to D-Bus: %s (%s)\n", berr.message, berr.name); goto out; } @@ -977,7 +977,7 @@ __public struct libnvme_global_ctx *libnvme_mi_scan_mctp(void) "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); if (!msg) { - libnvme_msg(ctx, LOG_ERR, "Failed creating call message\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed creating call message\n"); goto out; } @@ -986,7 +986,7 @@ __public struct libnvme_global_ctx *libnvme_mi_scan_mctp(void) &berr); dbus_message_unref(msg); if (!resp) { - libnvme_msg(ctx, LOG_ERR, "Failed querying MCTP D-Bus: %s (%s)\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed querying MCTP D-Bus: %s (%s)\n", berr.message, berr.name); goto out; } @@ -994,12 +994,12 @@ __public struct libnvme_global_ctx *libnvme_mi_scan_mctp(void) /* argument container */ drc = dbus_message_iter_init(resp, &args); if (!drc) { - libnvme_msg(ctx, LOG_ERR, "can't read dbus reply args\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "can't read dbus reply args\n"); goto out; } if (!dbus_object_is_dict(&args)) { - libnvme_msg(ctx, LOG_ERR, "error unmashalling args\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "error unmashalling args\n"); goto out; } diff --git a/libnvme/src/nvme/mi.c b/libnvme/src/nvme/mi.c index be0c555608..457cceb681 100644 --- a/libnvme/src/nvme/mi.c +++ b/libnvme/src/nvme/mi.c @@ -117,7 +117,7 @@ static bool libnvme_mi_compare_vid_mn(struct libnvme_mi_ep *ep, len = strlen(mn); if (len >= sizeof(id->mn)) { - libnvme_msg(ep->ctx, LOG_ERR, + libnvme_msg(ep->ctx, LIBNVME_LOG_ERR, "Internal error: invalid model number for %s\n", __func__); return false; @@ -197,7 +197,7 @@ void libnvme_mi_ep_probe(struct libnvme_mi_ep *ep) cmd.data_len = offsetof(struct nvme_id_ctrl, rab); rc = libnvme_submit_admin_passthru(hdl, &cmd); if (rc) { - libnvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "Identify Controller failed, no quirks applied\n"); goto out_close; } @@ -221,7 +221,7 @@ void libnvme_mi_ep_probe(struct libnvme_mi_ep *ep) char tmp[sizeof(id.mn) + 1]; libnvme_mi_format_mn(&id, tmp); - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "device %02x:%s: applying quirks 0x%08lx\n", id.vid, tmp, ep->quirks); } @@ -446,14 +446,14 @@ int libnvme_mi_async_read(libnvme_mi_ep_t ep, struct libnvme_mi_resp *resp) resp->data_len = 0;//No data to process return 0; } else if (rc) { - libnvme_msg(ep->ctx, LOG_INFO, "transport failure\n"); + libnvme_msg(ep->ctx, LIBNVME_LOG_INFO, "transport failure\n"); return rc; } if (ep->transport->mic_enabled) { rc = libnvme_mi_verify_resp_mic(resp); if (rc) { - libnvme_msg(ep->ctx, LOG_WARNING, "crc mismatch\n"); + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "crc mismatch\n"); return -EBADMSG; } } @@ -462,25 +462,25 @@ int libnvme_mi_async_read(libnvme_mi_ep_t ep, struct libnvme_mi_resp *resp) /* basic response checks */ if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "Bad response header len: %zd\n", resp->hdr_len); return -EPROTO; } if (resp->hdr->type != NVME_MI_MSGTYPE_NVME) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "Invalid message type 0x%02x\n", resp->hdr->type); return -EPROTO; } if (!(resp->hdr->nmp & ~(NVME_MI_ROR_REQ << 7))) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "ROR value in response indicates a response\n"); return -EIO; } if (!(resp->hdr->nmp & (NVME_MI_MT_AE << 3))) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "NMIMT does not indicate AEM\n"); resp->data_len = 0;//No data to process return 0; @@ -525,39 +525,39 @@ int libnvme_mi_submit(libnvme_mi_ep_t ep, struct libnvme_mi_req *req, libnvme_mi_record_resp_time(ep); if (rc) { - libnvme_msg(ep->ctx, LOG_INFO, "transport failure\n"); + libnvme_msg(ep->ctx, LIBNVME_LOG_INFO, "transport failure\n"); return rc; } if (ep->transport->mic_enabled) { rc = libnvme_mi_verify_resp_mic(resp); if (rc) { - libnvme_msg(ep->ctx, LOG_WARNING, "crc mismatch\n"); + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "crc mismatch\n"); return -EBADMSG; } } /* basic response checks */ if (resp->hdr_len < sizeof(struct nvme_mi_msg_hdr)) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "Bad response header len: %zd\n", resp->hdr_len); return -EPROTO; } if (resp->hdr->type != NVME_MI_MSGTYPE_NVME) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "Invalid message type 0x%02x\n", resp->hdr->type); return -EPROTO; } if (!(resp->hdr->nmp & (NVME_MI_ROR_RSP << 7))) { - libnvme_msg(ep->ctx, LOG_DEBUG, + libnvme_msg(ep->ctx, LIBNVME_LOG_DEBUG, "ROR value in response indicates a request\n"); return -EIO; } if ((resp->hdr->nmp & 0x1) != (req->hdr->nmp & 0x1)) { - libnvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "Command slot mismatch: req %d, resp %d\n", req->hdr->nmp & 0x1, resp->hdr->nmp & 0x1); @@ -817,13 +817,13 @@ int libnvme_mi_admin_admin_passthru(struct libnvme_transport_handle *hdl, bool has_read_data = false; if (direction == NVME_DATA_TFR_BIDIRECTIONAL) { - libnvme_msg(hdl->ctx, LOG_ERR, + libnvme_msg(hdl->ctx, LIBNVME_LOG_ERR, "libnvme_mi_admin_admin_passthru doesn't support bidirectional commands\n"); return -EINVAL; } if (cmd->data_len > 4096) { - libnvme_msg(hdl->ctx, LOG_ERR, + libnvme_msg(hdl->ctx, LIBNVME_LOG_ERR, "libnvme_mi_admin_admin_passthru doesn't support data_len over 4096 bytes.\n"); return -EINVAL; } @@ -1026,7 +1026,7 @@ __public int libnvme_mi_mi_read_mi_data_subsys(libnvme_mi_ep_t ep, return rc; if (len != sizeof(*s)) { - libnvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "MI read data length mismatch: " "got %zd bytes, expected %zd\n", len, sizeof(*s)); @@ -1120,7 +1120,7 @@ __public int libnvme_mi_mi_subsystem_health_status_poll(libnvme_mi_ep_t ep, bool return resp_hdr.status; if (resp.data_len != sizeof(*sshs)) { - libnvme_msg(ep->ctx, LOG_WARNING, + libnvme_msg(ep->ctx, LIBNVME_LOG_WARN, "MI Subsystem Health Status length mismatch: " "got %zd bytes, expected %zd\n", resp.data_len, sizeof(*sshs)); diff --git a/libnvme/src/nvme/nbft.c b/libnvme/src/nvme/nbft.c index 5caf15755d..694955cd92 100644 --- a/libnvme/src/nvme/nbft.c +++ b/libnvme/src/nvme/nbft.c @@ -75,7 +75,7 @@ static char *trtype_to_string(__u8 transport_type) #define verify(ctx, condition, message) \ do { \ if (!(condition)) { \ - libnvme_msg(ctx, LOG_DEBUG, "file %s: " message "\n", \ + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: " message "\n", \ nbft->filename); \ return -EINVAL; \ } \ @@ -91,7 +91,7 @@ static int __get_heap_obj(struct libnvme_global_ctx *ctx, return -ENOENT; if (!in_heap(header, obj)) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: field '%s' in descriptor '%s' has invalid offset or length\n", filename, fieldname, descriptorname); return -EINVAL; @@ -103,14 +103,14 @@ static int __get_heap_obj(struct libnvme_global_ctx *ctx, if (is_string) { if (strnlen(*output, le16_to_cpu(obj.length) + 1) < le16_to_cpu(obj.length)) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: string '%s' in descriptor '%s' is shorter (%zd) than specified length (%d)\n", filename, fieldname, descriptorname, strnlen(*output, le16_to_cpu(obj.length) + 1), le16_to_cpu(obj.length)); } else if (strnlen(*output, le16_to_cpu(obj.length) + 1) > le16_to_cpu(obj.length)) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: string '%s' in descriptor '%s' is not zero terminated\n", filename, fieldname, descriptorname); return -EINVAL; @@ -229,7 +229,7 @@ static int read_ssns(struct libnvme_global_ctx *ctx, ssns->discovery = discovery_from_index(nbft, raw_ssns->primary_discovery_ctrl_index); if (!ssns->discovery) - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: namespace %d discovery controller not found\n", nbft->filename, ssns->index); } @@ -266,7 +266,7 @@ static int read_ssns(struct libnvme_global_ctx *ctx, ssns->security = security_from_index(nbft, raw_ssns->security_desc_index); if (!ssns->security) - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: namespace %d security controller not found\n", nbft->filename, ssns->index); } @@ -286,7 +286,7 @@ static int read_ssns(struct libnvme_global_ctx *ctx, } ssns->hfis[0] = hfi_from_index(nbft, raw_ssns->primary_hfi_desc_index); if (!ssns->hfis[0]) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: SSNS %d: HFI %d not found\n", nbft->filename, ssns->index, raw_ssns->primary_hfi_desc_index); @@ -311,7 +311,7 @@ static int read_ssns(struct libnvme_global_ctx *ctx, duplicate = true; if (duplicate) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: SSNS %d skipping duplicate HFI index %d\n", nbft->filename, ssns->index, ss_hfi_indexes[i]); continue; @@ -319,7 +319,7 @@ static int read_ssns(struct libnvme_global_ctx *ctx, ssns->hfis[i + 1] = hfi_from_index(nbft, ss_hfi_indexes[i]); if (ss_hfi_indexes[i] && !ssns->hfis[i + 1]) - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: SSNS %d HFI %d not found\n", nbft->filename, ssns->index, ss_hfi_indexes[i]); else @@ -366,7 +366,7 @@ static int read_hfi_info_tcp(struct libnvme_global_ctx *ctx, verify(ctx, raw_hfi_info_tcp->version == 1, "invalid version in HFI transport descriptor"); if (le16_to_cpu(raw_hfi_info_tcp->hfi_index) != hfi->index) - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: HFI descriptor index %d does not match index in HFI transport descriptor\n", nbft->filename, hfi->index); @@ -440,7 +440,7 @@ static int read_hfi(struct libnvme_global_ctx *ctx, struct nbft_info *nbft, if (ret) goto fail; } else { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: invalid transport type %d\n", nbft->filename, raw_hfi->trtype); ret = -EINVAL; @@ -488,14 +488,14 @@ static int read_discovery(struct libnvme_global_ctx *ctx, discovery->hfi = hfi_from_index(nbft, raw_discovery->hfi_index); if (raw_discovery->hfi_index && !discovery->hfi) - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: discovery %d HFI not found\n", nbft->filename, discovery->index); discovery->security = security_from_index(nbft, raw_discovery->sec_index); if (raw_discovery->sec_index && !discovery->security) - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "file %s: discovery %d security descriptor not found\n", nbft->filename, discovery->index); @@ -751,14 +751,14 @@ __public int libnvme_read_nbft(struct libnvme_global_ctx *ctx, struct nbft_info */ raw_nbft_fp = fopen(filename, "rb"); if (raw_nbft_fp == NULL) { - libnvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to open %s: %s\n", filename, libnvme_strerror(errno)); return -EINVAL; } i = fseek(raw_nbft_fp, 0L, SEEK_END); if (i) { - libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to read from %s: %s\n", filename, libnvme_strerror(errno)); fclose(raw_nbft_fp); return -EINVAL; @@ -769,7 +769,7 @@ __public int libnvme_read_nbft(struct libnvme_global_ctx *ctx, struct nbft_info raw_nbft = malloc(raw_nbft_size); if (!raw_nbft) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to allocate memory for NBFT table"); fclose(raw_nbft_fp); return -ENOMEM; @@ -777,7 +777,7 @@ __public int libnvme_read_nbft(struct libnvme_global_ctx *ctx, struct nbft_info i = fread(raw_nbft, sizeof(*raw_nbft), raw_nbft_size, raw_nbft_fp); if (i != raw_nbft_size) { - libnvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to read from %s: %s\n", filename, libnvme_strerror(errno)); fclose(raw_nbft_fp); free(raw_nbft); @@ -791,7 +791,7 @@ __public int libnvme_read_nbft(struct libnvme_global_ctx *ctx, struct nbft_info */ *nbft = calloc(1, sizeof(struct nbft_info)); if (!*nbft) { - libnvme_msg(ctx, LOG_ERR, "Could not allocate memory for NBFT\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Could not allocate memory for NBFT\n"); free(raw_nbft); return -ENOMEM; } @@ -801,7 +801,7 @@ __public int libnvme_read_nbft(struct libnvme_global_ctx *ctx, struct nbft_info (*nbft)->raw_nbft_size = raw_nbft_size; if (parse_raw_nbft(ctx, *nbft)) { - libnvme_msg(ctx, LOG_ERR, "Failed to parse %s\n", filename); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to parse %s\n", filename); libnvme_free_nbft(ctx, *nbft); return -EINVAL; } diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 2e712f7074..c7e9e6a883 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -170,7 +170,7 @@ __public int libnvme_host_get_ids(struct libnvme_global_ctx *ctx, if (!hid) return -ENOMEM; - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "warning: using auto generated hostid and hostnqn\n"); } @@ -184,7 +184,7 @@ __public int libnvme_host_get_ids(struct libnvme_global_ctx *ctx, /* sanity checks */ nqn = nvme_hostid_from_hostnqn(hnqn); if (nqn && strcmp(nqn, hid)) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "warning: use hostid '%s' which does not match uuid in hostnqn '%s'\n", hid, hnqn); } @@ -225,7 +225,7 @@ static void libnvme_filter_subsystem(struct libnvme_global_ctx *ctx, if (f(s, NULL, NULL, f_args)) return; - libnvme_msg(ctx, LOG_DEBUG, "filter out subsystem %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "filter out subsystem %s\n", libnvme_subsystem_get_name(s)); libnvme_free_subsystem(s); } @@ -236,7 +236,7 @@ static void libnvme_filter_ns(struct libnvme_global_ctx *ctx, libnvme_ns_t n, if (f(NULL, NULL, n, f_args)) return; - libnvme_msg(ctx, LOG_DEBUG, "filter out namespace %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "filter out namespace %s\n", libnvme_ns_get_name(n)); libnvme_free_ns(n); } @@ -247,7 +247,7 @@ static void libnvme_filter_ctrl(struct libnvme_global_ctx *ctx, if (f(NULL, c, NULL, f_args)) return; - libnvme_msg(ctx, LOG_DEBUG, "filter out controller %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "filter out controller %s\n", libnvme_ctrl_get_name(c)); libnvme_free_ctrl(c); } @@ -293,7 +293,7 @@ __public int libnvme_scan_topology(struct libnvme_global_ctx *ctx, ctrls.num = libnvme_scan_ctrls(&ctrls.ents); if (ctrls.num < 0) { - libnvme_msg(ctx, LOG_DEBUG, "failed to scan ctrls: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan ctrls: %s\n", libnvme_strerror(-ctrls.num)); return ctrls.num; } @@ -303,7 +303,7 @@ __public int libnvme_scan_topology(struct libnvme_global_ctx *ctx, ret = libnvme_scan_ctrl(ctx, ctrls.ents[i]->d_name, &c); if (ret < 0) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan ctrl %s: %s\n", ctrls.ents[i]->d_name, libnvme_strerror(-ret)); continue; @@ -312,7 +312,7 @@ __public int libnvme_scan_topology(struct libnvme_global_ctx *ctx, subsys.num = libnvme_scan_subsystems(&subsys.ents); if (subsys.num < 0) { - libnvme_msg(ctx, LOG_DEBUG, "failed to scan subsystems: %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan subsystems: %s\n", libnvme_strerror(-subsys.num)); return subsys.num; } @@ -320,7 +320,7 @@ __public int libnvme_scan_topology(struct libnvme_global_ctx *ctx, for (i = 0; i < subsys.num; i++) { ret = libnvme_scan_subsystem(ctx, subsys.ents[i]->d_name); if (ret < 0) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan subsystem %s: %s\n", subsys.ents[i]->d_name, libnvme_strerror(-ret)); @@ -695,14 +695,14 @@ static int nvme_subsystem_scan_namespaces(struct libnvme_global_ctx *ctx, int i, ret; if (ctx->create_only) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "skipping namespace scan for subsys %s\n", s->subsysnqn); return 0; } namespaces.num = libnvme_scan_subsystem_namespaces(s, &namespaces.ents); if (namespaces.num < 0) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan namespaces for subsys %s: %s\n", s->subsysnqn, libnvme_strerror(-namespaces.num)); return namespaces.num; @@ -712,7 +712,7 @@ static int nvme_subsystem_scan_namespaces(struct libnvme_global_ctx *ctx, ret = libnvme_subsystem_scan_namespace(ctx, s, namespaces.ents[i]->d_name); if (ret < 0) - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan namespace %s: %s\n", namespaces.ents[i]->d_name, libnvme_strerror(-ret)); @@ -757,7 +757,7 @@ static int libnvme_scan_subsystem(struct libnvme_global_ctx *ctx, libnvme_host_t h = NULL; int ret; - libnvme_msg(ctx, LOG_DEBUG, "scan subsystem %s\n", name); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "scan subsystem %s\n", name); ret = asprintf(&path, "%s/%s", libnvme_subsys_sysfs_dir(), name); if (ret < 0) return -ENOMEM; @@ -787,7 +787,7 @@ static int libnvme_scan_subsystem(struct libnvme_global_ctx *ctx, * Create a subsystem with the default host * and hope for the best. */ - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "creating detached subsystem '%s'\n", name); ret = libnvme_get_host(ctx, NULL, NULL, &h); if (ret) @@ -798,7 +798,7 @@ static int libnvme_scan_subsystem(struct libnvme_global_ctx *ctx, if (nvme_subsystem_scan_namespaces(ctx, s)) return -EINVAL; } else if (strcmp(s->subsysnqn, subsysnqn)) { - libnvme_msg(ctx, LOG_DEBUG, "NQN mismatch for subsystem '%s'\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "NQN mismatch for subsystem '%s'\n", name); return -EINVAL; } @@ -846,7 +846,7 @@ static int libnvme_ctrl_scan_path(struct libnvme_global_ctx *ctx, __cleanup_free char *path = NULL, *grpid = NULL, *queue_depth = NULL; int ret; - libnvme_msg(ctx, LOG_DEBUG, "scan controller %s path %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "scan controller %s path %s\n", c->name, name); if (!c->s) return -ENXIO; @@ -895,7 +895,7 @@ __public struct libnvme_transport_handle *libnvme_ctrl_get_transport_handle( err = libnvme_open(c->ctx, c->name, &c->hdl); if (err) - libnvme_msg(c->ctx, LOG_ERR, + libnvme_msg(c->ctx, LIBNVME_LOG_ERR, "Failed to open ctrl %s, errno %d\n", c->name, err); } @@ -933,7 +933,7 @@ __public char *libnvme_ctrl_get_src_addr(libnvme_ctrl_t c, char *src_addr, p += strlen("src_addr="); l = strcspn(p, ",%"); /* % to eliminate IPv6 scope (if present) */ if (l >= src_addr_len) { - libnvme_msg(c->ctx, LOG_ERR, + libnvme_msg(c->ctx, LIBNVME_LOG_ERR, "Buffer for src_addr is too small (%zu must be > %zu)\n", src_addr_len, l); return NULL; @@ -1024,11 +1024,11 @@ __public int libnvme_disconnect_ctrl(libnvme_ctrl_t c) ret = libnvme_set_attr(libnvme_ctrl_get_sysfs_dir(c), "delete_controller", "1"); if (ret < 0) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "%s: failed to disconnect, error %d\n", c->name, errno); return ret; } - libnvme_msg(ctx, LOG_INFO, "%s: %s disconnected\n", + libnvme_msg(ctx, LIBNVME_LOG_INFO, "%s: %s disconnected\n", c->name, c->subsysnqn); nvme_deconfigure_ctrl(c); return 0; @@ -1102,18 +1102,18 @@ int _libnvme_create_ctrl(struct libnvme_global_ctx *ctx, struct libnvme_ctrl *c; if (!fctx->transport) { - libnvme_msg(ctx, LOG_ERR, "No transport specified\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "No transport specified\n"); return -EINVAL; } if (strncmp(fctx->transport, "loop", 4) && strncmp(fctx->transport, "pcie", 4) && strncmp(fctx->transport, "apple-nvme", 10) && !fctx->traddr) { - libnvme_msg(ctx, LOG_ERR, "No transport address for '%s'\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "No transport address for '%s'\n", fctx->transport); return -EINVAL; } if (!fctx->subsysnqn) { - libnvme_msg(ctx, LOG_ERR, "No subsystem NQN specified\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "No subsystem NQN specified\n"); return -EINVAL; } c = calloc(1, sizeof(*c)); @@ -1200,7 +1200,7 @@ static bool _tcp_ctrl_match_host_traddr_no_src_addr(struct libnvme_ctrl *c, * 100% positive match. Regardless, let's be optimistic * and assume that we have a match. */ - libnvme_msg(c->ctx, LOG_DEBUG, + libnvme_msg(c->ctx, LIBNVME_LOG_DEBUG, "Not enough data, but assume %s matches candidate's host_traddr: %s\n", libnvme_ctrl_get_name(c), candidate->host_traddr); @@ -1243,7 +1243,7 @@ static bool _tcp_ctrl_match_host_iface_no_src_addr(struct libnvme_ctrl *c, * 100% positive match. Regardless, let's be optimistic * and assume that we have a match. */ - libnvme_msg(c->ctx, LOG_DEBUG, + libnvme_msg(c->ctx, LIBNVME_LOG_DEBUG, "Not enough data, but assume %s matches candidate's host_iface: %s\n", libnvme_ctrl_get_name(c), candidate->host_iface); @@ -1595,7 +1595,7 @@ static int libnvme_ctrl_scan_paths(struct libnvme_global_ctx *ctx, int err, i; if (ctx->create_only) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "skipping path scan for ctrl %s\n", c->name); return 0; } @@ -1619,7 +1619,7 @@ static int libnvme_ctrl_scan_namespaces(struct libnvme_global_ctx *ctx, int err, i; if (ctx->create_only) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "skipping namespace scan for ctrl %s\n", c->name); return 0; } @@ -1652,7 +1652,7 @@ static int libnvme_ctrl_lookup_subsystem_name(struct libnvme_global_ctx *ctx, if (asprintf(&path, "%s/%s/%s", subsys_dir, subsys.ents[i]->d_name, ctrl_name) < 0) return -ENOMEM; - libnvme_msg(ctx, LOG_DEBUG, "lookup subsystem %s\n", path); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "lookup subsystem %s\n", path); if (stat(path, &st) < 0) { continue; } @@ -1681,7 +1681,7 @@ static int libnvme_ctrl_lookup_phy_slot(struct libnvme_global_ctx *ctx, slots_dir = opendir(slots_sysfs_dir); if (!slots_dir) { - libnvme_msg(ctx, LOG_WARNING, "failed to open slots dir %s\n", + libnvme_msg(ctx, LIBNVME_LOG_WARN, "failed to open slots dir %s\n", slots_sysfs_dir); return -errno; } @@ -1820,7 +1820,7 @@ static int libnvme_reconfigure_ctrl(struct libnvme_global_ctx *ctx, d = opendir(path); if (!d) { - libnvme_msg(ctx, LOG_ERR, + libnvme_msg(ctx, LIBNVME_LOG_ERR, "Failed to open ctrl dir %s, error %d\n", path, errno); return -ENODEV; } @@ -1871,7 +1871,7 @@ __public int libnvme_init_ctrl(libnvme_host_t h, libnvme_ctrl_t c, int instance) ret = libnvme_ctrl_lookup_subsystem_name(h->ctx, name, &subsys_name); if (ret) { - libnvme_msg(h->ctx, LOG_ERR, + libnvme_msg(h->ctx, LIBNVME_LOG_ERR, "Failed to lookup subsystem name for %s\n", c->name); return ENVME_CONNECT_LOOKUP_SUBSYS_NAME; @@ -1967,11 +1967,11 @@ int libnvme_ctrl_alloc(struct libnvme_global_ctx *ctx, libnvme_subsystem_t s, if (!c->name) break; if (!strcmp(c->name, name)) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "found existing ctrl %s\n", c->name); break; } - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "skipping ctrl %s\n", c->name); p = c; } @@ -1979,7 +1979,7 @@ int libnvme_ctrl_alloc(struct libnvme_global_ctx *ctx, libnvme_subsystem_t s, if (!c) c = p; if (!c && !p) { - libnvme_msg(ctx, LOG_ERR, "failed to lookup ctrl\n"); + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to lookup ctrl\n"); return -ENODEV; } FREE_CTRL_ATTR(c->address); @@ -2006,7 +2006,7 @@ __public int libnvme_scan_ctrl(struct libnvme_global_ctx *ctx, const char *name, libnvme_ctrl_t c; int ret; - libnvme_msg(ctx, LOG_DEBUG, "scan controller %s\n", name); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "scan controller %s\n", name); ret = asprintf(&path, "%s/%s", libnvme_ctrl_sysfs_dir(), name); if (ret < 0) return -ENOMEM; @@ -2031,7 +2031,7 @@ __public int libnvme_scan_ctrl(struct libnvme_global_ctx *ctx, const char *name, ret = libnvme_ctrl_lookup_subsystem_name(ctx, name, &subsysname); if (ret) { - libnvme_msg(ctx, LOG_DEBUG, + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to lookup subsystem for controller %s\n", name); return ret; @@ -2096,7 +2096,7 @@ int libnvme_ns_get_transport_handle(libnvme_ns_t n, err = libnvme_open(n->ctx, n->name, &n->hdl); if (err) { - libnvme_msg(n->ctx, LOG_ERR, "Failed to open ns %s, error %d\n", + libnvme_msg(n->ctx, LIBNVME_LOG_ERR, "Failed to open ns %s, error %d\n", n->name, err); return err; } @@ -2720,15 +2720,15 @@ static int libnvme_ctrl_scan_namespace(struct libnvme_global_ctx *ctx, struct libnvme_ns *n, *_n, *__n; int ret; - libnvme_msg(ctx, LOG_DEBUG, "scan controller %s namespace %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "scan controller %s namespace %s\n", c->name, name); if (!c->s) { - libnvme_msg(ctx, LOG_DEBUG, "no subsystem for %s\n", name); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "no subsystem for %s\n", name); return -EINVAL; } ret = __libnvme_scan_namespace(ctx, c->sysfs_dir, name, &n); if (ret) { - libnvme_msg(ctx, LOG_DEBUG, "failed to scan namespace %s\n", name); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan namespace %s\n", name); return ret; } libnvme_ctrl_for_each_ns_safe(c, _n, __n) { @@ -2750,11 +2750,11 @@ static int libnvme_subsystem_scan_namespace(struct libnvme_global_ctx *ctx, struct libnvme_ns *n, *_n, *__n; int ret; - libnvme_msg(ctx, LOG_DEBUG, "scan subsystem %s namespace %s\n", + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "scan subsystem %s namespace %s\n", s->name, name); ret = __libnvme_scan_namespace(ctx, s->sysfs_dir, name, &n); if (ret) { - libnvme_msg(ctx, LOG_DEBUG, "failed to scan namespace %s\n", name); + libnvme_msg(ctx, LIBNVME_LOG_DEBUG, "failed to scan namespace %s\n", name); return ret; } libnvme_subsystem_for_each_ns_safe(s, _n, __n) { diff --git a/libnvme/src/nvme/util.c b/libnvme/src/nvme/util.c index 2166e2cba6..e157a7b985 100644 --- a/libnvme/src/nvme/util.c +++ b/libnvme/src/nvme/util.c @@ -474,7 +474,7 @@ int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, ret = getaddrinfo(traddr, NULL, &hints, &host_info); if (ret) { - libnvme_msg(ctx, LOG_ERR, "failed to resolve host %s info\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to resolve host %s info\n", traddr); return -errno; } @@ -491,13 +491,13 @@ int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, addrstr, NVMF_TRADDR_SIZE); break; default: - libnvme_msg(ctx, LOG_ERR, "unrecognized address family (%d) %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "unrecognized address family (%d) %s\n", host_info->ai_family, traddr); return -EINVAL; } if (!p) { - libnvme_msg(ctx, LOG_ERR, "failed to get traddr for %s\n", + libnvme_msg(ctx, LIBNVME_LOG_ERR, "failed to get traddr for %s\n", traddr); return -EIO; } @@ -510,7 +510,7 @@ int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, #else /* HAVE_NETDB */ int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr, char **hostname) { - libnvme_msg(ctx, LOG_ERR, "No support for hostname IP address resolution; " \ + libnvme_msg(ctx, LIBNVME_LOG_ERR, "No support for hostname IP address resolution; " \ "recompile with libnss support.\n"); return -ENOTSUP; @@ -873,7 +873,7 @@ bool libnvme_ipaddrs_eq(const char *addr1, const char *addr2) #else /* HAVE_NETDB */ bool libnvme_ipaddrs_eq(const char *addr1, const char *addr2) { - libnvme_msg(NULL, LOG_ERR, "no support for hostname ip address resolution; " \ + libnvme_msg(NULL, LIBNVME_LOG_ERR, "no support for hostname ip address resolution; " \ "recompile with libnss support.\n"); return false; @@ -943,7 +943,7 @@ bool libnvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const char *libnvme_iface_matching_addr(const struct ifaddrs *iface_list, const char *addr) { - libnvme_msg(NULL, LOG_ERR, "no support for interface lookup; " + libnvme_msg(NULL, LIBNVME_LOG_ERR, "no support for interface lookup; " "recompile with libnss support.\n"); return NULL; @@ -952,7 +952,7 @@ const char *libnvme_iface_matching_addr(const struct ifaddrs *iface_list, bool libnvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const char *iface, const char *addr) { - libnvme_msg(NULL, LOG_ERR, "no support for interface lookup; " + libnvme_msg(NULL, LIBNVME_LOG_ERR, "no support for interface lookup; " "recompile with libnss support.\n"); return false; diff --git a/libnvme/test/config/config-dump.c b/libnvme/test/config/config-dump.c index 1139d1c92d..18b6b4d16e 100644 --- a/libnvme/test/config/config-dump.c +++ b/libnvme/test/config/config-dump.c @@ -18,7 +18,7 @@ static bool config_dump(const char *file) bool pass = false; int err; - ctx = libnvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_LOG_ERR); if (!ctx) return false; diff --git a/libnvme/test/config/hostnqn-order.c b/libnvme/test/config/hostnqn-order.c index bb73f503f8..5ccc522d21 100644 --- a/libnvme/test/config/hostnqn-order.c +++ b/libnvme/test/config/hostnqn-order.c @@ -18,7 +18,7 @@ static bool command_line(void) int err; char *hostnqn, *hostid, *hnqn, *hid; - ctx = libnvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_LOG_ERR); if (!ctx) return false; @@ -62,7 +62,7 @@ static bool json_config(char *file) setenv("LIBNVME_HOSTNQN", "", 1); setenv("LIBNVME_HOSTID", "", 1); - ctx = libnvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_LOG_ERR); if (!ctx) return false; @@ -114,7 +114,7 @@ static bool from_file(void) setenv("LIBNVME_HOSTNQN", hostnqn, 1); setenv("LIBNVME_HOSTID", hostid, 1); - ctx = libnvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_LOG_ERR); if (!ctx) return false; diff --git a/libnvme/test/config/psk-json.c b/libnvme/test/config/psk-json.c index f2fe1905cd..caed061465 100644 --- a/libnvme/test/config/psk-json.c +++ b/libnvme/test/config/psk-json.c @@ -56,7 +56,7 @@ static bool psk_json_test(char *file) libnvme_ctrl_t c; int err; - ctx = libnvme_create_global_ctx(stderr, LOG_ERR); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_LOG_ERR); if (!ctx) return false; diff --git a/libnvme/test/sysfs/tree-dump.c b/libnvme/test/sysfs/tree-dump.c index 607c00beca..f30f9dae17 100644 --- a/libnvme/test/sysfs/tree-dump.c +++ b/libnvme/test/sysfs/tree-dump.c @@ -17,7 +17,7 @@ static bool tree_dump(void) bool pass = false; int err; - ctx = libnvme_create_global_ctx(stdout, LOG_ERR); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_LOG_ERR); if (!ctx) return false; diff --git a/libnvme/test/tree.c b/libnvme/test/tree.c index 3a739dc0f8..84778dc548 100644 --- a/libnvme/test/tree.c +++ b/libnvme/test/tree.c @@ -128,7 +128,7 @@ static struct libnvme_global_ctx *create_tree() struct libnvme_global_ctx *ctx; libnvme_host_t h; - ctx = libnvme_create_global_ctx(stdout, LOG_DEBUG); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_LOG_DEBUG); assert(ctx); libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); assert(h); @@ -296,7 +296,7 @@ static bool test_src_addr() printf("\n" "test_src_addr:\n"); - ctx = libnvme_create_global_ctx(stdout, LOG_DEBUG); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_LOG_DEBUG); assert(ctx); libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); @@ -467,7 +467,7 @@ static bool ctrl_match(const char *tag, libnvme_ctrl_t found_ctrl; libnvme_subsystem_t s; - ctx = libnvme_create_global_ctx(stdout, LOG_INFO); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_LOG_INFO); assert(ctx); libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); @@ -1089,7 +1089,7 @@ static bool ctrl_config_match(const char *tag, libnvme_ctrl_t reference_ctrl; /* Existing controller (from sysfs) */ libnvme_subsystem_t s; - ctx = libnvme_create_global_ctx(stdout, LOG_INFO); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_LOG_INFO); assert(ctx); libnvme_get_host(ctx, DEFAULT_HOSTNQN, DEFAULT_HOSTID, &h); diff --git a/logging.c b/logging.c index 5f8a1cc18d..5c2489d61c 100644 --- a/logging.c +++ b/logging.c @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -37,32 +36,13 @@ bool is_printable_at_level(int level) int map_log_level(int verbose, bool quiet) { - int log_level; + if (verbose == 0 || quiet) + return LIBNVME_LOG_ERR; - /* - * LOG_NOTICE is unused thus the user has to provide two 'v' for getting - * any feedback at all. Thus skip this level - */ - verbose++; + if (verbose == 1) + return LIBNVME_LOG_INFO; - switch (verbose) { - case 0: - log_level = LOG_WARNING; - break; - case 1: - log_level = LOG_NOTICE; - break; - case 2: - log_level = LOG_INFO; - break; - default: - log_level = LOG_DEBUG; - break; - } - if (quiet) - log_level = LOG_ERR; - - return log_level; + return LIBNVME_LOG_DEBUG; } static void nvme_show_common(struct libnvme_passthru_cmd *cmd) @@ -102,7 +82,7 @@ static void nvme_show_latency(struct timeval start, struct timeval end) static void nvme_log_retry(int errnum) { - if (log_level < LOG_DEBUG) + if (log_level < LIBNVME_LOG_DEBUG) return; printf("passthru command returned '%s'\n", libnvme_strerror(errnum)); @@ -113,7 +93,7 @@ void *nvme_submit_entry(struct libnvme_transport_handle *hdl, { memset(&sb, 0, sizeof(sb)); - if (log_level >= LOG_DEBUG) + if (log_level >= LIBNVME_LOG_DEBUG) gettimeofday(&sb.start, NULL); return &sb; @@ -124,7 +104,7 @@ void nvme_submit_exit(struct libnvme_transport_handle *hdl, { struct submit_data *sb = user_data; - if (log_level >= LOG_DEBUG) { + if (log_level >= LIBNVME_LOG_DEBUG) { gettimeofday(&sb->end, NULL); nvme_show_command(cmd, err); nvme_show_latency(sb->start, sb->end); @@ -197,7 +177,7 @@ void *libnvme_mi_submit_entry(__u8 type, const struct nvme_mi_msg_hdr *hdr, size { memset(&sb, 0, sizeof(sb)); - if (log_level >= LOG_DEBUG) { + if (log_level >= LIBNVME_LOG_DEBUG) { nvme_show_req(type, hdr, hdr_len, data, data_len); gettimeofday(&sb.start, NULL); } @@ -240,7 +220,7 @@ void libnvme_mi_submit_exit(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t { struct submit_data *sb = user_data; - if (log_level >= LOG_DEBUG) { + if (log_level >= LIBNVME_LOG_DEBUG) { gettimeofday(&sb->end, NULL); nvme_show_resp(type, hdr, hdr_len, data, data_len); nvme_show_latency(sb->start, sb->end); diff --git a/logging.h b/logging.h index 5d48a800ff..dbf4e563ce 100644 --- a/logging.h +++ b/logging.h @@ -5,15 +5,17 @@ #include +#include + #define print_info(...) \ do { \ - if (is_printable_at_level(LOG_INFO)) \ + if (is_printable_at_level(LIBNVME_LOG_INFO)) \ printf(__VA_ARGS__); \ } while (false) #define print_debug(...) \ do { \ - if (is_printable_at_level(LOG_DEBUG)) \ + if (is_printable_at_level(LIBNVME_LOG_DEBUG)) \ printf(__VA_ARGS__); \ } while (false) diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 1e12da3c8c..acdf1d7749 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -5056,7 +5056,7 @@ static void stdout_lba_status_info(__u64 result) static bool line_equal(unsigned char *buf, int len, int width, int offset) { - if (!offset || len < offset + width || log_level >= LOG_DEBUG) + if (!offset || len < offset + width || log_level >= LIBNVME_LOG_DEBUG) return false; return !memcmp(buf + offset - width, buf + offset, width); diff --git a/nvme.c b/nvme.c index a7315af200..6579152e50 100644 --- a/nvme.c +++ b/nvme.c @@ -334,7 +334,7 @@ static int get_transport_handle(struct libnvme_global_ctx *ctx, int argc, ret = libnvme_open(ctx, devname, hdl); if (ret) nvme_show_err(ret, devname); - else if (log_level >= LOG_DEBUG) + else if (log_level >= LIBNVME_LOG_DEBUG) nvme_show_init(); return ret; @@ -5815,7 +5815,7 @@ static void *mmap_registers(struct libnvme_transport_handle *hdl, bool writable) sprintf(path, "/sys/class/nvme/%s/device/resource0", libnvme_transport_handle_get_name(hdl)); fd = open(path, writable ? O_RDWR : O_RDONLY); if (fd < 0) { - if (log_level >= LOG_INFO) + if (log_level >= LIBNVME_LOG_INFO) nvme_show_error("%s did not find a pci resource, open failed %s", libnvme_transport_handle_get_name(hdl), libnvme_strerror(errno)); return NULL; @@ -5823,7 +5823,7 @@ static void *mmap_registers(struct libnvme_transport_handle *hdl, bool writable) membase = mmap(NULL, getpagesize(), prot, MAP_SHARED, fd, 0); if (membase == MAP_FAILED) { - if (log_level >= LOG_INFO) { + if (log_level >= LIBNVME_LOG_INFO) { fprintf(stderr, "Failed to map registers to userspace.\n\n" "Did your kernel enable CONFIG_IO_STRICT_DEVMEM?\n" "You can disable this feature with command line argument\n\n" diff --git a/plugins/ocp/ocp-hardware-component-log.c b/plugins/ocp/ocp-hardware-component-log.c index 14ebfa5859..e13006e38e 100644 --- a/plugins/ocp/ocp-hardware-component-log.c +++ b/plugins/ocp/ocp-hardware-component-log.c @@ -17,13 +17,13 @@ #define print_info_array(...) \ do { \ - if (log_level >= LOG_INFO) \ + if (log_level >= LIBNVME_LOG_INFO) \ print_array(__VA_ARGS__); \ } while (false) #define print_info_error(...) \ do { \ - if (log_level >= LOG_INFO) \ + if (log_level >= LIBNVME_LOG_INFO) \ fprintf(stderr, __VA_ARGS__); \ } while (false) From ecc5ce81a6fb6b25e3854ae7baaf05a92b3bd539 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 11:51:18 +0000 Subject: [PATCH 10/14] lib: add LIBNVME_ prefix to DEFAULT_LOGLEVEL Use library prefix to avoid colliding with syslog.h definitions. Signed-off-by: Daniel Wagner --- libnvme/examples/discover-loop.c | 2 +- libnvme/examples/display-columnar.c | 2 +- libnvme/examples/display-tree.c | 2 +- libnvme/examples/mi-conf.c | 2 +- libnvme/examples/mi-mctp-ae.c | 2 +- libnvme/examples/mi-mctp-csi-test.c | 2 +- libnvme/examples/mi-mctp.c | 2 +- libnvme/examples/telemetry-listen.c | 2 +- libnvme/libnvme/nvme.i | 4 ++-- libnvme/src/nvme/lib.h | 4 ++-- libnvme/src/nvme/mi-mctp.c | 2 +- libnvme/test/cpp.cc | 2 +- libnvme/test/ioctl/ana.c | 2 +- libnvme/test/ioctl/discovery.c | 2 +- libnvme/test/ioctl/features.c | 2 +- libnvme/test/ioctl/identify.c | 2 +- libnvme/test/ioctl/logs.c | 2 +- libnvme/test/ioctl/misc.c | 2 +- libnvme/test/ioctl/zns.c | 2 +- libnvme/test/mi-mctp.c | 2 +- libnvme/test/mi.c | 2 +- libnvme/test/psk.c | 2 +- libnvme/test/test.c | 2 +- libnvme/test/zns.c | 2 +- plugins/huawei/huawei-nvme.c | 2 +- plugins/netapp/netapp-nvme.c | 4 ++-- plugins/zns/zns.c | 2 +- 27 files changed, 30 insertions(+), 30 deletions(-) diff --git a/libnvme/examples/discover-loop.c b/libnvme/examples/discover-loop.c index e43232d77d..a3151209ad 100644 --- a/libnvme/examples/discover-loop.c +++ b/libnvme/examples/discover-loop.c @@ -61,7 +61,7 @@ int main() libnvmf_default_config(&cfg); - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return 1; diff --git a/libnvme/examples/display-columnar.c b/libnvme/examples/display-columnar.c index c6753eee40..d4225a68df 100644 --- a/libnvme/examples/display-columnar.c +++ b/libnvme/examples/display-columnar.c @@ -25,7 +25,7 @@ int main() libnvme_ns_t n; int err; - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return 1; diff --git a/libnvme/examples/display-tree.c b/libnvme/examples/display-tree.c index 7ea623d607..af2dfb71cd 100644 --- a/libnvme/examples/display-tree.c +++ b/libnvme/examples/display-tree.c @@ -24,7 +24,7 @@ int main() libnvme_ns_t n, _n; int err; - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return 1; diff --git a/libnvme/examples/mi-conf.c b/libnvme/examples/mi-conf.c index 5a8abd993b..ab13730871 100644 --- a/libnvme/examples/mi-conf.c +++ b/libnvme/examples/mi-conf.c @@ -157,7 +157,7 @@ int main(int argc, char **argv) if (rc) errx(EXIT_FAILURE, "can't parse MI device string '%s'", devstr); - ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create global context"); diff --git a/libnvme/examples/mi-mctp-ae.c b/libnvme/examples/mi-mctp-ae.c index c77839844d..aec264319a 100644 --- a/libnvme/examples/mi-mctp-ae.c +++ b/libnvme/examples/mi-mctp-ae.c @@ -110,7 +110,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create NVMe root"); diff --git a/libnvme/examples/mi-mctp-csi-test.c b/libnvme/examples/mi-mctp-csi-test.c index 8bf04051f8..4b0a7c2baa 100644 --- a/libnvme/examples/mi-mctp-csi-test.c +++ b/libnvme/examples/mi-mctp-csi-test.c @@ -237,7 +237,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create NVMe root"); diff --git a/libnvme/examples/mi-mctp.c b/libnvme/examples/mi-mctp.c index 169983dba9..974777a91d 100644 --- a/libnvme/examples/mi-mctp.c +++ b/libnvme/examples/mi-mctp.c @@ -848,7 +848,7 @@ int main(int argc, char **argv) } libnvme_free_global_ctx(ctx); } else { - ctx = libnvme_create_global_ctx(stderr, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stderr, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) err(EXIT_FAILURE, "can't create NVMe root"); diff --git a/libnvme/examples/telemetry-listen.c b/libnvme/examples/telemetry-listen.c index 113108e913..f7d3ba68b2 100644 --- a/libnvme/examples/telemetry-listen.c +++ b/libnvme/examples/telemetry-listen.c @@ -139,7 +139,7 @@ int main() libnvme_ctrl_t c; libnvme_host_t h; - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return 1; diff --git a/libnvme/libnvme/nvme.i b/libnvme/libnvme/nvme.i index 56bf04ed1b..b202c52900 100644 --- a/libnvme/libnvme/nvme.i +++ b/libnvme/libnvme/nvme.i @@ -488,7 +488,7 @@ struct libnvme_ns { libnvme_global_ctx(const char *config_file = NULL) { struct libnvme_global_ctx *ctx; - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return NULL; @@ -507,7 +507,7 @@ struct libnvme_ns { return $self; } void log_level(const char *level) { - int log_level = DEFAULT_LOGLEVEL; + int log_level = LIBNVME_DEFAULT_LOGLEVEL; if (!strcmp(level, "debug")) log_level = LIBNVME_LOG_DEBUG; else if (!strcmp(level, "info")) log_level = LIBNVME_LOG_INFO; else if (!strcmp(level, "warning")) log_level = LIBNVME_LOG_WARN; diff --git a/libnvme/src/nvme/lib.h b/libnvme/src/nvme/lib.h index 8d8e506f4c..e1375db276 100644 --- a/libnvme/src/nvme/lib.h +++ b/libnvme/src/nvme/lib.h @@ -20,7 +20,7 @@ enum libnvme_log_level { LIBNVME_LOG_DEBUG = 3, }; -#define DEFAULT_LOGLEVEL LIBNVME_LOG_WARN +#define LIBNVME_DEFAULT_LOGLEVEL LIBNVME_LOG_WARN /** * libnvme_create_global_ctx() - Initialize global context object @@ -61,7 +61,7 @@ void libnvme_set_logging_level(struct libnvme_global_ctx *ctx, int log_level, * * Retrieves current values of logging variables. * - * Return: current log level value or DEFAULT_LOGLEVEL if not initialized. + * Return: current log level value or LIBNVME_DEFAULT_LOGLEVEL if not initialized. */ int libnvme_get_logging_level(struct libnvme_global_ctx *ctx, bool *log_pid, bool *log_tstamp); diff --git a/libnvme/src/nvme/mi-mctp.c b/libnvme/src/nvme/mi-mctp.c index d3cc7c2ae5..8f9d16ca90 100644 --- a/libnvme/src/nvme/mi-mctp.c +++ b/libnvme/src/nvme/mi-mctp.c @@ -957,7 +957,7 @@ __public struct libnvme_global_ctx *libnvme_mi_scan_mctp(void) dbus_bool_t drc; DBusError berr; - ctx = libnvme_create_global_ctx(NULL, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(NULL, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) { errno = ENOMEM; return NULL; diff --git a/libnvme/test/cpp.cc b/libnvme/test/cpp.cc index f1789aa4c7..d3cba9801e 100644 --- a/libnvme/test/cpp.cc +++ b/libnvme/test/cpp.cc @@ -20,7 +20,7 @@ int main() libnvme_ns_t n; int err; - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return 1; diff --git a/libnvme/test/ioctl/ana.c b/libnvme/test/ioctl/ana.c index 1bb2012bb7..f981993457 100644 --- a/libnvme/test/ioctl/ana.c +++ b/libnvme/test/ioctl/ana.c @@ -629,7 +629,7 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { struct libnvme_global_ctx *ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), diff --git a/libnvme/test/ioctl/discovery.c b/libnvme/test/ioctl/discovery.c index 452cb9d5ab..6e99e47695 100644 --- a/libnvme/test/ioctl/discovery.c +++ b/libnvme/test/ioctl/discovery.c @@ -439,7 +439,7 @@ static void run_test(struct libnvme_global_ctx *ctx, const char *test_name, int main(void) { struct libnvme_global_ctx *ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), diff --git a/libnvme/test/ioctl/features.c b/libnvme/test/ioctl/features.c index ca9839ab26..20db4f7389 100644 --- a/libnvme/test/ioctl/features.c +++ b/libnvme/test/ioctl/features.c @@ -1623,7 +1623,7 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { struct libnvme_global_ctx *ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); check(!libnvme_open(ctx, "NVME_TEST_FD64", &test_hdl), diff --git a/libnvme/test/ioctl/identify.c b/libnvme/test/ioctl/identify.c index a9b27864bb..7fc679df89 100644 --- a/libnvme/test/ioctl/identify.c +++ b/libnvme/test/ioctl/identify.c @@ -645,7 +645,7 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { struct libnvme_global_ctx * ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), diff --git a/libnvme/test/ioctl/logs.c b/libnvme/test/ioctl/logs.c index d6537344dc..a5c63d04c6 100644 --- a/libnvme/test/ioctl/logs.c +++ b/libnvme/test/ioctl/logs.c @@ -1103,7 +1103,7 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { struct libnvme_global_ctx * ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), diff --git a/libnvme/test/ioctl/misc.c b/libnvme/test/ioctl/misc.c index 0802ca399f..f5cda2f0df 100644 --- a/libnvme/test/ioctl/misc.c +++ b/libnvme/test/ioctl/misc.c @@ -1462,7 +1462,7 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { struct libnvme_global_ctx *ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); check(!libnvme_open(ctx, "NVME_TEST_FD64", &test_hdl), diff --git a/libnvme/test/ioctl/zns.c b/libnvme/test/ioctl/zns.c index 81fd939300..60767bffcf 100644 --- a/libnvme/test/ioctl/zns.c +++ b/libnvme/test/ioctl/zns.c @@ -163,7 +163,7 @@ static void run_test(const char *test_name, void (*test_fn)(void)) int main(void) { struct libnvme_global_ctx *ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); set_mock_fd(TEST_FD); check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl), diff --git a/libnvme/test/mi-mctp.c b/libnvme/test/mi-mctp.c index ca93e614d3..2f9ec06aa8 100644 --- a/libnvme/test/mi-mctp.c +++ b/libnvme/test/mi-mctp.c @@ -1463,7 +1463,7 @@ int main(void) __libnvme_mi_mctp_set_ops(&ops); - ctx = libnvme_create_global_ctx(fd, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(fd, LIBNVME_DEFAULT_LOGLEVEL); assert(ctx); ep = libnvme_mi_open_mctp(ctx, 0, 0); diff --git a/libnvme/test/mi.c b/libnvme/test/mi.c index 26372ee8df..6386c7e8be 100644 --- a/libnvme/test/mi.c +++ b/libnvme/test/mi.c @@ -2132,7 +2132,7 @@ int main(void) fd = test_setup_log(); - ctx = libnvme_create_global_ctx(fd, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(fd, LIBNVME_DEFAULT_LOGLEVEL); assert(ctx); ep = libnvme_mi_open_test(ctx); diff --git a/libnvme/test/psk.c b/libnvme/test/psk.c index 4b1def3916..f9f2529b30 100644 --- a/libnvme/test/psk.c +++ b/libnvme/test/psk.c @@ -345,7 +345,7 @@ static void identity_test_compat(struct libnvme_global_ctx *ctx, int main(void) { struct libnvme_global_ctx *ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); for (int i = 0; i < ARRAY_SIZE(test_data_psk); i++) export_test(ctx, &test_data_psk[i]); diff --git a/libnvme/test/test.c b/libnvme/test/test.c index 4e3a865800..756601c31d 100644 --- a/libnvme/test/test.c +++ b/libnvme/test/test.c @@ -391,7 +391,7 @@ int main(int argc, char **argv) const char *nqn_match = "testnqn"; printf("Test filter for common loop back target\n"); - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return 1; diff --git a/libnvme/test/zns.c b/libnvme/test/zns.c index 12de63e4fc..3243f5ba34 100644 --- a/libnvme/test/zns.c +++ b/libnvme/test/zns.c @@ -81,7 +81,7 @@ int main() libnvme_ns_t n; int err; - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) return 1; diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c index aede6699ea..b91b872849 100644 --- a/plugins/huawei/huawei-nvme.c +++ b/plugins/huawei/huawei-nvme.c @@ -297,7 +297,7 @@ static int huawei_list(int argc, char **argv, struct command *acmd, struct plugin *plugin) { __cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = - libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); char path[264]; struct dirent **devices; struct huawei_list_item *list_items; diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index 99d5754309..71eeb237bf 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -893,7 +893,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, struct plugin *plugin) { const char *desc = "Display information about E-Series volumes."; - __cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + __cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); struct dirent **devices; int num, i, ret, fmt; struct smdevice_info *smdevices; @@ -991,7 +991,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, static int netapp_ontapdevices(int argc, char **argv, struct command *acmd, struct plugin *plugin) { - __cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + __cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); const char *desc = "Display information about ONTAP devices."; struct dirent **devices; int num, i, ret, fmt; diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 3f179e993f..c89fc0a299 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -106,7 +106,7 @@ static int list(int argc, char **argv, struct command *acmd, }; struct table *t = table_init_with_columns(columns, ARRAY_SIZE(columns)); - ctx = libnvme_create_global_ctx(stdout, DEFAULT_LOGLEVEL); + ctx = libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL); if (!ctx) { fprintf(stderr, "Failed to create root object\n"); return -ENOMEM; From fc7d03f45b2eaba869f6539aaa66ede7519ad157 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 19:20:12 +0200 Subject: [PATCH 11/14] libnvme: add nvme- prefix to types.h and cmds.h Follow the recently introduced naming pattern by prefixing the types and cmds headers. This also allows introducing a global types.h for the entire library later. Signed-off-by: Daniel Wagner --- libnvme/doc/meson.build | 3 ++- libnvme/libnvme/nvme.i | 4 ++-- libnvme/src/libnvme-mi.h | 4 ++-- libnvme/src/libnvme.h.in | 8 ++++---- libnvme/src/meson.build | 6 +++--- libnvme/src/nvme/mi-types.h | 2 +- libnvme/src/nvme/{cmds.c => nvme-cmds.c} | 0 libnvme/src/nvme/{cmds.h => nvme-cmds.h} | 2 +- libnvme/src/nvme/{types.h => nvme-types.h} | 0 libnvme/src/nvme/tree.h | 2 +- libnvme/src/nvme/util.h | 2 +- libnvme/test/meson.build | 4 ++-- nvme-cmds.h | 3 +-- nvme.c | 2 -- types.h | 2 +- 15 files changed, 21 insertions(+), 23 deletions(-) rename libnvme/src/nvme/{cmds.c => nvme-cmds.c} (100%) rename libnvme/src/nvme/{cmds.h => nvme-cmds.h} (99%) rename libnvme/src/nvme/{types.h => nvme-types.h} (100%) diff --git a/libnvme/doc/meson.build b/libnvme/doc/meson.build index 315c8fd269..1044630606 100644 --- a/libnvme/doc/meson.build +++ b/libnvme/doc/meson.build @@ -15,8 +15,9 @@ api_files = [ 'linux.h', 'mi.h', 'nbft.h', + 'nvme-cmds.h', + 'nvme-types.h', 'tree.h', - 'types.h', 'util.h' ] diff --git a/libnvme/libnvme/nvme.i b/libnvme/libnvme/nvme.i index b202c52900..d6ef316f3b 100644 --- a/libnvme/libnvme/nvme.i +++ b/libnvme/libnvme/nvme.i @@ -1238,7 +1238,7 @@ struct libnvme_ns { "@param filename: file to read") nbft_get; PyObject *nbft_get(struct libnvme_global_ctx *ctx, const char * filename); -// We want to swig all the #define and enum from types.h, but none of the structs. +// We want to swig all the #define and enum from nvme-types.h, but none of the structs. #pragma SWIG nowarn=503 // Supress warnings about unnamed struct #define __attribute__(x) %rename($ignore, %$isclass) ""; // ignore all classes/structs @@ -1246,4 +1246,4 @@ PyObject *nbft_get(struct libnvme_global_ctx *ctx, const char * filename); %rename($ignore, %$isunion) ""; // ignore all unions %rename($ignore, %$isvariable) ""; // ignore all variables -%include "../src/nvme/types.h" +%include "../src/nvme/nvme-types.h" diff --git a/libnvme/src/libnvme-mi.h b/libnvme/src/libnvme-mi.h index bbd7d9243b..25bf565a93 100644 --- a/libnvme/src/libnvme-mi.h +++ b/libnvme/src/libnvme-mi.h @@ -14,9 +14,9 @@ extern "C" { #endif #include -#include -#include #include +#include +#include #ifdef __cplusplus } diff --git a/libnvme/src/libnvme.h.in b/libnvme/src/libnvme.h.in index 8168a69933..37964c82df 100644 --- a/libnvme/src/libnvme.h.in +++ b/libnvme/src/libnvme.h.in @@ -14,17 +14,17 @@ extern "C" { #endif -#include -@FABRICS_INCLUDE@ +#include #include #include #include #include #include +#include +#include #include -#include #include -#include +@FABRICS_INCLUDE@ #ifdef __cplusplus } diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index 2815d2ffee..1c0cb6371f 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -12,13 +12,13 @@ else sources += [ 'nvme/accessors.c', 'nvme/base64.c', - 'nvme/cmds.c', 'nvme/crc32.c', 'nvme/filters.c', 'nvme/ioctl.c', 'nvme/lib.c', 'nvme/linux.c', 'nvme/log.c', + 'nvme/nvme-cmds.c', 'nvme/sysfs.c', 'nvme/tree.c', 'nvme/util.c', @@ -26,14 +26,14 @@ else endif headers = [ 'nvme/accessors.h', - 'nvme/cmds.h', 'nvme/filters.h', 'nvme/ioctl.h', 'nvme/lib-types.h', 'nvme/lib.h', 'nvme/linux.h', + 'nvme/nvme-cmds.h', + 'nvme/nvme-types.h', 'nvme/tree.h', - 'nvme/types.h', 'nvme/util.h', ] diff --git a/libnvme/src/nvme/mi-types.h b/libnvme/src/nvme/mi-types.h index 3c5f0566c5..c84163c8c8 100644 --- a/libnvme/src/nvme/mi-types.h +++ b/libnvme/src/nvme/mi-types.h @@ -10,7 +10,7 @@ #include #include -#include +#include /** * NVME_MI_MSGTYPE_NVME - MCTP message type for NVMe-MI messages. diff --git a/libnvme/src/nvme/cmds.c b/libnvme/src/nvme/nvme-cmds.c similarity index 100% rename from libnvme/src/nvme/cmds.c rename to libnvme/src/nvme/nvme-cmds.c diff --git a/libnvme/src/nvme/cmds.h b/libnvme/src/nvme/nvme-cmds.h similarity index 99% rename from libnvme/src/nvme/cmds.h rename to libnvme/src/nvme/nvme-cmds.h index 97ba590fed..abd558bf56 100644 --- a/libnvme/src/nvme/cmds.h +++ b/libnvme/src/nvme/nvme-cmds.h @@ -15,7 +15,7 @@ #include #include -#include +#include enum nvme_cmd_dword_fields { NVME_DEVICE_SELF_TEST_CDW10_STC_SHIFT = 0, diff --git a/libnvme/src/nvme/types.h b/libnvme/src/nvme/nvme-types.h similarity index 100% rename from libnvme/src/nvme/types.h rename to libnvme/src/nvme/nvme-types.h diff --git a/libnvme/src/nvme/tree.h b/libnvme/src/nvme/tree.h index e59b09c052..ecbb05d505 100644 --- a/libnvme/src/nvme/tree.h +++ b/libnvme/src/nvme/tree.h @@ -12,7 +12,7 @@ #include #include -#include +#include /** * DOC: tree.h diff --git a/libnvme/src/nvme/util.h b/libnvme/src/nvme/util.h index 5ff0a655d6..8a9165a442 100644 --- a/libnvme/src/nvme/util.h +++ b/libnvme/src/nvme/util.h @@ -8,7 +8,7 @@ */ #pragma once -#include +#include /** * DOC: util.h diff --git a/libnvme/test/meson.build b/libnvme/test/meson.build index 035070a992..44aa1faa8f 100644 --- a/libnvme/test/meson.build +++ b/libnvme/test/meson.build @@ -194,7 +194,6 @@ if openssl_dep.found() endif foreach hdr : [ - 'cmds', 'fabrics', 'filters', 'ioctl', @@ -203,8 +202,9 @@ foreach hdr : [ 'linux', 'mi', 'nbft', + 'nvme-cmds', + 'nvme-types', 'tree', - 'types', 'util', ] hdr_conf = configuration_data() diff --git a/nvme-cmds.h b/nvme-cmds.h index 1dd8038f6c..d153227077 100644 --- a/nvme-cmds.h +++ b/nvme-cmds.h @@ -11,9 +11,8 @@ #ifndef NVME_CMDS #define NVME_CMDS -#include #include -#include +#include /** * nvme_flush() - Send an nvme flush command diff --git a/nvme.c b/nvme.c index 6579152e50..69bdb47751 100644 --- a/nvme.c +++ b/nvme.c @@ -55,8 +55,6 @@ #include "nvme-cmds.h" #include "nvme-print.h" #include "nvme.h" -#include "nvme/tree.h" -#include "nvme/types.h" #include "plugin.h" #include "util/argconfig.h" #include "util/base64.h" diff --git a/types.h b/types.h index e004c00d1a..3f583c5f45 100644 --- a/types.h +++ b/types.h @@ -2,7 +2,7 @@ #ifndef TYPES_H #define TYPES_H -#include "nvme/types.h" +#include /** * struct nvme_get_log_args - Arguments for the NVMe Admin Get Log command From c16355afb1196a18a87f5d9238389fd5055d329a Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 14:57:51 +0200 Subject: [PATCH 12/14] endian: provide endian helpers when missing Not all platforms provide an endian.h. in those cases, define the byte-order helper functions. Signed-off-by: Daniel Wagner --- libnvme/src/meson.build | 1 + libnvme/src/nvme/endian.h | 36 ++++++++++++++++++++++++++++++++++++ libnvme/src/nvme/mi-types.h | 2 +- libnvme/src/nvme/nvme-cmds.h | 2 +- libnvme/test/meson.build | 1 + nvme.h | 1 - 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 libnvme/src/nvme/endian.h diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index 1c0cb6371f..a2fa37d56c 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -26,6 +26,7 @@ else endif headers = [ 'nvme/accessors.h', + 'nvme/endian.h', 'nvme/filters.h', 'nvme/ioctl.h', 'nvme/lib-types.h', diff --git a/libnvme/src/nvme/endian.h b/libnvme/src/nvme/endian.h new file mode 100644 index 0000000000..00fb064e0b --- /dev/null +++ b/libnvme/src/nvme/endian.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * This file is part of libnvme. + * Copyright (c) 2026 SUSE Software Solutions + * + * Authors: Daniel Wagner + */ + +#pragma once + +#if defined(_WIN32) || defined(_WIN64) +#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + #define htobe16(x) (x) + #define htobe32(x) (x) + #define htobe64(x) (x) + #define htole16(x) __builtin_bswap16(x) + #define htole32(x) __builtin_bswap32(x) + #define htole64(x) __builtin_bswap64(x) + #define le16toh(x) __builtin_bswap16(x) + #define le32toh(x) __builtin_bswap32(x) + #define le64toh(x) __builtin_bswap64(x) +#else + /* Little-endian (most common case for Windows) */ + #define htobe16(x) __builtin_bswap16(x) + #define htobe32(x) __builtin_bswap32(x) + #define htobe64(x) __builtin_bswap64(x) + #define htole16(x) (x) + #define htole32(x) (x) + #define htole64(x) (x) + #define le16toh(x) (x) + #define le32toh(x) (x) + #define le64toh(x) (x) +#endif +#else +#include +#endif diff --git a/libnvme/src/nvme/mi-types.h b/libnvme/src/nvme/mi-types.h index c84163c8c8..30b98fa1f7 100644 --- a/libnvme/src/nvme/mi-types.h +++ b/libnvme/src/nvme/mi-types.h @@ -7,9 +7,9 @@ */ #pragma once -#include #include +#include #include /** diff --git a/libnvme/src/nvme/nvme-cmds.h b/libnvme/src/nvme/nvme-cmds.h index abd558bf56..c596044f05 100644 --- a/libnvme/src/nvme/nvme-cmds.h +++ b/libnvme/src/nvme/nvme-cmds.h @@ -10,10 +10,10 @@ #pragma once -#include #include #include +#include #include #include diff --git a/libnvme/test/meson.build b/libnvme/test/meson.build index 44aa1faa8f..548145436c 100644 --- a/libnvme/test/meson.build +++ b/libnvme/test/meson.build @@ -194,6 +194,7 @@ if openssl_dep.found() endif foreach hdr : [ + 'endian', 'fabrics', 'filters', 'ioctl', diff --git a/nvme.h b/nvme.h index a90b35db5c..e5ad01f950 100644 --- a/nvme.h +++ b/nvme.h @@ -17,7 +17,6 @@ #define _NVME_H #include -#include #include #include #include From ce7409d9dba72fc916126254851757a620f3f733 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 14:59:27 +0200 Subject: [PATCH 13/14] types: provide base types when missing Not all platforms define the base types used throughout the library. Inthat case, define them. Signed-off-by: Daniel Wagner --- fabrics.c | 2 - libnvme/src/libnvme.h.in | 1 + libnvme/src/meson.build | 1 + libnvme/src/nvme/accessors-fabrics.h | 3 +- libnvme/src/nvme/accessors.h | 3 +- libnvme/src/nvme/lib-types.h | 2 +- libnvme/src/nvme/mi-mctp-compat.h | 2 +- libnvme/src/nvme/nbft.h | 1 - libnvme/src/nvme/nvme-types.h | 2 +- libnvme/src/nvme/private-fabrics.h | 2 - libnvme/src/nvme/types.h | 41 +++++++++++++++++++ libnvme/tools/generator/generate-accessors.md | 3 +- libnvme/tools/generator/generate-accessors.py | 4 +- logging.c | 2 - plugins/memblaze/memblaze-nvme.c | 1 - plugins/ocp/ocp-fw-activation-history.h | 1 - plugins/ocp/ocp-smart-extended-log.h | 3 +- plugins/ocp/ocp-telemetry-decode.c | 1 - .../solidigm/solidigm-garbage-collection.c | 1 - plugins/solidigm/solidigm-smart.c | 1 - util/argconfig.h | 2 +- util/types.h | 2 - 22 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 libnvme/src/nvme/types.h diff --git a/fabrics.c b/fabrics.c index 9d194c4315..07f2de1bc0 100644 --- a/fabrics.c +++ b/fabrics.c @@ -33,8 +33,6 @@ #include #include -#include - #include #include diff --git a/libnvme/src/libnvme.h.in b/libnvme/src/libnvme.h.in index 37964c82df..84e655d4b9 100644 --- a/libnvme/src/libnvme.h.in +++ b/libnvme/src/libnvme.h.in @@ -23,6 +23,7 @@ extern "C" { #include #include #include +#include #include @FABRICS_INCLUDE@ diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index a2fa37d56c..bcfc7c8800 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -35,6 +35,7 @@ headers = [ 'nvme/nvme-cmds.h', 'nvme/nvme-types.h', 'nvme/tree.h', + 'nvme/types.h', 'nvme/util.h', ] diff --git a/libnvme/src/nvme/accessors-fabrics.h b/libnvme/src/nvme/accessors-fabrics.h index 4c628f1bbf..3ff6edef1a 100644 --- a/libnvme/src/nvme/accessors-fabrics.h +++ b/libnvme/src/nvme/accessors-fabrics.h @@ -24,7 +24,8 @@ #include #include #include -#include /* __u32, __u64, etc. */ + +#include /* Forward declarations. These are internal (opaque) structs. */ struct libnvmf_discovery_args; diff --git a/libnvme/src/nvme/accessors.h b/libnvme/src/nvme/accessors.h index e15e450825..94c7f2a725 100644 --- a/libnvme/src/nvme/accessors.h +++ b/libnvme/src/nvme/accessors.h @@ -24,7 +24,8 @@ #include #include #include -#include /* __u32, __u64, etc. */ + +#include /* Forward declarations. These are internal (opaque) structs. */ struct libnvme_path; diff --git a/libnvme/src/nvme/lib-types.h b/libnvme/src/nvme/lib-types.h index bfda16167d..e804e7a9ea 100644 --- a/libnvme/src/nvme/lib-types.h +++ b/libnvme/src/nvme/lib-types.h @@ -8,7 +8,7 @@ */ #pragma once -#include +#include struct libnvme_global_ctx; struct libnvme_transport_handle; diff --git a/libnvme/src/nvme/mi-mctp-compat.h b/libnvme/src/nvme/mi-mctp-compat.h index b6427dda01..04e6e825ed 100644 --- a/libnvme/src/nvme/mi-mctp-compat.h +++ b/libnvme/src/nvme/mi-mctp-compat.h @@ -3,7 +3,7 @@ #ifndef _MI_MCTP_COMPAT_H #define _MI_MCTP_COMPAT_H -#include +#include /* As of kernel v5.15, these AF_MCTP-related definitions are provided by * linux/mctp.h. However, we provide a set here while that header percolates diff --git a/libnvme/src/nvme/nbft.h b/libnvme/src/nvme/nbft.h index f5e46d3bdd..5aa1a03d1d 100644 --- a/libnvme/src/nvme/nbft.h +++ b/libnvme/src/nvme/nbft.h @@ -10,7 +10,6 @@ #include -#include #include #include diff --git a/libnvme/src/nvme/nvme-types.h b/libnvme/src/nvme/nvme-types.h index 5eaaccb2bf..757a62fbb2 100644 --- a/libnvme/src/nvme/nvme-types.h +++ b/libnvme/src/nvme/nvme-types.h @@ -12,7 +12,7 @@ #include #include -#include +#include /** * DOC: types.h diff --git a/libnvme/src/nvme/private-fabrics.h b/libnvme/src/nvme/private-fabrics.h index dd0a69957f..891e0be658 100644 --- a/libnvme/src/nvme/private-fabrics.h +++ b/libnvme/src/nvme/private-fabrics.h @@ -7,8 +7,6 @@ */ #pragma once -#include - #include /** diff --git a/libnvme/src/nvme/types.h b/libnvme/src/nvme/types.h new file mode 100644 index 0000000000..6e0d826e78 --- /dev/null +++ b/libnvme/src/nvme/types.h @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * This file is part of libnvme. + * Copyright (c) 2026 SUSE Software Solutions + * + * Authors: Daniel Wagner + */ + +#pragma once + +#if defined(__linux__) +#include +#else +#include + +/* Standard type definitions for linux/types.h compatibility */ +typedef uint8_t __u8; +typedef uint16_t __u16; +typedef uint32_t __u32; +typedef uint64_t __u64; +typedef int8_t __s8; +typedef int16_t __s16; +typedef int32_t __s32; +typedef int64_t __s64; + +/* Little-endian types (Windows is little-endian) */ +typedef __u16 __le16; +typedef __u32 __le32; +typedef __u64 __le64; +typedef __s16 __le16s; +typedef __s32 __le32s; +typedef __s64 __le64s; + +/* Big-endian types for completeness */ +typedef __u16 __be16; +typedef __u32 __be32; +typedef __u64 __be64; +typedef __s16 __be16s; +typedef __s32 __be32s; +typedef __s64 __be64s; +#endif diff --git a/libnvme/tools/generator/generate-accessors.md b/libnvme/tools/generator/generate-accessors.md index 2dc1fc16bf..f11ccd9572 100644 --- a/libnvme/tools/generator/generate-accessors.md +++ b/libnvme/tools/generator/generate-accessors.md @@ -124,7 +124,8 @@ python3 generate-accessors.py person.h #include #include #include -#include /* __u32, __u64, etc. */ + +#include /* Forward declarations. These are internal (opaque) structs. */ struct person; diff --git a/libnvme/tools/generator/generate-accessors.py b/libnvme/tools/generator/generate-accessors.py index cdd78af57a..c0190cf997 100755 --- a/libnvme/tools/generator/generate-accessors.py +++ b/libnvme/tools/generator/generate-accessors.py @@ -630,8 +630,8 @@ def main(): f'#include \n' f'#include \n' f'#include \n' - f'#include \n' - f'#include /* __u32, __u64, etc. */\n' + f'#include \n\n' + f'#include \n' f'\n' ) f.write('/* Forward declarations. These are internal (opaque) structs. */\n') diff --git a/logging.c b/logging.c index 5c2489d61c..3f4ddad463 100644 --- a/logging.c +++ b/logging.c @@ -6,8 +6,6 @@ #include #include -#include - #include #include diff --git a/plugins/memblaze/memblaze-nvme.c b/plugins/memblaze/memblaze-nvme.c index 0c11e4f61c..2ce7020e72 100644 --- a/plugins/memblaze/memblaze-nvme.c +++ b/plugins/memblaze/memblaze-nvme.c @@ -10,7 +10,6 @@ #include #include "common.h" -#include "linux/types.h" #include "nvme-cmds.h" #include "nvme-print.h" #include "nvme.h" diff --git a/plugins/ocp/ocp-fw-activation-history.h b/plugins/ocp/ocp-fw-activation-history.h index f5c5277ad7..2eb0a3f93d 100644 --- a/plugins/ocp/ocp-fw-activation-history.h +++ b/plugins/ocp/ocp-fw-activation-history.h @@ -7,7 +7,6 @@ #include #include "common.h" -#include "linux/types.h" #ifndef OCP_FIRMWARE_ACTIVATION_HISTORY_H #define OCP_FIRMWARE_ACTIVATION_HISTORY_H diff --git a/plugins/ocp/ocp-smart-extended-log.h b/plugins/ocp/ocp-smart-extended-log.h index bbb2cefc1e..ebac413316 100644 --- a/plugins/ocp/ocp-smart-extended-log.h +++ b/plugins/ocp/ocp-smart-extended-log.h @@ -6,8 +6,9 @@ * Venkat Ramesh */ +#include + #include "common.h" -#include "linux/types.h" #ifndef OCP_SMART_EXTENDED_LOG_H #define OCP_SMART_EXTENDED_LOG_H diff --git a/plugins/ocp/ocp-telemetry-decode.c b/plugins/ocp/ocp-telemetry-decode.c index 2cba1c7db1..9f83c622b4 100644 --- a/plugins/ocp/ocp-telemetry-decode.c +++ b/plugins/ocp/ocp-telemetry-decode.c @@ -8,7 +8,6 @@ #include "common.h" #include "nvme.h" #include "plugin.h" -#include "linux/types.h" #include "util/types.h" #include "nvme-print.h" diff --git a/plugins/solidigm/solidigm-garbage-collection.c b/plugins/solidigm/solidigm-garbage-collection.c index 035e560cba..da84625495 100644 --- a/plugins/solidigm/solidigm-garbage-collection.c +++ b/plugins/solidigm/solidigm-garbage-collection.c @@ -17,7 +17,6 @@ #include "common.h" #include "nvme.h" #include "plugin.h" -#include "linux/types.h" #include "nvme-print.h" #include "solidigm-garbage-collection.h" #include "solidigm-util.h" diff --git a/plugins/solidigm/solidigm-smart.c b/plugins/solidigm/solidigm-smart.c index ba8650e3c2..9e3cfbeafb 100644 --- a/plugins/solidigm/solidigm-smart.c +++ b/plugins/solidigm/solidigm-smart.c @@ -16,7 +16,6 @@ #include "common.h" #include "nvme.h" #include "plugin.h" -#include "linux/types.h" #include "nvme-print.h" #include "solidigm-smart.h" diff --git a/util/argconfig.h b/util/argconfig.h index 2bbd567628..f27a20b3f6 100644 --- a/util/argconfig.h +++ b/util/argconfig.h @@ -41,7 +41,7 @@ #include #include -#include +#include enum argconfig_types { CFG_FLAG, diff --git a/util/types.h b/util/types.h index c009f2f1fa..7f8d783c01 100644 --- a/util/types.h +++ b/util/types.h @@ -7,8 +7,6 @@ #include #include -#include - #include #define ABSOLUTE_ZERO_CELSIUS -273 From ae37a3c3417ee6cdc50e0700972a4c36c5bf0214 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 14 Apr 2026 18:23:36 +0200 Subject: [PATCH 14/14] CI: select ucrt64 compiler MSYS gcc (/usr/bin/gcc) is not the native Windows compiler. Select the UCRT64 compiler explicitly. Without this, the header guards in endian.h and types.h do not work. Signed-off-by: Daniel Wagner --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7dac8c4118..95ecf20cd9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -253,11 +253,11 @@ jobs: which git git --version git config --global --add safe.directory "$GITHUB_WORKSPACE" - scripts/build.sh -b release -c gcc + scripts/build.sh -b release -c /ucrt64/bin/gcc - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 if: failure() with: name: windows-msys2-ucrt64-logs path: | - .build-ci/meson-logs/*.txt \ No newline at end of file + .build-ci/meson-logs/*.txt