diff mbox series

t_stripealign: add stripe alignment check for all extents

Message ID 20240711015812.95489-1-chizhiling@163.com (mailing list archive)
State New, archived
Headers show
Series t_stripealign: add stripe alignment check for all extents | expand

Commit Message

Chi Zhiling July 11, 2024, 1:58 a.m. UTC
From: Chi Zhiling <chizhiling@kylinos.cn>

When testing generic/223, if the file occupies multiple extents,
the t_stripealign only checks the first extent. Therefore, this
patch adds a check for all extents

Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
 src/t_stripealign.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/src/t_stripealign.c b/src/t_stripealign.c
index 00a5a3d1..87c2c4e8 100644
--- a/src/t_stripealign.c
+++ b/src/t_stripealign.c
@@ -1,7 +1,7 @@ 
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * t_stripealign.c
- * Print whether the file start block is stripe-aligned.
+ * Print whether the file start block of all extents is stripe-aligned.
  * Copyright (c) 2010 Eric Sandeen <sandeen@sandeen.net>
  */
 #include <unistd.h>
@@ -13,6 +13,7 @@ 
 #include <sys/ioctl.h>
 #include <linux/fiemap.h>
 #include <linux/fs.h>
+#include <sys/stat.h>
 
 #ifndef FIEMAP_EXTENT_SHARED
 # define FIEMAP_EXTENT_SHARED	0x00002000
@@ -32,13 +33,16 @@ 
 int main(int argc, char ** argv)
 {
 	struct statfs		sb;
+	struct stat		st;
 	struct fiemap		*fie;
 	struct fiemap_extent	*fe;
 	int			fd;
 	int			ret;
 	int			sunit = 0;	/* in blocks */
+	int			fsize;
 	char			*filename;
 	unsigned long long	block;
+	unsigned long long	offset = 0;
 
         if (argc < 3) {
                 printf("Usage: %s <filename> <sunit in blocks>\n", argv[0]);
@@ -61,13 +65,25 @@  int main(int argc, char ** argv)
 		return 1;
 	}
 
+	/* Read file size */
+	ret = fstat(fd, &st);
+	if (ret) {
+		perror(filename);
+		close(fd);
+		return 1;
+	}
+	fsize = st.st_size;
+
 	fie = calloc(1, sizeof(struct fiemap) + sizeof(struct fiemap_extent));
 	if (!fie) {
 		close(fd);
 		perror("malloc");
 		return 1;
 	}
-	fie->fm_length = 1;
+
+next_extent:
+	fie->fm_start = offset;
+	fie->fm_length = fsize - offset;
 	fie->fm_flags = FIEMAP_FLAG_SYNC;
 	fie->fm_extent_count = 1;
 
@@ -86,6 +102,7 @@  int main(int argc, char ** argv)
 			return 1;
 		}
 		block = bmap;
+		offset += fsize;
 		goto check;
 	}
 
@@ -105,11 +122,14 @@  int main(int argc, char ** argv)
 	}
 
 	block = fie->fm_extents[0].fe_physical / sb.f_bsize;
+	offset += fie->fm_extents[0].fe_length;
 check:
 	if (block % sunit) {
-		printf("%s: Start block %llu not multiple of sunit %u\n",
-			filename, block, sunit);
+		printf("%s: Start block %llu (offset %llu) not multiple of sunit %u\n",
+			filename, block, offset, sunit);
 		return 1;
+	} else if (offset < fsize) {
+		goto next_extent;
 	} else
 		printf("%s: well-aligned\n", filename);
 	free(fie);