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@xxxxxxx> --- 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