linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: <linux-fsdevel@vger.kernel.org>
Cc: Dave Chinner <david@fromorbit.com>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 08/13] fs: Teach callers of kiocb_start_write() to handle errors
Date: Wed,  7 Aug 2024 20:29:53 +0200	[thread overview]
Message-ID: <20240807183003.23562-8-jack@suse.cz> (raw)
In-Reply-To: <20240807180706.30713-1-jack@suse.cz>

sb_start_write() will be returning error on shutdown filesystem. Teach
callers of kiocb_start_write() to handle the error.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/aio.c           | 14 +++++++++-----
 fs/read_write.c    |  4 +++-
 include/linux/fs.h |  3 ++-
 io_uring/rw.c      |  7 +++++--
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 48d99221ff57..3b94081118bc 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1626,12 +1626,16 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,
 	if (ret < 0)
 		return ret;
 	ret = rw_verify_area(WRITE, file, &req->ki_pos, iov_iter_count(&iter));
-	if (!ret) {
-		if (S_ISREG(file_inode(file)->i_mode))
-			kiocb_start_write(req);
-		req->ki_flags |= IOCB_WRITE;
-		aio_rw_done(req, file->f_op->write_iter(req, &iter));
+	if (unlikely(ret))
+		goto out;
+	if (S_ISREG(file_inode(file)->i_mode)) {
+		ret = kiocb_start_write(req);
+		if (unlikely(ret))
+			goto out;
 	}
+	req->ki_flags |= IOCB_WRITE;
+	aio_rw_done(req, file->f_op->write_iter(req, &iter));
+out:
 	kfree(iovec);
 	return ret;
 }
diff --git a/fs/read_write.c b/fs/read_write.c
index 90e283b31ca1..12996892bb1d 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -859,7 +859,9 @@ ssize_t vfs_iocb_iter_write(struct file *file, struct kiocb *iocb,
 	if (ret < 0)
 		return ret;
 
-	kiocb_start_write(iocb);
+	ret = kiocb_start_write(iocb);
+	if (ret < 0)
+		return ret;
 	ret = file->f_op->write_iter(iocb, iter);
 	if (ret != -EIOCBQUEUED)
 		kiocb_end_write(iocb);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 52841aab13fb..3ac37d9884f5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2920,7 +2920,7 @@ static inline void file_end_write(struct file *file)
  * This is a variant of sb_start_write() for async io submission.
  * Should be matched with a call to kiocb_end_write().
  */
-static inline void kiocb_start_write(struct kiocb *iocb)
+static inline int __must_check kiocb_start_write(struct kiocb *iocb)
 {
 	struct inode *inode = file_inode(iocb->ki_filp);
 
@@ -2930,6 +2930,7 @@ static inline void kiocb_start_write(struct kiocb *iocb)
 	 * doesn't complain about the held lock when we return to userspace.
 	 */
 	__sb_writers_release(inode->i_sb, SB_FREEZE_WRITE);
+	return 0;
 }
 
 /**
diff --git a/io_uring/rw.c b/io_uring/rw.c
index c004d21e2f12..a9dc9f84fb60 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -1040,8 +1040,11 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags)
 	if (unlikely(ret))
 		return ret;
 
-	if (req->flags & REQ_F_ISREG)
-		kiocb_start_write(kiocb);
+	if (req->flags & REQ_F_ISREG) {
+		ret = kiocb_start_write(kiocb);
+		if (unlikely(ret))
+			return ret;
+	}
 	kiocb->ki_flags |= IOCB_WRITE;
 
 	if (likely(req->file->f_op->write_iter))
-- 
2.35.3


  parent reply	other threads:[~2024-08-07 18:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 18:29 [PATCH RFC 0/13] fs: generic filesystem shutdown handling Jan Kara
2024-08-07 18:29 ` [PATCH 01/13] fs: Define bit numbers for SB_I_ flags Jan Kara
2024-08-07 18:29 ` [PATCH 02/13] fs: Convert fs_context use of SB_I_ flags to new constants Jan Kara
2024-08-07 18:29 ` [PATCH 03/13] fs: Convert mount_too_revealing() to new s_iflags handling functions Jan Kara
2024-08-07 18:29 ` [PATCH 04/13] fs: Convert remaining usage of SB_I_ flags Jan Kara
2024-08-07 18:29 ` [PATCH 05/13] fs: Drop old SB_I_ constants Jan Kara
2024-08-07 18:29 ` [PATCH 06/13] fs: Drop unnecessary underscore from _SB_I_ constants Jan Kara
2024-08-08 11:47   ` Amir Goldstein
2024-08-08 14:35     ` Darrick J. Wong
2024-08-08 14:50       ` Christian Brauner
2024-08-08 17:34         ` Jan Kara
2024-08-07 18:29 ` [PATCH 07/13] overlayfs: Make ovl_start_write() return error Jan Kara
2024-08-08 12:01   ` Amir Goldstein
2024-08-07 18:29 ` Jan Kara [this message]
2024-08-07 18:29 ` [PATCH 09/13] fs: Teach callers of file_start_write() to handle errors Jan Kara
2024-08-07 18:29 ` [PATCH 10/13] fs: Add __must_check annotations to sb_start_write_trylock() and similar Jan Kara
2024-08-07 18:29 ` [PATCH 11/13] fs: Make sb_start_write() return error on shutdown filesystem Jan Kara
2024-08-07 18:29 ` [PATCH 12/13] fs: Make sb_start_pagefault() " Jan Kara
2024-08-07 18:29 ` [PATCH 13/13] ext4: Replace EXT4_FLAGS_SHUTDOWN flag with a generic SB_I_SHUTDOWN Jan Kara
2024-08-07 23:18 ` [PATCH RFC 0/13] fs: generic filesystem shutdown handling Dave Chinner
2024-08-08 14:32   ` Jan Kara
2024-08-13 12:46     ` Christian Brauner
2024-08-14  0:09     ` Dave Chinner
2024-08-08 14:51   ` Darrick J. Wong
2024-08-09  2:30     ` Dave Chinner

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=20240807183003.23562-8-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=brauner@kernel.org \
    --cc=david@fromorbit.com \
    --cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).