From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Christian Brauner <brauner@kernel.org>,
Carlos Maiolino <cem@kernel.org>,
linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 06/10] iomap: factor out a iomap_dio_done helper
Date: Thu, 19 Dec 2024 10:22:43 -0800 [thread overview]
Message-ID: <20241219182243.GF6156@frogsfrogsfrogs> (raw)
In-Reply-To: <20241219173954.22546-7-hch@lst.de>
On Thu, Dec 19, 2024 at 05:39:11PM +0000, Christoph Hellwig wrote:
> Split out the struct iomap-dio level final completion from
> iomap_dio_bio_end_io into a helper to clean up the code and make it
> reusable.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/iomap/direct-io.c | 76 ++++++++++++++++++++++----------------------
> 1 file changed, 38 insertions(+), 38 deletions(-)
>
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 641649a04614..ed658eb09a1a 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -165,43 +165,31 @@ static inline void iomap_dio_set_error(struct iomap_dio *dio, int ret)
> cmpxchg(&dio->error, 0, ret);
> }
>
> -void iomap_dio_bio_end_io(struct bio *bio)
> +/*
> + * Called when dio->ref reaches zero from and I/O completion.
an I/O completion
This hoist looks fine to me, so with that fixed:
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> + */
> +static void iomap_dio_done(struct iomap_dio *dio)
> {
> - struct iomap_dio *dio = bio->bi_private;
> - bool should_dirty = (dio->flags & IOMAP_DIO_DIRTY);
> struct kiocb *iocb = dio->iocb;
>
> - if (bio->bi_status)
> - iomap_dio_set_error(dio, blk_status_to_errno(bio->bi_status));
> - if (!atomic_dec_and_test(&dio->ref))
> - goto release_bio;
> -
> - /*
> - * Synchronous dio, task itself will handle any completion work
> - * that needs after IO. All we need to do is wake the task.
> - */
> if (dio->wait_for_completion) {
> + /*
> + * Synchronous I/O, task itself will handle any completion work
> + * that needs after IO. All we need to do is wake the task.
> + */
> struct task_struct *waiter = dio->submit.waiter;
>
> WRITE_ONCE(dio->submit.waiter, NULL);
> blk_wake_io_task(waiter);
> - goto release_bio;
> - }
> -
> - /*
> - * Flagged with IOMAP_DIO_INLINE_COMP, we can complete it inline
> - */
> - if (dio->flags & IOMAP_DIO_INLINE_COMP) {
> + } else if (dio->flags & IOMAP_DIO_INLINE_COMP) {
> WRITE_ONCE(iocb->private, NULL);
> iomap_dio_complete_work(&dio->aio.work);
> - goto release_bio;
> - }
> -
> - /*
> - * If this dio is flagged with IOMAP_DIO_CALLER_COMP, then schedule
> - * our completion that way to avoid an async punt to a workqueue.
> - */
> - if (dio->flags & IOMAP_DIO_CALLER_COMP) {
> + } else if (dio->flags & IOMAP_DIO_CALLER_COMP) {
> + /*
> + * If this dio is flagged with IOMAP_DIO_CALLER_COMP, then
> + * schedule our completion that way to avoid an async punt to a
> + * workqueue.
> + */
> /* only polled IO cares about private cleared */
> iocb->private = dio;
> iocb->dio_complete = iomap_dio_deferred_complete;
> @@ -219,19 +207,31 @@ void iomap_dio_bio_end_io(struct bio *bio)
> * issuer.
> */
> iocb->ki_complete(iocb, 0);
> - goto release_bio;
> + } else {
> + struct inode *inode = file_inode(iocb->ki_filp);
> +
> + /*
> + * Async DIO completion that requires filesystem level
> + * completion work gets punted to a work queue to complete as
> + * the operation may require more IO to be issued to finalise
> + * filesystem metadata changes or guarantee data integrity.
> + */
> + INIT_WORK(&dio->aio.work, iomap_dio_complete_work);
> + queue_work(inode->i_sb->s_dio_done_wq, &dio->aio.work);
> }
> +}
> +
> +void iomap_dio_bio_end_io(struct bio *bio)
> +{
> + struct iomap_dio *dio = bio->bi_private;
> + bool should_dirty = (dio->flags & IOMAP_DIO_DIRTY);
> +
> + if (bio->bi_status)
> + iomap_dio_set_error(dio, blk_status_to_errno(bio->bi_status));
> +
> + if (atomic_dec_and_test(&dio->ref))
> + iomap_dio_done(dio);
>
> - /*
> - * Async DIO completion that requires filesystem level completion work
> - * gets punted to a work queue to complete as the operation may require
> - * more IO to be issued to finalise filesystem metadata changes or
> - * guarantee data integrity.
> - */
> - INIT_WORK(&dio->aio.work, iomap_dio_complete_work);
> - queue_work(file_inode(iocb->ki_filp)->i_sb->s_dio_done_wq,
> - &dio->aio.work);
> -release_bio:
> if (should_dirty) {
> bio_check_pages_dirty(bio);
> } else {
> --
> 2.45.2
>
>
next prev parent reply other threads:[~2024-12-19 18:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 17:39 iomap patches for zoned XFS v1 Christoph Hellwig
2024-12-19 17:39 ` [PATCH 01/10] iomap: allow the file system to submit the writeback bios Christoph Hellwig
2024-12-19 17:54 ` Darrick J. Wong
2024-12-19 17:39 ` [PATCH 02/10] iomap: simplify io_flags and io_type in struct iomap_ioend Christoph Hellwig
2024-12-19 17:56 ` Darrick J. Wong
2024-12-19 17:39 ` [PATCH 03/10] iomap: add a IOMAP_F_ANON_WRITE flag Christoph Hellwig
2024-12-19 18:02 ` Darrick J. Wong
2024-12-19 18:24 ` Christoph Hellwig
2024-12-19 17:39 ` [PATCH 04/10] iomap: split bios to zone append limits in the submission handlers Christoph Hellwig
2024-12-19 18:17 ` Darrick J. Wong
2024-12-19 18:19 ` Christoph Hellwig
2024-12-19 17:39 ` [PATCH 05/10] iomap: move common ioend code to ioend.c Christoph Hellwig
2024-12-19 18:20 ` Darrick J. Wong
2024-12-19 17:39 ` [PATCH 06/10] iomap: factor out a iomap_dio_done helper Christoph Hellwig
2024-12-19 18:22 ` Darrick J. Wong [this message]
2024-12-19 17:39 ` [PATCH 07/10] iomap: optionally use ioends for direct I/O Christoph Hellwig
2024-12-19 18:25 ` Darrick J. Wong
2024-12-19 17:39 ` [PATCH 08/10] iomap: pass private data to iomap_page_mkwrite Christoph Hellwig
2024-12-19 17:39 ` [PATCH 09/10] iomap: pass private data to iomap_zero_range Christoph Hellwig
2024-12-19 17:39 ` [PATCH 10/10] iomap: pass private data to iomap_truncate_page Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241219182243.GF6156@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox