* Re: [PATCH v2 0/2] ublk: fix infinite loop in ublk server teardown
From: Jens Axboe @ 2026-04-06 14:38 UTC (permalink / raw)
To: Ming Lei, zhang, the-essence-of-life, Caleb Sander Mateos,
Shuah Khan, Uday Shankar
Cc: linux-block, linux-kernel, linux-kselftest
In-Reply-To: <20260405-cancel-v2-0-02d711e643c2@purestorage.com>
On Sun, 05 Apr 2026 22:25:29 -0600, Uday Shankar wrote:
> Fix an infinite loop in ublk server teardown which can arise when a ublk
> server dies while recovering a device. Also add a test which
> demonstrates the problem and verifies the fix.
Applied, thanks!
[1/2] ublk: reset per-IO canceled flag on each fetch
commit: 0842186d2c4e67d2f8c8c2d1d779e8acffd41b5b
[2/2] selftests: ublk: test that teardown after incomplete recovery completes
commit: 320f9b1c6a942a73c26be56742ee1da04f893a4f
Best regards,
--
Jens Axboe
^ permalink raw reply
* Re: [PATCH v2 07/33] rust: allow globally `clippy::incompatible_msrv`
From: Miguel Ojeda @ 2026-04-06 14:37 UTC (permalink / raw)
To: Tamir Duberstein
Cc: Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Danilo Krummrich,
Andreas Hindborg, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Courbot, David Airlie,
Simona Vetter, Brendan Higgins, David Gow, Greg Kroah-Hartman,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Carlos Llamas, Alice Ryhl, Jonathan Corbet, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Trevor Gross, rust-for-linux,
linux-kbuild, Lorenzo Stoakes, Vlastimil Babka, Liam R . Howlett,
Uladzislau Rezki, linux-block, linux-arm-kernel, Alexandre Ghiti,
linux-riscv, nouveau, dri-devel, Rae Moar, linux-kselftest,
kunit-dev, Nick Desaulniers, Bill Wendling, Justin Stitt, llvm,
linux-kernel, Shuah Khan, linux-doc
In-Reply-To: <177548573697.95472.13544191227699996309.b4-review@b4>
On Mon, Apr 6, 2026 at 4:29 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> Could you add a reference to the upstream bug report [0] here?
Of course, thanks for the tags!
Cheers,
Miguel
^ permalink raw reply
* Re: [PATCH v2 32/33] rust: kbuild: support global per-version flags
From: Tamir Duberstein @ 2026-04-06 14:28 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nathan Chancellor, Nicolas Schier, Danilo Krummrich,
Andreas Hindborg, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Courbot, David Airlie,
Simona Vetter, Brendan Higgins, David Gow, Greg Kroah-Hartman,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Carlos Llamas, Alice Ryhl, Jonathan Corbet, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Trevor Gross, rust-for-linux,
linux-kbuild, Lorenzo Stoakes, Vlastimil Babka, Liam R . Howlett,
Uladzislau Rezki, linux-block, linux-arm-kernel, Alexandre Ghiti,
linux-riscv, nouveau, dri-devel, Rae Moar, linux-kselftest,
kunit-dev, Nick Desaulniers, Bill Wendling, Justin Stitt, llvm,
linux-kernel, Shuah Khan, linux-doc
In-Reply-To: <20260405235309.418950-33-ojeda@kernel.org>
On Mon, 06 Apr 2026 01:53:08 +0200, Miguel Ojeda <ojeda@kernel.org> wrote:
> Sometimes it is useful to gate global Rust flags per compiler version.
> For instance, we may want to disable a lint that has false positives in
> a single version [1].
>
> We already had helpers like `rustc-min-version` for that, which we use
> elsewhere, but we cannot currently use them for `rust_common_flags`,
> which contains the global flags for all Rust code (kernel and host),
> because `rustc-min-version` depends on `CONFIG_RUSTC_VERSION`, which
> does not exist when `rust_common_flags` is defined.
>
> [...]
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
--
Tamir Duberstein <tamird@kernel.org>
^ permalink raw reply
* Re: [PATCH v2 15/33] rust: macros: simplify code using `feature(extract_if)`
From: Tamir Duberstein @ 2026-04-06 14:28 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nathan Chancellor, Nicolas Schier, Danilo Krummrich,
Andreas Hindborg, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Courbot, David Airlie,
Simona Vetter, Brendan Higgins, David Gow, Greg Kroah-Hartman,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Carlos Llamas, Alice Ryhl, Jonathan Corbet, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Trevor Gross, rust-for-linux,
linux-kbuild, Lorenzo Stoakes, Vlastimil Babka, Liam R . Howlett,
Uladzislau Rezki, linux-block, linux-arm-kernel, Alexandre Ghiti,
linux-riscv, nouveau, dri-devel, Rae Moar, linux-kselftest,
kunit-dev, Nick Desaulniers, Bill Wendling, Justin Stitt, llvm,
linux-kernel, Shuah Khan, linux-doc
In-Reply-To: <20260405235309.418950-16-ojeda@kernel.org>
On Mon, 06 Apr 2026 01:52:51 +0200, Miguel Ojeda <ojeda@kernel.org> wrote:
> `feature(extract_if)` [1] was stabilized in Rust 1.87.0 [2], and the last
> significant change happened in Rust 1.85.0 [3] when the range parameter
> was added.
>
> That is, with our new minimum version, we can start using the feature.
>
> Thus simplify the code using the feature and remove the TODO comment.
>
> [...]
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
--
Tamir Duberstein <tamird@kernel.org>
^ permalink raw reply
* Re: [PATCH v2 07/33] rust: allow globally `clippy::incompatible_msrv`
From: Tamir Duberstein @ 2026-04-06 14:28 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nathan Chancellor, Nicolas Schier, Danilo Krummrich,
Andreas Hindborg, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Courbot, David Airlie,
Simona Vetter, Brendan Higgins, David Gow, Greg Kroah-Hartman,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Carlos Llamas, Alice Ryhl, Jonathan Corbet, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Trevor Gross, rust-for-linux,
linux-kbuild, Lorenzo Stoakes, Vlastimil Babka, Liam R . Howlett,
Uladzislau Rezki, linux-block, linux-arm-kernel, Alexandre Ghiti,
linux-riscv, nouveau, dri-devel, Rae Moar, linux-kselftest,
kunit-dev, Nick Desaulniers, Bill Wendling, Justin Stitt, llvm,
linux-kernel, Shuah Khan, linux-doc
In-Reply-To: <20260405235309.418950-8-ojeda@kernel.org>
On Mon, 06 Apr 2026 01:52:43 +0200, Miguel Ojeda <ojeda@kernel.org> wrote:
> diff --git a/Makefile b/Makefile
> index a63684c36d60..78f5ee173eda 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -486,6 +486,7 @@ export rust_common_flags := --edition=2021 \
> -Wclippy::as_underscore \
> -Wclippy::cast_lossless \
> -Wclippy::ignored_unit_patterns \
> + -Aclippy::incompatible_msrv \
Could you add a reference to the upstream bug report [0] here?
Link: https://github.com/rust-lang/rust-clippy/issues/14425 [0]
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
--
Tamir Duberstein <tamird@kernel.org>
^ permalink raw reply
* Re: [PATCH v2 01/33] rust: kbuild: remove `--remap-path-prefix` workarounds
From: Tamir Duberstein @ 2026-04-06 14:28 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nathan Chancellor, Nicolas Schier, Danilo Krummrich,
Andreas Hindborg, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Courbot, David Airlie,
Simona Vetter, Brendan Higgins, David Gow, Greg Kroah-Hartman,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Carlos Llamas, Alice Ryhl, Jonathan Corbet, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Trevor Gross, rust-for-linux,
linux-kbuild, Lorenzo Stoakes, Vlastimil Babka, Liam R . Howlett,
Uladzislau Rezki, linux-block, linux-arm-kernel, Alexandre Ghiti,
linux-riscv, nouveau, dri-devel, Rae Moar, linux-kselftest,
kunit-dev, Nick Desaulniers, Bill Wendling, Justin Stitt, llvm,
linux-kernel, Shuah Khan, linux-doc
In-Reply-To: <20260405235309.418950-2-ojeda@kernel.org>
On Mon, 06 Apr 2026 01:52:37 +0200, Miguel Ojeda <ojeda@kernel.org> wrote:
> Commit 8cf5b3f83614 ("Revert "kbuild, rust: use -fremap-path-prefix
> to make paths relative"") removed `--remap-path-prefix` from the build
> system, so the workarounds are not needed anymore.
>
> Thus remove them.
>
> Note that the flag has landed again in parallel in this cycle in
> commit dda135077ecc ("rust: build: remap path to avoid absolute path"),
> together with `--remap-path-scope=macro` [1]. However, they are gated on
> `rustc-option-yn, --remap-path-scope=macro`, which means they are both
> only passed starting with Rust 1.95.0 [2]:
>
> [...]
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
--
Tamir Duberstein <tamird@kernel.org>
^ permalink raw reply
* Re: [PATCH v2 2/2] selftests: ublk: test that teardown after incomplete recovery completes
From: Ming Lei @ 2026-04-06 14:19 UTC (permalink / raw)
To: Uday Shankar
Cc: zhang, the-essence-of-life, Caleb Sander Mateos, Jens Axboe,
Shuah Khan, linux-block, linux-kernel, linux-kselftest
In-Reply-To: <20260405-cancel-v2-2-02d711e643c2@purestorage.com>
On Sun, Apr 05, 2026 at 10:25:31PM -0600, Uday Shankar wrote:
> Before the fix, teardown of a ublk server that was attempting to recover
> a device, but died when it had submitted a nonempty proper subset of the
> fetch commands to any queue would loop forever. Add a test to verify
> that, after the fix, teardown completes. This is done by:
>
> - Adding a new argument to the fault_inject target that causes it die
> after fetching a nonempty proper subset of the IOs to a queue
> - Using that argument in a new test while trying to recover an
> already-created device
> - Attempting to delete the ublk device at the end of the test; this
> hangs forever if teardown from the fault-injected ublk server never
> completed.
>
> It was manually verified that the test passes with the fix and hangs
> without it.
>
> Signed-off-by: Uday Shankar <ushankar@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
^ permalink raw reply
* Re: [PATCH blktests] src/dio-offsets.c: Fix err() usage
From: Bart Van Assche @ 2026-04-06 13:51 UTC (permalink / raw)
To: Shinichiro Kawasaki
Cc: Damien Le Moal, linux-block@vger.kernel.org, Keith Busch
In-Reply-To: <adDM7QhRRlnntRB5@shinmob>
On 4/4/26 1:35 AM, Shinichiro Kawasaki wrote:
> One thing I found is that one more err(EIO,...) is left in __compare() after
> applying the patch. Should we convert it also into err_errno()? If so, I will
> fold-in the hunk below.
>
> diff --git a/src/dio-offsets.c b/src/dio-offsets.c
> index 9fc7b92..c40ce68 100644
> --- a/src/dio-offsets.c
> +++ b/src/dio-offsets.c
> @@ -131,7 +131,7 @@ static void __compare(void *a, void *b, size_t size, const char *test)
> {
> if (!memcmp(a, b, size))
> return;
> - err(EIO, "%s: data corruption", test);
> + err_errno(EIO, "%s: data corruption", test);
> }
> #define compare(a, b, size) __compare(a, b, size, __func__)
Folding in this change sounds good to me.
Thanks,
Bart.
^ permalink raw reply
* Re: [PATCH 33/33] rust: kbuild: allow `clippy::precedence` for Rust < 1.86.0
From: Miguel Ojeda @ 2026-04-06 13:21 UTC (permalink / raw)
To: Tamir Duberstein
Cc: Miguel Ojeda, Nathan Chancellor, Nicolas Schier, Danilo Krummrich,
Andreas Hindborg, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Courbot, David Airlie,
Simona Vetter, Brendan Higgins, David Gow, Greg Kroah-Hartman,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Carlos Llamas, Alice Ryhl, Jonathan Corbet, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Trevor Gross, rust-for-linux,
linux-kbuild, Lorenzo Stoakes, Vlastimil Babka, Liam R . Howlett,
Uladzislau Rezki, linux-block, linux-arm-kernel, Alexandre Ghiti,
linux-riscv, nouveau, dri-devel, Rae Moar, linux-kselftest,
kunit-dev, Nick Desaulniers, Bill Wendling, Justin Stitt, llvm,
linux-kernel, Shuah Khan, linux-doc
In-Reply-To: <177508434476.73816.11744805605122440072.b4-review@b4>
On Thu, Apr 2, 2026 at 1:02 AM Tamir Duberstein <tamird@kernel.org> wrote:
>
> Might be good to retain some of this in a code comment.
Bah, I missed this note among the rest, sorry (I didn't reply to the
ones where the commit went away due to the changes in v2) -- I agree
it wouldn't hurt to remember why it is there, even if it is already in
the Git log.
I will probably add it for tomorrow, especially if I have to rebase.
Thanks!
Cheers,
Miguel
^ permalink raw reply
* Re: [PATCH v2 1/2] ublk: reset per-IO canceled flag on each fetch
From: Ming Lei @ 2026-04-06 11:18 UTC (permalink / raw)
To: Hannes Reinecke
Cc: Uday Shankar, zhang, the-essence-of-life, Caleb Sander Mateos,
Jens Axboe, Shuah Khan, linux-block, linux-kernel,
linux-kselftest
In-Reply-To: <53aec093-5494-4b4b-a103-bc166381f236@suse.de>
On Mon, Apr 06, 2026 at 09:22:13AM +0200, Hannes Reinecke wrote:
> On 4/6/26 06:25, Uday Shankar wrote:
> > If a ublk server starts recovering devices but dies before issuing fetch
> > commands for all IOs, cancellation of the fetch commands that were
> > successfully issued may never complete. This is because the per-IO
> > canceled flag can remain set even after the fetch for that IO has been
> > submitted - the per-IO canceled flags for all IOs in a queue are reset
> > together only once all IOs for that queue have been fetched. So if a
> > nonempty proper subset of the IOs for a queue are fetched when the ublk
> > server dies, the IOs in that subset will never successfully be canceled,
> > as their canceled flags remain set, and this prevents ublk_cancel_cmd
> > from actually calling io_uring_cmd_done on the commands, despite the
> > fact that they are outstanding.
> >
> > Fix this by resetting the per-IO cancel flags immediately when each IO
> > is fetched instead of waiting for all IOs for the queue (which may never
> > happen).
> >
> > Signed-off-by: Uday Shankar <ushankar@purestorage.com>
> > Fixes: 728cbac5fe21 ("ublk: move device reset into ublk_ch_release()")
> > Reviewed-by: Ming Lei <ming.lei@redhat.com>
> > Reviewed-by: zhang, the-essence-of-life <zhangweize9@gmail.com>
> > ---
> > drivers/block/ublk_drv.c | 21 +++++++++++++--------
> > 1 file changed, 13 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 3ba7da94d31499590a06a8b307ed151919a027cb..92dabeb820344107c9fadfae94396082b933d84e 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -2916,22 +2916,26 @@ static void ublk_stop_dev(struct ublk_device *ub)
> > ublk_cancel_dev(ub);
> > }
> > +static void ublk_reset_io_flags(struct ublk_queue *ubq, struct ublk_io *io)
> > +{
> > + /* UBLK_IO_FLAG_CANCELED can be cleared now */
> > + spin_lock(&ubq->cancel_lock);
> > + io->flags &= ~UBLK_IO_FLAG_CANCELED;
> > + spin_unlock(&ubq->cancel_lock);
> > +}
> > +
> One wonders why we can't use 'set_bit' here, or, rather,
> convert 'flags' usage to set_bit().
It isn't necessary, because UBLK_F_PER_IO_DAEMON is enabled.
> The spinlock feels a bit silly as it's now per-io, and one would think
> that we don't have concurrent accesses to the same io...
UBLK_IO_FLAG_CANCELED is only used in slow path, yes, it is supposed to be
accessed concurrently.
It could be moved out of io->flags, but we do want to make `struct ublk_io`
held in single cache line.
>
> > /* reset per-queue io flags */
> > static void ublk_queue_reset_io_flags(struct ublk_queue *ubq)
> > {
> > - int j;
> > -
> > - /* UBLK_IO_FLAG_CANCELED can be cleared now */
> > spin_lock(&ubq->cancel_lock);
> > - for (j = 0; j < ubq->q_depth; j++)
> > - ubq->ios[j].flags &= ~UBLK_IO_FLAG_CANCELED;
> > ubq->canceling = false;
> > spin_unlock(&ubq->cancel_lock);
> > ubq->fail_io = false;
> > }
> Similar here; as we don't loop anymore, why do we need the spinlock?
> Isn't WRITE_ONCE() sufficient here?
WRITE_ONCE() isn't enough, because we have to make sure that io->cmd is
only completed once, please see ublk_cancel_cmd().
Anyway, all these comments should belong to improvement or new issue,
not a blocker for current bug fix.
Thanks,
Ming
^ permalink raw reply
* Re: [PATCH v2 00/33] rust: bump minimum Rust and `bindgen` versions
From: Miguel Ojeda @ 2026-04-06 9:03 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nathan Chancellor, Nicolas Schier, Danilo Krummrich,
Andreas Hindborg, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Courbot, David Airlie,
Simona Vetter, Brendan Higgins, David Gow, Greg Kroah-Hartman,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Carlos Llamas, Alice Ryhl, Jonathan Corbet, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Trevor Gross, rust-for-linux,
linux-kbuild, Lorenzo Stoakes, Vlastimil Babka, Liam R . Howlett,
Uladzislau Rezki, linux-block, moderated for non-subscribers,
Alexandre Ghiti, linux-riscv, nouveau, dri-devel, Rae Moar,
linux-kselftest, kunit-dev, Nick Desaulniers, Bill Wendling,
Justin Stitt, llvm, linux-kernel, Shuah Khan, linux-doc
In-Reply-To: <20260405235309.418950-1-ojeda@kernel.org>
On Mon, Apr 6, 2026 at 1:53 AM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> As proposed in the past in e.g. LPC 2025 and the Maintainers Summit [1],
> we are going to follow Debian Stable's Rust versions as our minimum
> supported version.
>
> Debian Trixie was released with a Rust 1.85.0 toolchain [2], which it
> still uses to this day [3] (i.e. no update to Rust 1.85.1).
>
> Debian Trixie was released with `bindgen` 0.71.1, which it also still
> uses to this day [4].
>
> Debian Trixie's release happened on 2025-08-09 [5], which means that a
> fair amount of time has passed since its release for kernel developers
> to upgrade.
>
> Thus bump the minimum to the new versions, i.e.
>
> - Rust: 1.78.0 -> 1.85.0
> - bindgen: 0.65.1 -> 0.71.1
>
> There are a few main parts to the series, in this order:
>
> - A few cleanups that can be performed before the bumps.
> - The Rust bump (and its cleanups).
> - The `bindgen` bump (and its cleanups).
> - Documentation updates.
> - The `cfi_encoding` patch, added here, which needs the bump.
> - The per-version flags support and a Clippy cleanup on top.
>
> Link: https://lwn.net/Articles/1050174/ [1]
> Link: https://www.debian.org/releases/trixie/release-notes/whats-new.en.html#desktops-and-well-known-packages [2]
> Link: https://packages.debian.org/trixie/rustc [3]
> Link: https://packages.debian.org/trixie/bindgen [4]
> Link: https://www.debian.org/releases/trixie/ [5]
Applied series to `rust-next` -- thanks everyone!
Let's see if we find any issue in -next.
(If someone wants to give tags today, then I am happy to pick them up)
Cheers,
Miguel
^ permalink raw reply
* Re: [PATCH v2 1/2] ublk: reset per-IO canceled flag on each fetch
From: Hannes Reinecke @ 2026-04-06 7:22 UTC (permalink / raw)
To: Uday Shankar, Ming Lei, zhang, the-essence-of-life,
Caleb Sander Mateos, Jens Axboe, Shuah Khan
Cc: linux-block, linux-kernel, linux-kselftest
In-Reply-To: <20260405-cancel-v2-1-02d711e643c2@purestorage.com>
On 4/6/26 06:25, Uday Shankar wrote:
> If a ublk server starts recovering devices but dies before issuing fetch
> commands for all IOs, cancellation of the fetch commands that were
> successfully issued may never complete. This is because the per-IO
> canceled flag can remain set even after the fetch for that IO has been
> submitted - the per-IO canceled flags for all IOs in a queue are reset
> together only once all IOs for that queue have been fetched. So if a
> nonempty proper subset of the IOs for a queue are fetched when the ublk
> server dies, the IOs in that subset will never successfully be canceled,
> as their canceled flags remain set, and this prevents ublk_cancel_cmd
> from actually calling io_uring_cmd_done on the commands, despite the
> fact that they are outstanding.
>
> Fix this by resetting the per-IO cancel flags immediately when each IO
> is fetched instead of waiting for all IOs for the queue (which may never
> happen).
>
> Signed-off-by: Uday Shankar <ushankar@purestorage.com>
> Fixes: 728cbac5fe21 ("ublk: move device reset into ublk_ch_release()")
> Reviewed-by: Ming Lei <ming.lei@redhat.com>
> Reviewed-by: zhang, the-essence-of-life <zhangweize9@gmail.com>
> ---
> drivers/block/ublk_drv.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3ba7da94d31499590a06a8b307ed151919a027cb..92dabeb820344107c9fadfae94396082b933d84e 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -2916,22 +2916,26 @@ static void ublk_stop_dev(struct ublk_device *ub)
> ublk_cancel_dev(ub);
> }
>
> +static void ublk_reset_io_flags(struct ublk_queue *ubq, struct ublk_io *io)
> +{
> + /* UBLK_IO_FLAG_CANCELED can be cleared now */
> + spin_lock(&ubq->cancel_lock);
> + io->flags &= ~UBLK_IO_FLAG_CANCELED;
> + spin_unlock(&ubq->cancel_lock);
> +}
> +
One wonders why we can't use 'set_bit' here, or, rather,
convert 'flags' usage to set_bit().
The spinlock feels a bit silly as it's now per-io, and one would think
that we don't have concurrent accesses to the same io...
> /* reset per-queue io flags */
> static void ublk_queue_reset_io_flags(struct ublk_queue *ubq)
> {
> - int j;
> -
> - /* UBLK_IO_FLAG_CANCELED can be cleared now */
> spin_lock(&ubq->cancel_lock);
> - for (j = 0; j < ubq->q_depth; j++)
> - ubq->ios[j].flags &= ~UBLK_IO_FLAG_CANCELED;
> ubq->canceling = false;
> spin_unlock(&ubq->cancel_lock);
> ubq->fail_io = false;
> }
Similar here; as we don't loop anymore, why do we need the spinlock?
Isn't WRITE_ONCE() sufficient here?
>
> /* device can only be started after all IOs are ready */
> -static void ublk_mark_io_ready(struct ublk_device *ub, u16 q_id)
> +static void ublk_mark_io_ready(struct ublk_device *ub, u16 q_id,
> + struct ublk_io *io)
> __must_hold(&ub->mutex)
> {
> struct ublk_queue *ubq = ublk_get_queue(ub, q_id);
> @@ -2940,6 +2944,7 @@ static void ublk_mark_io_ready(struct ublk_device *ub, u16 q_id)
> ub->unprivileged_daemons = true;
>
> ubq->nr_io_ready++;
> + ublk_reset_io_flags(ubq, io);
>
> /* Check if this specific queue is now fully ready */
> if (ublk_queue_ready(ubq)) {
> @@ -3202,7 +3207,7 @@ static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
> if (!ret)
> ret = ublk_config_io_buf(ub, io, cmd, buf_addr, NULL);
> if (!ret)
> - ublk_mark_io_ready(ub, q_id);
> + ublk_mark_io_ready(ub, q_id, io);
> mutex_unlock(&ub->mutex);
> return ret;
> }
> @@ -3610,7 +3615,7 @@ static int ublk_batch_prep_io(struct ublk_queue *ubq,
> ublk_io_unlock(io);
>
> if (!ret)
> - ublk_mark_io_ready(data->ub, ubq->q_id);
> + ublk_mark_io_ready(data->ub, ubq->q_id, io);
>
> return ret;
> }
>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply
* Re: [PATCH 4/4] xfs: use bio_await in xfs_zone_gc_reset_sync
From: Damien Le Moal @ 2026-04-06 7:09 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Carlos Maiolino, Bart Van Assche, linux-block, linux-xfs
In-Reply-To: <20260406055728.472919-5-hch@lst.de>
On 2026/04/06 7:57, Christoph Hellwig wrote:
> Replace the open-coded bio wait logic with the new bio_await helper.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply
* Re: [PATCH 3/4] block: add a bio_submit_or_kill helper
From: Damien Le Moal @ 2026-04-06 7:08 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Carlos Maiolino, Bart Van Assche, linux-block, linux-xfs
In-Reply-To: <20260406055728.472919-4-hch@lst.de>
On 2026/04/06 7:57, Christoph Hellwig wrote:
> Factor the common logic for the ioctl helpers to either submit a bio or
> end if the process is being killed. As this is now the only user of
> bio_await_chain, open code that.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks good to me. Just one comment below.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> ---
> block/bio.c | 23 ++++++++++++++---------
> block/blk-lib.c | 16 ++--------------
> block/blk.h | 2 +-
> block/ioctl.c | 11 ++---------
> 4 files changed, 19 insertions(+), 33 deletions(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index c7e75d532666..994db354439f 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -1520,6 +1520,20 @@ static void bio_endio_cb(struct bio *bio, void *priv)
> bio_endio(bio);
> }
>
> +/*
> + * Submit @bio synchronously, or call bio_endio on it if the current process
> + * is being killed.
> + */
> +int bio_submit_or_kill(struct bio *bio, unsigned int flags)
> +{
> + if ((flags & BLKDEV_ZERO_KILLABLE) && fatal_signal_pending(current)) {
> + bio_await(bio, NULL, bio_endio_cb);
> + return -EINTR;
This was like this in the previous code, so not big deal, but should we perhaps
return the bio error if there was one ? And return -EINTR if there was no error.
--
Damien Le Moal
Western Digital Research
^ permalink raw reply
* Re: [PATCH 2/4] block: factor out a bio_await helper
From: Damien Le Moal @ 2026-04-06 7:05 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Carlos Maiolino, Bart Van Assche, linux-block, linux-xfs
In-Reply-To: <20260406055728.472919-3-hch@lst.de>
On 2026/04/06 7:57, Christoph Hellwig wrote:
> Add a new helper to wait for a bio and anything chained off it to
> complete synchronous after kicking it. This factors common code out
s/synchronous after kicking it/synchronously after submitting it
(kicking is a little confusing as it could mean "rejecting")
> of submit_bio_wait and bio_await_chain and will also be useful for
> file system code and thus is exported.
>
> Note that this will now set REQ_SYNC also for the bio_await case for
> consistency. Nothing should look at the flag in the end_io handler,
> but if did, having the flag set makes more sense.
s/if did/if something does ?
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> block/bio.c | 53 +++++++++++++++++++++++++++++++--------------
> include/linux/bio.h | 2 ++
> 2 files changed, 39 insertions(+), 16 deletions(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index 434e41182c05..c7e75d532666 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -1468,17 +1468,20 @@ static void bio_wait_end_io(struct bio *bio)
> }
>
> /**
> - * submit_bio_wait - submit a bio, and wait until it completes
> - * @bio: The &struct bio which describes the I/O
> + * bio_await - call a function on a bio, and wait until it completes
> + * @bio: the bio which describes the I/O
> + * @kick: function called to "kick off" the bio
To be consistent with my comment above, I think a better (clearer) name her
would be simply "submit".
Other than these nits, looks all good to me. So feel free to add:
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply
* Re: [PATCH 1/4] block: unify the synchronous bi_end_io callbacks
From: Damien Le Moal @ 2026-04-06 6:59 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Carlos Maiolino, Bart Van Assche, linux-block, linux-xfs
In-Reply-To: <20260406055728.472919-2-hch@lst.de>
On 2026/04/06 7:57, Christoph Hellwig wrote:
> Put the bio in bio_await_chain after waiting for the completion, and
> share the now identical callbacks between submit_bio_wait and
> bio_await_chain.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Looks good to me.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply
* Re: [PATCH 5/6] t10-pi: use bio_integrity_intervals() helper
From: Christoph Hellwig @ 2026-04-06 6:36 UTC (permalink / raw)
To: Caleb Sander Mateos
Cc: Jens Axboe, Sagi Grimberg, Chaitanya Kulkarni, Martin K. Petersen,
linux-block, linux-kernel, linux-nvme, linux-scsi, target-devel
In-Reply-To: <20260403194109.2255933-6-csander@purestorage.com>
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply
* Re: [PATCH 4/6] bio-integrity-fs: use integrity interval instead of sector as seed
From: Christoph Hellwig @ 2026-04-06 6:36 UTC (permalink / raw)
To: Caleb Sander Mateos
Cc: Jens Axboe, Sagi Grimberg, Chaitanya Kulkarni, Martin K. Petersen,
linux-block, linux-kernel, linux-nvme, linux-scsi, target-devel
In-Reply-To: <20260403194109.2255933-5-csander@purestorage.com>
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply
* Re: [PATCH 3/6] bio-integrity-fs: pass data iter to bio_integrity_verify()
From: Christoph Hellwig @ 2026-04-06 6:35 UTC (permalink / raw)
To: Caleb Sander Mateos
Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni,
Martin K. Petersen, linux-block, linux-kernel, linux-nvme,
linux-scsi, target-devel
In-Reply-To: <20260403194109.2255933-4-csander@purestorage.com>
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply
* Re: [PATCH 2/6] block: use integrity interval instead of sector as seed
From: Christoph Hellwig @ 2026-04-06 6:34 UTC (permalink / raw)
To: Caleb Sander Mateos
Cc: Jens Axboe, Sagi Grimberg, Chaitanya Kulkarni, Martin K. Petersen,
linux-block, linux-kernel, linux-nvme, linux-scsi, target-devel
In-Reply-To: <20260403194109.2255933-3-csander@purestorage.com>
On Fri, Apr 03, 2026 at 01:41:05PM -0600, Caleb Sander Mateos wrote:
> void bio_integrity_setup_default(struct bio *bio)
> {
> struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
> struct bio_integrity_payload *bip = bio_integrity(bio);
>
> - bip_set_seed(bip, bio->bi_iter.bi_sector);
> + bip_set_seed(bip, bio_integrity_intervals(bi, bio->bi_iter.bi_sector));
Should we simply switch bip_set_seed to take a bio bvec_iter argument and
lift all this logic into it? That feels a lot less fragile.
Bonus points for writing useful documentation for the new bip_set_seed.
^ permalink raw reply
* Re: [PATCH 1/6] blk-integrity: take sector_t in bio_integrity_intervals()
From: Christoph Hellwig @ 2026-04-06 6:31 UTC (permalink / raw)
To: Caleb Sander Mateos
Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni,
Martin K. Petersen, linux-block, linux-kernel, linux-nvme,
linux-scsi, target-devel
In-Reply-To: <20260403194109.2255933-2-csander@purestorage.com>
> /**
> - * bio_integrity_intervals - Return number of integrity intervals for a bio
> + * bio_integrity_intervals - Convert sectors to integrity intervals
> * @bi: blk_integrity profile for device
> - * @sectors: Size of the bio in 512-byte sectors
> + * @sectors: Number of 512-byte sectors
> *
> * Description: The block layer calculates everything in 512 byte
> * sectors but integrity metadata is done in terms of the data integrity
> * interval size of the storage device. Convert the block layer sectors
> * to the appropriate number of integrity intervals.
> */
> -static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi,
> - unsigned int sectors)
> +static inline u64 bio_integrity_intervals(struct blk_integrity *bi,
> + sector_t sectors)
sector_t is a sector number, not a number of sectors. So if you need a
64-bit value here, it should just be a u64.
> {
> return sectors >> (bi->interval_exp - 9);
If you touch this, maybe also replace 9 with SECTOR_SHIFT?
^ permalink raw reply
* Re: [PATCH] t10-pi: reduce ref tag code duplication
From: Christoph Hellwig @ 2026-04-06 6:24 UTC (permalink / raw)
To: Caleb Sander Mateos; +Cc: Jens Axboe, linux-block, linux-kernel
In-Reply-To: <20260403185101.2172135-1-csander@purestorage.com>
On Fri, Apr 03, 2026 at 12:51:00PM -0600, Caleb Sander Mateos wrote:
> t10_pi_ref_tag() and ext_pi_ref_tag() are identical except for the final
> truncation of the ref tag to 32 or 48 bits. Factor out a helper
> full_pi_ref_tag() to return the untruncated ref tag and use it in
> t10_pi_ref_tag() and ext_pi_ref_tag().
>
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
> include/linux/t10-pi.h | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/t10-pi.h b/include/linux/t10-pi.h
> index 2c59fe3efcd4..c6fe5db47c7a 100644
> --- a/include/linux/t10-pi.h
> +++ b/include/linux/t10-pi.h
> @@ -35,18 +35,23 @@ struct t10_pi_tuple {
> };
>
> #define T10_PI_APP_ESCAPE cpu_to_be16(0xffff)
> #define T10_PI_REF_ESCAPE cpu_to_be32(0xffffffff)
>
> -static inline u32 t10_pi_ref_tag(struct request *rq)
> +static inline u64 full_pi_ref_tag(struct request *rq)
> {
> unsigned int shift = ilog2(queue_logical_block_size(rq->q));
>
> if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
> rq->q->limits.integrity.interval_exp)
> shift = rq->q->limits.integrity.interval_exp;
> - return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT) & 0xffffffff;
> + return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT);
> +}
This should probably move abouve the struct t10_pi_tuple definition
so that we keep clear blocks for classic vs extended PI.
> +
> +static inline u32 t10_pi_ref_tag(struct request *rq)
> +{
> + return full_pi_ref_tag(rq) & 0xffffffff;
Use lower_32_bits here to make it more clear and mirror the ext version?
Otherwise looks good.
^ permalink raw reply
* [PATCH 4/4] xfs: use bio_await in xfs_zone_gc_reset_sync
From: Christoph Hellwig @ 2026-04-06 5:57 UTC (permalink / raw)
To: Jens Axboe; +Cc: Carlos Maiolino, Bart Van Assche, linux-block, linux-xfs
In-Reply-To: <20260406055728.472919-1-hch@lst.de>
Replace the open-coded bio wait logic with the new bio_await helper.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/xfs/xfs_zone_gc.c | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
index eebe6f4fee1f..b2626a482563 100644
--- a/fs/xfs/xfs_zone_gc.c
+++ b/fs/xfs/xfs_zone_gc.c
@@ -900,9 +900,10 @@ xfs_zone_gc_finish_reset(
static void
xfs_submit_zone_reset_bio(
- struct xfs_rtgroup *rtg,
- struct bio *bio)
+ struct bio *bio,
+ void *priv)
{
+ struct xfs_rtgroup *rtg = priv;
struct xfs_mount *mp = rtg_mount(rtg);
trace_xfs_zone_reset(rtg);
@@ -934,26 +935,16 @@ xfs_submit_zone_reset_bio(
submit_bio(bio);
}
-static void xfs_bio_wait_endio(struct bio *bio)
-{
- complete(bio->bi_private);
-}
-
int
xfs_zone_gc_reset_sync(
struct xfs_rtgroup *rtg)
{
- DECLARE_COMPLETION_ONSTACK(done);
struct bio bio;
int error;
bio_init(&bio, rtg_mount(rtg)->m_rtdev_targp->bt_bdev, NULL, 0,
REQ_OP_ZONE_RESET | REQ_SYNC);
- bio.bi_private = &done;
- bio.bi_end_io = xfs_bio_wait_endio;
- xfs_submit_zone_reset_bio(rtg, &bio);
- wait_for_completion_io(&done);
-
+ bio_await(&bio, rtg, xfs_submit_zone_reset_bio);
error = blk_status_to_errno(bio.bi_status);
bio_uninit(&bio);
return error;
@@ -990,7 +981,7 @@ xfs_zone_gc_reset_zones(
chunk->data = data;
WRITE_ONCE(chunk->state, XFS_GC_BIO_NEW);
list_add_tail(&chunk->entry, &data->resetting);
- xfs_submit_zone_reset_bio(rtg, bio);
+ xfs_submit_zone_reset_bio(bio, rtg);
} while (next);
}
--
2.47.3
^ permalink raw reply related
* [PATCH 3/4] block: add a bio_submit_or_kill helper
From: Christoph Hellwig @ 2026-04-06 5:57 UTC (permalink / raw)
To: Jens Axboe; +Cc: Carlos Maiolino, Bart Van Assche, linux-block, linux-xfs
In-Reply-To: <20260406055728.472919-1-hch@lst.de>
Factor the common logic for the ioctl helpers to either submit a bio or
end if the process is being killed. As this is now the only user of
bio_await_chain, open code that.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/bio.c | 23 ++++++++++++++---------
block/blk-lib.c | 16 ++--------------
block/blk.h | 2 +-
block/ioctl.c | 11 ++---------
4 files changed, 19 insertions(+), 33 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index c7e75d532666..994db354439f 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1520,6 +1520,20 @@ static void bio_endio_cb(struct bio *bio, void *priv)
bio_endio(bio);
}
+/*
+ * Submit @bio synchronously, or call bio_endio on it if the current process
+ * is being killed.
+ */
+int bio_submit_or_kill(struct bio *bio, unsigned int flags)
+{
+ if ((flags & BLKDEV_ZERO_KILLABLE) && fatal_signal_pending(current)) {
+ bio_await(bio, NULL, bio_endio_cb);
+ return -EINTR;
+ }
+
+ return submit_bio_wait(bio);
+}
+
/**
* bdev_rw_virt - synchronously read into / write from kernel mapping
* @bdev: block device to access
@@ -1550,15 +1564,6 @@ int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
}
EXPORT_SYMBOL_GPL(bdev_rw_virt);
-/*
- * bio_await_chain - ends @bio and waits for every chained bio to complete
- */
-void bio_await_chain(struct bio *bio)
-{
- bio_await(bio, NULL, bio_endio_cb);
- bio_put(bio);
-}
-
void __bio_advance(struct bio *bio, unsigned bytes)
{
if (bio_integrity(bio))
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 3213afc7f0d5..688bc67cbf73 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -155,13 +155,7 @@ static int blkdev_issue_write_zeroes(struct block_device *bdev, sector_t sector,
__blkdev_issue_write_zeroes(bdev, sector, nr_sects, gfp, &bio,
flags, limit);
if (bio) {
- if ((flags & BLKDEV_ZERO_KILLABLE) &&
- fatal_signal_pending(current)) {
- bio_await_chain(bio);
- blk_finish_plug(&plug);
- return -EINTR;
- }
- ret = submit_bio_wait(bio);
+ ret = bio_submit_or_kill(bio, flags);
bio_put(bio);
}
blk_finish_plug(&plug);
@@ -236,13 +230,7 @@ static int blkdev_issue_zero_pages(struct block_device *bdev, sector_t sector,
blk_start_plug(&plug);
__blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp, &bio, flags);
if (bio) {
- if ((flags & BLKDEV_ZERO_KILLABLE) &&
- fatal_signal_pending(current)) {
- bio_await_chain(bio);
- blk_finish_plug(&plug);
- return -EINTR;
- }
- ret = submit_bio_wait(bio);
+ ret = bio_submit_or_kill(bio, flags);
bio_put(bio);
}
blk_finish_plug(&plug);
diff --git a/block/blk.h b/block/blk.h
index 103cb1d0b9cb..ec4674cdf2ea 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -55,7 +55,7 @@ bool __blk_freeze_queue_start(struct request_queue *q,
struct task_struct *owner);
int __bio_queue_enter(struct request_queue *q, struct bio *bio);
void submit_bio_noacct_nocheck(struct bio *bio, bool split);
-void bio_await_chain(struct bio *bio);
+int bio_submit_or_kill(struct bio *bio, unsigned int flags);
static inline bool blk_try_enter_queue(struct request_queue *q, bool pm)
{
diff --git a/block/ioctl.c b/block/ioctl.c
index 0b04661ac809..fc3be0549aa7 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -153,13 +153,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
nr_sects = len >> SECTOR_SHIFT;
blk_start_plug(&plug);
- while (1) {
- if (fatal_signal_pending(current)) {
- if (prev)
- bio_await_chain(prev);
- err = -EINTR;
- goto out_unplug;
- }
+ while (!fatal_signal_pending(current)) {
bio = blk_alloc_discard_bio(bdev, §or, &nr_sects,
GFP_KERNEL);
if (!bio)
@@ -167,12 +161,11 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
prev = bio_chain_and_submit(prev, bio);
}
if (prev) {
- err = submit_bio_wait(prev);
+ err = bio_submit_or_kill(prev, BLKDEV_ZERO_KILLABLE);
if (err == -EOPNOTSUPP)
err = 0;
bio_put(prev);
}
-out_unplug:
blk_finish_plug(&plug);
fail:
filemap_invalidate_unlock(bdev->bd_mapping);
--
2.47.3
^ permalink raw reply related
* [PATCH 2/4] block: factor out a bio_await helper
From: Christoph Hellwig @ 2026-04-06 5:57 UTC (permalink / raw)
To: Jens Axboe; +Cc: Carlos Maiolino, Bart Van Assche, linux-block, linux-xfs
In-Reply-To: <20260406055728.472919-1-hch@lst.de>
Add a new helper to wait for a bio and anything chained off it to
complete synchronous after kicking it. This factors common code out
of submit_bio_wait and bio_await_chain and will also be useful for
file system code and thus is exported.
Note that this will now set REQ_SYNC also for the bio_await case for
consistency. Nothing should look at the flag in the end_io handler,
but if did, having the flag set makes more sense.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/bio.c | 53 +++++++++++++++++++++++++++++++--------------
include/linux/bio.h | 2 ++
2 files changed, 39 insertions(+), 16 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index 434e41182c05..c7e75d532666 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1468,17 +1468,20 @@ static void bio_wait_end_io(struct bio *bio)
}
/**
- * submit_bio_wait - submit a bio, and wait until it completes
- * @bio: The &struct bio which describes the I/O
+ * bio_await - call a function on a bio, and wait until it completes
+ * @bio: the bio which describes the I/O
+ * @kick: function called to "kick off" the bio
+ * @priv: private data passed to @kick.
*
- * Simple wrapper around submit_bio(). Returns 0 on success, or the error from
- * bio_endio() on failure.
+ * Wait for the bio as well as any bio chained off it after executing the
+ * passed in callback @kick. The wait for the bio is set up before calling
+ * @kick to ensure that the completion is captured. If @kick is %NULL,
+ * submit_bio() is used instead to submit the bio.
*
- * WARNING: Unlike to how submit_bio() is usually used, this function does not
- * result in bio reference to be consumed. The caller must drop the reference
- * on his own.
+ * Note: this overrides the bi_private and bi_end_io fields in the bio.
*/
-int submit_bio_wait(struct bio *bio)
+void bio_await(struct bio *bio, void *priv,
+ void (*kick)(struct bio *bio, void *priv))
{
DECLARE_COMPLETION_ONSTACK_MAP(done,
bio->bi_bdev->bd_disk->lockdep_map);
@@ -1486,13 +1489,37 @@ int submit_bio_wait(struct bio *bio)
bio->bi_private = &done;
bio->bi_end_io = bio_wait_end_io;
bio->bi_opf |= REQ_SYNC;
- submit_bio(bio);
+ if (kick)
+ kick(bio, priv);
+ else
+ submit_bio(bio);
blk_wait_io(&done);
+}
+EXPORT_SYMBOL_GPL(bio_await);
+/**
+ * submit_bio_wait - submit a bio, and wait until it completes
+ * @bio: The &struct bio which describes the I/O
+ *
+ * Simple wrapper around submit_bio(). Returns 0 on success, or the error from
+ * bio_endio() on failure.
+ *
+ * WARNING: Unlike to how submit_bio() is usually used, this function does not
+ * result in bio reference to be consumed. The caller must drop the reference
+ * on his own.
+ */
+int submit_bio_wait(struct bio *bio)
+{
+ bio_await(bio, NULL, NULL);
return blk_status_to_errno(bio->bi_status);
}
EXPORT_SYMBOL(submit_bio_wait);
+static void bio_endio_cb(struct bio *bio, void *priv)
+{
+ bio_endio(bio);
+}
+
/**
* bdev_rw_virt - synchronously read into / write from kernel mapping
* @bdev: block device to access
@@ -1528,13 +1555,7 @@ EXPORT_SYMBOL_GPL(bdev_rw_virt);
*/
void bio_await_chain(struct bio *bio)
{
- DECLARE_COMPLETION_ONSTACK_MAP(done,
- bio->bi_bdev->bd_disk->lockdep_map);
-
- bio->bi_private = &done;
- bio->bi_end_io = bio_wait_end_io;
- bio_endio(bio);
- blk_wait_io(&done);
+ bio_await(bio, NULL, bio_endio_cb);
bio_put(bio);
}
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 984844d2870b..adcca9ad4eec 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -432,6 +432,8 @@ extern void bio_uninit(struct bio *);
void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf);
void bio_reuse(struct bio *bio, blk_opf_t opf);
void bio_chain(struct bio *, struct bio *);
+void bio_await(struct bio *bio, void *priv,
+ void (*kick)(struct bio *bio, void *priv));
int __must_check bio_add_page(struct bio *bio, struct page *page, unsigned len,
unsigned off);
--
2.47.3
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox