XLIO
The NVIDIA® Accelerated IO
xlio.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3  * Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4  * SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
5  */
6 
27 #ifndef XLIO_H
28 #define XLIO_H
29 
30 #include <fcntl.h>
31 #include <poll.h>
32 #include <sched.h>
33 #include <signal.h>
34 #include <stdint.h>
35 #include <sys/epoll.h>
36 #include <sys/stat.h>
37 #include <sys/time.h>
38 
39 #include "xlio_types.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 int xlio_socket(int __domain, int __type, int __protocol);
46 
47 int xlio_close(int __fd);
48 
49 int xlio_shutdown(int __fd, int __how);
50 
51 int xlio_listen(int __fd, int backlog);
52 
53 int xlio_accept(int __fd, struct sockaddr *__addr, socklen_t *__addrlen);
54 
55 int xlio_accept4(int __fd, struct sockaddr *__addr, socklen_t *__addrlen, int __flags);
56 
57 int xlio_bind(int __fd, const struct sockaddr *__addr, socklen_t __addrlen);
58 
59 int xlio_connect(int __fd, const struct sockaddr *__to, socklen_t __tolen);
60 
61 int xlio_setsockopt(int __fd, int __level, int __optname, __const void *__optval,
62  socklen_t __optlen);
63 
64 int xlio_getsockopt(int __fd, int __level, int __optname, void *__optval, socklen_t *__optlen);
65 
66 int xlio_fcntl(int __fd, int __cmd, ...);
67 
68 int xlio_fcntl64(int __fd, int __cmd, ...);
69 
70 int xlio_getsockname(int __fd, struct sockaddr *__name, socklen_t *__namelen);
71 
72 int xlio_getpeername(int __fd, struct sockaddr *__name, socklen_t *__namelen);
73 
74 ssize_t xlio_read(int __fd, void *__buf, size_t __nbytes);
75 
76 ssize_t xlio_readv(int __fd, const struct iovec *iov, int iovcnt);
77 
78 ssize_t xlio_recv(int __fd, void *__buf, size_t __nbytes, int __flags);
79 
80 ssize_t xlio_recvmsg(int __fd, struct msghdr *__msg, int __flags);
81 
82 struct mmsghdr;
83 
84 int xlio_recvmmsg(int __fd, struct mmsghdr *__mmsghdr, unsigned int __vlen, int __flags,
85  const struct timespec *__timeout);
86 
87 ssize_t xlio_recvfrom(int __fd, void *__buf, size_t __nbytes, int __flags, struct sockaddr *__from,
88  socklen_t *__fromlen);
89 
90 ssize_t xlio_write(int __fd, __const void *__buf, size_t __nbytes);
91 
92 ssize_t xlio_writev(int __fd, const struct iovec *iov, int iovcnt);
93 
94 ssize_t xlio_send(int __fd, __const void *__buf, size_t __nbytes, int __flags);
95 
96 ssize_t xlio_sendmsg(int __fd, __const struct msghdr *__msg, int __flags);
97 
98 int xlio_sendmmsg(int __fd, struct mmsghdr *__mmsghdr, unsigned int __vlen, int __flags);
99 
100 ssize_t xlio_sendto(int __fd, __const void *__buf, size_t __nbytes, int __flags,
101  const struct sockaddr *__to, socklen_t __tolen);
102 
103 ssize_t xlio_sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
104 
105 ssize_t xlio_sendfile64(int out_fd, int in_fd, __off64_t *offset, size_t count);
106 
107 int xlio_select(int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds,
108  struct timeval *__timeout);
109 
110 int xlio_pselect(int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__errorfds,
111  const struct timespec *__timeout, const sigset_t *__sigmask);
112 int xlio_poll(struct pollfd *__fds, nfds_t __nfds, int __timeout);
113 
114 int xlio_ppoll(struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout,
115  const sigset_t *__sigmask);
116 
117 int xlio_epoll_create(int __size);
118 
119 int xlio_epoll_create1(int __flags);
120 
121 int xlio_epoll_ctl(int __epfd, int __op, int __fd, struct epoll_event *__event);
122 
123 int xlio_epoll_wait(int __epfd, struct epoll_event *__events, int __maxevents, int __timeout);
124 
125 int xlio_epoll_pwait(int __epfd, struct epoll_event *__events, int __maxevents, int __timeout,
126  const sigset_t *__sigmask);
127 int xlio_socketpair(int __domain, int __type, int __protocol, int __sv[2]);
128 
129 int xlio_pipe(int __filedes[2]);
130 
131 int xlio_open(__const char *__file, int __oflag, ...);
132 
133 int xlio_creat(const char *__pathname, mode_t __mode);
134 
135 int xlio_dup(int __fd);
136 
137 int xlio_dup2(int __fd, int __fd2);
138 
139 /*
140  * Add a libxlio.conf rule to the top of the list.
141  * This rule will not apply to existing sockets which already considered the conf rules.
142  * (around connect/listen/send/recv ..)
143  * @param config_line A char buffer with the exact format as defined in libxlio.conf, and should
144  * end with '\0'.
145  * @return 0 on success, or error code on failure.
146  */
147 int xlio_add_conf_rule(const char *config_line);
148 
149 /*
150  * Create sockets on pthread tid as offloaded/not-offloaded.
151  * This does not affect existing sockets.
152  * Offloaded sockets are still subject to libxlio.conf rules.
153  * @param offload 1 for offloaded, 0 for not-offloaded.
154  * @return 0 on success, or error code on failure.
155  */
156 int xlio_thread_offload(int offload, pthread_t tid);
157 
158 /*
159  * Dump fd statistics using the library logger.
160  * @param fd to dump, 0 for all open fds.
161  * @param log_level dumping level corresponding vlog_levels_t enum (vlogger.h).
162  * @return 0 on success, or error code on failure.
163  */
164 int xlio_dump_fd_stats(int fd, int log_level);
165 
166 /*
167  * Register a received packet notification callback.
168  *
169  * @param s Socket file descriptor.
170  * @param callback Callback function.
171  * @param context user contex for callback function.
172  * @return 0 - success, -1 - error
173  *
174  * errno is set to: EINVAL - not offloaded socket
175  */
176 int xlio_register_recv_callback(int s, xlio_recv_callback_t callback, void *context);
177 
263 /* Forward declaration. */
264 struct ibv_pd;
265 
287 int xlio_init_ex(const struct xlio_init_attr *attr);
288 
305 int xlio_init(void);
306 
314 int xlio_exit(void);
315  // end of xlio_init group
317 
362 
373 
388 
402  // end of xlio_poll_group group
404 
436 int xlio_socket_create(const struct xlio_socket_attr *attr, xlio_socket_t *sock_out);
437 
455 
467 int xlio_socket_update(xlio_socket_t sock, unsigned flags, uintptr_t userdata_sq);
468 
484 int xlio_socket_setsockopt(xlio_socket_t sock, int level, int optname, const void *optval,
485  socklen_t optlen);
486 
499 int xlio_socket_getsockname(xlio_socket_t sock, struct sockaddr *addr, socklen_t *addrlen);
500 
513 int xlio_socket_getpeername(xlio_socket_t sock, struct sockaddr *addr, socklen_t *addrlen);
514 
531 int xlio_socket_bind(xlio_socket_t sock, const struct sockaddr *addr, socklen_t addrlen);
532 
556 int xlio_socket_connect(xlio_socket_t sock, const struct sockaddr *to, socklen_t tolen);
557 
579 
591 struct ibv_pd *xlio_socket_get_pd(xlio_socket_t sock);
592 
612 
630  // end of xlio_socket group
632 
677 int xlio_socket_send(xlio_socket_t sock, const void *data, size_t len,
678  const struct xlio_socket_send_attr *attr);
679 
693 int xlio_socket_sendv(xlio_socket_t sock, const struct iovec *iov, unsigned iovcnt,
694  const struct xlio_socket_send_attr *attr);
695 
709 
725  // end of xlio_tx group
727 
760 
773  // end of xlio_rx group
775  // end of xlio_ultra_api group
777 
778 #ifdef __cplusplus
779 }
780 #endif
781 #endif /* XLIO_H */
int xlio_exit(void)
Finalize XLIO.
int xlio_init(void)
Initialize XLIO.
int xlio_init_ex(const struct xlio_init_attr *attr)
Initialize the XLIO Ultra API.
int xlio_poll_group_destroy(xlio_poll_group_t group)
Destroy a polling group.
int xlio_poll_group_create(const struct xlio_poll_group_attr *attr, xlio_poll_group_t *group_out)
Create a new polling group.
int xlio_poll_group_update(xlio_poll_group_t group, const struct xlio_poll_group_attr *attr)
Update polling group attributes.
uintptr_t xlio_poll_group_t
Polling group handle.
Definition: xlio_types.h:164
void xlio_poll_group_poll(xlio_poll_group_t group)
Poll for events on a polling group.
void xlio_socket_buf_free(xlio_socket_t sock, struct xlio_buf *buf)
Free a receive buffer (socket-specific)
void xlio_poll_group_buf_free(xlio_poll_group_t group, struct xlio_buf *buf)
Free a receive buffer (group-specific)
int xlio_socket_attach_group(xlio_socket_t sock, xlio_poll_group_t group)
Attach socket to polling group.
int xlio_socket_create(const struct xlio_socket_attr *attr, xlio_socket_t *sock_out)
Create a new XLIO socket.
int xlio_socket_update(xlio_socket_t sock, unsigned flags, uintptr_t userdata_sq)
Update socket attributes.
uintptr_t xlio_socket_t
Socket handle.
Definition: xlio_types.h:172
struct ibv_pd * xlio_socket_get_pd(xlio_socket_t sock)
Get InfiniBand protection domain.
int xlio_socket_listen(xlio_socket_t sock)
Listen for incoming connections.
int xlio_socket_getsockname(xlio_socket_t sock, struct sockaddr *addr, socklen_t *addrlen)
Get socket name.
int xlio_socket_destroy(xlio_socket_t sock)
Destroy an XLIO socket.
int xlio_socket_getpeername(xlio_socket_t sock, struct sockaddr *addr, socklen_t *addrlen)
Get peer name.
int xlio_socket_detach_group(xlio_socket_t sock)
Detach socket from polling group.
int xlio_socket_setsockopt(xlio_socket_t sock, int level, int optname, const void *optval, socklen_t optlen)
Set socket options.
int xlio_socket_bind(xlio_socket_t sock, const struct sockaddr *addr, socklen_t addrlen)
Bind socket to address.
int xlio_socket_connect(xlio_socket_t sock, const struct sockaddr *to, socklen_t tolen)
Connect socket to remote address.
void xlio_poll_group_flush(xlio_poll_group_t group)
Flush all dirty sockets in a polling group.
int xlio_socket_sendv(xlio_socket_t sock, const struct iovec *iov, unsigned iovcnt, const struct xlio_socket_send_attr *attr)
Send vectored data on a socket.
int xlio_socket_send(xlio_socket_t sock, const void *data, size_t len, const struct xlio_socket_send_attr *attr)
Send data on a socket.
void xlio_socket_flush(xlio_socket_t sock)
Flush pending data on a socket.
Buffer descriptor.
Definition: xlio_types.h:198
XLIO initialization attributes.
Definition: xlio_types.h:371
Polling group attributes.
Definition: xlio_types.h:414
Socket creation attributes.
Definition: xlio_types.h:450
Send operation attributes.
Definition: xlio_types.h:489
XLIO API type definitions and structures.