Skip to content

Commit 064aa3d

Browse files
committed
examples/zcrx: add nodev support
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
1 parent 5d8c767 commit 064aa3d

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

examples/zcrx.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,23 @@ static void zcrx_populate_area(struct io_uring_zcrx_area_reg *area_reg)
257257
static void setup_zcrx(struct io_uring *ring)
258258
{
259259
struct io_uring_zcrx_area_reg area_reg;
260-
unsigned int ifindex;
261260
unsigned int rq_entries = cfg_rq_entries;
261+
unsigned int qidx = cfg_queue_id;
262+
unsigned ifq_flags = 0;
262263
unsigned rq_flags = 0;
264+
unsigned int ifindex;
263265
size_t ring_size;
264266
int ret;
265267

266-
ifindex = if_nametoindex(cfg_ifname);
267-
if (!ifindex)
268-
t_error(1, 0, "bad interface name: %s", cfg_ifname);
268+
if (cfg_ifname) {
269+
ifindex = if_nametoindex(cfg_ifname);
270+
if (!ifindex)
271+
t_error(1, 0, "bad interface name: %s", cfg_ifname);
272+
} else {
273+
ifq_flags |= ZCRX_REG_NODEV;
274+
ifindex = 0;
275+
qidx = 0;
276+
}
269277

270278
ring_size = get_refill_ring_size(rq_entries);
271279
ring_ptr = NULL;
@@ -289,7 +297,8 @@ static void setup_zcrx(struct io_uring *ring)
289297

290298
struct io_uring_zcrx_ifq_reg reg = {
291299
.if_idx = ifindex,
292-
.if_rxq = cfg_queue_id,
300+
.if_rxq = qidx,
301+
.flags = ifq_flags,
293302
.rq_entries = rq_entries,
294303
.area_ptr = uring_ptr_to_u64(&area_reg),
295304
.region_ptr = uring_ptr_to_u64(&region_reg),
@@ -663,9 +672,9 @@ static void parse_opts(int argc, char **argv)
663672
}
664673
}
665674

666-
if (!cfg_ifname)
667-
t_error(1, -EINVAL, "Interface is not specified");
668-
if (cfg_queue_id == -1)
675+
if (!cfg_ifname && cfg_queue_id != -1)
676+
t_error(1, -EINVAL, "Queue index passed for device-less zcrx");
677+
if (cfg_ifname && cfg_queue_id == -1)
669678
t_error(1, -EINVAL, "Queue idx is not specified");
670679
}
671680

src/include/liburing/io_uring.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,14 @@ struct io_uring_zcrx_area_reg {
10371037
};
10381038

10391039
enum zcrx_reg_flags {
1040-
ZCRX_REG_IMPORT = 1,
1040+
ZCRX_REG_IMPORT = 1,
1041+
1042+
/*
1043+
* Register a zcrx instance without a net device. All data will be
1044+
* copied. The refill queue entries might not be automatically
1045+
* consmumed and need to be flushed, see ZCRX_CTRL_FLUSH_RQ.
1046+
*/
1047+
ZCRX_REG_NODEV = 2,
10411048
};
10421049

10431050
/*

0 commit comments

Comments
 (0)