xfsprogs: xfs_fsr: Interpret arguments of qsort's compare function correctly
PATCH 1/2 xfsprogs: xfs_fsr: Interpret arguments of qsort's compare function correctly
The first argument passed to qsort() in fsrfs() is an array of "struct xfs_bulkstat". Hence the two arguments to the cmp() function must be interpreted as being of type "struct xfs_bulkstat *" as against "struct xfs_bstat *" that is being used to currently typecast them.
--- fsr/xfs_fsr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fsr/xfs_fsr.c +2 -3
@@ -702,9 +702,8 @@ out0:int cmp (const void *s1,const void *s2) { -return ( ((struct xfs_bstat *)s2)->bs_extents - - ((struct xfs_bstat *)s1)->bs_extents); - +return ( ((struct xfs_bulkstat *)s2)->bs_extents - + ((struct xfs_bulkstat *)s1)->bs_extents); }/*
Signature · 1 line
2.29.2
PATCH 2/2 xfsprogs: xfs_fsr: Limit the scope of cmp()
cmp() function is being referred to by only from within fsr/xfs_fsr.c. Hence this commit limits its scope to the current file.
--- fsr/xfs_fsr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fsr/xfs_fsr.c +2 -2
@@ -81,7 +81,7 @@ char * gettmpname(char *fname);char *getparent (char *fname);int fsrprintf (const char *fmt, ...);int read_fd_bmap (int ,struct xfs_bstat *,int *); -int cmp (const void *,const void *); +static int cmp (const void *,const void *);static void tmp_init (char *mnt);static char *tmp_next (char *mnt);static void tmp_close (char *mnt);
@@ -699,7 +699,7 @@ out0:/* * To compare bstat structs for qsort. */ -int +static int cmp (const void *s1,const void *s2) { return( ((struct xfs_bulkstat *)s2)->bs_extents -
Signature · 1 line
2.29.2
Re: [PATCH 2/2] xfsprogs: xfs_fsr: Limit the scope of cmp()
Quoted 4 lines · Chandan Babu R
cmp()function is being referred to by only from withinfsr/xfs_fsr.c. Hence this commit limits its scope to the current file.Signed-off-by Chandan Babu R <[email protected]>
Might be nice to move cmp just ahead of fsrfs() so we don't need the forward declaration but *shrug*
Quoted 27 lines
--- fsr/xfs_fsr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fsr/xfs_fsr.c +2
-2@@ -81,7 +81,7 @@ char * gettmpname(char *fname);char *getparent (char *fname);int fsrprintf (const char *fmt, ...);int read_fd_bmap (int ,struct xfs_bstat *,int *); -int cmp (const void *,const void *); +static int cmp (const void *,const void *);static void tmp_init (char *mnt);static char *tmp_next (char *mnt);static void tmp_close (char *mnt);@@ -699,7 +699,7 @@ out0:/* * To compare bstat structs for qsort. */ -int +static int cmp (const void *s1,const void *s2) { return( ((struct xfs_bulkstat *)s2)->bs_extents -
Quoted 6 lines · Chandan Babu R
The first argument passed to
qsort()infsrfs()is an array of "structxfs_bulkstat". Hence the two arguments to thecmp()function must be interpreted as being of type "structxfs_bulkstat*" as against "structxfs_bstat*" that is being used to currently typecast them.Signed-off-by Chandan Babu R <[email protected]>
Yikes. Broken since 5.3.0, and the structures have different sizes and different bs_extents offsets. :(
At least it's only affecting the whole-fs defragment which is generally not recommended, but is still available and does get used.
I wonder if it explains this bug report:
Jan 07 20:52:44 <Tharn> hey, quick question... the first time I ran xfs_fsr last night, it ran for 2 hours and looking at the console log, it ended with a lot of "start inode=0" repeating
Quoted 21 lines
--- fsr/xfs_fsr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fsr/xfs_fsr.c +2
-3@@ -702,9 +702,8 @@ out0:int cmp (const void *s1,const void *s2) { -return ( ((struct xfs_bstat *)s2)->bs_extents - - ((struct xfs_bstat *)s1)->bs_extents); - +return ( ((struct xfs_bulkstat *)s2)->bs_extents - + ((struct xfs_bulkstat *)s1)->bs_extents); }/*
PATCH 1/1 xfsprogs: xfs_fsr: Limit the scope of cmp()
In reply to Eric Sandeencmp() function is being referred to from within fsr/xfs_fsr.c. Hence this commit limits its scope to the current file.
--- fsr/xfs_fsr.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
fsr/xfs_fsr.c +10 -11
@@ -81,7 +81,6 @@ char * gettmpname(char *fname);char *getparent (char *fname);int fsrprintf (const char *fmt, ...);int read_fd_bmap (int ,struct xfs_bstat *,int *); -int cmp (const void *,const void *);static void tmp_init (char *mnt);static char *tmp_next (char *mnt);static void tmp_close (char *mnt);
@@ -577,6 +576,16 @@ fsrall_cleanup(int timeout) } } +/* +* To compare bstat structs for qsort. +*/ +static int +cmp (const void *s1,const void *s2) +{ +return ( ((struct xfs_bulkstat *)s2)->bs_extents - + ((struct xfs_bulkstat *)s1)->bs_extents); +} +/* * fsrfs -- reorganize a file system */
@@ -696,16 +705,6 @@ out0:return 0 ; } -/* -* To compare bstat structs for qsort. -*/ -int -cmp (const void *s1,const void *s2) -{ -return ( ((struct xfs_bulkstat *)s2)->bs_extents - - ((struct xfs_bulkstat *)s1)->bs_extents); -} -/* * reorganize by directory hierarchy. * Stay in dev (a restriction based on structure of this program -- either
Signature · 1 line
2.29.2
Quoted 11 lines · Darrick J. Wong
Quoted 10 lines · Chandan Babu R
The first argument passed to
qsort()infsrfs()is an array of "structxfs_bulkstat". Hence the two arguments to thecmp()function must be interpreted as being of type "structxfs_bulkstat*" as against "structxfs_bstat*" that is being used to currently typecast them.Signed-off-by Chandan Babu R <[email protected]>--- fsr/xfs_fsr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Quoted 17 lines
fsr/xfs_fsr.c out0: · line 706
Quoted 13 lines
fsr/xfs_fsr.c +2
-3@@ -702,9 +702,8 @@ out0:int cmp (const void *s1,const void *s2) { -return ( ((struct xfs_bstat *)s2)->bs_extents - - ((struct xfs_bstat *)s1)->bs_extents); - +return ( ((struct xfs_bulkstat *)s2)->bs_extents - + ((struct xfs_bulkstat *)s1)->bs_extents);It might be a good idea to check
bs_versionhere to avoid future maintainer screwups <coughs this maintainer>
Sure, I will write a new patch to add that.
Quoted 3 lines
Thanks for catching this,
Reviewed-by Darrick J. Wong <[email protected]>
Signature · 1 line
chandan
Quoted 14 lines · Eric Sandeen
Quoted 6 lines · Chandan Babu R
The first argument passed to
qsort()infsrfs()is an array of "structxfs_bulkstat". Hence the two arguments to thecmp()function must be interpreted as being of type "structxfs_bulkstat*" as against "structxfs_bstat*" that is being used to currently typecast them.Signed-off-by Chandan Babu R <[email protected]>Yikes. Broken since 5.3.0, and the structures have different sizes and different
bs_extentsoffsets. :(Fixes 4cca629d6 ("misc: convert xfrog_bulkstat functions to have v5 semantics")Reviewed-by Eric Sandeen <[email protected]>
Quoted 6 lines
At least it's only affecting the whole-fs defragment which is generally not recommended, but is still available and does get used.
I wonder if it explains this bug report:
Jan 07 20:52:44 <Tharn> hey, quick question... the first time I ran xfs_fsr last night, it ran for 2 hours and looking at the console log, it ended with a lot of "start inode=0" repeating
With my limited understanding of xfs_fsr code, looks like the bug reporter saw the logs corresponding to the default (i.e. 10) number of passes that xfs_fsr executes on the inodes of the filesystem. Sorry, I couldn't be of much help in this case.
Quoted 20 lines
Quoted 20 lines
--- fsr/xfs_fsr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fsr/xfs_fsr.c +2
-3@@ -702,9 +702,8 @@ out0:int cmp (const void *s1,const void *s2) { -return ( ((struct xfs_bstat *)s2)->bs_extents - - ((struct xfs_bstat *)s1)->bs_extents); - +return ( ((struct xfs_bulkstat *)s2)->bs_extents - + ((struct xfs_bulkstat *)s1)->bs_extents); }
Quoted 2 lines
fsr/xfs_fsr.c out0: · line 709
Quoted 2 lines
fsr/xfs_fsr.c +0
-0/*
--
chandan
Quoted 15 lines · Chandan Babu R
The first argument passed to
qsort()infsrfs()is an array of "structxfs_bulkstat". Hence the two arguments to thecmp()function must be interpreted as being of type "structxfs_bulkstat*" as against "structxfs_bstat*" that is being used to currently typecast them.Signed-off-by Chandan Babu R <[email protected]>--- fsr/xfs_fsr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fsr/xfs_fsr.c +0
-0
fsr/xfs_fsr.c out0: · line 706
Quoted 8 lines
fsr/xfs_fsr.c +2
-3@@ -702,9 +702,8 @@ out0:int cmp (const void *s1,const void *s2) { -return ( ((struct xfs_bstat *)s2)->bs_extents - - ((struct xfs_bstat *)s1)->bs_extents); - +return ( ((struct xfs_bulkstat *)s2)->bs_extents - + ((struct xfs_bulkstat *)s1)->bs_extents);
It might be a good idea to check bs_version here to avoid future maintainer screwups <coughs this maintainer>
Thanks for catching this,
--D
Quoted 6 lines
fsr/xfs_fsr.c +0
-0}/* Signature · 1 line
2.29.2
Re: [PATCH V1.1] xfsprogs: xfs_fsr: Limit the scope of cmp()
In reply to Chandan Babu RQuoted 4 lines · Chandan Babu R
cmp()function is being referred to from withinfsr/xfs_fsr.c. Hence this commit limits its scope to the current file.Signed-off-by Chandan Babu R <[email protected]>
Thanks,