From: Yunlei He <heyunlei@huawei.com>
To: jaegeuk@kernel.org, yuchao0@huawei.com,
linux-f2fs-devel@lists.sourceforge.net
Cc: zhangdianfang@huawei.com
Subject: [PATCH] f2fs: fix missing clear FI_NO_PREALLOC in some error case
Date: Mon, 23 Apr 2018 11:36:04 +0800 [thread overview]
Message-ID: <1524454564-3299-1-git-send-email-heyunlei@huawei.com> (raw)
This patch clean f2fs_file_write_iter to avoid missing clear
FI_NO_PREALLOC in some error case.
Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
fs/f2fs/file.c | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 16dad2b..c7dff0b 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2894,12 +2894,13 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
struct file *file = iocb->ki_filp;
struct inode *inode = file_inode(file);
+ int o_direct = iocb->ki_flags & IOCB_DIRECT;
ssize_t ret;
if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
return -EIO;
- if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
+ if ((iocb->ki_flags & IOCB_NOWAIT) && !o_direct)
return -EINVAL;
if (!inode_trylock(inode)) {
@@ -2910,44 +2911,40 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
ret = generic_write_checks(iocb, from);
if (ret > 0) {
- bool preallocated = false;
size_t target_size = 0;
- int err;
- if (iov_iter_fault_in_readable(from, iov_iter_count(from)))
- set_inode_flag(inode, FI_NO_PREALLOC);
-
- if ((iocb->ki_flags & IOCB_NOWAIT) &&
- (iocb->ki_flags & IOCB_DIRECT)) {
+ if ((iocb->ki_flags & IOCB_NOWAIT) && o_direct) {
if (!f2fs_overwrite_io(inode, iocb->ki_pos,
iov_iter_count(from)) ||
f2fs_has_inline_data(inode) ||
f2fs_force_buffered_io(inode, WRITE)) {
- inode_unlock(inode);
- return -EAGAIN;
+ ret = -EAGAIN;
+ goto out;
}
} else {
- preallocated = true;
+ if (iov_iter_fault_in_readable(from, iov_iter_count(from)))
+ set_inode_flag(inode, FI_NO_PREALLOC);
+
target_size = iocb->ki_pos + iov_iter_count(from);
- err = f2fs_preallocate_blocks(iocb, from);
- if (err) {
- clear_inode_flag(inode, FI_NO_PREALLOC);
- inode_unlock(inode);
- return err;
- }
+ ret = f2fs_preallocate_blocks(iocb, from);
+ if (ret)
+ goto out;
}
ret = __generic_file_write_iter(iocb, from);
- clear_inode_flag(inode, FI_NO_PREALLOC);
/* if we couldn't write data, we should deallocate blocks. */
- if (preallocated && i_size_read(inode) < target_size)
+ if (!is_inode_flag_set(inode, FI_NO_PREALLOC) &&
+ i_size_read(inode) < target_size)
f2fs_truncate(inode);
if (ret > 0)
f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret);
}
+
+out:
+ clear_inode_flag(inode, FI_NO_PREALLOC);
inode_unlock(inode);
if (ret > 0)
--
1.9.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
next reply other threads:[~2018-04-23 3:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-23 3:36 Yunlei He [this message]
2018-04-23 8:38 ` [PATCH] f2fs: fix missing clear FI_NO_PREALLOC in some error case Chao Yu
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=1524454564-3299-1-git-send-email-heyunlei@huawei.com \
--to=heyunlei@huawei.com \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=yuchao0@huawei.com \
--cc=zhangdianfang@huawei.com \
/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).