XLIO
The NVIDIA® Accelerated IO
Loading...
Searching...
No Matches
xlio_extra.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3 * Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4 * SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
5 */
6
16#ifndef XLIO_EXTRA_H
17#define XLIO_EXTRA_H
18
19#include <stddef.h>
20#include <stdint.h>
21#include <sys/socket.h>
22
23#include "xlio_types.h"
24
25/* Magic value for xlio_get_api (NVDAXLIO) */
26#define XLIO_MAGIC_NUMBER (0x4f494c584144564eULL)
27
28/* Forward declaration. */
29struct ibv_pd;
30
31/*
32 * XLIO Extended Socket API
33 */
34
35enum {
36 XLIO_EXTRA_API_ADD_CONF_RULE = (1 << 3),
37 XLIO_EXTRA_API_THREAD_OFFLOAD = (1 << 4),
38 XLIO_EXTRA_API_DUMP_FD_STATS = (1 << 11),
39 XLIO_EXTRA_API_XLIO_ULTRA = (1 << 13),
40};
41
42struct __attribute__((packed)) xlio_api_t {
43
44 /*
45 * Used to verify that API structure returned from xlio_get_api call is
46 * compatible with current XLIO library version.
47 */
48 uint64_t magic;
49
50 /*
51 * Used to identify which methods were initialized by XLIO as part of xlio_get_api().
52 * The value content is based on cap_mask bit field.
53 * Order of fields in this structure should not be changed to keep abi compatibility.
54 */
55 uint64_t cap_mask;
56
57 /*
58 * Add a libxlio.conf rule to the top of the list.
59 * This rule will not apply to existing sockets which already considered the conf rules.
60 * (around connect/listen/send/recv ..)
61 * @param config_line A char buffer with the exact format as defined in libxlio.conf, and should
62 * end with '\0'.
63 * @return 0 on success, or error code on failure.
64 */
65 int (*add_conf_rule)(const char *config_line);
66
67 /*
68 * Create sockets on pthread tid as offloaded/not-offloaded.
69 * This does not affect existing sockets.
70 * Offloaded sockets are still subject to libxlio.conf rules.
71 * @param offload 1 for offloaded, 0 for not-offloaded.
72 * @return 0 on success, or error code on failure.
73 */
74 int (*thread_offload)(int offload, pthread_t tid);
75
76 /*
77 * Dump fd statistics using the library logger.
78 * @param fd to dump, 0 for all open fds.
79 * @param log_level dumping level corresponding vlog_levels_t enum (vlogger.h).
80 * @return 0 on success, or error code on failure.
81 */
82 int (*dump_fd_stats)(int fd, int log_level);
83
84 /*
85 * XLIO Ultra API.
86 */
87 int (*xlio_init_ex)(const struct xlio_init_attr *attr);
88 int (*xlio_exit)(void);
89 int (*xlio_poll_group_create)(const struct xlio_poll_group_attr *attr,
90 xlio_poll_group_t *group_out);
93 int (*xlio_socket_create)(const struct xlio_socket_attr *attr, xlio_socket_t *sock_out);
95 int (*xlio_socket_update)(xlio_socket_t sock, unsigned flags, uintptr_t userdata_sq);
96 int (*xlio_socket_setsockopt)(xlio_socket_t sock, int level, int optname, const void *optval,
97 socklen_t optlen);
98 int (*xlio_socket_getsockname)(xlio_socket_t sock, struct sockaddr *addr, socklen_t *addrlen);
99 int (*xlio_socket_getpeername)(xlio_socket_t sock, struct sockaddr *addr, socklen_t *addrlen);
100 int (*xlio_socket_bind)(xlio_socket_t sock, const struct sockaddr *addr, socklen_t addrlen);
101 int (*xlio_socket_connect)(xlio_socket_t sock, const struct sockaddr *to, socklen_t tolen);
103 struct ibv_pd *(*xlio_socket_get_pd)(xlio_socket_t sock);
106 int (*xlio_socket_send)(xlio_socket_t sock, const void *data, size_t len,
107 const struct xlio_socket_send_attr *attr);
108 int (*xlio_socket_sendv)(xlio_socket_t sock, const struct iovec *iov, unsigned iovcnt,
109 const struct xlio_socket_send_attr *attr);
111 void (*xlio_socket_flush)(xlio_socket_t sock);
112 void (*xlio_socket_buf_free)(xlio_socket_t sock, struct xlio_buf *buf);
113 void (*xlio_poll_group_buf_free)(xlio_poll_group_t group, struct xlio_buf *buf);
114};
115
116/*
117 * Retrieve XLIO extended API.
118 * This function can be called as an alternative to getsockopt() call
119 * when library is preloaded using LD_PRELOAD
120 * getsockopt() call should be used in case application loads library
121 * using dlopen()/dlsym().
122 *
123 * @return Pointer to the XLIO Extended Socket API, or NULL if XLIO not found.
124 */
125static inline struct xlio_api_t *xlio_get_api()
126{
127 struct xlio_api_t *api_ptr = NULL;
128 socklen_t len = sizeof(api_ptr);
129
130 /* coverity[negative_returns] */
131 int err = getsockopt(-2, SOL_SOCKET, SO_XLIO_GET_API, &api_ptr, &len);
132 if (err < 0) {
133 return NULL;
134 }
135 if (len < sizeof(struct xlio_api_t *) || api_ptr == NULL ||
136 api_ptr->magic != XLIO_MAGIC_NUMBER) {
137 return NULL;
138 }
139 return api_ptr;
140}
141
142#endif /* XLIO_EXTRA_H */
int xlio_exit(void)
Finalize 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.
uintptr_t xlio_poll_group_t
Polling group handle.
Definition xlio_types.h:101
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:109
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:135
XLIO initialization attributes.
Definition xlio_types.h:308
Polling group attributes.
Definition xlio_types.h:351
Socket creation attributes.
Definition xlio_types.h:387
Send operation attributes.
Definition xlio_types.h:426
XLIO API type definitions and structures.