mkfs: fix libxfs_iget return value sign inversion
PATCH 1/2 mkfs: fix libxfs_iget return value sign inversion
From: Darrick J. Wong <[email protected]>
libxfs functions return negative errno, so utilities must invert the return values from such functions. Caught by xfs/437.
--- mkfs/proto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/proto.c +1 -1
@@ -1425,7 +1425,7 @@ handle_hardlink(if (dst_ino ==0 )return false; - error =libxfs_iget (mp,NULL , dst_ino,0 , &ip); + error = -libxfs_iget (mp,NULL , dst_ino,0 , &ip);if (error)fail (_ ("failed to get inode" ), error);
PATCH 2/2 libfrog: pass mode to xfrog_file_setattr
From: Darrick J. Wong <[email protected]>
xfs/633 crashes rdump_fileattrs_path passes a NULL struct stat pointer and then the fallback code dereferences it to get the file mode. Instead, let's just pass the stat mode directly to it, because that's the only piece of information that it needs.
--- libfrog/file_attr.h | 9 ++------- db/rdump.c | 4 ++-- io/attr.c | 4 ++-- libfrog/file_attr.c | 4 ++-- quota/project.c | 6 ++++-- 5 files changed, 12 insertions(+), 15 deletions(-)
libfrog/file_attr.h +2 -7
@@ -24,12 +24,7 @@ xfrog_file_getattr(struct file_attr *fa, const unsigned int at_flags); -int -xfrog_file_setattr ( -const int dfd, -const char *path, -const struct stat *stat, -struct file_attr *fa, -const unsigned int at_flags); +int xfrog_file_setattr (const int dfd,const char *path,const mode_t mode, +struct file_attr *fa,const unsigned int at_flags);#endif /* __LIBFROG_FILE_ATTR_H__ */
db/rdump.c +2 -2
@@ -188,8 +188,8 @@ rdump_fileattrs_path(return 1 ; } - ret =xfrog_file_setattr (destdir->fd, pbuf->path,NULL , &fa, -AT_SYMLINK_NOFOLLOW ); + ret =xfrog_file_setattr (destdir->fd, pbuf->path,VFS_I (ip)->i_mode, + &fa,AT_SYMLINK_NOFOLLOW );if (ret) {if (errno ==EOPNOTSUPP || errno ==EPERM || errno ==ENOTTY ) lost_mask |=LOST_FSXATTR ;
io/attr.c +2 -2
@@ -261,7 +261,7 @@ chattr_callback( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error =xfrog_file_setattr (AT_FDCWD , path, stat, &attr, + error =xfrog_file_setattr (AT_FDCWD , path, stat->st_mode, &attr,AT_SYMLINK_NOFOLLOW );if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
@@ -357,7 +357,7 @@ chattr_f( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error =xfrog_file_setattr (AT_FDCWD , name, &st, &attr, + error =xfrog_file_setattr (AT_FDCWD , name, st.st_mode, &attr,AT_SYMLINK_NOFOLLOW );if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
libfrog/file_attr.c +2 -2
@@ -85,7 +85,7 @@ intxfrog_file_setattr ( const int dfd, const char *path, - const struct stat *stat, + const mode_t mode, struct file_attr *fa, const unsigned int at_flags) {
@@ -103,7 +103,7 @@ xfrog_file_setattr(return error;#endif -if (SPECIAL_FILE (stat->st_mode)) { +if (SPECIAL_FILE (mode)) { errno =EOPNOTSUPP ;return -1 ; }
quota/project.c +4 -2
@@ -157,7 +157,8 @@ clear_project( fa.fa_projid =0 ; fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT ; - error =xfrog_file_setattr (dfd, path, stat, &fa,AT_SYMLINK_NOFOLLOW ); + error =xfrog_file_setattr (dfd, path, stat->st_mode, &fa, +AT_SYMLINK_NOFOLLOW );if (error) {fprintf (stderr,_ ("%s: cannot clear project on %s: %s\n" ), progname, path,strerror (errno));
@@ -205,7 +206,8 @@ setup_project(if (S_ISDIR (stat->st_mode)) fa.fa_xflags |=FS_XFLAG_PROJINHERIT ; - error =xfrog_file_setattr (dfd, path, stat, &fa,AT_SYMLINK_NOFOLLOW ); + error =xfrog_file_setattr (dfd, path, stat->st_mode, &fa, +AT_SYMLINK_NOFOLLOW );if (error) {fprintf (stderr,_ ("%s: cannot set project on %s: %s\n" ), progname, path,strerror (errno));
Re: [PATCH 2/2] libfrog: pass mode to xfrog_file_setattr
Quoted 4 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xfs/633 crashes
rdump_fileattrs_pathpasses a NULL struct stat pointer and then the fallback code dereferences it to get the file mode.
Oh is it latest xfsprogs with older kernel (without file_[g]etattr)?
(I see this on 6.16)
Quoted 20 lines
Instead, let's just pass the stat mode directly to it, because that's the only piece of information that it needs.
Fixes 128ac4dadbd633 ("xfs_db: use file_setattr to copy attributes on special files with rdump")Signed-off-by "Darrick J. Wong" <[email protected]>--- libfrog/file_attr.h | 9 ++------- db/rdump.c | 4 ++-- io/attr.c | 4 ++-- libfrog/file_attr.c | 4 ++-- quota/project.c | 6 ++++-- 5 files changed, 12 insertions(+), 15 deletions(-)libfrog/file_attr.h +0
-0@@ -24,12 +24,7 @@ xfrog_file_getattr(struct file_attr *fa, const unsigned int at_flags);
libfrog/file_attr.h xfrog_file_getattr( · line 28
Quoted 10 lines
libfrog/file_attr.h +2
-7-int -xfrog_file_setattr ( -const int dfd, -const char *path, -const struct stat *stat, -struct file_attr *fa, -const unsigned int at_flags); +int xfrog_file_setattr (const int dfd,const char *path,const mode_t mode, +struct file_attr *fa,const unsigned int at_flags);
Is this formatting change intentional? (maybe then the xfrog_file_getattr also)
otherwise lgtm
Quoted 86 lines
libfrog/file_attr.h +0
-0#endif /* __LIBFROG_FILE_ATTR_H__ */ db/rdump.c +2
-2@@ -188,8 +188,8 @@ rdump_fileattrs_path(return 1 ; } - ret =xfrog_file_setattr (destdir->fd, pbuf->path,NULL , &fa, -AT_SYMLINK_NOFOLLOW ); + ret =xfrog_file_setattr (destdir->fd, pbuf->path,VFS_I (ip)->i_mode, + &fa,AT_SYMLINK_NOFOLLOW );if (ret) {if (errno ==EOPNOTSUPP || errno ==EPERM || errno ==ENOTTY ) lost_mask |=LOST_FSXATTR ;io/attr.c +2
-2@@ -261,7 +261,7 @@ chattr_callback( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error =xfrog_file_setattr (AT_FDCWD , path, stat, &attr, + error =xfrog_file_setattr (AT_FDCWD , path, stat->st_mode, &attr,AT_SYMLINK_NOFOLLOW );if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),@@ -357,7 +357,7 @@ chattr_f( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error =xfrog_file_setattr (AT_FDCWD , name, &st, &attr, + error =xfrog_file_setattr (AT_FDCWD , name, st.st_mode, &attr,AT_SYMLINK_NOFOLLOW );if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),libfrog/file_attr.c +2
-2@@ -85,7 +85,7 @@ intxfrog_file_setattr ( const int dfd, const char *path, - const struct stat *stat, + const mode_t mode, struct file_attr *fa, const unsigned int at_flags) {@@ -103,7 +103,7 @@ xfrog_file_setattr(return error;#endif -if (SPECIAL_FILE (stat->st_mode)) { +if (SPECIAL_FILE (mode)) { errno =EOPNOTSUPP ;return -1 ; }quota/project.c +4
-2@@ -157,7 +157,8 @@ clear_project( fa.fa_projid =0 ; fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT ; - error =xfrog_file_setattr (dfd, path, stat, &fa,AT_SYMLINK_NOFOLLOW ); + error =xfrog_file_setattr (dfd, path, stat->st_mode, &fa, +AT_SYMLINK_NOFOLLOW );if (error) {fprintf (stderr,_ ("%s: cannot clear project on %s: %s\n" ), progname, path,strerror (errno));@@ -205,7 +206,8 @@ setup_project(if (S_ISDIR (stat->st_mode)) fa.fa_xflags |=FS_XFLAG_PROJINHERIT ; - error =xfrog_file_setattr (dfd, path, stat, &fa,AT_SYMLINK_NOFOLLOW ); + error =xfrog_file_setattr (dfd, path, stat->st_mode, &fa, +AT_SYMLINK_NOFOLLOW );if (error) {fprintf (stderr,_ ("%s: cannot set project on %s: %s\n" ), progname, path,strerror (errno));
Signature · 1 line
- Andrey
Re: [PATCH 2/2] libfrog: pass mode to xfrog_file_setattr
Quoted 9 lines · Andrey Albershteyn
Quoted 4 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xfs/633 crashes
rdump_fileattrs_pathpasses a NULL struct stat pointer and then the fallback code dereferences it to get the file mode.Oh is it latest xfsprogs with older kernel (without file_[g]etattr)?
(I see this on 6.16)
Yes, the crash happens on 6.16-rc7 where there is no file_setattr call, and does not happen on for-next where file_setattr does exist.
Quoted 21 lines
Quoted 21 lines
Instead, let's just pass the stat mode directly to it, because that's the only piece of information that it needs.
Fixes 128ac4dadbd633 ("xfs_db: use file_setattr to copy attributes on special files with rdump")Signed-off-by "Darrick J. Wong" <[email protected]>--- libfrog/file_attr.h | 9 ++------- db/rdump.c | 4 ++-- io/attr.c | 4 ++-- libfrog/file_attr.c | 4 ++-- quota/project.c | 6 ++++-- 5 files changed, 12 insertions(+), 15 deletions(-)libfrog/file_attr.h +0
-0@@ -24,12 +24,7 @@ xfrog_file_getattr(struct file_attr *fa, const unsigned int at_flags);
Quoted 12 lines
libfrog/file_attr.h xfrog_file_getattr( · line 28
Quoted 9 lines
libfrog/file_attr.h +2
-7-int -xfrog_file_setattr ( -const int dfd, -const char *path, -const struct stat *stat, -struct file_attr *fa, -const unsigned int at_flags); +int xfrog_file_setattr (const int dfd,const char *path,const mode_t mode, +struct file_attr *fa,const unsigned int at_flags);Is this formatting change intentional? (maybe then the
xfrog_file_getattralso)
Yes, compressed is the usual style for function declarations. It's only the definition that gets the expanded format.
(I didn't hassle you about it when you submitted the original patch because I'm trying to stop doing that to people ;))
Quoted 2 lines
otherwise lgtm
Reviewed-by Andrey Albershteyn <[email protected]>
Thanks!
--D
Quoted 91 lines
Quoted 86 lines
libfrog/file_attr.h +0
-0#endif /* __LIBFROG_FILE_ATTR_H__ */ db/rdump.c +2
-2@@ -188,8 +188,8 @@ rdump_fileattrs_path(return 1 ; } - ret =xfrog_file_setattr (destdir->fd, pbuf->path,NULL , &fa, -AT_SYMLINK_NOFOLLOW ); + ret =xfrog_file_setattr (destdir->fd, pbuf->path,VFS_I (ip)->i_mode, + &fa,AT_SYMLINK_NOFOLLOW );if (ret) {if (errno ==EOPNOTSUPP || errno ==EPERM || errno ==ENOTTY ) lost_mask |=LOST_FSXATTR ;io/attr.c +2
-2@@ -261,7 +261,7 @@ chattr_callback( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error =xfrog_file_setattr (AT_FDCWD , path, stat, &attr, + error =xfrog_file_setattr (AT_FDCWD , path, stat->st_mode, &attr,AT_SYMLINK_NOFOLLOW );if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),@@ -357,7 +357,7 @@ chattr_f( attr.fa_xflags |= orflags; attr.fa_xflags &= ~andflags; - error =xfrog_file_setattr (AT_FDCWD , name, &st, &attr, + error =xfrog_file_setattr (AT_FDCWD , name, st.st_mode, &attr,AT_SYMLINK_NOFOLLOW );if (error) { fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),libfrog/file_attr.c +2
-2@@ -85,7 +85,7 @@ intxfrog_file_setattr ( const int dfd, const char *path, - const struct stat *stat, + const mode_t mode, struct file_attr *fa, const unsigned int at_flags) {@@ -103,7 +103,7 @@ xfrog_file_setattr(return error;#endif -if (SPECIAL_FILE (stat->st_mode)) { +if (SPECIAL_FILE (mode)) { errno =EOPNOTSUPP ;return -1 ; }quota/project.c +4
-2@@ -157,7 +157,8 @@ clear_project( fa.fa_projid =0 ; fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT ; - error =xfrog_file_setattr (dfd, path, stat, &fa,AT_SYMLINK_NOFOLLOW ); + error =xfrog_file_setattr (dfd, path, stat->st_mode, &fa, +AT_SYMLINK_NOFOLLOW );if (error) {fprintf (stderr,_ ("%s: cannot clear project on %s: %s\n" ), progname, path,strerror (errno));@@ -205,7 +206,8 @@ setup_project(if (S_ISDIR (stat->st_mode)) fa.fa_xflags |=FS_XFLAG_PROJINHERIT ; - error =xfrog_file_setattr (dfd, path, stat, &fa,AT_SYMLINK_NOFOLLOW ); + error =xfrog_file_setattr (dfd, path, stat->st_mode, &fa, +AT_SYMLINK_NOFOLLOW );if (error) {fprintf (stderr,_ ("%s: cannot set project on %s: %s\n" ), progname, path,strerror (errno));Signature · 1 line
- Andrey
Quoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
libxfs functions return negative errno, so utilities must invert the return values from such functions. Caught by xfs/437.
Fixes 8a4ea72724930c ("proto: add ability to populate a filesystem from a directory")Signed-off-by "Darrick J. Wong" <[email protected]>
lgtm
Quoted 18 lines
--- mkfs/proto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mkfs/proto.c +1
-1@@ -1425,7 +1425,7 @@ handle_hardlink(if (dst_ino ==0 )return false; - error =libxfs_iget (mp,NULL , dst_ino,0 , &ip); + error = -libxfs_iget (mp,NULL , dst_ino,0 , &ip);if (error)fail (_ ("failed to get inode" ), error);
Signature · 1 line
- Andrey