From 4da5b4b2fba02bd3e78f16828359cef79a757911 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 24 Dec 2023 08:51:44 +0100 Subject: Adding upstream version 1.7.1. Signed-off-by: Daniel Baumann --- src/nvme/tree.h | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) (limited to 'src/nvme/tree.h') diff --git a/src/nvme/tree.h b/src/nvme/tree.h index bcf3636..a30e8eb 100644 --- a/src/nvme/tree.h +++ b/src/nvme/tree.h @@ -15,6 +15,7 @@ #include #include +#include #include "ioctl.h" #include "util.h" @@ -61,6 +62,17 @@ void nvme_root_set_application(nvme_root_t r, const char *a); */ const char *nvme_root_get_application(nvme_root_t r); +/** + * nvme_root_release_fds - Close all opened file descriptors in the tree + * @r: &nvme_root_t object + * + * Controller and Namespace objects cache the file descriptors + * of opened nvme devices. This API can be used to close and + * clear all cached fds in the tree. + * + */ +void nvme_root_release_fds(nvme_root_t r); + /** * nvme_free_tree() - Free root object * @r: &nvme_root_t object @@ -295,6 +307,51 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport, const char *host_iface, const char *trsvcid, nvme_ctrl_t p); +/** + * nvme_ctrl_find() - Locate an existing controller + * @s: &nvme_subsystem_t object + * @transport: Transport name + * @traddr: Transport address + * @trsvcid: Transport service identifier + * @subsysnqn: Subsystem NQN + * @host_traddr: Host transport address + * @host_iface: Host interface name + * + * Lookup a controller in @s based on @transport, @traddr, @trsvcid, + * @subsysnqn, @host_traddr, and @host_iface. @transport must be specified, + * other fields may be required depending on the transport. Parameters set + * to NULL will be ignored. + * + * Unlike nvme_lookup_ctrl(), this function does not create a new object if + * an existing controller cannot be found. + * + * Return: Controller instance on success, NULL otherwise. + */ +nvme_ctrl_t nvme_ctrl_find(nvme_subsystem_t s, const char *transport, + const char *traddr, const char *trsvcid, + const char *subsysnqn, const char *host_traddr, + const char *host_iface); + +/** + * nvme_ctrl_config_match() - Check if ctrl @c matches config params + * @c: An existing controller instance + * @transport: Transport name + * @traddr: Transport address + * @trsvcid: Transport service identifier + * @subsysnqn: Subsystem NQN + * @host_traddr: Host transport address + * @host_iface: Host interface name + * + * Check that controller @c matches parameters: @transport, @traddr, + * @trsvcid, @subsysnqn, @host_traddr, and @host_iface. Parameters set + * to NULL will be ignored. + * + * Return: true if there's a match, false otherwise. + */ +bool nvme_ctrl_config_match(struct nvme_ctrl *c, const char *transport, + const char *traddr, const char *trsvcid, + const char *subsysnqn, const char *host_traddr, + const char *host_iface); /** * nvme_create_ctrl() - Allocate an unconnected NVMe controller @@ -484,10 +541,24 @@ nvme_ns_t nvme_subsystem_next_ns(nvme_subsystem_t s, nvme_ns_t n); * nvme_ns_get_fd() - Get associated file descriptor * @n: Namespace instance * + * libnvme will open() the file (if not already opened) and keep + * an internal copy of the file descriptor. Following calls to + * this API retrieve the internal cached copy of the file + * descriptor. The file will remain opened and the fd will + * remain cached until the ns object is deleted or + * nvme_ns_release_fd() is called. + * * Return: File descriptor associated with @n or -1 */ int nvme_ns_get_fd(nvme_ns_t n); +/** + * nvme_ns_release_fd() - Close fd and clear fd from ns object + * @n: Namespace instance + * + */ +void nvme_ns_release_fd(nvme_ns_t n); + /** * nvme_ns_get_nsid() - NSID of a namespace * @n: Namespace instance @@ -772,10 +843,24 @@ nvme_ns_t nvme_path_get_ns(nvme_path_t p); * nvme_ctrl_get_fd() - Get associated file descriptor * @c: Controller instance * + * libnvme will open() the file (if not already opened) and keep + * an internal copy of the file descriptor. Following calls to + * this API retrieve the internal cached copy of the file + * descriptor. The file will remain opened and the fd will + * remain cached until the controller object is deleted or + * nvme_ctrl_release_fd() is called. + * * Return: File descriptor associated with @c or -1 */ int nvme_ctrl_get_fd(nvme_ctrl_t c); +/** + * nvme_ctrl_release_fd() - Close fd and clear fd from controller object + * @c: Controller instance + * + */ +void nvme_ctrl_release_fd(nvme_ctrl_t c); + /** * nvme_ctrl_get_name() - sysfs name of a controller * @c: Controller instance @@ -801,6 +886,16 @@ const char *nvme_ctrl_get_sysfs_dir(nvme_ctrl_t c); */ const char *nvme_ctrl_get_address(nvme_ctrl_t c); +/** + * nvme_ctrl_get_src_addr() - Extract src_addr from the c->address string + * @c: Controller instance + * @src_addr: Where to copy the src_addr. Size must be at least INET6_ADDRSTRLEN. + * @src_addr_len: Length of the buffer @src_addr. + * + * Return: Pointer to @src_addr on success. NULL on failure to extract the src_addr. + */ +char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len); + /** * nvme_ctrl_get_phy_slot() - PCI physical slot number of a controller * @c: Controller instance @@ -827,7 +922,7 @@ const char *nvme_ctrl_get_firmware(nvme_ctrl_t c); const char *nvme_ctrl_get_model(nvme_ctrl_t c); /** - * nvme_ctrl_get_state() - Running state of an controller + * nvme_ctrl_get_state() - Running state of a controller * @c: Controller instance * * Return: String indicating the running state of @c @@ -1147,6 +1242,14 @@ const char *nvme_subsystem_get_application(nvme_subsystem_t s); */ void nvme_subsystem_set_application(nvme_subsystem_t s, const char *a); +/** + * nvme_subsystem_get_iopolicy() - Return the IO policy of subsytem + * @s: nvme_subsystem_t object + * + * Return: IO policy used by current subsystem + */ +const char *nvme_subsystem_get_iopolicy(nvme_subsystem_t s); + /** * nvme_scan_topology() - Scan NVMe topology and apply filter * @r: nvme_root_t object @@ -1176,6 +1279,16 @@ const char *nvme_host_get_hostnqn(nvme_host_t h); */ const char *nvme_host_get_hostid(nvme_host_t h); +/** + * nvme_host_release_fds() - Close all opened file descriptors under host + * @h: nvme_host_t object + * + * Controller and Namespace objects cache the file descriptors + * of opened nvme devices. This API can be used to close and + * clear all cached fds under this host. + */ +void nvme_host_release_fds(struct nvme_host *h); + /** * nvme_free_host() - Free nvme_host_t object * @h: nvme_host_t object @@ -1292,6 +1405,18 @@ char *nvme_get_ns_attr(nvme_ns_t n, const char *attr); nvme_ns_t nvme_subsystem_lookup_namespace(struct nvme_subsystem *s, __u32 nsid); +/** + * nvme_subsystem_release_fds() - Close all opened fds under subsystem + * @s: nvme_subsystem_t object + * + * Controller and Namespace objects cache the file descriptors + * of opened nvme devices. This API can be used to close and + * clear all cached fds under this subsystem. + * + */ +void nvme_subsystem_release_fds(struct nvme_subsystem *s); + + /** * nvme_get_path_attr() - Read path sysfs attribute * @p: nvme_path_t object -- cgit v1.2.3