Skip to content

libnvme: Add nvme_getifaddrs()#3090

Merged
igaw merged 1 commit intolinux-nvme:masterfrom
martin-belanger:getifaddrs_wrapper-v2
Feb 12, 2026
Merged

libnvme: Add nvme_getifaddrs()#3090
igaw merged 1 commit intolinux-nvme:masterfrom
martin-belanger:getifaddrs_wrapper-v2

Conversation

@martin-belanger
Copy link

@martin-belanger martin-belanger commented Feb 10, 2026

The POSIX getifaddrs() API returns the list of network interfaces on the system, but invoking it can be costly. On large-scale systems with hundreds of NVMe-over-TCP connections, this API may be called hundreds of times, resulting in increased latency.

This patch introduces nvme_getifaddrs(), a wrapper around getifaddrs() that caches the results on the first invocation and reuses the cached data on subsequent calls.

Fixes: linux-nvme/libnvme#1098

*
* Return: 0 on success, -1 on error (with errno set).
*/
int nvme_getifaddrs(struct ifaddrs **ifap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this function private and don't expose it to user.

@igaw
Copy link
Collaborator

igaw commented Feb 11, 2026

it would be indeed good to tie it to the global context. If I read it correctly, the users of this function are getting either a struct nvme_ctrl * or a struct nvme_subystem * pointer as input:

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)
{
	_cleanup_candidate_ struct candidate_args candidate = {};
	ctrl_match_t ctrl_match;

	/* Init candidate and get the matching function to use */
	ctrl_match = _candidate_init(&candidate, transport, traddr, trsvcid,
				     subsysnqn, host_traddr, host_iface);

	return ctrl_match(c, &candidate);
}

That means it is possible to access the global context via those two pointers, c->ctx or s->h->ctx. They should be valid at this point (famous last words :)).

@martin-belanger
Copy link
Author

Ah! You're right. It's been so long since I've worked on libnvme that I forgot how to access the ctx from a ctrl or subsys object. Let me rework this.

The POSIX `getifaddrs()` API returns the list of network
interfaces on the system, but invoking it can be costly. On
large-scale systems with hundreds of NVMe-over-TCP connections,
this API may be called hundreds of times, resulting in increased
latency.

This patch introduces `nvme_getifaddrs()`, a wrapper around
`getifaddrs()` that caches the results on the first invocation
and reuses the cached data on subsequent calls.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
@martin-belanger
Copy link
Author

@igaw - Thanks for your suggestion. I am now saving the cache in the global context.

@igaw igaw merged commit 7567f01 into linux-nvme:master Feb 12, 2026
20 checks passed
@igaw
Copy link
Collaborator

igaw commented Feb 12, 2026

Yes, this looks way better! Thanks!

@martin-belanger martin-belanger deleted the getifaddrs_wrapper-v2 branch February 13, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nvme list slows to a crawl with 500 interfaces and 20 connected nvmeof (tcp) devices

2 participants