* [f2fs-dev] [PATCH] f2fs_io: ranndread: support block device
@ 2025-11-03 6:39 Chao Yu via Linux-f2fs-devel
0 siblings, 0 replies; only message in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-11-03 6:39 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel
Otherwise, f2fs_io randread will fail due to i_size of block device
inode is zero.
- f2fs_io randread 1 1000 buffered 1 /dev/vdc
fadvise RANDOM|WILLNEED to a file: /dev/vdc
File is too small to random read
Signed-off-by: Chao Yu <chao@kernel.org>
---
tools/f2fs_io/f2fs_io.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 1f26c7c..231da47 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1225,6 +1225,7 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
int fd, advice;
time_t t;
struct stat stbuf;
+ u64 size;
if (argc != 6) {
fputs("Excess arguments\n\n", stderr);
@@ -1261,7 +1262,17 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
if (fstat(fd, &stbuf) != 0)
die_errno("fstat of source file failed");
- aligned_size = (u64)stbuf.st_size & ~((u64)(F2FS_DEFAULT_BLKSIZE - 1));
+ if (S_ISBLK(stbuf.st_mode)) {
+ u64 devsize;
+
+ if (ioctl(fd, BLKGETSIZE64, &devsize) < 0)
+ die_errno("BLKGETSIZE64 failed");
+ size = devsize;
+ } else {
+ size = (u64)stbuf.st_size;
+ }
+
+ aligned_size = (u64)size & ~((u64)(F2FS_DEFAULT_BLKSIZE - 1));
if (aligned_size < buf_size)
die("File is too small to random read");
end_idx = (u64)(aligned_size - buf_size) / (u64)F2FS_DEFAULT_BLKSIZE + 1;
--
2.49.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-11-03 6:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 6:39 [f2fs-dev] [PATCH] f2fs_io: ranndread: support block device Chao Yu via Linux-f2fs-devel
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).