From e861a30255c9780425ee5193325d30882fbe7410 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Tue, 28 Jun 2022 13:21:23 -0700 Subject: [PATCH] seek_sanity_test: fix allocation unit detection on XFS realtime The seek sanity test tries to figure out a file space allocation unit by calling stat and then using an iterative SEEK_DATA method to try to detect a smaller blocksize based on SEEK_DATA's consultation of the filesystem's internal block mapping. This was put in (AFAICT) because XFS' stat implementation returns max(filesystem blocksize, PAGESIZE) for most regular files. Unfortunately, for a realtime file with an extent size larger than a single filesystem block this doesn't work at all because block mappings still work at filesystem block granularity, but allocation units do not. To fix this, detect the specific case where st_blksize != PAGE_SIZE and trust the fstat results. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Zorro Lang --- src/seek_sanity_test.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c index 76587b7f1..1030d0c56 100644 --- a/src/seek_sanity_test.c +++ b/src/seek_sanity_test.c @@ -45,6 +45,7 @@ static int get_io_sizes(int fd) off_t pos = 0, offset = 1; struct stat buf; int shift, ret; + int pagesz = sysconf(_SC_PAGE_SIZE); ret = fstat(fd, &buf); if (ret) { @@ -53,8 +54,16 @@ static int get_io_sizes(int fd) return ret; } - /* st_blksize is typically also the allocation size */ + /* + * st_blksize is typically also the allocation size. However, XFS + * rounds this up to the page size, so if the stat blocksize is exactly + * one page, use this iterative algorithm to see if SEEK_DATA will hint + * at a more precise answer based on the filesystem's (pre)allocation + * decisions. + */ alloc_size = buf.st_blksize; + if (alloc_size != pagesz) + goto done; /* try to discover the actual alloc size */ while (pos == 0 && offset < alloc_size) { @@ -80,6 +89,7 @@ static int get_io_sizes(int fd) if (!shift) offset += pos ? 0 : 1; alloc_size = offset; +done: fprintf(stdout, "Allocation size: %ld\n", alloc_size); return 0; -- 2.49.0