support for discard block commands
cover support for discard block commands
Add helpers for the block layer discard commands, as well as some tests and man pages.
Pavel Begunkov (3):
Add io_uring_prep_cmd_discard
test: add discard cmd tests man/io_uring_prep_cmd_discard.3: add discard man pages
configure | 32 +++ man/io_uring_prep_cmd_discard.3 | 60 +++++ src/include/liburing.h | 10 + test/Makefile | 1 + test/cmd-discard.c | 402 ++++++++++++++++++++++++++++++++ 5 files changed, 505 insertions(+) create mode 100644 man/io_uring_prep_cmd_discard.3 create mode 100644 test/cmd-discard.c
Signature · 1 line
2.46.0
PATCH 1/3 Add io_uring_prep_cmd_discard
Add a helper for io_uring block discard commands. Since the discard opcode is in newly added linux/blkdev.h we need to do some configure magic defining it ourselves if the header is missing from the system.
--- configure | 32 ++++++++++++++++++++++++++++++++ src/include/liburing.h | 10 ++++++++++ 2 files changed, 42 insertions(+)
configure +32 -0
@@ -417,6 +417,21 @@ if compile_prog "" "" "futexv"; then fi print_config "futex waitv support" "$futexv" +########################################## +# Check block discard cmd support +discard_cmd="no" +cat > $TMPC << EOF +#include <linux/blkdev.h> +int main(void) +{ + return BLOCK_URING_CMD_DISCARD; +} +EOF +if compile_prog "" "" "discard command"; then + discard_cmd="yes" +fi +print_config "io_uring discard command support" "$discard_cmd" + ########################################## # Check idtype_t support has_idtype_t="no"
@@ -651,6 +666,23 @@ typedef enum } idtype_t; EOF fi + +if test "$discard_cmd" != "yes"; then +cat >> $compat_h << EOF + +#include <linux/ioctl.h> + +#ifndef BLOCK_URING_CMD_DISCARD +#define BLOCK_URING_CMD_DISCARD _IO(0x12, 0) +#endif + +EOF +else cat >> $discard_cmd << EOF +#include <linux/blkdev.h> + +EOF +fi + cat >> $compat_h << EOF #endif EOF
src/include/liburing.h +10 -0
@@ -1292,6 +1292,16 @@ IOURINGINLINE void io_uring_prep_ftruncate(struct io_uring_sqe *sqe, }#endif +IOURINGINLINE void io_uring_prep_cmd_discard(struct io_uring_sqe *sqe, +int fd, +uint64_t offset,uint64_t nbytes) +{ +io_uring_prep_rw (IORING_OP_URING_CMD , sqe, fd,0 ,0 ,0 ); + sqe->cmd_op =BLOCK_URING_CMD_DISCARD ; + sqe->addr = offset; + sqe->addr3 = nbytes; +} +/* * Returns number of unconsumed (if SQPOLL) or unsubmitted entries exist in * the SQ ring
Signature · 1 line
2.46.0
PATCH 2/3 test: add discard cmd tests
In reply to Pavel Begunkov--- test/Makefile | 1 + test/cmd-discard.c | 402 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 403 insertions(+) create mode 100644 test/cmd-discard.c
test/Makefile +1 -0
@@ -65,6 +65,7 @@ test_srcs := \ connect.c \ connect-rep.c \ coredump.c \ + cmd-discard.c \ cq-full.c \ cq-overflow.c \ cq-peek-batch.c \
test/cmd-discard.c new file +402 -0
402 lines not on this page · raw message
Signature · 1 line
2.46.0
PATCH 3/3 man/io_uring_prep_cmd_discard.3: add discard man pages
In reply to Pavel Begunkov--- man/io_uring_prep_cmd_discard.3 | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 man/io_uring_prep_cmd_discard.3
man/io_uring_prep_cmd_discard.3 new file +60 -0
@@ -0,0 +1,60 @@ +.\" Copyright (C) 2024 Pavel Begunkov <[email protected]> +.\" +.\" SPDX-License-Identifier: LGPL-2.0-or-later +.\" +.TH io_uring_prep_cmd_discard 3 "Oct 13, 2024" "liburing-2.8" "liburing Manual" +.SH NAME +io_uring_prep_cmd_discard \- prepare a discard command +.SH SYNOPSIS +.nf +.B #include <liburing.h> +.PP +.BI "void io_uring_prep_cmd_discard(struct io_uring_sqe *" sqe "," +.BI " int " fd "," +.BI " uint64_t " offset "," +.BI " uint64_t " nbytes ");" +.fi +.SH DESCRIPTION +The +.BR io_uring_prep_cmd_discard (3) +function prepares a discard command request. The submission queue entry +.I sqe +is setup to use the file descriptor +.IR fd +to start discarding +.I nbytes +at the specified +.IR offset . + +The command is an asynchronous equivalent of +.B BLOCK_URING_CMD_DISCARD +ioctl with a few differences. It allows multiple parallel discards, and it does +not exclude concurrent writes and reads. As a result, it may lead to races for +the data on the disk, and it's the user's responsibility to account for that. +Furthermore, we only do best effort to invalidate page caches, the user has +to make sure there are no other inflight requests are modifying or reading +the range(s), otherwise it might result in stale page cache and data +inconsistencies. + +Available since 6.12. + +.SH RETURN VALUE +None +.SH ERRORS +The CQE +.I res +field will contain the result of the operation. See the related man page for +details on possible values. Note that where synchronous system calls will return +.B -1 +on failure and set +.I errno +to the actual error value, io_uring never uses +.IR errno . +Instead it returns the negated +.I errno +directly in the CQE +.I res +field. +.SH SEE ALSO +.BR io_uring_get_sqe (3), +.BR io_uring_submit (3),
Signature · 1 line
2.46.0
Quoted 9 lines · Pavel Begunkov
Add helpers for the block layer discard commands, as well as some tests and man pages.
Pavel Begunkov (3):
Addio_uring_prep_cmd_discard
test: add discard cmd tests man/io_uring_prep_cmd_discard.3: add discard man pages[...]
Applied, thanks!
[1/3] Add io_uring_prep_cmd_discard
commit: 906a4567312346a688ccb05ae94459cb00b889a6
[2/3] test: add discard cmd tests
commit: 244be25e45c32981008cf50c9923d0ea1bd4e2e5
[3/3] man/io_uring_prep_cmd_discard.3: add discard man pages
commit: bafd87251db3fa942c310eb8afd137b6c3cd0369Best regards,
Signature · 1 line
Jens Axboe