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 09/13] fs: Teach callers of file_start_write() to handle errors
Date: Wed,  7 Aug 2024 20:29:54 +0200	[thread overview]
Message-ID: <20240807183003.23562-9-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 file_start_write() to handle the error.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/backing-file.c      |  4 +++-
 fs/btrfs/ioctl.c       |  4 +++-
 fs/coredump.c          |  4 +++-
 fs/open.c              |  4 +++-
 fs/read_write.c        | 20 +++++++++++++++-----
 fs/remap_range.c       |  4 +++-
 fs/splice.c            |  8 ++++++--
 fs/xfs/xfs_exchrange.c |  4 +++-
 include/linux/fs.h     |  5 +++--
 9 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/fs/backing-file.c b/fs/backing-file.c
index afb557446c27..3df3fb48cb42 100644
--- a/fs/backing-file.c
+++ b/fs/backing-file.c
@@ -308,7 +308,9 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
 		return ret;
 
 	old_cred = override_creds(ctx->cred);
-	file_start_write(out);
+	ret = file_start_write(out);
+	if (ret)
+		return ret;
 	ret = iter_file_splice_write(pipe, out, ppos, len, flags);
 	file_end_write(out);
 	revert_creds(old_cred);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index e0a664b8a46a..4cadba17a5a3 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4676,7 +4676,9 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool
 		goto out_iov;
 	kiocb.ki_pos = pos;
 
-	file_start_write(file);
+	ret = file_start_write(file);
+	if (ret < 0)
+		goto out_iov;
 
 	ret = btrfs_do_write_iter(&kiocb, &iter, &args);
 	if (ret > 0)
diff --git a/fs/coredump.c b/fs/coredump.c
index 7f12ff6ad1d3..aa24964dc1e4 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -763,7 +763,9 @@ void do_coredump(const kernel_siginfo_t *siginfo)
 		if (!dump_vma_snapshot(&cprm))
 			goto close_fail;
 
-		file_start_write(cprm.file);
+		retval = file_start_write(cprm.file);
+		if (retval)
+			goto close_fail;
 		core_dumped = binfmt->core_dump(&cprm);
 		/*
 		 * Ensures that file size is big enough to contain the current
diff --git a/fs/open.c b/fs/open.c
index 22adbef7ecc2..4bce4ba776ab 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -330,7 +330,9 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (!file->f_op->fallocate)
 		return -EOPNOTSUPP;
 
-	file_start_write(file);
+	ret = file_start_write(file);
+	if (ret)
+		return ret;
 	ret = file->f_op->fallocate(file, mode, offset, len);
 
 	/*
diff --git a/fs/read_write.c b/fs/read_write.c
index 12996892bb1d..4d2831891e84 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -560,7 +560,9 @@ ssize_t kernel_write(struct file *file, const void *buf, size_t count,
 	if (ret)
 		return ret;
 
-	file_start_write(file);
+	ret = file_start_write(file);
+	if (ret)
+		return ret;
 	ret =  __kernel_write(file, buf, count, pos);
 	file_end_write(file);
 	return ret;
@@ -583,7 +585,9 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
 		return ret;
 	if (count > MAX_RW_COUNT)
 		count =  MAX_RW_COUNT;
-	file_start_write(file);
+	ret = file_start_write(file);
+	if (ret)
+		return ret;
 	if (file->f_op->write)
 		ret = file->f_op->write(file, buf, count, pos);
 	else if (file->f_op->write_iter)
@@ -893,7 +897,9 @@ ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos,
 	if (ret < 0)
 		return ret;
 
-	file_start_write(file);
+	ret = file_start_write(file);
+	if (ret)
+		return ret;
 	ret = do_iter_readv_writev(file, iter, ppos, WRITE, flags);
 	if (ret > 0)
 		fsnotify_modify(file);
@@ -968,7 +974,9 @@ static ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
 	if (ret < 0)
 		goto out;
 
-	file_start_write(file);
+	ret = file_start_write(file);
+	if (ret < 0)
+		goto out;
 	if (file->f_op->write_iter)
 		ret = do_iter_readv_writev(file, &iter, pos, WRITE, flags);
 	else
@@ -1509,7 +1517,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 	if (len == 0)
 		return 0;
 
-	file_start_write(file_out);
+	ret = file_start_write(file_out);
+	if (unlikely(ret))
+		return ret;
 
 	/*
 	 * Cloning is supported by more file systems, so we implement copy on
diff --git a/fs/remap_range.c b/fs/remap_range.c
index 28246dfc8485..d1aa23c16f15 100644
--- a/fs/remap_range.c
+++ b/fs/remap_range.c
@@ -399,7 +399,9 @@ loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in,
 	if (ret)
 		return ret;
 
-	file_start_write(file_out);
+	ret = file_start_write(file_out);
+	if (ret)
+		return ret;
 	ret = file_in->f_op->remap_file_range(file_in, pos_in,
 			file_out, pos_out, len, remap_flags);
 	file_end_write(file_out);
diff --git a/fs/splice.c b/fs/splice.c
index 60aed8de21f8..5d66a4dc93fc 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1160,7 +1160,9 @@ static int direct_splice_actor(struct pipe_inode_info *pipe,
 	struct file *file = sd->u.file;
 	long ret;
 
-	file_start_write(file);
+	ret = file_start_write(file);
+	if (ret)
+		return ret;
 	ret = do_splice_from(pipe, file, sd->opos, sd->total_len, sd->flags);
 	file_end_write(file);
 	return ret;
@@ -1350,7 +1352,9 @@ ssize_t do_splice(struct file *in, loff_t *off_in, struct file *out,
 		if (in->f_flags & O_NONBLOCK)
 			flags |= SPLICE_F_NONBLOCK;
 
-		file_start_write(out);
+		ret = file_start_write(out);
+		if (unlikely(ret))
+			return ret;
 		ret = do_splice_from(ipipe, out, &offset, len, flags);
 		file_end_write(out);
 
diff --git a/fs/xfs/xfs_exchrange.c b/fs/xfs/xfs_exchrange.c
index c8a655c92c92..e4840cbbe276 100644
--- a/fs/xfs/xfs_exchrange.c
+++ b/fs/xfs/xfs_exchrange.c
@@ -756,7 +756,9 @@ xfs_exchange_range(
 	if (!(fxr->file2->f_mode & FMODE_NOCMTIME) && !IS_NOCMTIME(inode2))
 		fxr->flags |= __XFS_EXCHANGE_RANGE_UPD_CMTIME2;
 
-	file_start_write(fxr->file2);
+	ret = file_start_write(fxr->file2);
+	if (ret)
+		return ret;
 	ret = xfs_exchrange_contents(fxr);
 	file_end_write(fxr->file2);
 	if (ret)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3ac37d9884f5..952f11170296 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2886,11 +2886,12 @@ static inline bool inode_wrong_type(const struct inode *inode, umode_t mode)
  * This is a variant of sb_start_write() which is a noop on non-regualr file.
  * Should be matched with a call to file_end_write().
  */
-static inline void file_start_write(struct file *file)
+static inline int __must_check file_start_write(struct file *file)
 {
 	if (!S_ISREG(file_inode(file)->i_mode))
-		return;
+		return 0;
 	sb_start_write(file_inode(file)->i_sb);
+	return 0;
 }
 
 static inline bool file_start_write_trylock(struct file *file)
-- 
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 ` [PATCH 08/13] fs: Teach callers of kiocb_start_write() to handle errors Jan Kara
2024-08-07 18:29 ` Jan Kara [this message]
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-9-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).