[PATCH 1/9] seek_sanity_test: fix allocation unit detection on XFS realtime

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



From: Darrick J. Wong <djwong@xxxxxxxxxx>

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 <djwong@xxxxxxxxxx>
---
 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 76587b7f..1030d0c5 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;
 




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux