From: Daniel Wagner Date: Tue, 5 Mar 2024 14:32:59 +0000 (+0100) Subject: ioctl: export nvme_submit_passthru{64} as weak symbol X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=016a656dfb8b11262445bd256731b884338e3caf;p=users%2Fsagi%2Flibnvme.git ioctl: export nvme_submit_passthru{64} as weak symbol Export the two low level ioctl function as weak symbol. This allows the user application to provide their own version of this function, e.g. in order to allow meassuring the time spend in the function or printing the struct nvme_passthru_cmd{64}. Signed-off-by: Daniel Wagner --- diff --git a/src/libnvme.map b/src/libnvme.map index c8163cbd..e8bd9f10 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -1,4 +1,10 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +LIBNVME_1.9 { + global: + nvme_submit_passthru; + nvme_submit_passthru64; +}; + LIBNVME_1_8 { global: nvme_uuid_find; diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 04dc8894..42b614c3 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -78,9 +78,10 @@ int nvme_get_nsid(int fd, __u32 *nsid) return -1 * (errno != 0); } -static int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, - struct nvme_passthru_cmd64 *cmd, - __u64 *result) +__attribute__((weak)) +int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, + struct nvme_passthru_cmd64 *cmd, + __u64 *result) { int err = ioctl(fd, ioctl_cmd, cmd); @@ -115,8 +116,9 @@ static void nvme_show_command(struct nvme_passthru_cmd *cmd, int err, struct tim (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec)); } -static int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, - struct nvme_passthru_cmd *cmd, __u32 *result) +__attribute__((weak)) +int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, + struct nvme_passthru_cmd *cmd, __u32 *result) { struct timeval start; struct timeval end; diff --git a/src/nvme/linux.h b/src/nvme/linux.h index 11ee76e2..f38b6a60 100644 --- a/src/nvme/linux.h +++ b/src/nvme/linux.h @@ -335,4 +335,39 @@ char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn, int version, int hmac, unsigned char *configured_key, int key_len); +/** + * nvme_submit_passthru - Low level ioctl wrapper for passthru commands + * @fd: File descriptor of the nvme device + * @ioctl_cmd: IOCTL command id + * @cmd: Passhtru command + * @result: Optional field to return the result + * + * This is a low level library function which should not be used directly. It is + * exposed as weak symbol so that the user application is able to provide their own + * implementation of this function with additional debugging or logging code. + * + * Return: The value from the ioctl system call (see ioctl documentation) + */ +__attribute__((weak)) +int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, + struct nvme_passthru_cmd *cmd, __u32 *result); + +/** + * nvme_submit_passthru64 - Low level ioctl wrapper for passthru commands + * @fd: File descriptor of the nvme device + * @ioctl_cmd: IOCTL command id + * @cmd: Passhtru command + * @result: Optional field to return the result + * + * This is a low level library function which should not be used directly. It is + * exposed as weak symbol so that the user application is able to provide their own + * implementation of this function with additional debugging or logging code. + * + * Return: The value from the ioctl system call (see ioctl documentation) + */ +__attribute__((weak)) +int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd, + struct nvme_passthru_cmd64 *cmd, + __u64 *result); + #endif /* _LIBNVME_LINUX_H */