mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: Shakeel Butt <shakeel.butt@linux.dev>,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Jens Axboe <axboe@kernel.dk>,
	 linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	 io-uring@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	 linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
	 linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	 linux-unionfs@vger.kernel.org, bpf@vger.kernel.org,
	 linux-nfs@vger.kernel.org,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH v2 01/17] fs: add kiocb_start_write_trylock()
Date: Mon, 16 Nov 2026 12:03:41 +0100	[thread overview]
Message-ID: <20261116-work-fs-frozen_writes-v2-1-ecc4a2aac40e@kernel.org> (raw)
In-Reply-To: <20261116-work-fs-frozen_writes-v2-0-ecc4a2aac40e@kernel.org>

kiocb_start_write() waits until a frozen filesystem is thawed. A
nonblocking submission can't use it. io_uring open-codes the trylock
variant for its IOCB_NOWAIT writes.

Add kiocb_start_write_trylock() next to kiocb_start_write() and use it
in io_uring. kiocb_write_iter() is going to need it as well.

No functional changes.

Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 include/linux/fs.h | 22 ++++++++++++++++++++++
 io_uring/rw.c      |  9 +--------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 99caef43ff3c4..eefc2c9d4af19 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2801,6 +2801,28 @@ static inline void kiocb_start_write(struct kiocb *iocb)
 	__sb_writers_release(inode->i_sb, SB_FREEZE_WRITE);
 }
 
+/**
+ * kiocb_start_write_trylock - try to get write access to a superblock for
+ *			       async file io
+ * @iocb: the io context we want to submit the write with
+ *
+ * This is kiocb_start_write() for a submission that must not wait until a
+ * frozen filesystem is thawed. Should be matched with a call to
+ * kiocb_end_write() if it succeeds.
+ *
+ * Return: true if write access was acquired, false if it wasn't.
+ */
+static inline bool kiocb_start_write_trylock(struct kiocb *iocb)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	if (!sb_start_write_trylock(inode->i_sb))
+		return false;
+	/* Fool lockdep just like kiocb_start_write() does. */
+	__sb_writers_release(inode->i_sb, SB_FREEZE_WRITE);
+	return true;
+}
+
 /**
  * kiocb_end_write - drop write access to a superblock after async file io
  * @iocb: the io context we sumbitted the write with
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 3a8559ff4dc66..a0a16fc521455 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -1095,9 +1095,6 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
 
 static bool io_kiocb_start_write(struct io_kiocb *req, struct kiocb *kiocb)
 {
-	struct inode *inode;
-	bool ret;
-
 	if (!(req->flags & REQ_F_ISREG))
 		return true;
 	if (!(kiocb->ki_flags & IOCB_NOWAIT)) {
@@ -1105,11 +1102,7 @@ static bool io_kiocb_start_write(struct io_kiocb *req, struct kiocb *kiocb)
 		return true;
 	}
 
-	inode = file_inode(kiocb->ki_filp);
-	ret = sb_start_write_trylock(inode->i_sb);
-	if (ret)
-		__sb_writers_release(inode->i_sb, SB_FREEZE_WRITE);
-	return ret;
+	return kiocb_start_write_trylock(kiocb);
 }
 
 int io_write(struct io_kiocb *req, unsigned int issue_flags)

-- 
2.53.0


  reply	other threads:[~2026-11-16 11:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 11:03 [PATCH v2 00/17] fs: take freeze protection for writes to backing files Christian Brauner
2026-11-16 11:03 ` Christian Brauner [this message]
2026-11-16 11:03 ` [PATCH v2 02/17] fs: add kiocb_write_iter() and kiocb_end_write_iter() Christian Brauner
2026-11-16 11:03 ` [PATCH v2 03/17] fs: add file_write guard Christian Brauner
2026-11-16 11:03 ` [PATCH v2 04/17] zloop: take freeze protection for writes Christian Brauner
2026-11-16 11:03 ` [PATCH v2 05/17] nvmet: take freeze protection for writes to files Christian Brauner
2026-11-16 11:03 ` [PATCH v2 06/17] target: fileio: don't free the aio command under the filesystem Christian Brauner
2026-11-16 11:03 ` [PATCH v2 07/17] target: fileio: take freeze protection for aio writes Christian Brauner
2026-11-16 11:03 ` [PATCH v2 08/17] loop: take freeze protection for discard and write zeroes Christian Brauner
2026-11-16 11:03 ` [PATCH v2 09/17] zloop: take freeze protection when recording write pointers Christian Brauner
2026-11-16 11:03 ` [PATCH v2 10/17] target: fileio: take freeze protection for unmap Christian Brauner
2026-11-16 11:03 ` [PATCH v2 11/17] coredump: take freeze protection for the truncate Christian Brauner
2026-11-16 11:03 ` [PATCH v2 12/17] ovl: take freeze protection when storing the uuid Christian Brauner
2026-11-16 11:03 ` [PATCH v2 13/17] bpf: fs/xattr: take freeze protection in the xattr kfuncs Christian Brauner
2026-11-16 11:03 ` [PATCH v2 14/17] nfsd: take freeze protection for the truncate on open Christian Brauner
2026-11-16 11:03 ` [PATCH v2 15/17] loop: use kiocb_write_iter() Christian Brauner
2026-11-16 11:03 ` [PATCH v2 16/17] fs: use kiocb_write_iter() in vfs_iocb_iter_write() Christian Brauner
2026-11-16 11:03 ` [PATCH v2 17/17] backing-file: use kiocb_end_write_iter() Christian Brauner

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=20261116-work-fs-frozen_writes-v2-1-ecc4a2aac40e@kernel.org \
    --to=brauner@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bpf@vger.kernel.org \
    --cc=hch@lst.de \
    --cc=io-uring@vger.kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=target-devel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®