public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] f2fs: fix to adjust appropriate length for fiemap
@ 2024-11-04  1:56 Zhiguo Niu
  2024-11-05  3:15 ` Chao Yu
  2024-11-05  7:04 ` Chao Yu
  0 siblings, 2 replies; 22+ messages in thread
From: Zhiguo Niu @ 2024-11-04  1:56 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, zhiguo.niu, ke.wang,
	Hao_hao.Wang

If user give a file size as "length" parameter for fiemap
operations, but if this size is non-block size aligned,
it will show 2 segments fiemap results even this whole file
is contiguous on disk, such as the following results:

 ./f2fs_io fiemap 0 19034 ylog/analyzer.py
Fiemap: offset = 0 len = 19034
        logical addr.    physical addr.   length           flags
0       0000000000000000 0000000020baa000 0000000000004000 00001000
1       0000000000004000 0000000020bae000 0000000000001000 00001001

after this patch:
./f2fs_io fiemap 0 19034 ylog/analyzer.py
Fiemap: offset = 0 len = 19034
    logical addr.    physical addr.   length           flags
0    0000000000000000 00000000315f3000 0000000000005000 00001001

Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
V2: correct commit msg according to Chao's questions
f2fs_io has been modified for testing, the length for fiemap is
real file size, not block number
---
 fs/f2fs/data.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 306b86b0..9fc229d 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1966,8 +1966,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 			goto out;
 	}
 
-	if (bytes_to_blks(inode, len) == 0)
-		len = blks_to_bytes(inode, 1);
+	if (len & (blks_to_bytes(inode, 1) - 1))
+		len = round_up(len, blks_to_bytes(inode, 1));
 
 	start_blk = bytes_to_blks(inode, start);
 	last_blk = bytes_to_blks(inode, start + len - 1);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-11-08  1:53 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-04  1:56 [PATCH V2] f2fs: fix to adjust appropriate length for fiemap Zhiguo Niu
2024-11-05  3:15 ` Chao Yu
2024-11-05  4:02   ` Zhiguo Niu
2024-11-05  6:56     ` Chao Yu
2024-11-05  7:04 ` Chao Yu
2024-11-05  7:28   ` Zhiguo Niu
2024-11-05 10:39     ` Chao Yu
2024-11-05 11:02       ` Zhiguo Niu
2024-11-06  2:16         ` Chao Yu
2024-11-06  2:26           ` Zhiguo Niu
2024-11-06  2:40             ` Chao Yu
2024-11-06  2:54               ` Zhiguo Niu
2024-11-06  6:45                 ` Chao Yu
2024-11-06  6:08               ` Zhiguo Niu
2024-11-06  7:40                 ` Chao Yu
2024-11-06  8:41                   ` Zhiguo Niu
2024-11-07  6:18                     ` Chao Yu
2024-11-07  6:54                       ` Zhiguo Niu
2024-11-07  8:22                         ` Chao Yu
2024-11-07 10:53                           ` Zhiguo Niu
2024-11-08  1:22                             ` Chao Yu
2024-11-08  1:53                               ` Zhiguo Niu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox