Skip to content

Commit e4df54b

Browse files
tacslontohojo
authored andcommitted
libxdp: Use opts-style API to create umem in libxdp tests
Signed-off-by: Muyang Tian <[email protected]>
1 parent 794e49d commit e4df54b

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

lib/libxdp/tests/test_xsk_non_privileged.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ static void run_non_privileged_preconfig(const char *ifname,
9191

9292
static struct xsk_umem *create_umem_non_privileged(int sock_fd)
9393
{
94-
struct xsk_umem_config config = {
95-
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
96-
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
97-
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
98-
};
9994
struct xsk_umem *umem = NULL;
10095
struct xsk_ring_cons cq;
10196
struct xsk_ring_prod fq;
@@ -107,16 +102,29 @@ static struct xsk_umem *create_umem_non_privileged(int sock_fd)
107102
}
108103

109104
/* This variant requires CAP_NET_RAW, so should fail. */
110-
if (!xsk_umem__create(&umem, b, UMEM_SIZE,
111-
&fq, &cq, &config) || umem) {
112-
perror("xsk_umem__create succeeded");
105+
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts_cap,
106+
.size = UMEM_SIZE,
107+
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
108+
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
109+
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
110+
);
111+
umem = xsk_umem__create_opts(b, &fq, &cq, &opts_cap);
112+
if (umem) {
113+
perror("xsk_umem__create_opts succeeded");
113114
exit(EXIT_FAILURE);
114115
}
115116

116117
/* This variant shouldn't need any capabilities, so should pass. */
117-
if (xsk_umem__create_with_fd(&umem, sock_fd, b, UMEM_SIZE,
118-
&fq, &cq, &config) || !umem) {
119-
perror("xsk_umem__create_with_fd failed");
118+
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts,
119+
.fd = sock_fd,
120+
.size = UMEM_SIZE,
121+
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
122+
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
123+
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
124+
);
125+
umem = xsk_umem__create_opts(b, &fq, &cq, &opts);
126+
if (!umem) {
127+
perror("xsk_umem__create_opts failed");
120128
exit(EXIT_FAILURE);
121129
}
122130

lib/libxdp/tests/test_xsk_refcnt.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,17 @@ static struct xsk_socket_info *xsks[MAX_NUM_QUEUES];
107107
static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
108108
{
109109
struct xsk_umem_info *umem;
110-
int ret;
111110

112111
umem = calloc(1, sizeof(*umem));
113112
if (!umem)
114113
exit(EXIT_FAILURE);
115114

116-
ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq,
117-
NULL);
118-
if (ret)
119-
exit(ret);
115+
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts,
116+
.size = size,
117+
);
118+
umem->umem = xsk_umem__create_opts(buffer, &umem->fq, &umem->cq, &opts);
119+
if (!umem->umem)
120+
exit(errno);
120121

121122
umem->buffer = buffer;
122123
return umem;

0 commit comments

Comments
 (0)