From: Zhiguo Niu <zhiguo.niu@unisoc.com>
To: <jaegeuk@kernel.org>, <chao@kernel.org>
Cc: <linux-f2fs-devel@lists.sourceforge.net>,
<linux-kernel@vger.kernel.org>, <niuzhiguo84@gmail.com>,
<zhiguo.niu@unisoc.com>, <ke.wang@unisoc.com>,
<hongyu.jin@unisoc.com>
Subject: [PATCH V3] f2fs: fix to adjust appropirate defragment pg_end
Date: Wed, 27 Mar 2024 16:53:40 +0800 [thread overview]
Message-ID: <1711529620-17576-1-git-send-email-zhiguo.niu@unisoc.com> (raw)
A length that exceeds the real size of the inode may be
specified from user, although these out-of-range areas
are not mapped, but they still need to be check in
while loop, which is unnecessary.
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
v3: adjust code positions according to Chao's suggestions
v2: check i_size within inode lock according to Chao's suggestions
---
---
fs/f2fs/file.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index bc190d5..9908017 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2627,12 +2627,13 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
bool fragmented = false;
int err;
- pg_start = range->start >> PAGE_SHIFT;
- pg_end = (range->start + range->len) >> PAGE_SHIFT;
-
f2fs_balance_fs(sbi, true);
inode_lock(inode);
+ pg_start = range->start >> PAGE_SHIFT;
+ pg_end = min_t(pgoff_t,
+ (range->start + range->len) >> PAGE_SHIFT,
+ DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
err = -EINVAL;
@@ -2647,8 +2648,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
}
/* writeback all dirty pages in the range */
- err = filemap_write_and_wait_range(inode->i_mapping, range->start,
- range->start + range->len - 1);
+ err = filemap_write_and_wait_range(inode->i_mapping,
+ pg_start << PAGE_SHIFT,
+ pg_end << PAGE_SHIFT - 1);
if (err)
goto out;
--
1.9.1
next reply other threads:[~2024-03-27 8:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 8:53 Zhiguo Niu [this message]
2024-03-29 6:11 ` 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=1711529620-17576-1-git-send-email-zhiguo.niu@unisoc.com \
--to=zhiguo.niu@unisoc.com \
--cc=chao@kernel.org \
--cc=hongyu.jin@unisoc.com \
--cc=jaegeuk@kernel.org \
--cc=ke.wang@unisoc.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=niuzhiguo84@gmail.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
all inboxes | Powered by JetHome®