From e4df54bdb1e6f5eb63c25a91cf52fc2568b9f747 Mon Sep 17 00:00:00 2001 From: Muyang Tian Date: Sat, 14 Dec 2024 15:12:19 +0800 Subject: [PATCH] libxdp: Use opts-style API to create umem in libxdp tests Signed-off-by: Muyang Tian --- lib/libxdp/tests/test_xsk_non_privileged.c | 30 ++++++++++++++-------- lib/libxdp/tests/test_xsk_refcnt.c | 11 ++++---- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/libxdp/tests/test_xsk_non_privileged.c b/lib/libxdp/tests/test_xsk_non_privileged.c index 540ee834..f08c4114 100644 --- a/lib/libxdp/tests/test_xsk_non_privileged.c +++ b/lib/libxdp/tests/test_xsk_non_privileged.c @@ -91,11 +91,6 @@ static void run_non_privileged_preconfig(const char *ifname, static struct xsk_umem *create_umem_non_privileged(int sock_fd) { - struct xsk_umem_config config = { - .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, - .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, - .frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE, - }; struct xsk_umem *umem = NULL; struct xsk_ring_cons cq; struct xsk_ring_prod fq; @@ -107,16 +102,29 @@ static struct xsk_umem *create_umem_non_privileged(int sock_fd) } /* This variant requires CAP_NET_RAW, so should fail. */ - if (!xsk_umem__create(&umem, b, UMEM_SIZE, - &fq, &cq, &config) || umem) { - perror("xsk_umem__create succeeded"); + DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts_cap, + .size = UMEM_SIZE, + .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, + .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, + .frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE, + ); + umem = xsk_umem__create_opts(b, &fq, &cq, &opts_cap); + if (umem) { + perror("xsk_umem__create_opts succeeded"); exit(EXIT_FAILURE); } /* This variant shouldn't need any capabilities, so should pass. */ - if (xsk_umem__create_with_fd(&umem, sock_fd, b, UMEM_SIZE, - &fq, &cq, &config) || !umem) { - perror("xsk_umem__create_with_fd failed"); + DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts, + .fd = sock_fd, + .size = UMEM_SIZE, + .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, + .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, + .frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE, + ); + umem = xsk_umem__create_opts(b, &fq, &cq, &opts); + if (!umem) { + perror("xsk_umem__create_opts failed"); exit(EXIT_FAILURE); } diff --git a/lib/libxdp/tests/test_xsk_refcnt.c b/lib/libxdp/tests/test_xsk_refcnt.c index edaf78a0..87546e65 100644 --- a/lib/libxdp/tests/test_xsk_refcnt.c +++ b/lib/libxdp/tests/test_xsk_refcnt.c @@ -107,16 +107,17 @@ static struct xsk_socket_info *xsks[MAX_NUM_QUEUES]; static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size) { struct xsk_umem_info *umem; - int ret; umem = calloc(1, sizeof(*umem)); if (!umem) exit(EXIT_FAILURE); - ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq, - NULL); - if (ret) - exit(ret); + DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts, + .size = size, + ); + umem->umem = xsk_umem__create_opts(buffer, &umem->fq, &umem->cq, &opts); + if (!umem->umem) + exit(errno); umem->buffer = buffer; return umem;