t_stripealign: add stripe alignment check for all extents
PATCH 1/1 t_stripealign: add stripe alignment check for all extents
From: Chi Zhiling <[email protected]>
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 <[email protected]>
--- src/t_stripealign.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)
src/t_stripealign.c +24 -4
@@ -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 <[email protected]> */ #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);
Signature · 1 line
2.43.0