Skip to content

Commit 76192a4

Browse files
Christoph Hellwigbrauner
authored andcommitted
iomap: invert the polarity of IOMAP_DIO_INLINE_COMP
Replace IOMAP_DIO_INLINE_COMP with a flag to indicate that the completion should be offloaded. This removes a tiny bit of boilerplate code, but more importantly just makes the code easier to follow as this new flag gets set most of the time and only cleared in one place, while it was the inverse for the old version. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20251113170633.1453259-6-hch@lst.de Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent eca9dc2 commit 76192a4

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

fs/iomap/direct-io.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* iomap.h:
1818
*/
1919
#define IOMAP_DIO_NO_INVALIDATE (1U << 26)
20-
#define IOMAP_DIO_INLINE_COMP (1U << 27)
20+
#define IOMAP_DIO_COMP_WORK (1U << 27)
2121
#define IOMAP_DIO_WRITE_THROUGH (1U << 28)
2222
#define IOMAP_DIO_NEED_SYNC (1U << 29)
2323
#define IOMAP_DIO_WRITE (1U << 30)
@@ -182,7 +182,7 @@ static void iomap_dio_done(struct iomap_dio *dio)
182182
* for error handling.
183183
*/
184184
if (dio->error)
185-
dio->flags &= ~IOMAP_DIO_INLINE_COMP;
185+
dio->flags |= IOMAP_DIO_COMP_WORK;
186186

187187
/*
188188
* Never invalidate pages from this context to avoid deadlocks with
@@ -192,17 +192,14 @@ static void iomap_dio_done(struct iomap_dio *dio)
192192
* right between this check and the actual completion.
193193
*/
194194
if ((dio->flags & IOMAP_DIO_WRITE) &&
195-
(dio->flags & IOMAP_DIO_INLINE_COMP)) {
195+
!(dio->flags & IOMAP_DIO_COMP_WORK)) {
196196
if (dio->iocb->ki_filp->f_mapping->nrpages)
197-
dio->flags &= ~IOMAP_DIO_INLINE_COMP;
197+
dio->flags |= IOMAP_DIO_COMP_WORK;
198198
else
199199
dio->flags |= IOMAP_DIO_NO_INVALIDATE;
200200
}
201201

202-
if (dio->flags & IOMAP_DIO_INLINE_COMP) {
203-
WRITE_ONCE(iocb->private, NULL);
204-
iomap_dio_complete_work(&dio->aio.work);
205-
} else {
202+
if (dio->flags & IOMAP_DIO_COMP_WORK) {
206203
struct inode *inode = file_inode(iocb->ki_filp);
207204

208205
/*
@@ -213,7 +210,11 @@ static void iomap_dio_done(struct iomap_dio *dio)
213210
*/
214211
INIT_WORK(&dio->aio.work, iomap_dio_complete_work);
215212
queue_work(inode->i_sb->s_dio_done_wq, &dio->aio.work);
213+
return;
216214
}
215+
216+
WRITE_ONCE(iocb->private, NULL);
217+
iomap_dio_complete_work(&dio->aio.work);
217218
}
218219

219220
void iomap_dio_bio_end_io(struct bio *bio)
@@ -251,7 +252,7 @@ u32 iomap_finish_ioend_direct(struct iomap_ioend *ioend)
251252
* that we are already called from the ioend completion
252253
* workqueue.
253254
*/
254-
dio->flags |= IOMAP_DIO_INLINE_COMP;
255+
dio->flags &= ~IOMAP_DIO_COMP_WORK;
255256
iomap_dio_done(dio);
256257
}
257258

@@ -399,7 +400,7 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
399400
* handled in __iomap_dio_rw().
400401
*/
401402
if (need_completion_work)
402-
dio->flags &= ~IOMAP_DIO_INLINE_COMP;
403+
dio->flags |= IOMAP_DIO_COMP_WORK;
403404

404405
bio_opf |= REQ_OP_WRITE;
405406
} else {
@@ -422,7 +423,7 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
422423
* ones we set for inline and deferred completions. If none of those
423424
* are available for this IO, clear the polled flag.
424425
*/
425-
if (!(dio->flags & IOMAP_DIO_INLINE_COMP))
426+
if (dio->flags & IOMAP_DIO_COMP_WORK)
426427
dio->iocb->ki_flags &= ~IOCB_HIPRI;
427428

428429
if (need_zeroout) {
@@ -661,12 +662,6 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
661662
if (dio_flags & IOMAP_DIO_FSBLOCK_ALIGNED)
662663
dio->flags |= IOMAP_DIO_FSBLOCK_ALIGNED;
663664

664-
/*
665-
* Try to complete inline if we can. For reads this is always possible,
666-
* but for writes we'll end up clearing this more often than not.
667-
*/
668-
dio->flags |= IOMAP_DIO_INLINE_COMP;
669-
670665
if (iov_iter_rw(iter) == READ) {
671666
if (iomi.pos >= dio->i_size)
672667
goto out_free_dio;
@@ -713,7 +708,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
713708
* i_size updates must to happen from process context.
714709
*/
715710
if (iomi.pos + iomi.len > dio->i_size)
716-
dio->flags &= ~IOMAP_DIO_INLINE_COMP;
711+
dio->flags |= IOMAP_DIO_COMP_WORK;
717712

718713
/*
719714
* Try to invalidate cache pages for the range we are writing.
@@ -794,7 +789,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
794789
if (dio->flags & IOMAP_DIO_WRITE_THROUGH)
795790
dio->flags &= ~IOMAP_DIO_NEED_SYNC;
796791
else if (dio->flags & IOMAP_DIO_NEED_SYNC)
797-
dio->flags &= ~IOMAP_DIO_INLINE_COMP;
792+
dio->flags |= IOMAP_DIO_COMP_WORK;
798793

799794
/*
800795
* We are about to drop our additional submission reference, which

0 commit comments

Comments
 (0)