improve libxfs device handling
Hi all,
this series how libxfs deals with the data, log and rt devices. A lot of it is just tidying up cruft old code, but it then introduces a libxfs_dev structure that describes a single device to further simplify the code.
Diffstat:
copy/xfs_copy.c | 19 -- db/crc.c | 2 db/fuzz.c | 2 db/info.c | 2 db/init.c | 29 +-- db/init.h | 3 db/metadump.c | 4 db/output.c | 2 db/sb.c | 18 +- db/write.c | 2 growfs/xfs_growfs.c | 24 +-- include/libxfs.h | 87 +++++------ include/libxlog.h | 7 include/xfs_mount.h | 3 libfrog/linux.c | 39 +---- libfrog/platform.h | 6 libxfs/init.c | 398 +++++++++++++++------------------------------------- libxfs/libxfs_io.h | 5 libxfs/rdwr.c | 16 -- libxfs/topology.c | 23 +-- libxfs/topology.h | 4 libxlog/util.c | 49 +++--- logprint/logprint.c | 79 ++++------ mkfs/xfs_mkfs.c | 249 +++++++++++++------------------- repair/globals.h | 2 repair/init.c | 40 ++--- repair/phase2.c | 27 --- repair/prefetch.c | 2 repair/protos.h | 2 repair/sb.c | 18 +- repair/xfs_repair.c | 15 - 31 files changed, 453 insertions(+), 725 deletions(-)
PATCH 1/23 libxfs: remove the unused icache_flags member from struct libxfs_xinit
--- include/libxfs.h | 1 - 1 file changed, 1 deletion(-)
include/libxfs.h +0 -1
@@ -124,7 +124,6 @@ typedef struct libxfs_xinit {int dfd;/* data subvolume file descriptor */ int logfd;/* log subvolume file descriptor */ int rtfd;/* realtime subvolume file descriptor */ -int icache_flags;/* cache init flags */ int bcache_flags;/* cache init flags */ } libxfs_init_t;
Signature · 1 line
2.39.2
Re: [PATCH 01/23] libxfs: remove the unused icache_flags member from struct libxfs_xinit
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 20 lines
--- include/libxfs.h | 1 - 1 file changed, 1 deletion(-)include/libxfs.h +0
-2@@ -124,7 +124,6 @@ typedef struct libxfs_xinit {int dfd;/* data subvolume file descriptor */ int logfd;/* log subvolume file descriptor */ int rtfd;/* realtime subvolume file descriptor */ -int icache_flags;/* cache init flags */ int bcache_flags;/* cache init flags */ } libxfs_init_t; --2.39.2
PATCH 2/23 libxfs: remove the dead {d,log,rt}path variables in libxfs_init
In reply to Christoph HellwigThese variables are only initialized, and then unlink is called if they were changed from the initial value, which can't happen. Remove the variables and the conditional unlink calls.
--- libxfs/init.c | 10 ---------- 1 file changed, 10 deletions(-)
libxfs/init.c +0 -10
@@ -307,17 +307,13 @@ libxfs_init(libxfs_init_t *a) {char *blockfile;char *dname; -char dpath[25 ];int fd;char *logname; -char logpath[25 ];char *rawfile;char *rtname; -char rtpath[25 ];int rval =0 ;int flags; - dpath[0 ] = logpath[0 ] = rtpath[0 ] ='\0' ; dname = a->dname; logname = a->logname; rtname = a->rtname;
@@ -418,12 +414,6 @@ libxfs_init(libxfs_init_t *a)init_caches (); rval =1 ; done: -if (dpath[0 ]) -unlink (dpath); -if (logpath[0 ]) -unlink (logpath); -if (rtpath[0 ]) -unlink (rtpath);if (fd >=0 )close (fd);if (!rval) {
Signature · 1 line
2.39.2
Re: [PATCH 02/23] libxfs: remove the dead {d,log,rt}path variables in libxfs_init
Quoted 5 lines · Christoph Hellwig
These variables are only initialized, and then unlink is called if they were changed from the initial value, which can't happen. Remove the variables and the conditional unlink calls.
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 42 lines
--- libxfs/init.c | 10 ---------- 1 file changed, 10 deletions(-)libxfs/init.c +0
-11@@ -307,17 +307,13 @@ libxfs_init(libxfs_init_t *a) {char *blockfile;char *dname; -char dpath[25 ];int fd;char *logname; -char logpath[25 ];char *rawfile;char *rtname; -char rtpath[25 ];int rval =0 ;int flags; - dpath[0 ] = logpath[0 ] = rtpath[0 ] ='\0' ; dname = a->dname; logname = a->logname; rtname = a->rtname;@@ -418,12 +414,6 @@ libxfs_init(libxfs_init_t *a)init_caches (); rval =1 ; done: -if (dpath[0 ]) -unlink (dpath); -if (logpath[0 ]) -unlink (logpath); -if (rtpath[0 ]) -unlink (rtpath);if (fd >=0 )close (fd);if (!rval) { --2.39.2
PATCH 3/23 libxfs/frog: remove latform_find{raw,block}path
In reply to Christoph HellwigStop pretending we try to distinguish between the legacy Unix raw and block devices nodes. Linux as the only currently support platform never had them, but other modern Unix variants like FreeBSD also got rid of this distinction years ago.
--- libfrog/linux.c | 12 ------------ libfrog/platform.h | 2 -- libxfs/init.c | 42 ++++++++++++++---------------------------- 3 files changed, 14 insertions(+), 42 deletions(-)
libfrog/linux.c +0 -12
@@ -232,18 +232,6 @@ platform_findsizes(char *path, int fd, long long *sz, int *bsz) max_block_alignment = *bsz; } -char * -platform_findrawpath (char *path) -{ -return path; -} - -char * -platform_findblockpath (char *path) -{ -return path; -} -int platform_direct_blockdev (void ) {
libfrog/platform.h +0 -2
@@ -13,8 +13,6 @@ int platform_check_iswritable(char *path, char *block, struct stat *sptr);int platform_set_blocksize (int fd,char *path,dev_t device,int bsz,int fatal);int platform_flush_device (int fd,dev_t device); -char *platform_findrawpath (char *path); -char *platform_findblockpath (char *path);int platform_direct_blockdev (void );int platform_align_blockdev (void );unsigned long platform_physmem (void );/* in kilobytes */
libxfs/init.c +14 -28
99 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH 03/23] libxfs/frog: remove latform_find{raw,block}path
Quoted 6 lines · Christoph Hellwig
Stop pretending we try to distinguish between the legacy Unix raw and block devices nodes. Linux as the only currently support platform never had them, but other modern Unix variants like FreeBSD also got rid of this distinction years ago.
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 156 lines
--- libfrog/linux.c | 12 ------------ libfrog/platform.h | 2 -- libxfs/init.c | 42 ++++++++++++++---------------------------- 3 files changed, 14 insertions(+), 42 deletions(-)libfrog/linux.c +0
-12@@ -232,18 +232,6 @@ platform_findsizes(char *path, int fd, long long *sz, int *bsz) max_block_alignment = *bsz; } -char * -platform_findrawpath (char *path) -{ -return path; -} - -char * -platform_findblockpath (char *path) -{ -return path; -} -int platform_direct_blockdev (void ) {libfrog/platform.h +0
-2@@ -13,8 +13,6 @@ int platform_check_iswritable(char *path, char *block, struct stat *sptr);int platform_set_blocksize (int fd,char *path,dev_t device,int bsz,int fatal);int platform_flush_device (int fd,dev_t device); -char *platform_findrawpath (char *path); -char *platform_findblockpath (char *path);int platform_direct_blockdev (void );int platform_align_blockdev (void );unsigned long platform_physmem (void );/* in kilobytes */ libxfs/init.c +14
-29@@ -197,7 +197,7 @@ libxfs_device_close(dev_t dev) }static int -check_open (char *path,int flags,char **rawfile,char **blockfile) +check_open (char *path,int flags) {int readonly = (flags &LIBXFS_ISREADONLY );int inactive = (flags &LIBXFS_ISINACTIVE );@@ -208,22 +208,10 @@ check_open(char *path, int flags, char **rawfile, char **blockfile)perror (path);return 0 ; } -if (!(*rawfile =platform_findrawpath (path))) { -fprintf (stderr,_ ("%s: " -"can't find a character device matching %s\n" ), - progname, path); -return 0 ; - } -if (!(*blockfile =platform_findblockpath (path))) { -fprintf (stderr,_ ("%s: " -"can't find a block device matching %s\n" ), - progname, path); -return 0 ; - } -if (!readonly && !inactive &&platform_check_ismounted (path, *blockfile,NULL ,1 )) +if (!readonly && !inactive &&platform_check_ismounted (path, path,NULL ,1 ))return 0 ; -if (inactive &&check_isactive (path, *blockfile, ((readonly|dangerously)?1 :0 ))) +if (inactive &&check_isactive (path, path, ((readonly|dangerously)?1 :0 )))return 0 ;return 1 ;@@ -305,11 +293,9 @@ libxfs_close_devices(int libxfs_init (libxfs_init_t *a) { -char *blockfile;char *dname;int fd;char *logname; -char *rawfile;char *rtname;int rval =0 ;int flags;@@ -330,9 +316,9 @@ libxfs_init(libxfs_init_t *a)radix_tree_init ();if (a->volname) { -if (!check_open (a->volname,flags,&rawfile,&blockfile)) +if (!check_open (a->volname, flags)) goto done; - fd =open (rawfile,O_RDONLY ); + fd =open (a->volname,O_RDONLY ); dname = a->dname = a->volname; a->volname =NULL ; }@@ -344,12 +330,12 @@ libxfs_init(libxfs_init_t *a)platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); }else { -if (!check_open (dname, flags, &rawfile, &blockfile)) +if (!check_open (dname, flags)) goto done; - a->ddev =libxfs_device_open (rawfile, + a->ddev =libxfs_device_open (dname, a->dcreat, flags, a->setblksize); a->dfd =libxfs_device_to_fd (a->ddev); -platform_findsizes (rawfile, a->dfd, +platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); } }else @@ -362,12 +348,12 @@ libxfs_init(libxfs_init_t *a)platform_findsizes (dname, a->logfd, &a->logBBsize, &a->lbsize); }else { -if (!check_open (logname, flags, &rawfile, &blockfile)) +if (!check_open (logname, flags)) goto done; - a->logdev =libxfs_device_open (rawfile, + a->logdev =libxfs_device_open (logname, a->lcreat, flags, a->setblksize); a->logfd =libxfs_device_to_fd (a->logdev); -platform_findsizes (rawfile, a->logfd, +platform_findsizes (logname, a->logfd, &a->logBBsize, &a->lbsize); } }else @@ -380,12 +366,12 @@ libxfs_init(libxfs_init_t *a)platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); }else { -if (!check_open (rtname, flags, &rawfile, &blockfile)) +if (!check_open (rtname, flags)) goto done; - a->rtdev =libxfs_device_open (rawfile, + a->rtdev =libxfs_device_open (rtname, a->rcreat, flags, a->setblksize); a->rtfd =libxfs_device_to_fd (a->rtdev); -platform_findsizes (rawfile, a->rtfd, +platform_findsizes (rtname, a->rtfd, &a->rtsize, &a->rtbsize); } }else --2.39.2
PATCH 4/23 libxfs: remove the volname concept
In reply to Christoph HellwigIRIX has the concept of a volume that has data/log/rt subvolumes (that's where the subvolume name in Linux comes from), but in the current Linux-only xfsprogs version trying to pretend we do anything with that it is just utterly confusing. The volname is basically just a very obsfucated second way to pass the data device name, so get rid of it in the libxfs and progs internals.
--- copy/xfs_copy.c | 7 ++---- db/info.c | 2 +- db/init.c | 13 +++------- db/init.h | 1 - db/output.c | 2 +- include/libxfs.h | 1 - libxfs/init.c | 24 ++++-------------- libxfs/topology.c | 10 ++++---- mkfs/xfs_mkfs.c | 63 ++++++++++------------------------------------- repair/init.c | 11 ++------- 10 files changed, 33 insertions(+), 101 deletions(-)
copy/xfs_copy.c +2 -5
@@ -718,11 +718,8 @@ main(int argc, char **argv) xargs.isdirect =LIBXFS_DIRECT ; xargs.isreadonly =LIBXFS_ISREADONLY ; -if (source_is_file) { - xargs.dname = source_name; - xargs.disfile =1 ; - }else - xargs.volname = source_name; + xargs.dname = source_name; + xargs.disfile = source_is_file;if (!libxfs_init (&xargs)) { do_log(_("%s: couldn't initialize XFS library\n"
db/info.c +1 -1
@@ -30,7 +30,7 @@ info_f(struct xfs_fsop_geom geo;libxfs_fs_geometry (mp, &geo,XFS_FS_GEOM_MAX_STRUCT_VER ); -xfs_report_geom (&geo, fsdevice, x.logname, x.rtname); +xfs_report_geom (&geo, x.dname, x.logname, x.rtname);return 0 ; }
db/init.c +4 -9
@@ -19,7 +19,6 @@static char **cmdline;static int ncmdline; -char *fsdevice;int blkbb;int exitcode;int expert_mode;
@@ -91,11 +90,7 @@ init(if (optind +1 != argc)usage (); - fsdevice = argv[optind]; -if (!x.disfile) - x.volname = fsdevice; -else - x.dname = fsdevice; + x.dname = argv[optind]; x.isdirect =LIBXFS_DIRECT ; x.bcache_flags =CACHE_MISCOMPARE_PURGE ;
@@ -115,7 +110,7 @@ init( 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL);if (error) {fprintf (stderr,_ ("%s: %s is invalid (cannot read first 512 " -"bytes)\n" ), progname, fsdevice); +"bytes)\n" ), progname, x.dname);exit (1 ); }
@@ -126,7 +121,7 @@ init( sbp = &xmount.m_sb;if (sbp->sb_magicnum !=XFS_SB_MAGIC ) {fprintf (stderr,_ ("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n" ), - progname, fsdevice, sbp->sb_magicnum); + progname, x.dname, sbp->sb_magicnum);if (!force) {fprintf (stderr,_ ("Use -F to force a read attempt.\n" ));exit (EXIT_FAILURE );
@@ -139,7 +134,7 @@ init(if (!mp) {fprintf (stderr,_ ("%s: device %s unusable (not an XFS filesystem?)\n" ), - progname, fsdevice); + progname, x.dname);exit (1 ); } mp->m_log = &xlog;
db/init.h +0 -1
@@ -4,7 +4,6 @@* All Rights Reserved. */ -extern char *fsdevice;extern int blkbb;extern int exitcode;extern int expert_mode;
db/output.c +1 -1
@@ -34,7 +34,7 @@ dbprintf(const char *fmt, ...)blockint (); i =0 ;if (dbprefix) - i +=printf ("%s: " , fsdevice); + i +=printf ("%s: " , x.dname); i +=vprintf (fmt, ap);unblockint ();va_end (ap);
include/libxfs.h +0 -1
@@ -94,7 +94,6 @@ struct iomap;*/ typedef struct libxfs_xinit { /* input parameters */ - char *volname; /* pathname of volume */ char *dname; /* pathname of data "subvolume" */ char *logname; /* pathname of log "subvolume" */ char *rtname; /* pathname of realtime "subvolume" */
libxfs/init.c +5 -19
@@ -294,10 +294,8 @@ int libxfs_init(libxfs_init_t *a) {char *dname; -int fd;char *logname;char *rtname; -int rval =0 ;int flags; dname = a->dname;
@@ -308,20 +306,12 @@ libxfs_init(libxfs_init_t *a) a->dsize = a->lbsize = a->rtbsize =0 ; a->dbsize = a->logBBsize = a->logBBstart = a->rtsize =0 ; - fd =-1 ; flags = (a->isreadonly | a->isdirect);rcu_init ();rcu_register_thread ();radix_tree_init (); -if (a->volname) { -if (!check_open (a->volname, flags)) - goto done; - fd =open (a->volname,O_RDONLY ); - dname = a->dname = a->volname; - a->volname =NULL ; - }if (dname) {if (a->disfile) { a->ddev= libxfs_device_open(dname, a->dcreat, flags,
@@ -398,16 +388,12 @@ libxfs_init(libxfs_init_t *a) use_xfs_buf_lock = a->usebuflock;xfs_dir_startup ();init_caches (); - rval =1 ; -done: -if (fd >=0 ) -close (fd); -if (!rval) { -libxfs_close_devices (a); -rcu_unregister_thread (); - } +return 1 ; -return rval; +done: +libxfs_close_devices (a); +rcu_unregister_thread (); +return 0 ; }
libxfs/topology.c +5 -5
@@ -292,7 +292,6 @@ void get_topology( int force_overwrite) {struct stat statbuf; -char *dfile = xi->volname ? xi->volname : xi->dname;/* * If our target is a regular file, use platform_findsizes
@@ -300,7 +299,7 @@ void get_topology(* for direct IO; we'll set our sector size to that if possible. */ if (xi->disfile || - (!stat (dfile, &statbuf) &&S_ISREG (statbuf.st_mode))) { + (!stat (xi->dname, &statbuf) &&S_ISREG (statbuf.st_mode))) {int fd;int flags =O_RDONLY ;long long dummy;
@@ -309,15 +308,16 @@ void get_topology(if (xi->disfile) flags |=O_CREAT ; - fd =open (dfile, flags,0666 ); + fd =open (xi->dname, flags,0666 );if (fd >=0 ) { -platform_findsizes (dfile, fd, &dummy, &ft->lsectorsize); +platform_findsizes (xi->dname, fd, &dummy, + &ft->lsectorsize);close (fd); ft->psectorsize = ft->lsectorsize; }else ft->psectorsize = ft->lsectorsize =BBSIZE ; }else { -blkid_get_topology (dfile, &ft->dsunit, &ft->dswidth, +blkid_get_topology (xi->dname, &ft->dsunit, &ft->dswidth, &ft->lsectorsize, &ft->psectorsize, force_overwrite); }
mkfs/xfs_mkfs.c +13 -50
152 lines not on this page · raw message
repair/init.c +2 -9
@@ -54,15 +54,8 @@ xfs_init(libxfs_init_t *args) {memset (args,0 ,sizeof (libxfs_init_t)); -if (isa_file) { - args->disfile =1 ; - args->dname = fs_name; - args->volname =NULL ; - }else { - args->disfile =0 ; - args->volname = fs_name; - args->dname =NULL ; - } + args->dname = fs_name; + args->disfile = isa_file;if (log_spec) {/* External log specified */ args->logname = log_name;
Signature · 1 line
2.39.2
Re: [PATCH 04/23] libxfs: remove the volname concept
Quoted 6 lines · Christoph Hellwig
IRIX has the concept of a volume that has data/log/rt subvolumes (that's where the subvolume name in Linux comes from), but in the current Linux-only xfsprogs version trying to pretend we do anything with that it is just utterly confusing. The volname is basically just a very obsfucated second way to pass the data device name, so get rid of it in the libxfs and progs internals.
And thanks for the history lecture.
Carlos
Quoted 427 lines
Signed-off-by Christoph Hellwig <[email protected]>--- copy/xfs_copy.c | 7 ++---- db/info.c | 2 +- db/init.c | 13 +++------- db/init.h | 1 - db/output.c | 2 +- include/libxfs.h | 1 - libxfs/init.c | 24 ++++-------------- libxfs/topology.c | 10 ++++---- mkfs/xfs_mkfs.c | 63 ++++++++++------------------------------------- repair/init.c | 11 ++------- 10 files changed, 33 insertions(+), 101 deletions(-)copy/xfs_copy.c +2
-5@@ -718,11 +718,8 @@ main(int argc, char **argv) xargs.isdirect =LIBXFS_DIRECT ; xargs.isreadonly =LIBXFS_ISREADONLY ; -if (source_is_file) { - xargs.dname = source_name; - xargs.disfile =1 ; - }else - xargs.volname = source_name; + xargs.dname = source_name; + xargs.disfile = source_is_file;if (!libxfs_init (&xargs)) { do_log(_("%s: couldn't initialize XFS library\n"db/info.c +1
-1@@ -30,7 +30,7 @@ info_f(struct xfs_fsop_geom geo;libxfs_fs_geometry (mp, &geo,XFS_FS_GEOM_MAX_STRUCT_VER ); -xfs_report_geom (&geo, fsdevice, x.logname, x.rtname); +xfs_report_geom (&geo, x.dname, x.logname, x.rtname);return 0 ; }db/init.c +4
-9@@ -19,7 +19,6 @@static char **cmdline;static int ncmdline; -char *fsdevice;int blkbb;int exitcode;int expert_mode;@@ -91,11 +90,7 @@ init(if (optind +1 != argc)usage (); - fsdevice = argv[optind]; -if (!x.disfile) - x.volname = fsdevice; -else - x.dname = fsdevice; + x.dname = argv[optind]; x.isdirect =LIBXFS_DIRECT ; x.bcache_flags =CACHE_MISCOMPARE_PURGE ;@@ -115,7 +110,7 @@ init( 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL);if (error) {fprintf (stderr,_ ("%s: %s is invalid (cannot read first 512 " -"bytes)\n" ), progname, fsdevice); +"bytes)\n" ), progname, x.dname);exit (1 ); }@@ -126,7 +121,7 @@ init( sbp = &xmount.m_sb;if (sbp->sb_magicnum !=XFS_SB_MAGIC ) {fprintf (stderr,_ ("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n" ), - progname, fsdevice, sbp->sb_magicnum); + progname, x.dname, sbp->sb_magicnum);if (!force) {fprintf (stderr,_ ("Use -F to force a read attempt.\n" ));exit (EXIT_FAILURE );@@ -139,7 +134,7 @@ init(if (!mp) {fprintf (stderr,_ ("%s: device %s unusable (not an XFS filesystem?)\n" ), - progname, fsdevice); + progname, x.dname);exit (1 ); } mp->m_log = &xlog;db/init.h +0
-1@@ -4,7 +4,6 @@* All Rights Reserved. */ -extern char *fsdevice;extern int blkbb;extern int exitcode;extern int expert_mode;db/output.c +1
-1@@ -34,7 +34,7 @@ dbprintf(const char *fmt, ...)blockint (); i =0 ;if (dbprefix) - i +=printf ("%s: " , fsdevice); + i +=printf ("%s: " , x.dname); i +=vprintf (fmt, ap);unblockint ();va_end (ap);include/libxfs.h +0
-1@@ -94,7 +94,6 @@ struct iomap;*/ typedef struct libxfs_xinit { /* input parameters */ - char *volname; /* pathname of volume */ char *dname; /* pathname of data "subvolume" */ char *logname; /* pathname of log "subvolume" */ char *rtname; /* pathname of realtime "subvolume" */libxfs/init.c +5
-19@@ -294,10 +294,8 @@ int libxfs_init(libxfs_init_t *a) {char *dname; -int fd;char *logname;char *rtname; -int rval =0 ;int flags; dname = a->dname;@@ -308,20 +306,12 @@ libxfs_init(libxfs_init_t *a) a->dsize = a->lbsize = a->rtbsize =0 ; a->dbsize = a->logBBsize = a->logBBstart = a->rtsize =0 ; - fd =-1 ; flags = (a->isreadonly | a->isdirect);rcu_init ();rcu_register_thread ();radix_tree_init (); -if (a->volname) { -if (!check_open (a->volname, flags)) - goto done; - fd =open (a->volname,O_RDONLY ); - dname = a->dname = a->volname; - a->volname =NULL ; - }if (dname) {if (a->disfile) { a->ddev= libxfs_device_open(dname, a->dcreat, flags,@@ -398,16 +388,12 @@ libxfs_init(libxfs_init_t *a) use_xfs_buf_lock = a->usebuflock;xfs_dir_startup ();init_caches (); - rval =1 ; -done: -if (fd >=0 ) -close (fd); -if (!rval) { -libxfs_close_devices (a); -rcu_unregister_thread (); - } +return 1 ; -return rval; +done: +libxfs_close_devices (a); +rcu_unregister_thread (); +return 0 ; }libxfs/topology.c +5
-5@@ -292,7 +292,6 @@ void get_topology( int force_overwrite) {struct stat statbuf; -char *dfile = xi->volname ? xi->volname : xi->dname;/* * If our target is a regular file, use platform_findsizes @@ -300,7 +299,7 @@ void get_topology(* for direct IO; we'll set our sector size to that if possible. */ if (xi->disfile || - (!stat (dfile, &statbuf) &&S_ISREG (statbuf.st_mode))) { + (!stat (xi->dname, &statbuf) &&S_ISREG (statbuf.st_mode))) {int fd;int flags =O_RDONLY ;long long dummy;@@ -309,15 +308,16 @@ void get_topology(if (xi->disfile) flags |=O_CREAT ; - fd =open (dfile, flags,0666 ); + fd =open (xi->dname, flags,0666 );if (fd >=0 ) { -platform_findsizes (dfile, fd, &dummy, &ft->lsectorsize); +platform_findsizes (xi->dname, fd, &dummy, + &ft->lsectorsize);close (fd); ft->psectorsize = ft->lsectorsize; }else ft->psectorsize = ft->lsectorsize =BBSIZE ; }else { -blkid_get_topology (dfile, &ft->dsunit, &ft->dswidth, +blkid_get_topology (xi->dname, &ft->dsunit, &ft->dswidth, &ft->lsectorsize, &ft->psectorsize, force_overwrite); }mkfs/xfs_mkfs.c +13
-50@@ -1959,7 +1959,6 @@ validate_sectorsize(struct cli_params *cli, struct mkfs_default_params *dft, struct fs_topology *ft, - char *dfile, int dry_run, int force_overwrite) {@@ -1967,7 +1966,8 @@ validate_sectorsize(* Before anything else, verify that we are correctly operating on * files or block devices and set the control parameters correctly. */ -check_device_type (dfile, &cli->xi->disfile, !cli->dsize, !dfile, +check_device_type (cli->xi->dname, &cli->xi->disfile, + !cli->dsize, !cli->xi->dname, dry_run ?NULL : &cli->xi->dcreat,"d" );if (!cli->loginternal) check_device_type(cli->xi->logname, &cli->xi->lisfile,@@ -2929,36 +2929,17 @@ reported by the device (%u).\n"), } } -/* -* This is more complex than it needs to be because we still support volume -* based external logs. They are only discovered *after* the devices have been -* opened, hence the crazy "is this really an internal log" checks here. -*/ static void validate_logdev (struct mkfs_params *cfg, -struct cli_params *cli, -char **devname) +struct cli_params *cli) {struct libxfs_xinit *xi = cli->xi; - *devname =NULL ; - -/* check for volume log first */ -if (cli->loginternal && xi->volname && xi->logdev) { - *devname =_ ("volume log" ); - cfg->loginternal = false; - }else - cfg->loginternal = cli->loginternal; + cfg->loginternal = cli->loginternal;/* now run device checks */ if (cfg->loginternal) { -if (xi->logdev) { -fprintf (stderr, -_ ("can't have both external and internal logs\n" )); -usage (); - } -/* * if no sector size has been specified on the command line, * use what has been configured and validated for the data @@ -2980,14 +2961,11 @@ _("log size %lld too large for internal log\n"), (long long)cfg->logblocks);usage (); } - *devname =_ ("internal log" );return ; }/* External/log subvolume checks */ -if (xi->logname) - *devname = xi->logname; -if (!*devname || !xi->logdev) { +if (!*xi->logname || !xi->logdev) {fprintf (stderr,_ ("no log subvolume or external log.\n" ));usage (); }@@ -3018,13 +2996,10 @@ reported by the device (%u).\n"),static void validate_rtdev (struct mkfs_params *cfg, -struct cli_params *cli, -char **devname) +struct cli_params *cli) {struct libxfs_xinit *xi = cli->xi; - *devname =NULL ; -if (!xi->rtdev) {if (cli->rtsize) { fprintf(stderr,@@ -3032,7 +3007,6 @@ _("size specified for non-existent rt subvolume\n"));usage (); } - *devname =_ ("none" ); cfg->rtblocks =0 ; cfg->rtextents =0 ; cfg->rtbmblocks =0 ;@@ -3043,12 +3017,6 @@ _("size specified for non-existent rt subvolume\n"));usage (); } -/* volume rtdev */ -if (xi->volname) - *devname =_ ("volume rt" ); -else - *devname = xi->rtname; -if (cli->rtsize) {if (cfg->rtblocks >DTOBT (xi->rtsize, cfg->blocklog)) { fprintf(stderr,@@ -4080,9 +4048,6 @@ main(xfs_agnumber_t agno;struct xfs_buf *buf;int c; -char *dfile =NULL ; -char *logfile =NULL ; -char *rtfile =NULL ;int dry_run =0 ;int discard =1 ;int force_overwrite =0 ;@@ -4222,9 +4187,8 @@ main(fprintf (stderr,_ ("extra arguments\n" ));usage (); }else if (argc - optind ==1 ) { - dfile = xi.volname =getstr (argv[optind], &dopts,D_NAME ); - }else - dfile = xi.dname; + xi.dname =getstr (argv[optind], &dopts,D_NAME ); + }/* * Now we have all the options parsed, we can read in the option file @@ -4241,8 +4205,7 @@ main(* before opening the libxfs devices. */ validate_blocksize (&cfg, &cli, &dft); -validate_sectorsize (&cfg, &cli, &dft, &ft, dfile, dry_run, - force_overwrite); +validate_sectorsize (&cfg, &cli, &dft, &ft, dry_run, force_overwrite);/* * XXX: we still need to set block size and sector size global variables @@ -4277,10 +4240,10 @@ main(* Open and validate the device configurations */ open_devices (&cfg, &xi); -validate_overwrite (dfile, force_overwrite); +validate_overwrite (xi.dname, force_overwrite);validate_datadev (&cfg, &cli); -validate_logdev (&cfg, &cli, &logfile); -validate_rtdev (&cfg, &cli, &rtfile); +validate_logdev (&cfg, &cli); +validate_rtdev (&cfg, &cli);calc_stripe_factors (&cfg, &cli, &ft);/* @@ -4321,7 +4284,7 @@ main(struct xfs_fsop_geom geo;libxfs_fs_geometry (mp, &geo,XFS_FS_GEOM_MAX_STRUCT_VER ); -xfs_report_geom (&geo, dfile, logfile, rtfile); +xfs_report_geom (&geo, xi.dname, xi.logname, xi.rtname);if (dry_run)exit (0 ); }repair/init.c +2
-10@@ -54,15 +54,8 @@ xfs_init(libxfs_init_t *args) {memset (args,0 ,sizeof (libxfs_init_t)); -if (isa_file) { - args->disfile =1 ; - args->dname = fs_name; - args->volname =NULL ; - }else { - args->disfile =0 ; - args->volname = fs_name; - args->dname =NULL ; - } + args->dname = fs_name; + args->disfile = isa_file;if (log_spec) {/* External log specified */ args->logname = log_name; --2.39.2
PATCH 5/23 xfs_logprint: move all code to set up the fake xlog into logstat()
In reply to Christoph HellwigIsolate the code that sets up the fake xlog into the logstat() helper to prepare for upcoming changes.
--- logprint/logprint.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
logprint/logprint.c +11 -10
@@ -52,7 +52,9 @@ Options:\n\ }static int -logstat (xfs_mount_t *mp) +logstat ( +struct xfs_mount *mp, +struct xlog *log) {int fd;char buf[BBSIZE ];
@@ -103,6 +105,11 @@ logstat(xfs_mount_t *mp) x.lbsize =BBSIZE ; } + log->l_dev = mp->m_logdev_targp; + log->l_logBBstart = x.logBBstart; + log->l_logBBsize = x.logBBsize; + log->l_sectBBsize =BTOBB (x.lbsize); + log->l_mp = mp;if (x.logname && *x.logname) {/* External log */ if ((fd =open (x.logname,O_RDONLY )) ==-1 ) {
@@ -212,8 +219,8 @@ main(int argc, char **argv)if (!libxfs_init (&x))exit (1 ); -logstat (&mount);libxfs_buftarg_init (&mount, x.ddev, x.logdev, x.rtdev); +logstat (&mount, &log); logfd = (x.logfd <0 ) ? x.dfd : x.logfd;
@@ -226,15 +233,9 @@ main(int argc, char **argv) }printf (_ ("daddr: %lld length: %lld\n\n" ), - (long long )x.logBBstart, (long long )x.logBBsize); + (long long )log.l_logBBstart, (long long )log.l_logBBsize); -ASSERT (x.logBBsize <=INT_MAX ); - - log.l_dev = mount.m_logdev_targp; - log.l_logBBstart = x.logBBstart; - log.l_logBBsize = x.logBBsize; - log.l_sectBBsize =BTOBB (x.lbsize); - log.l_mp = &mount; +ASSERT (log.l_logBBsize <=INT_MAX );switch (print_operation) {case OP_PRINT :
Signature · 1 line
2.39.2
Re: [PATCH 05/23] xfs_logprint: move all code to set up the fake xlog into logstat()
Quoted 4 lines · Christoph Hellwig
Isolate the code that sets up the fake xlog into the
logstat()helper to prepare for upcoming changes.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 62 lines
--- logprint/logprint.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)logprint/logprint.c +11
-11@@ -52,7 +52,9 @@ Options:\n\ }static int -logstat (xfs_mount_t *mp) +logstat ( +struct xfs_mount *mp, +struct xlog *log) {int fd;char buf[BBSIZE ];@@ -103,6 +105,11 @@ logstat(xfs_mount_t *mp) x.lbsize =BBSIZE ; } + log->l_dev = mp->m_logdev_targp; + log->l_logBBstart = x.logBBstart; + log->l_logBBsize = x.logBBsize; + log->l_sectBBsize =BTOBB (x.lbsize); + log->l_mp = mp;if (x.logname && *x.logname) {/* External log */ if ((fd =open (x.logname,O_RDONLY )) ==-1 ) {@@ -212,8 +219,8 @@ main(int argc, char **argv)if (!libxfs_init (&x))exit (1 ); -logstat (&mount);libxfs_buftarg_init (&mount, x.ddev, x.logdev, x.rtdev); +logstat (&mount, &log); logfd = (x.logfd <0 ) ? x.dfd : x.logfd;@@ -226,15 +233,9 @@ main(int argc, char **argv) }printf (_ ("daddr: %lld length: %lld\n\n" ), - (long long )x.logBBstart, (long long )x.logBBsize); + (long long )log.l_logBBstart, (long long )log.l_logBBsize); -ASSERT (x.logBBsize <=INT_MAX ); - - log.l_dev = mount.m_logdev_targp; - log.l_logBBstart = x.logBBstart; - log.l_logBBsize = x.logBBsize; - log.l_sectBBsize =BTOBB (x.lbsize); - log.l_mp = &mount; +ASSERT (log.l_logBBsize <=INT_MAX );switch (print_operation) {case OP_PRINT : --2.39.2
PATCH 6/23 libxlog: remove the verbose argument to xlog_is_dirty
In reply to Christoph HellwigNo caller passes a non-zero verbose argument to xlog_is_dirty. Remove the argument the code keyed off by it.
--- copy/xfs_copy.c | 2 +- db/metadump.c | 4 ++-- db/sb.c | 2 +- include/libxlog.h | 3 +-- libxlog/util.c | 8 +------- 5 files changed, 6 insertions(+), 13 deletions(-)
copy/xfs_copy.c +1 -1
@@ -784,7 +784,7 @@ main(int argc, char **argv)*/ memset (&xlog,0 ,sizeof (struct xlog )); mp->m_log = &xlog; - c =xlog_is_dirty (mp, mp->m_log, &xargs,0 ); + c =xlog_is_dirty (mp, mp->m_log, &xargs);if (!duplicate) {if (c ==1 ) { do_log(_(
db/metadump.c +2 -2
@@ -2615,7 +2615,7 @@ copy_log(void)if (!metadump.obfuscate && !metadump.zero_stale_data) goto done; - dirty =xlog_is_dirty (mp, &log, &x,0 ); + dirty =xlog_is_dirty (mp, &log, &x);switch (dirty) {case 0 :
@@ -2945,7 +2945,7 @@ metadump_f(if (iocur_top->data) {/* best effort */ struct xlog log; -if (xlog_is_dirty (mp, &log, &x,0 )) +if (xlog_is_dirty (mp, &log, &x)) metadump.dirty_log = true; }pop_cur ();
db/sb.c +1 -1
@@ -235,7 +235,7 @@ sb_logcheck(void)libxfs_buftarg_init (mp, x.ddev, x.logdev, x.rtdev); - dirty =xlog_is_dirty (mp, mp->m_log, &x,0 ); + dirty =xlog_is_dirty (mp, mp->m_log, &x);if (dirty ==-1 ) {dbprintf (_ ("ERROR: cannot find log head/tail, run xfs_repair\n" ));return 0 ;
include/libxlog.h +1 -2
@@ -71,9 +71,8 @@ extern int print_record_header;/* libxfs parameters */ extern libxfs_init_t x; +int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x); -extern int xlog_is_dirty (struct xfs_mount *,struct xlog *,libxfs_init_t *, -int );extern struct xfs_buf *xlog_get_bp (struct xlog *,int );extern int xlog_bread (struct xlog *log,xfs_daddr_t blk_no,int nbblks,struct xfs_buf *bp,char **offset);
libxlog/util.c +1 -7
@@ -19,8 +19,7 @@ intxlog_is_dirty ( struct xfs_mount *mp, struct xlog *log, - libxfs_init_t *x, - int verbose) + libxfs_init_t *x) { int error;xfs_daddr_t head_blk, tail_blk;
@@ -58,11 +57,6 @@ xlog_is_dirty(return -1 ; } -if (verbose) -xlog_warn ( -_ ("%s: head block %" PRId64" tail block %" PRId64"\n" ), - __func__, head_blk, tail_blk); -if (head_blk != tail_blk)return 1 ;
Signature · 1 line
2.39.2
Re: [PATCH 06/23] libxlog: remove the verbose argument to xlog_is_dirty
Quoted 4 lines · Christoph Hellwig
No caller passes a non-zero verbose argument to
xlog_is_dirty. Remove the argument the code keyed off by it.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 100 lines
--- copy/xfs_copy.c | 2 +- db/metadump.c | 4 ++-- db/sb.c | 2 +- include/libxlog.h | 3 +-- libxlog/util.c | 8 +------- 5 files changed, 6 insertions(+), 13 deletions(-)copy/xfs_copy.c +1
-1@@ -784,7 +784,7 @@ main(int argc, char **argv)*/ memset (&xlog,0 ,sizeof (struct xlog )); mp->m_log = &xlog; - c =xlog_is_dirty (mp, mp->m_log, &xargs,0 ); + c =xlog_is_dirty (mp, mp->m_log, &xargs);if (!duplicate) {if (c ==1 ) { do_log(_(db/metadump.c +2
-2@@ -2615,7 +2615,7 @@ copy_log(void)if (!metadump.obfuscate && !metadump.zero_stale_data) goto done; - dirty =xlog_is_dirty (mp, &log, &x,0 ); + dirty =xlog_is_dirty (mp, &log, &x);switch (dirty) {case 0 :@@ -2945,7 +2945,7 @@ metadump_f(if (iocur_top->data) {/* best effort */ struct xlog log; -if (xlog_is_dirty (mp, &log, &x,0 )) +if (xlog_is_dirty (mp, &log, &x)) metadump.dirty_log = true; }pop_cur ();db/sb.c +1
-1@@ -235,7 +235,7 @@ sb_logcheck(void)libxfs_buftarg_init (mp, x.ddev, x.logdev, x.rtdev); - dirty =xlog_is_dirty (mp, mp->m_log, &x,0 ); + dirty =xlog_is_dirty (mp, mp->m_log, &x);if (dirty ==-1 ) {dbprintf (_ ("ERROR: cannot find log head/tail, run xfs_repair\n" ));return 0 ;include/libxlog.h +1
-2@@ -71,9 +71,8 @@ extern int print_record_header;/* libxfs parameters */ extern libxfs_init_t x; +int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x); -extern int xlog_is_dirty (struct xfs_mount *,struct xlog *,libxfs_init_t *, -int );extern struct xfs_buf *xlog_get_bp (struct xlog *,int );extern int xlog_bread (struct xlog *log,xfs_daddr_t blk_no,int nbblks,struct xfs_buf *bp,char **offset);libxlog/util.c +1
-8@@ -19,8 +19,7 @@ intxlog_is_dirty ( struct xfs_mount *mp, struct xlog *log, - libxfs_init_t *x, - int verbose) + libxfs_init_t *x) { int error;xfs_daddr_t head_blk, tail_blk;@@ -58,11 +57,6 @@ xlog_is_dirty(return -1 ; } -if (verbose) -xlog_warn ( -_ ("%s: head block %" PRId64" tail block %" PRId64"\n" ), - __func__, head_blk, tail_blk); -if (head_blk != tail_blk)return 1 ; --2.39.2
PATCH 7/23 libxlog: add a helper to initialize a xlog without clobbering the x structure
In reply to Christoph Hellwigxfsprogs has three copies of a code sequence to initialize an xlog structure from a libxfs_init structure. Factor the code into a helper.
--- include/libxlog.h | 1 + libxlog/util.c | 25 +++++++++++++++++-------- logprint/logprint.c | 25 +++++++++---------------- repair/phase2.c | 23 +---------------------- 4 files changed, 28 insertions(+), 46 deletions(-)
include/libxlog.h +1 -0
@@ -71,6 +71,7 @@ extern int print_record_header;/* libxfs parameters */ extern libxfs_init_t x; +void xlog_init (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x);int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x);extern struct xfs_buf *xlog_get_bp (struct xlog *,int );
libxlog/util.c +17 -8
@@ -12,18 +12,12 @@ int print_skip_uuid;int print_record_header;libxfs_init_t x; -/* -* Return 1 for dirty, 0 for clean, -1 for errors -*/ -int -xlog_is_dirty ( +void +xlog_init (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x) { -int error; -xfs_daddr_t head_blk, tail_blk; -memset (log,0 ,sizeof (*log));/* We (re-)init members of libxfs_init_t here? really? */
@@ -48,6 +42,21 @@ xlog_is_dirty(ASSERT (mp->m_sb.sb_logsectlog >=BBSHIFT ); } log->l_sectbb_mask = (1 << log->l_sectbb_log) -1 ; +} + +/* +* Return 1 for dirty, 0 for clean, -1 for errors +*/ +int +xlog_is_dirty ( +struct xfs_mount *mp, +struct xlog *log, +libxfs_init_t *x) +{ +int error; +xfs_daddr_t head_blk, tail_blk; + +xlog_init (mp, log, x); error =xlog_find_tail (log, &head_blk, &tail_blk);if (error) {
logprint/logprint.c +9 -16
@@ -58,7 +58,6 @@ logstat( {int fd;char buf[BBSIZE ]; -xfs_sb_t *sb;/* On Linux we always read the superblock of the * filesystem. We need this to get the length of the
@@ -77,19 +76,16 @@ logstat(close (fd);if (!x.disfile) { +struct xfs_sb *sb = &mp->m_sb; +/* * Conjure up a mount structure */ - sb = &mp->m_sb;libxfs_sb_from_disk (sb, (struct xfs_dsb *)buf); mp->m_features |=libxfs_sb_version_to_features (&mp->m_sb); mp->m_blkbb_log = sb->sb_blocklog -BBSHIFT ; - x.logBBsize =XFS_FSB_TO_BB (mp, sb->sb_logblocks); - x.logBBstart =XFS_FSB_TO_DADDR (mp, sb->sb_logstart); - x.lbsize =BBSIZE ; -if (xfs_has_sector (mp)) - x.lbsize <<= (sb->sb_logsectlog -BBSHIFT ); +xlog_init (mp, log, &x);if (!x.logname && sb->sb_logstart ==0 ) {fprintf (stderr,_ (" external log device not specified\n\n" ));
@@ -100,16 +96,13 @@ logstat(struct stat s;stat (x.dname, &s); - x.logBBsize = s.st_size >>9 ; - x.logBBstart =0 ; - x.lbsize =BBSIZE ; - } - log->l_dev = mp->m_logdev_targp; - log->l_logBBstart = x.logBBstart; - log->l_logBBsize = x.logBBsize; - log->l_sectBBsize =BTOBB (x.lbsize); - log->l_mp = mp; + log->l_logBBsize = s.st_size >>9 ; + log->l_logBBstart =0 ; + log->l_sectBBsize =BTOBB (BBSIZE ); + log->l_dev = mp->m_logdev_targp; + log->l_mp = mp; + }if (x.logname && *x.logname) {/* External log */ if ((fd =open (x.logname,O_RDONLY )) ==-1 ) {
repair/phase2.c +1 -22
@@ -30,28 +30,7 @@ zero_log(xfs_daddr_t tail_blk;struct xlog *log = mp->m_log; -memset (log,0 ,sizeof (struct xlog )); - x.logBBsize =XFS_FSB_TO_BB (mp, mp->m_sb.sb_logblocks); - x.logBBstart =XFS_FSB_TO_DADDR (mp, mp->m_sb.sb_logstart); - x.lbsize =BBSIZE ; -if (xfs_has_sector (mp)) - x.lbsize <<= (mp->m_sb.sb_logsectlog -BBSHIFT ); - - log->l_dev = mp->m_logdev_targp; - log->l_logBBsize = x.logBBsize; - log->l_logBBstart = x.logBBstart; - log->l_sectBBsize =BTOBB (x.lbsize); - log->l_mp = mp; -if (xfs_has_sector (mp)) { - log->l_sectbb_log = mp->m_sb.sb_logsectlog -BBSHIFT ; -ASSERT (log->l_sectbb_log <= mp->m_sectbb_log); -/* for larger sector sizes, must have v2 or external log */ -ASSERT (log->l_sectbb_log ==0 || - log->l_logBBstart ==0 || -xfs_has_logv2 (mp)); -ASSERT (mp->m_sb.sb_logsectlog >=BBSHIFT ); - } - log->l_sectbb_mask = (1 << log->l_sectbb_log) -1 ; +xlog_init (mp, mp->m_log, &x);/* * Find the log head and tail and alert the user to the situation if the
Signature · 1 line
2.39.2
Re: [PATCH 07/23] libxlog: add a helper to initialize a xlog without clobbering the x structure
Quoted 4 lines · Christoph Hellwig
xfsprogs has three copies of a code sequence to initialize an xlog structure from a
libxfs_initstructure. Factor the code into a helper.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 161 lines
--- include/libxlog.h | 1 + libxlog/util.c | 25 +++++++++++++++++-------- logprint/logprint.c | 25 +++++++++---------------- repair/phase2.c | 23 +---------------------- 4 files changed, 28 insertions(+), 46 deletions(-)include/libxlog.h +1
-0@@ -71,6 +71,7 @@ extern int print_record_header;/* libxfs parameters */ extern libxfs_init_t x; +void xlog_init (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x);int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x);extern struct xfs_buf *xlog_get_bp (struct xlog *,int );libxlog/util.c +17
-8@@ -12,18 +12,12 @@ int print_skip_uuid;int print_record_header;libxfs_init_t x; -/* -* Return 1 for dirty, 0 for clean, -1 for errors -*/ -int -xlog_is_dirty ( +void +xlog_init (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x) { -int error; -xfs_daddr_t head_blk, tail_blk; -memset (log,0 ,sizeof (*log));/* We (re-)init members of libxfs_init_t here? really? */ @@ -48,6 +42,21 @@ xlog_is_dirty(ASSERT (mp->m_sb.sb_logsectlog >=BBSHIFT ); } log->l_sectbb_mask = (1 << log->l_sectbb_log) -1 ; +} + +/* +* Return 1 for dirty, 0 for clean, -1 for errors +*/ +int +xlog_is_dirty ( +struct xfs_mount *mp, +struct xlog *log, +libxfs_init_t *x) +{ +int error; +xfs_daddr_t head_blk, tail_blk; + +xlog_init (mp, log, x); error =xlog_find_tail (log, &head_blk, &tail_blk);if (error) {logprint/logprint.c +9
-16@@ -58,7 +58,6 @@ logstat( {int fd;char buf[BBSIZE ]; -xfs_sb_t *sb;/* On Linux we always read the superblock of the * filesystem. We need this to get the length of the @@ -77,19 +76,16 @@ logstat(close (fd);if (!x.disfile) { +struct xfs_sb *sb = &mp->m_sb; +/* * Conjure up a mount structure */ - sb = &mp->m_sb;libxfs_sb_from_disk (sb, (struct xfs_dsb *)buf); mp->m_features |=libxfs_sb_version_to_features (&mp->m_sb); mp->m_blkbb_log = sb->sb_blocklog -BBSHIFT ; - x.logBBsize =XFS_FSB_TO_BB (mp, sb->sb_logblocks); - x.logBBstart =XFS_FSB_TO_DADDR (mp, sb->sb_logstart); - x.lbsize =BBSIZE ; -if (xfs_has_sector (mp)) - x.lbsize <<= (sb->sb_logsectlog -BBSHIFT ); +xlog_init (mp, log, &x);if (!x.logname && sb->sb_logstart ==0 ) {fprintf (stderr,_ (" external log device not specified\n\n" ));@@ -100,16 +96,13 @@ logstat(struct stat s;stat (x.dname, &s); - x.logBBsize = s.st_size >>9 ; - x.logBBstart =0 ; - x.lbsize =BBSIZE ; - } - log->l_dev = mp->m_logdev_targp; - log->l_logBBstart = x.logBBstart; - log->l_logBBsize = x.logBBsize; - log->l_sectBBsize =BTOBB (x.lbsize); - log->l_mp = mp; + log->l_logBBsize = s.st_size >>9 ; + log->l_logBBstart =0 ; + log->l_sectBBsize =BTOBB (BBSIZE ); + log->l_dev = mp->m_logdev_targp; + log->l_mp = mp; + }if (x.logname && *x.logname) {/* External log */ if ((fd =open (x.logname,O_RDONLY )) ==-1 ) {repair/phase2.c +1
-23@@ -30,28 +30,7 @@ zero_log(xfs_daddr_t tail_blk;struct xlog *log = mp->m_log; -memset (log,0 ,sizeof (struct xlog )); - x.logBBsize =XFS_FSB_TO_BB (mp, mp->m_sb.sb_logblocks); - x.logBBstart =XFS_FSB_TO_DADDR (mp, mp->m_sb.sb_logstart); - x.lbsize =BBSIZE ; -if (xfs_has_sector (mp)) - x.lbsize <<= (mp->m_sb.sb_logsectlog -BBSHIFT ); - - log->l_dev = mp->m_logdev_targp; - log->l_logBBsize = x.logBBsize; - log->l_logBBstart = x.logBBstart; - log->l_sectBBsize =BTOBB (x.lbsize); - log->l_mp = mp; -if (xfs_has_sector (mp)) { - log->l_sectbb_log = mp->m_sb.sb_logsectlog -BBSHIFT ; -ASSERT (log->l_sectbb_log <= mp->m_sectbb_log); -/* for larger sector sizes, must have v2 or external log */ -ASSERT (log->l_sectbb_log ==0 || - log->l_logBBstart ==0 || -xfs_has_logv2 (mp)); -ASSERT (mp->m_sb.sb_logsectlog >=BBSHIFT ); - } - log->l_sectbb_mask = (1 << log->l_sectbb_log) -1 ; +xlog_init (mp, mp->m_log, &x);/* * Find the log head and tail and alert the user to the situation if the -- 2.39.2
PATCH 8/23 libxlog: don't require a libxfs_xinit structure for xlog_init
In reply to Christoph Hellwigxlog_init currently requires a libxfs_args structure to be passed in, and then clobbers various log-related arguments to it. There is no good reason for that as all the required information can be calculated without it.
Remove the x argument to xlog_init and xlog_is_dirty and the now unused logBBstart member in struct libxfs_xinit.
--- copy/xfs_copy.c | 2 +- db/metadump.c | 4 ++-- db/sb.c | 2 +- include/libxfs.h | 1 - include/libxlog.h | 4 ++-- libxfs/init.c | 2 +- libxlog/util.c | 25 ++++++++++--------------- logprint/logprint.c | 2 +- repair/phase2.c | 2 +- 9 files changed, 19 insertions(+), 25 deletions(-)
copy/xfs_copy.c +1 -1
@@ -784,7 +784,7 @@ main(int argc, char **argv)*/ memset (&xlog,0 ,sizeof (struct xlog )); mp->m_log = &xlog; - c =xlog_is_dirty (mp, mp->m_log, &xargs); + c =xlog_is_dirty (mp, mp->m_log);if (!duplicate) {if (c ==1 ) { do_log(_(
db/metadump.c +2 -2
@@ -2615,7 +2615,7 @@ copy_log(void)if (!metadump.obfuscate && !metadump.zero_stale_data) goto done; - dirty =xlog_is_dirty (mp, &log, &x); + dirty =xlog_is_dirty (mp, &log);switch (dirty) {case 0 :
@@ -2945,7 +2945,7 @@ metadump_f(if (iocur_top->data) {/* best effort */ struct xlog log; -if (xlog_is_dirty (mp, &log, &x)) +if (xlog_is_dirty (mp, &log)) metadump.dirty_log = true; }pop_cur ();
db/sb.c +1 -1
@@ -235,7 +235,7 @@ sb_logcheck(void)libxfs_buftarg_init (mp, x.ddev, x.logdev, x.rtdev); - dirty =xlog_is_dirty (mp, mp->m_log, &x); + dirty =xlog_is_dirty (mp, mp->m_log);if (dirty ==-1 ) {dbprintf (_ ("ERROR: cannot find log head/tail, run xfs_repair\n" ));return 0 ;
include/libxfs.h +0 -1
@@ -115,7 +115,6 @@ typedef struct libxfs_xinit {long long logBBsize;/* size of log subvolume (BBs) */ /* (blocks allocated for use as * log is stored in mount structure) */ -long long logBBstart;/* start block of log subvolume (BBs) */ long long rtsize;/* size of realtime subvolume (BBs) */ int dbsize;/* data subvolume device blksize */ int lbsize;/* log subvolume device blksize */
include/libxlog.h +2 -2
@@ -71,8 +71,8 @@ extern int print_record_header;/* libxfs parameters */ extern libxfs_init_t x; -void xlog_init (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x); -int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x); +void xlog_init (struct xfs_mount *mp,struct xlog *log); +int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log);extern struct xfs_buf *xlog_get_bp (struct xlog *,int ); extern int xlog_bread(struct xlog *log, xfs_daddr_t blk_no, int nbblks,
libxfs/init.c +1 -1
@@ -304,7 +304,7 @@ libxfs_init(libxfs_init_t *a) a->dfd = a->logfd = a->rtfd =-1 ; a->ddev = a->logdev = a->rtdev =0 ; a->dsize = a->lbsize = a->rtbsize =0 ; - a->dbsize = a->logBBsize = a->logBBstart = a->rtsize =0 ; + a->dbsize = a->logBBsize = a->rtsize =0 ; flags = (a->isreadonly | a->isdirect);
libxlog/util.c +10 -15
@@ -15,22 +15,18 @@ libxfs_init_t x;void xlog_init (struct xfs_mount *mp, -struct xlog *log, -libxfs_init_t *x) +struct xlog *log) { -memset (log,0 ,sizeof (*log)); +unsigned int log_sect_size =BBSIZE ; -/* We (re-)init members of libxfs_init_t here? really? */ - x->logBBsize =XFS_FSB_TO_BB (mp, mp->m_sb.sb_logblocks); - x->logBBstart =XFS_FSB_TO_DADDR (mp, mp->m_sb.sb_logstart); - x->lbsize =BBSIZE ; -if (xfs_has_sector (mp)) - x->lbsize <<= (mp->m_sb.sb_logsectlog -BBSHIFT ); +memset (log,0 ,sizeof (*log)); log->l_dev = mp->m_logdev_targp; - log->l_logBBsize = x->logBBsize; - log->l_logBBstart = x->logBBstart; - log->l_sectBBsize =BTOBB (x->lbsize); + log->l_logBBsize =XFS_FSB_TO_BB (mp, mp->m_sb.sb_logblocks); + log->l_logBBstart =XFS_FSB_TO_DADDR (mp, mp->m_sb.sb_logstart); +if (xfs_has_sector (mp)) + log_sect_size <<= (mp->m_sb.sb_logsectlog -BBSHIFT ); + log->l_sectBBsize =BTOBB (log_sect_size); log->l_mp = mp;if (xfs_has_sector (mp)) { log->l_sectbb_log = mp->m_sb.sb_logsectlog -BBSHIFT ;
@@ -50,13 +46,12 @@ xlog_init(int xlog_is_dirty (struct xfs_mount *mp, -struct xlog *log, -libxfs_init_t *x) +struct xlog *log) {int error;xfs_daddr_t head_blk, tail_blk; -xlog_init (mp, log, x); +xlog_init (mp, log); error =xlog_find_tail (log, &head_blk, &tail_blk);if (error) {
logprint/logprint.c +1 -1
@@ -85,7 +85,7 @@ logstat( mp->m_features |=libxfs_sb_version_to_features (&mp->m_sb); mp->m_blkbb_log = sb->sb_blocklog -BBSHIFT ; -xlog_init (mp, log, &x); +xlog_init (mp, log);if (!x.logname && sb->sb_logstart ==0 ) {fprintf (stderr,_ (" external log device not specified\n\n" ));
repair/phase2.c +1 -1
@@ -30,7 +30,7 @@ zero_log(xfs_daddr_t tail_blk;struct xlog *log = mp->m_log; -xlog_init (mp, mp->m_log, &x); +xlog_init (mp, mp->m_log);/* * Find the log head and tail and alert the user to the situation if the
Signature · 1 line
2.39.2
Re: [PATCH 08/23] libxlog: don't require a libxfs_xinit structure for xlog_init
Quoted 9 lines · Christoph Hellwig
xlog_initcurrently requires alibxfs_argsstructure to be passed in, and then clobbers various log-related arguments to it. There is no good reason for that as all the required information can be calculated without it.Remove the x argument to
xlog_initandxlog_is_dirtyand the now unused logBBstart member in structlibxfs_xinit.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 181 lines
--- copy/xfs_copy.c | 2 +- db/metadump.c | 4 ++-- db/sb.c | 2 +- include/libxfs.h | 1 - include/libxlog.h | 4 ++-- libxfs/init.c | 2 +- libxlog/util.c | 25 ++++++++++--------------- logprint/logprint.c | 2 +- repair/phase2.c | 2 +- 9 files changed, 19 insertions(+), 25 deletions(-)copy/xfs_copy.c +1
-1@@ -784,7 +784,7 @@ main(int argc, char **argv)*/ memset (&xlog,0 ,sizeof (struct xlog )); mp->m_log = &xlog; - c =xlog_is_dirty (mp, mp->m_log, &xargs); + c =xlog_is_dirty (mp, mp->m_log);if (!duplicate) {if (c ==1 ) { do_log(_(db/metadump.c +2
-2@@ -2615,7 +2615,7 @@ copy_log(void)if (!metadump.obfuscate && !metadump.zero_stale_data) goto done; - dirty =xlog_is_dirty (mp, &log, &x); + dirty =xlog_is_dirty (mp, &log);switch (dirty) {case 0 :@@ -2945,7 +2945,7 @@ metadump_f(if (iocur_top->data) {/* best effort */ struct xlog log; -if (xlog_is_dirty (mp, &log, &x)) +if (xlog_is_dirty (mp, &log)) metadump.dirty_log = true; }pop_cur ();db/sb.c +1
-1@@ -235,7 +235,7 @@ sb_logcheck(void)libxfs_buftarg_init (mp, x.ddev, x.logdev, x.rtdev); - dirty =xlog_is_dirty (mp, mp->m_log, &x); + dirty =xlog_is_dirty (mp, mp->m_log);if (dirty ==-1 ) {dbprintf (_ ("ERROR: cannot find log head/tail, run xfs_repair\n" ));return 0 ;include/libxfs.h +0
-1@@ -115,7 +115,6 @@ typedef struct libxfs_xinit {long long logBBsize;/* size of log subvolume (BBs) */ /* (blocks allocated for use as * log is stored in mount structure) */ -long long logBBstart;/* start block of log subvolume (BBs) */ long long rtsize;/* size of realtime subvolume (BBs) */ int dbsize;/* data subvolume device blksize */ int lbsize;/* log subvolume device blksize */ include/libxlog.h +2
-2@@ -71,8 +71,8 @@ extern int print_record_header;/* libxfs parameters */ extern libxfs_init_t x; -void xlog_init (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x); -int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log,libxfs_init_t *x); +void xlog_init (struct xfs_mount *mp,struct xlog *log); +int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log);extern struct xfs_buf *xlog_get_bp (struct xlog *,int ); extern int xlog_bread(struct xlog *log, xfs_daddr_t blk_no, int nbblks,libxfs/init.c +1
-1@@ -304,7 +304,7 @@ libxfs_init(libxfs_init_t *a) a->dfd = a->logfd = a->rtfd =-1 ; a->ddev = a->logdev = a->rtdev =0 ; a->dsize = a->lbsize = a->rtbsize =0 ; - a->dbsize = a->logBBsize = a->logBBstart = a->rtsize =0 ; + a->dbsize = a->logBBsize = a->rtsize =0 ; flags = (a->isreadonly | a->isdirect);libxlog/util.c +10
-15@@ -15,22 +15,18 @@ libxfs_init_t x;void xlog_init (struct xfs_mount *mp, -struct xlog *log, -libxfs_init_t *x) +struct xlog *log) { -memset (log,0 ,sizeof (*log)); +unsigned int log_sect_size =BBSIZE ; -/* We (re-)init members of libxfs_init_t here? really? */ - x->logBBsize =XFS_FSB_TO_BB (mp, mp->m_sb.sb_logblocks); - x->logBBstart =XFS_FSB_TO_DADDR (mp, mp->m_sb.sb_logstart); - x->lbsize =BBSIZE ; -if (xfs_has_sector (mp)) - x->lbsize <<= (mp->m_sb.sb_logsectlog -BBSHIFT ); +memset (log,0 ,sizeof (*log)); log->l_dev = mp->m_logdev_targp; - log->l_logBBsize = x->logBBsize; - log->l_logBBstart = x->logBBstart; - log->l_sectBBsize =BTOBB (x->lbsize); + log->l_logBBsize =XFS_FSB_TO_BB (mp, mp->m_sb.sb_logblocks); + log->l_logBBstart =XFS_FSB_TO_DADDR (mp, mp->m_sb.sb_logstart); +if (xfs_has_sector (mp)) + log_sect_size <<= (mp->m_sb.sb_logsectlog -BBSHIFT ); + log->l_sectBBsize =BTOBB (log_sect_size); log->l_mp = mp;if (xfs_has_sector (mp)) { log->l_sectbb_log = mp->m_sb.sb_logsectlog -BBSHIFT ;@@ -50,13 +46,12 @@ xlog_init(int xlog_is_dirty (struct xfs_mount *mp, -struct xlog *log, -libxfs_init_t *x) +struct xlog *log) {int error;xfs_daddr_t head_blk, tail_blk; -xlog_init (mp, log, x); +xlog_init (mp, log); error =xlog_find_tail (log, &head_blk, &tail_blk);if (error) {logprint/logprint.c +1
-1@@ -85,7 +85,7 @@ logstat( mp->m_features |=libxfs_sb_version_to_features (&mp->m_sb); mp->m_blkbb_log = sb->sb_blocklog -BBSHIFT ; -xlog_init (mp, log, &x); +xlog_init (mp, log);if (!x.logname && sb->sb_logstart ==0 ) {fprintf (stderr,_ (" external log device not specified\n\n" ));repair/phase2.c +1
-2@@ -30,7 +30,7 @@ zero_log(xfs_daddr_t tail_blk;struct xlog *log = mp->m_log; -xlog_init (mp, mp->m_log, &x); +xlog_init (mp, mp->m_log);/* * Find the log head and tail and alert the user to the situation if the -- 2.39.2
PATCH 9/23 libxlog: remove the global libxfs_xinit x structure
In reply to Christoph HellwigThere is no need to export a libxfs_xinit with the somewhat unsuitable name x from libxlog. Move it into the tools linking against libxlog that actually need it.
--- db/init.c | 1 + include/libxlog.h | 3 --- libxlog/util.c | 1 - logprint/logprint.c | 1 + repair/globals.h | 2 ++ repair/init.c | 2 ++ 6 files changed, 6 insertions(+), 4 deletions(-)
db/init.c +1 -0
@@ -27,6 +27,7 @@ static struct xfs_mount xmount;struct xfs_mount *mp;static struct xlog xlog;xfs_agnumber_t cur_agno =NULLAGNUMBER ; +libxfs_init_t x;static void usage (void )
include/libxlog.h +0 -3
@@ -68,9 +68,6 @@ extern int print_exit;extern int print_skip_uuid;extern int print_record_header; -/* libxfs parameters */ -extern libxfs_init_t x; -void xlog_init (struct xfs_mount *mp,struct xlog *log);int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log);
libxlog/util.c +0 -1
@@ -10,7 +10,6 @@int print_exit;int print_skip_uuid;int print_record_header; -libxfs_init_t x;void xlog_init(
logprint/logprint.c +1 -0
@@ -25,6 +25,7 @@ int print_overwrite;int print_no_data;int print_no_print;static int print_operation =OP_PRINT ; +static struct libxfs_xinit x;static void usage (void )
repair/globals.h +2 -0
@@ -169,4 +169,6 @@ extern int thread_count;/* If nonzero, simulate failure after this phase. */ extern int fail_after_phase; +extern libxfs_init_t x; +#endif /* _XFS_REPAIR_GLOBAL_H */
repair/init.c +2 -0
@@ -18,6 +18,8 @@#include "libfrog/dahashselftest.h" #include <sys/resource.h> +struct libxfs_xinit x; +static void ts_create (void ) {
Signature · 1 line
2.39.2
Re: [PATCH 09/23] libxlog: remove the global libxfs_xinit x structure
Quoted 5 lines · Christoph Hellwig
There is no need to export a
libxfs_xinitwith the somewhat unsuitable name x from libxlog. Move it into the tools linking against libxlog that actually need it.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 86 lines
--- db/init.c | 1 + include/libxlog.h | 3 --- libxlog/util.c | 1 - logprint/logprint.c | 1 + repair/globals.h | 2 ++ repair/init.c | 2 ++ 6 files changed, 6 insertions(+), 4 deletions(-)db/init.c +1
-0@@ -27,6 +27,7 @@ static struct xfs_mount xmount;struct xfs_mount *mp;static struct xlog xlog;xfs_agnumber_t cur_agno =NULLAGNUMBER ; +libxfs_init_t x;static void usage (void )include/libxlog.h +0
-3@@ -68,9 +68,6 @@ extern int print_exit;extern int print_skip_uuid;extern int print_record_header; -/* libxfs parameters */ -extern libxfs_init_t x; -void xlog_init (struct xfs_mount *mp,struct xlog *log);int xlog_is_dirty (struct xfs_mount *mp,struct xlog *log);libxlog/util.c +0
-1@@ -10,7 +10,6 @@int print_exit;int print_skip_uuid;int print_record_header; -libxfs_init_t x;void xlog_init(logprint/logprint.c +1
-0@@ -25,6 +25,7 @@ int print_overwrite;int print_no_data;int print_no_print;static int print_operation =OP_PRINT ; +static struct libxfs_xinit x;static void usage (void )repair/globals.h +2
-0@@ -169,4 +169,6 @@ extern int thread_count;/* If nonzero, simulate failure after this phase. */ extern int fail_after_phase; +extern libxfs_init_t x; +#endif /* _XFS_REPAIR_GLOBAL_H */ repair/init.c +2
-1@@ -18,6 +18,8 @@#include "libfrog/dahashselftest.h" #include <sys/resource.h> +struct libxfs_xinit x; +static void ts_create (void ) { --2.39.2
PATCH 10/23 libxfs: rename struct libxfs_xinit to libxfs_init
In reply to Christoph HellwigMake the struct name more usual, and remove the libxfs_init_t typedef.
--- copy/xfs_copy.c | 2 +- db/init.c | 2 +- db/init.h | 2 +- growfs/xfs_growfs.c | 2 +- include/libxfs.h | 10 ++++++---- libxfs/init.c | 6 +++--- libxfs/topology.c | 5 +++-- libxfs/topology.h | 4 ++-- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 18 +++++++++--------- repair/globals.h | 2 +- repair/init.c | 6 +++--- repair/protos.h | 2 +- repair/sb.c | 2 +- 14 files changed, 34 insertions(+), 31 deletions(-)
copy/xfs_copy.c +1 -1
@@ -582,7 +582,7 @@ main(int argc, char **argv)xfs_alloc_rec_t *rec_ptr;extern char *optarg;extern int optind; -libxfs_init_t xargs; +struct libxfs_init xargs;thread_args *tcarg;struct stat statbuf;int error;
db/init.c +1 -1
@@ -27,7 +27,7 @@ static struct xfs_mount xmount;struct xfs_mount *mp;static struct xlog xlog;xfs_agnumber_t cur_agno =NULLAGNUMBER ; -libxfs_init_t x; +struct libxfs_init x;static void usage (void )
db/init.h +1 -1
@@ -8,5 +8,5 @@ extern int blkbb;extern int exitcode;extern int expert_mode;extern xfs_mount_t *mp; -extern libxfs_init_t x; +extern struct libxfs_init x;extern xfs_agnumber_t cur_agno;
growfs/xfs_growfs.c +1 -1
@@ -61,7 +61,7 @@ main(int argc, char **argv)char *logdev;/* log device name */ char *rtdev;/* RT device name */ fs_path_t *fs;/* mount point information */ -libxfs_init_t xi;/* libxfs structure */ +struct libxfs_init xi;/* libxfs structure */ char rpath[PATH_MAX ];int ret;
include/libxfs.h +6 -4
@@ -92,7 +92,7 @@ struct iomap;/* * Argument structure for libxfs_init(). */ -typedef struct libxfs_xinit { +struct libxfs_init {/* input parameters */ char *dname;/* pathname of data "subvolume" */ char *logname;/* pathname of log "subvolume" */
@@ -123,7 +123,7 @@ typedef struct libxfs_xinit {int logfd;/* log subvolume file descriptor */ int rtfd;/* realtime subvolume file descriptor */ int bcache_flags;/* cache init flags */ -} libxfs_init_t; +};#define LIBXFS_ISREADONLY 0x0002/* disallow all mounted filesystems */ #define LIBXFS_ISINACTIVE 0x0004/* allow mounted only if mounted ro */
@@ -133,8 +133,10 @@ typedef struct libxfs_xinit {extern char *progname;extern xfs_lsn_t libxfs_max_lsn; -extern int libxfs_init (libxfs_init_t *); -void libxfs_destroy (struct libxfs_xinit *li); + +int libxfs_init (struct libxfs_init *); +void libxfs_destroy (struct libxfs_init *li); +extern int libxfs_device_to_fd (dev_t );extern dev_t libxfs_device_open (char *,int ,int ,int );extern void libxfs_device_close (dev_t );
libxfs/init.c +3 -3
@@ -273,7 +273,7 @@ destroy_caches(void)static void libxfs_close_devices ( -struct libxfs_xinit *li) +struct libxfs_init *li) {if (li->ddev)libxfs_device_close (li->ddev);
@@ -291,7 +291,7 @@ libxfs_close_devices(* Caller gets a 0 on failure (and we print a message), 1 on success. */ int -libxfs_init (libxfs_init_t *a) +libxfs_init (struct libxfs_init *a) {char *dname;char *logname;
@@ -1034,7 +1034,7 @@ libxfs_umount(*/ void libxfs_destroy ( -struct libxfs_xinit *li) +struct libxfs_init *li) {int leaked;
libxfs/topology.c +3 -2
@@ -286,8 +286,9 @@ static void blkid_get_topology(#endif /* ENABLE_BLKID */ -void get_topology ( -libxfs_init_t *xi, +void +get_topology ( +struct libxfs_init *xi,struct fs_topology *ft,int force_overwrite) {
libxfs/topology.h +2 -2
@@ -18,9 +18,9 @@ typedef struct fs_topology {int psectorsize;/* physical sector size */ } fs_topology_t; -extern void +void get_topology ( -libxfs_init_t *xi, +struct libxfs_init *xi,struct fs_topology *ft,int force_overwrite);
logprint/logprint.c +1 -1
@@ -25,7 +25,7 @@ int print_overwrite;int print_no_data;int print_no_print;static int print_operation =OP_PRINT ; -static struct libxfs_xinit x; +static struct libxfs_init x;static void usage (void )
mkfs/xfs_mkfs.c +9 -9
@@ -907,7 +907,7 @@ struct cli_params {struct fsxattr fsx;/* libxfs device setup */ -struct libxfs_xinit *xi; +struct libxfs_init *xi; };/*
@@ -1246,7 +1246,7 @@ validate_ag_geometry(static void zero_old_xfs_structures ( -libxfs_init_t *xi, +struct libxfs_init *xi,xfs_sb_t *new_sb) {void *buf;
@@ -2834,7 +2834,7 @@ _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"static void open_devices (struct mkfs_params *cfg, -struct libxfs_xinit *xi) +struct libxfs_init *xi) {uint64_t sector_mask;
@@ -2867,7 +2867,7 @@ open_devices(static void discard_devices ( -struct libxfs_xinit *xi, +struct libxfs_init *xi,int quiet) {/*
@@ -2887,7 +2887,7 @@ validate_datadev(struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi;if (!xi->dsize) {/*
@@ -2934,7 +2934,7 @@ validate_logdev(struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi; cfg->loginternal = cli->loginternal;
@@ -2998,7 +2998,7 @@ validate_rtdev(struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi;if (!xi->rtdev) {if (cli->rtsize) {
@@ -3750,7 +3750,7 @@ alloc_write_buf(static void prepare_devices (struct mkfs_params *cfg, -struct libxfs_xinit *xi, +struct libxfs_init *xi,struct xfs_mount *mp,struct xfs_sb *sbp,bool clear_stale)
@@ -4055,7 +4055,7 @@ main(char *protostring =NULL ;int worst_freelist =0 ; -struct libxfs_xinit xi = { +struct libxfs_init xi = { .isdirect =LIBXFS_DIRECT , .isreadonly =LIBXFS_EXCLUSIVELY , };
repair/globals.h +1 -1
@@ -169,6 +169,6 @@ extern int thread_count;/* If nonzero, simulate failure after this phase. */ extern int fail_after_phase; -extern libxfs_init_t x; +extern struct libxfs_init x;#endif /* _XFS_REPAIR_GLOBAL_H */
repair/init.c +3 -3
@@ -18,7 +18,7 @@#include "libfrog/dahashselftest.h" #include <sys/resource.h> -struct libxfs_xinit x; +struct libxfs_init x;static void ts_create (void )
@@ -52,9 +52,9 @@ increase_rlimit(void) }void -xfs_init (libxfs_init_t *args) +xfs_init (struct libxfs_init *args) { -memset (args,0 ,sizeof (libxfs_init_t)); +memset (args,0 ,sizeof (*args)); args->dname = fs_name; args->disfile = isa_file;
repair/protos.h +1 -1
@@ -4,7 +4,7 @@* All Rights Reserved. */ -void xfs_init (libxfs_init_t *args); +void xfs_init (struct libxfs_init *args); int verify_sb(char *sb_buf, xfs_sb_t *sb,
repair/sb.c +1 -1
@@ -176,7 +176,7 @@ static intguess_default_geometry ( uint64_t *agsize, uint64_t *agcount, - libxfs_init_t *x) + struct libxfs_init *x) {struct fs_topology ft;int blocklog;
Signature · 1 line
2.39.2
Re: [PATCH 10/23] libxfs: rename struct libxfs_xinit to libxfs_init
Quoted 3 lines · Christoph Hellwig
Make the struct name more usual, and remove the
libxfs_init_ttypedef.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 329 lines
--- copy/xfs_copy.c | 2 +- db/init.c | 2 +- db/init.h | 2 +- growfs/xfs_growfs.c | 2 +- include/libxfs.h | 10 ++++++---- libxfs/init.c | 6 +++--- libxfs/topology.c | 5 +++-- libxfs/topology.h | 4 ++-- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 18 +++++++++--------- repair/globals.h | 2 +- repair/init.c | 6 +++--- repair/protos.h | 2 +- repair/sb.c | 2 +- 14 files changed, 34 insertions(+), 31 deletions(-)copy/xfs_copy.c +1
-1@@ -582,7 +582,7 @@ main(int argc, char **argv)xfs_alloc_rec_t *rec_ptr;extern char *optarg;extern int optind; -libxfs_init_t xargs; +struct libxfs_init xargs;thread_args *tcarg;struct stat statbuf;int error;db/init.c +1
-1@@ -27,7 +27,7 @@ static struct xfs_mount xmount;struct xfs_mount *mp;static struct xlog xlog;xfs_agnumber_t cur_agno =NULLAGNUMBER ; -libxfs_init_t x; +struct libxfs_init x;static void usage (void )db/init.h +1
-1@@ -8,5 +8,5 @@ extern int blkbb;extern int exitcode;extern int expert_mode;extern xfs_mount_t *mp; -extern libxfs_init_t x; +extern struct libxfs_init x;extern xfs_agnumber_t cur_agno;growfs/xfs_growfs.c +1
-1@@ -61,7 +61,7 @@ main(int argc, char **argv)char *logdev;/* log device name */ char *rtdev;/* RT device name */ fs_path_t *fs;/* mount point information */ -libxfs_init_t xi;/* libxfs structure */ +struct libxfs_init xi;/* libxfs structure */ char rpath[PATH_MAX ];int ret;include/libxfs.h +6
-4@@ -92,7 +92,7 @@ struct iomap;/* * Argument structure for libxfs_init(). */ -typedef struct libxfs_xinit { +struct libxfs_init {/* input parameters */ char *dname;/* pathname of data "subvolume" */ char *logname;/* pathname of log "subvolume" */ @@ -123,7 +123,7 @@ typedef struct libxfs_xinit {int logfd;/* log subvolume file descriptor */ int rtfd;/* realtime subvolume file descriptor */ int bcache_flags;/* cache init flags */ -} libxfs_init_t; +};#define LIBXFS_ISREADONLY 0x0002/* disallow all mounted filesystems */ #define LIBXFS_ISINACTIVE 0x0004/* allow mounted only if mounted ro */ @@ -133,8 +133,10 @@ typedef struct libxfs_xinit {extern char *progname;extern xfs_lsn_t libxfs_max_lsn; -extern int libxfs_init (libxfs_init_t *); -void libxfs_destroy (struct libxfs_xinit *li); + +int libxfs_init (struct libxfs_init *); +void libxfs_destroy (struct libxfs_init *li); +extern int libxfs_device_to_fd (dev_t );extern dev_t libxfs_device_open (char *,int ,int ,int );extern void libxfs_device_close (dev_t );libxfs/init.c +3
-3@@ -273,7 +273,7 @@ destroy_caches(void)static void libxfs_close_devices ( -struct libxfs_xinit *li) +struct libxfs_init *li) {if (li->ddev)libxfs_device_close (li->ddev);@@ -291,7 +291,7 @@ libxfs_close_devices(* Caller gets a 0 on failure (and we print a message), 1 on success. */ int -libxfs_init (libxfs_init_t *a) +libxfs_init (struct libxfs_init *a) {char *dname;char *logname;@@ -1034,7 +1034,7 @@ libxfs_umount(*/ void libxfs_destroy ( -struct libxfs_xinit *li) +struct libxfs_init *li) {int leaked;libxfs/topology.c +3
-2@@ -286,8 +286,9 @@ static void blkid_get_topology(#endif /* ENABLE_BLKID */ -void get_topology ( -libxfs_init_t *xi, +void +get_topology ( +struct libxfs_init *xi,struct fs_topology *ft,int force_overwrite) {libxfs/topology.h +2
-2@@ -18,9 +18,9 @@ typedef struct fs_topology {int psectorsize;/* physical sector size */ } fs_topology_t; -extern void +void get_topology ( -libxfs_init_t *xi, +struct libxfs_init *xi,struct fs_topology *ft,int force_overwrite);logprint/logprint.c +1
-1@@ -25,7 +25,7 @@ int print_overwrite;int print_no_data;int print_no_print;static int print_operation =OP_PRINT ; -static struct libxfs_xinit x; +static struct libxfs_init x;static void usage (void )mkfs/xfs_mkfs.c +9
-9@@ -907,7 +907,7 @@ struct cli_params {struct fsxattr fsx;/* libxfs device setup */ -struct libxfs_xinit *xi; +struct libxfs_init *xi; };/* @@ -1246,7 +1246,7 @@ validate_ag_geometry(static void zero_old_xfs_structures ( -libxfs_init_t *xi, +struct libxfs_init *xi,xfs_sb_t *new_sb) {void *buf;@@ -2834,7 +2834,7 @@ _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"static void open_devices (struct mkfs_params *cfg, -struct libxfs_xinit *xi) +struct libxfs_init *xi) {uint64_t sector_mask;@@ -2867,7 +2867,7 @@ open_devices(static void discard_devices ( -struct libxfs_xinit *xi, +struct libxfs_init *xi,int quiet) {/* @@ -2887,7 +2887,7 @@ validate_datadev(struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi;if (!xi->dsize) {/* @@ -2934,7 +2934,7 @@ validate_logdev(struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi; cfg->loginternal = cli->loginternal;@@ -2998,7 +2998,7 @@ validate_rtdev(struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi;if (!xi->rtdev) {if (cli->rtsize) {@@ -3750,7 +3750,7 @@ alloc_write_buf(static void prepare_devices (struct mkfs_params *cfg, -struct libxfs_xinit *xi, +struct libxfs_init *xi,struct xfs_mount *mp,struct xfs_sb *sbp,bool clear_stale)@@ -4055,7 +4055,7 @@ main(char *protostring =NULL ;int worst_freelist =0 ; -struct libxfs_xinit xi = { +struct libxfs_init xi = { .isdirect =LIBXFS_DIRECT , .isreadonly =LIBXFS_EXCLUSIVELY , };repair/globals.h +1
-1@@ -169,6 +169,6 @@ extern int thread_count;/* If nonzero, simulate failure after this phase. */ extern int fail_after_phase; -extern libxfs_init_t x; +extern struct libxfs_init x;#endif /* _XFS_REPAIR_GLOBAL_H */ repair/init.c +3
-3@@ -18,7 +18,7 @@#include "libfrog/dahashselftest.h" #include <sys/resource.h> -struct libxfs_xinit x; +struct libxfs_init x;static void ts_create (void )@@ -52,9 +52,9 @@ increase_rlimit(void) }void -xfs_init (libxfs_init_t *args) +xfs_init (struct libxfs_init *args) { -memset (args,0 ,sizeof (libxfs_init_t)); +memset (args,0 ,sizeof (*args)); args->dname = fs_name; args->disfile = isa_file;repair/protos.h +1
-1@@ -4,7 +4,7 @@* All Rights Reserved. */ -void xfs_init (libxfs_init_t *args); +void xfs_init (struct libxfs_init *args); int verify_sb(char *sb_buf, xfs_sb_t *sb,repair/sb.c +1
-2@@ -176,7 +176,7 @@ static intguess_default_geometry ( uint64_t *agsize, uint64_t *agcount, - libxfs_init_t *x) + struct libxfs_init *x) {struct fs_topology ft;int blocklog; --2.39.2
PATCH 11/23 libxfs: pass a struct libxfs_init to libxfs_mount
In reply to Christoph HellwigPass a libxfs_init structure to libxfs_mount instead of three separate dev_t values.
--- copy/xfs_copy.c | 2 +- db/init.c | 3 +-- include/xfs_mount.h | 3 ++- libxfs/init.c | 8 +++----- mkfs/xfs_mkfs.c | 5 +++-- repair/xfs_repair.c | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-)
copy/xfs_copy.c +1 -1
@@ -755,7 +755,7 @@ main(int argc, char **argv) }libxfs_buf_relse (sbp); - mp =libxfs_mount (&mbuf, sb, xargs.ddev, xargs.logdev, xargs.rtdev,0 ); + mp =libxfs_mount (&mbuf, sb, &xargs,0 );if (mp ==NULL ) {do_log (_ ("%s: %s filesystem failed to initialize\n" "%s: Aborting.\n" ), progname, source_name, progname);
db/init.c +1 -2
@@ -130,8 +130,7 @@ init( } agcount = sbp->sb_agcount; - mp =libxfs_mount (&xmount, sbp, x.ddev, x.logdev, x.rtdev, -LIBXFS_MOUNT_DEBUGGER ); + mp =libxfs_mount (&xmount, sbp, &x,LIBXFS_MOUNT_DEBUGGER );if (!mp) { fprintf(stderr, _("%s: device %s unusable (not an XFS filesystem?)\n"),
include/xfs_mount.h +2 -1
@@ -10,6 +10,7 @@struct xfs_inode ;struct xfs_buftarg ;struct xfs_da_geometry ; +struct libxfs_init ;typedef void (*buf_writeback_fn )(struct xfs_buf *bp);
@@ -272,7 +273,7 @@ __XFS_UNSUPP_OPSTATE(shutdown)void libxfs_compute_all_maxlevels (struct xfs_mount *mp);struct xfs_mount *libxfs_mount (struct xfs_mount *mp,struct xfs_sb *sb, -dev_t dev,dev_t logdev,dev_t rtdev,unsigned int flags); +struct libxfs_init *xi,unsigned int flags);int libxfs_flush_mount (struct xfs_mount *mp);int libxfs_umount (struct xfs_mount *mp);extern void libxfs_rtmount_destroy (xfs_mount_t *);
libxfs/init.c +3 -5
@@ -744,9 +744,7 @@ struct xfs_mount *libxfs_mount ( struct xfs_mount *mp, struct xfs_sb *sb, - dev_t dev, - dev_t logdev, - dev_t rtdev, + struct libxfs_init *xi, unsigned int flags) { struct xfs_buf *bp;
@@ -759,7 +757,7 @@ libxfs_mount(xfs_set_debugger (mp);if (flags &LIBXFS_MOUNT_REPORT_CORRUPTION )xfs_set_reporting_corruption (mp); -libxfs_buftarg_init (mp, dev, logdev, rtdev); +libxfs_buftarg_init (mp, xi->ddev, xi->logdev, xi->rtdev); mp->m_finobt_nores = true;xfs_set_inode32 (mp);
@@ -825,7 +823,7 @@ libxfs_mount(/* Initialize the precomputed transaction reservations values */ xfs_trans_init (mp); -if (dev ==0 )/* maxtrres, we have no device so leave now */ +if (xi->ddev ==0 )/* maxtrres, we have no device so leave now */ return mp;/* device size checks must pass unless we're a debugger. */
mkfs/xfs_mkfs.c +3 -2
@@ -3483,11 +3483,12 @@ calculate_log_size(int min_logblocks;/* absolute minimum */ int max_logblocks;/* absolute max for this AG */ struct xfs_mount mount; +struct libxfs_init dummy_init = { };/* we need a temporary mount to calculate the minimum log size. */ memset (&mount,0 ,sizeof (mount)); mount.m_sb = *sbp; -libxfs_mount (&mount, &mp->m_sb,0 ,0 ,0 ,0 ); +libxfs_mount (&mount, &mp->m_sb, &dummy_init,0 ); min_logblocks =libxfs_log_calc_minimum_size (&mount);libxfs_umount (&mount);
@@ -4320,7 +4321,7 @@ main(* mount. */ prepare_devices (&cfg, &xi, mp, sbp, force_overwrite); - mp =libxfs_mount (mp, sbp, xi.ddev, xi.logdev, xi.rtdev,0 ); + mp =libxfs_mount (mp, sbp, &xi,0 );if (mp ==NULL ) {fprintf (stderr,_ ("%s: filesystem failed to initialize\n" ), progname);
repair/xfs_repair.c +1 -1
@@ -1034,7 +1034,7 @@ main(int argc, char **argv)* initialized in phase 2. */ memset (&xfs_m,0 ,sizeof (xfs_mount_t)); - mp =libxfs_mount (&xfs_m, &psb, x.ddev, x.logdev, x.rtdev,0 ); + mp =libxfs_mount (&xfs_m, &psb, &x,0 );if (!mp) { fprintf(stderr,
Signature · 1 line
2.39.2
Re: [PATCH 11/23] libxfs: pass a struct libxfs_init to libxfs_mount
Quoted 4 lines · Christoph Hellwig
Pass a
libxfs_initstructure tolibxfs_mountinstead of three separatedev_tvalues.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 134 lines
--- copy/xfs_copy.c | 2 +- db/init.c | 3 +-- include/xfs_mount.h | 3 ++- libxfs/init.c | 8 +++----- mkfs/xfs_mkfs.c | 5 +++-- repair/xfs_repair.c | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-)copy/xfs_copy.c +1
-1@@ -755,7 +755,7 @@ main(int argc, char **argv) }libxfs_buf_relse (sbp); - mp =libxfs_mount (&mbuf, sb, xargs.ddev, xargs.logdev, xargs.rtdev,0 ); + mp =libxfs_mount (&mbuf, sb, &xargs,0 );if (mp ==NULL ) {do_log (_ ("%s: %s filesystem failed to initialize\n" "%s: Aborting.\n" ), progname, source_name, progname);db/init.c +1
-2@@ -130,8 +130,7 @@ init( } agcount = sbp->sb_agcount; - mp =libxfs_mount (&xmount, sbp, x.ddev, x.logdev, x.rtdev, -LIBXFS_MOUNT_DEBUGGER ); + mp =libxfs_mount (&xmount, sbp, &x,LIBXFS_MOUNT_DEBUGGER );if (!mp) { fprintf(stderr, _("%s: device %s unusable (not an XFS filesystem?)\n"),include/xfs_mount.h +2
-1@@ -10,6 +10,7 @@struct xfs_inode ;struct xfs_buftarg ;struct xfs_da_geometry ; +struct libxfs_init ;typedef void (*buf_writeback_fn )(struct xfs_buf *bp);@@ -272,7 +273,7 @@ __XFS_UNSUPP_OPSTATE(shutdown)void libxfs_compute_all_maxlevels (struct xfs_mount *mp);struct xfs_mount *libxfs_mount (struct xfs_mount *mp,struct xfs_sb *sb, -dev_t dev,dev_t logdev,dev_t rtdev,unsigned int flags); +struct libxfs_init *xi,unsigned int flags);int libxfs_flush_mount (struct xfs_mount *mp);int libxfs_umount (struct xfs_mount *mp);extern void libxfs_rtmount_destroy (xfs_mount_t *);libxfs/init.c +3
-5@@ -744,9 +744,7 @@ struct xfs_mount *libxfs_mount ( struct xfs_mount *mp, struct xfs_sb *sb, - dev_t dev, - dev_t logdev, - dev_t rtdev, + struct libxfs_init *xi, unsigned int flags) { struct xfs_buf *bp;@@ -759,7 +757,7 @@ libxfs_mount(xfs_set_debugger (mp);if (flags &LIBXFS_MOUNT_REPORT_CORRUPTION )xfs_set_reporting_corruption (mp); -libxfs_buftarg_init (mp, dev, logdev, rtdev); +libxfs_buftarg_init (mp, xi->ddev, xi->logdev, xi->rtdev); mp->m_finobt_nores = true;xfs_set_inode32 (mp);@@ -825,7 +823,7 @@ libxfs_mount(/* Initialize the precomputed transaction reservations values */ xfs_trans_init (mp); -if (dev ==0 )/* maxtrres, we have no device so leave now */ +if (xi->ddev ==0 )/* maxtrres, we have no device so leave now */ return mp;/* device size checks must pass unless we're a debugger. */ mkfs/xfs_mkfs.c +3
-2@@ -3483,11 +3483,12 @@ calculate_log_size(int min_logblocks;/* absolute minimum */ int max_logblocks;/* absolute max for this AG */ struct xfs_mount mount; +struct libxfs_init dummy_init = { };/* we need a temporary mount to calculate the minimum log size. */ memset (&mount,0 ,sizeof (mount)); mount.m_sb = *sbp; -libxfs_mount (&mount, &mp->m_sb,0 ,0 ,0 ,0 ); +libxfs_mount (&mount, &mp->m_sb, &dummy_init,0 ); min_logblocks =libxfs_log_calc_minimum_size (&mount);libxfs_umount (&mount);@@ -4320,7 +4321,7 @@ main(* mount. */ prepare_devices (&cfg, &xi, mp, sbp, force_overwrite); - mp =libxfs_mount (mp, sbp, xi.ddev, xi.logdev, xi.rtdev,0 ); + mp =libxfs_mount (mp, sbp, &xi,0 );if (mp ==NULL ) {fprintf (stderr,_ ("%s: filesystem failed to initialize\n" ), progname);repair/xfs_repair.c +1
-2@@ -1034,7 +1034,7 @@ main(int argc, char **argv)* initialized in phase 2. */ memset (&xfs_m,0 ,sizeof (xfs_mount_t)); - mp =libxfs_mount (&xfs_m, &psb, x.ddev, x.logdev, x.rtdev,0 ); + mp =libxfs_mount (&xfs_m, &psb, &x,0 );if (!mp) { fprintf(stderr, --2.39.2
PATCH 12/23 libxfs: pass a struct libxfs_init to libxfs_alloc_buftarg
In reply to Christoph HellwigPass a libxfs_init structure to libxfs_alloc_buftarg instead of three separate dev_t values.
--- copy/xfs_copy.c | 2 +- db/init.c | 2 +- db/sb.c | 2 +- libxfs/init.c | 26 +++++++++++++------------- libxfs/libxfs_io.h | 4 ++-- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-)
copy/xfs_copy.c +1 -1
@@ -730,7 +730,7 @@ main(int argc, char **argv)memset (&mbuf,0 ,sizeof (xfs_mount_t));/* We don't yet know the sector size, so read maximal size */ -libxfs_buftarg_init (&mbuf, xargs.ddev, xargs.logdev, xargs.rtdev); +libxfs_buftarg_init (&mbuf, &xargs); error = -libxfs_buf_read_uncached (mbuf.m_ddev_targp,XFS_SB_DADDR ,1 << (XFS_MAX_SECTORSIZE_LOG -BBSHIFT ),0 , &sbp,NULL );if (error) {
db/init.c +1 -1
@@ -106,7 +106,7 @@ init(* tool and so need to be able to mount busted filesystems. */ memset (&xmount,0 ,sizeof (struct xfs_mount )); -libxfs_buftarg_init (&xmount, x.ddev, x.logdev, x.rtdev); +libxfs_buftarg_init (&xmount, &x); error = -libxfs_buf_read_uncached (xmount.m_ddev_targp,XFS_SB_DADDR ,1 << (XFS_MAX_SECTORSIZE_LOG -BBSHIFT ),0 , &bp,NULL );if (error) {
db/sb.c +1 -1
@@ -233,7 +233,7 @@ sb_logcheck(void) } } -libxfs_buftarg_init (mp, x.ddev, x.logdev, x.rtdev); +libxfs_buftarg_init (mp, &x); dirty =xlog_is_dirty (mp, mp->m_log);if (dirty ==-1 ) {
libxfs/init.c +13 -13
@@ -607,9 +607,7 @@ static char *wf_opts[] = {void libxfs_buftarg_init (struct xfs_mount *mp, -dev_t dev, -dev_t logdev, -dev_t rtdev) +struct libxfs_init *xi) {char *p =getenv ("LIBXFS_DEBUG_WRITE_CRASH" );unsigned long dfail =0 , lfail =0 , rfail =0 ;
@@ -653,29 +651,30 @@ libxfs_buftarg_init(if (mp->m_ddev_targp) {/* should already have all buftargs initialised */ -if (mp->m_ddev_targp->bt_bdev != dev || +if (mp->m_ddev_targp->bt_bdev != xi->ddev || mp->m_ddev_targp->bt_mount != mp) {fprintf (stderr,_ ("%s: bad buftarg reinit, ddev\n" ), progname);exit (1 ); } -if (!logdev || logdev == dev) { +if (!xi->logdev || xi->logdev == xi->ddev) {if (mp->m_logdev_targp != mp->m_ddev_targp) {fprintf (stderr,_ ("%s: bad buftarg reinit, ldev mismatch\n" ), progname);exit (1 ); } - }else if (mp->m_logdev_targp->bt_bdev != logdev || + }else if (mp->m_logdev_targp->bt_bdev != xi->logdev || mp->m_logdev_targp->bt_mount != mp) {fprintf (stderr,_ ("%s: bad buftarg reinit, logdev\n" ), progname);exit (1 ); } -if (rtdev && (mp->m_rtdev_targp->bt_bdev != rtdev || - mp->m_rtdev_targp->bt_mount != mp)) { +if (xi->rtdev && + (mp->m_rtdev_targp->bt_bdev != xi->rtdev || + mp->m_rtdev_targp->bt_mount != mp)) {fprintf (stderr,_ ("%s: bad buftarg reinit, rtdev\n" ), progname);
@@ -684,12 +683,13 @@ libxfs_buftarg_init(return ; } - mp->m_ddev_targp =libxfs_buftarg_alloc (mp, dev, dfail); -if (!logdev || logdev == dev) + mp->m_ddev_targp =libxfs_buftarg_alloc (mp, xi->ddev, dfail); +if (!xi->logdev || xi->logdev == xi->ddev) mp->m_logdev_targp = mp->m_ddev_targp;else - mp->m_logdev_targp =libxfs_buftarg_alloc (mp, logdev, lfail); - mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, rtdev, rfail); + mp->m_logdev_targp =libxfs_buftarg_alloc (mp, xi->logdev, + lfail); + mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, xi->rtdev, rfail); }/* Compute maximum possible height for per-AG btree types for this fs. */
@@ -757,7 +757,7 @@ libxfs_mount(xfs_set_debugger (mp);if (flags &LIBXFS_MOUNT_REPORT_CORRUPTION )xfs_set_reporting_corruption (mp); -libxfs_buftarg_init (mp, xi->ddev, xi->logdev, xi->rtdev); +libxfs_buftarg_init (mp, xi); mp->m_finobt_nores = true;xfs_set_inode32 (mp);
libxfs/libxfs_io.h +2 -2
@@ -14,6 +14,7 @@struct xfs_buf ;struct xfs_mount ;struct xfs_perag ; +struct libxfs_init ;/* * IO verifier callbacks need the xfs_mount pointer, so we have to behave
@@ -50,8 +51,7 @@ xfs_buftarg_trip_write(pthread_mutex_unlock (&btp->lock); } -extern void libxfs_buftarg_init (struct xfs_mount *mp,dev_t ddev, -dev_t logdev,dev_t rtdev); +void libxfs_buftarg_init (struct xfs_mount *mp,struct libxfs_init *xi);int libxfs_blkdev_issue_flush (struct xfs_buftarg *btp);#define LIBXFS_BBTOOFF64 (bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
logprint/logprint.c +1 -1
@@ -213,7 +213,7 @@ main(int argc, char **argv)if (!libxfs_init (&x))exit (1 ); -libxfs_buftarg_init (&mount, x.ddev, x.logdev, x.rtdev); +libxfs_buftarg_init (&mount, &x);logstat (&mount, &log); logfd = (x.logfd <0 ) ? x.dfd : x.logfd;
mkfs/xfs_mkfs.c +1 -1
@@ -4313,7 +4313,7 @@ main(/* * we need the libxfs buffer cache from here on in. */ -libxfs_buftarg_init (mp, xi.ddev, xi.logdev, xi.rtdev); +libxfs_buftarg_init (mp, &xi);/* * Before we mount the filesystem we need to make sure the devices have
Signature · 1 line
2.39.2
Re: [PATCH 12/23] libxfs: pass a struct libxfs_init to libxfs_alloc_buftarg
Quoted 4 lines · Christoph Hellwig
Pass a
libxfs_initstructure tolibxfs_alloc_buftarginstead of three separatedev_tvalues.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 178 lines
--- copy/xfs_copy.c | 2 +- db/init.c | 2 +- db/sb.c | 2 +- libxfs/init.c | 26 +++++++++++++------------- libxfs/libxfs_io.h | 4 ++-- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-)copy/xfs_copy.c +1
-1@@ -730,7 +730,7 @@ main(int argc, char **argv)memset (&mbuf,0 ,sizeof (xfs_mount_t));/* We don't yet know the sector size, so read maximal size */ -libxfs_buftarg_init (&mbuf, xargs.ddev, xargs.logdev, xargs.rtdev); +libxfs_buftarg_init (&mbuf, &xargs); error = -libxfs_buf_read_uncached (mbuf.m_ddev_targp,XFS_SB_DADDR ,1 << (XFS_MAX_SECTORSIZE_LOG -BBSHIFT ),0 , &sbp,NULL );if (error) {db/init.c +1
-1@@ -106,7 +106,7 @@ init(* tool and so need to be able to mount busted filesystems. */ memset (&xmount,0 ,sizeof (struct xfs_mount )); -libxfs_buftarg_init (&xmount, x.ddev, x.logdev, x.rtdev); +libxfs_buftarg_init (&xmount, &x); error = -libxfs_buf_read_uncached (xmount.m_ddev_targp,XFS_SB_DADDR ,1 << (XFS_MAX_SECTORSIZE_LOG -BBSHIFT ),0 , &bp,NULL );if (error) {db/sb.c +1
-1@@ -233,7 +233,7 @@ sb_logcheck(void) } } -libxfs_buftarg_init (mp, x.ddev, x.logdev, x.rtdev); +libxfs_buftarg_init (mp, &x); dirty =xlog_is_dirty (mp, mp->m_log);if (dirty ==-1 ) {libxfs/init.c +13
-13@@ -607,9 +607,7 @@ static char *wf_opts[] = {void libxfs_buftarg_init (struct xfs_mount *mp, -dev_t dev, -dev_t logdev, -dev_t rtdev) +struct libxfs_init *xi) {char *p =getenv ("LIBXFS_DEBUG_WRITE_CRASH" );unsigned long dfail =0 , lfail =0 , rfail =0 ;@@ -653,29 +651,30 @@ libxfs_buftarg_init(if (mp->m_ddev_targp) {/* should already have all buftargs initialised */ -if (mp->m_ddev_targp->bt_bdev != dev || +if (mp->m_ddev_targp->bt_bdev != xi->ddev || mp->m_ddev_targp->bt_mount != mp) {fprintf (stderr,_ ("%s: bad buftarg reinit, ddev\n" ), progname);exit (1 ); } -if (!logdev || logdev == dev) { +if (!xi->logdev || xi->logdev == xi->ddev) {if (mp->m_logdev_targp != mp->m_ddev_targp) {fprintf (stderr,_ ("%s: bad buftarg reinit, ldev mismatch\n" ), progname);exit (1 ); } - }else if (mp->m_logdev_targp->bt_bdev != logdev || + }else if (mp->m_logdev_targp->bt_bdev != xi->logdev || mp->m_logdev_targp->bt_mount != mp) {fprintf (stderr,_ ("%s: bad buftarg reinit, logdev\n" ), progname);exit (1 ); } -if (rtdev && (mp->m_rtdev_targp->bt_bdev != rtdev || - mp->m_rtdev_targp->bt_mount != mp)) { +if (xi->rtdev && + (mp->m_rtdev_targp->bt_bdev != xi->rtdev || + mp->m_rtdev_targp->bt_mount != mp)) {fprintf (stderr,_ ("%s: bad buftarg reinit, rtdev\n" ), progname);@@ -684,12 +683,13 @@ libxfs_buftarg_init(return ; } - mp->m_ddev_targp =libxfs_buftarg_alloc (mp, dev, dfail); -if (!logdev || logdev == dev) + mp->m_ddev_targp =libxfs_buftarg_alloc (mp, xi->ddev, dfail); +if (!xi->logdev || xi->logdev == xi->ddev) mp->m_logdev_targp = mp->m_ddev_targp;else - mp->m_logdev_targp =libxfs_buftarg_alloc (mp, logdev, lfail); - mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, rtdev, rfail); + mp->m_logdev_targp =libxfs_buftarg_alloc (mp, xi->logdev, + lfail); + mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, xi->rtdev, rfail); }/* Compute maximum possible height for per-AG btree types for this fs. */ @@ -757,7 +757,7 @@ libxfs_mount(xfs_set_debugger (mp);if (flags &LIBXFS_MOUNT_REPORT_CORRUPTION )xfs_set_reporting_corruption (mp); -libxfs_buftarg_init (mp, xi->ddev, xi->logdev, xi->rtdev); +libxfs_buftarg_init (mp, xi); mp->m_finobt_nores = true;xfs_set_inode32 (mp);libxfs/libxfs_io.h +2
-2@@ -14,6 +14,7 @@struct xfs_buf ;struct xfs_mount ;struct xfs_perag ; +struct libxfs_init ;/* * IO verifier callbacks need the xfs_mount pointer, so we have to behave @@ -50,8 +51,7 @@ xfs_buftarg_trip_write(pthread_mutex_unlock (&btp->lock); } -extern void libxfs_buftarg_init (struct xfs_mount *mp,dev_t ddev, -dev_t logdev,dev_t rtdev); +void libxfs_buftarg_init (struct xfs_mount *mp,struct libxfs_init *xi);int libxfs_blkdev_issue_flush (struct xfs_buftarg *btp);#define LIBXFS_BBTOOFF64 (bbs) (((xfs_off_t)(bbs)) << BBSHIFT)logprint/logprint.c +1
-1@@ -213,7 +213,7 @@ main(int argc, char **argv)if (!libxfs_init (&x))exit (1 ); -libxfs_buftarg_init (&mount, x.ddev, x.logdev, x.rtdev); +libxfs_buftarg_init (&mount, &x);logstat (&mount, &log); logfd = (x.logfd <0 ) ? x.dfd : x.logfd;mkfs/xfs_mkfs.c +1
-2@@ -4313,7 +4313,7 @@ main(/* * we need the libxfs buffer cache from here on in. */ -libxfs_buftarg_init (mp, xi.ddev, xi.logdev, xi.rtdev); +libxfs_buftarg_init (mp, &xi);/* * Before we mount the filesystem we need to make sure the devices have -- 2.39.2
PATCH 13/23 libxfs: merge the file vs device cases in libxfs_init
In reply to Christoph HellwigThe only special handling for an XFS device on a regular file is that we skip the checks in check_open. Simplify perform those conditionally instead of duplicating the entire sequence.
--- libxfs/init.c | 74 ++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 51 deletions(-)
libxfs/init.c +23 -51
@@ -313,59 +313,31 @@ libxfs_init(struct libxfs_init *a)radix_tree_init ();if (dname) { -if (a->disfile) { - a->ddev=libxfs_device_open (dname, a->dcreat, flags, - a->setblksize); - a->dfd =libxfs_device_to_fd (a->ddev); -platform_findsizes (dname, a->dfd, &a->dsize, - &a->dbsize); - }else { -if (!check_open (dname, flags)) - goto done; - a->ddev =libxfs_device_open (dname, - a->dcreat, flags, a->setblksize); - a->dfd =libxfs_device_to_fd (a->ddev); -platform_findsizes (dname, a->dfd, - &a->dsize, &a->dbsize); - } - }else - a->dsize =0 ; +if (!a->disfile && !check_open (dname, flags)) + goto done; + a->ddev =libxfs_device_open (dname, a->dcreat, flags, + a->setblksize); + a->dfd =libxfs_device_to_fd (a->ddev); +platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); + }if (logname) { -if (a->lisfile) { - a->logdev =libxfs_device_open (logname, - a->lcreat, flags, a->setblksize); - a->logfd =libxfs_device_to_fd (a->logdev); -platform_findsizes (dname, a->logfd, &a->logBBsize, - &a->lbsize); - }else { -if (!check_open (logname, flags)) - goto done; - a->logdev =libxfs_device_open (logname, - a->lcreat, flags, a->setblksize); - a->logfd =libxfs_device_to_fd (a->logdev); -platform_findsizes (logname, a->logfd, - &a->logBBsize, &a->lbsize); - } - }else - a->logBBsize =0 ; +if (!a->lisfile && !check_open (logname, flags)) + goto done; + a->logdev =libxfs_device_open (logname, a->lcreat, flags, + a->setblksize); + a->logfd =libxfs_device_to_fd (a->logdev); +platform_findsizes (logname, a->logfd, &a->logBBsize, + &a->lbsize); + }if (rtname) { -if (a->risfile) { - a->rtdev =libxfs_device_open (rtname, - a->rcreat, flags, a->setblksize); - a->rtfd =libxfs_device_to_fd (a->rtdev); -platform_findsizes (dname, a->rtfd, &a->rtsize, - &a->rtbsize); - }else { -if (!check_open (rtname, flags)) - goto done; - a->rtdev =libxfs_device_open (rtname, - a->rcreat, flags, a->setblksize); - a->rtfd =libxfs_device_to_fd (a->rtdev); -platform_findsizes (rtname, a->rtfd, - &a->rtsize, &a->rtbsize); - } - }else - a->rtsize =0 ; +if (a->risfile && !check_open (rtname, flags)) + goto done; + a->rtdev =libxfs_device_open (rtname, a->rcreat, flags, + a->setblksize); + a->rtfd =libxfs_device_to_fd (a->rtdev); +platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); + } +if (a->dsize <0 ) {fprintf (stderr,_ ("%s: can't get size for data subvolume\n" ), progname);
Signature · 1 line
2.39.2
Re: [PATCH 13/23] libxfs: merge the file vs device cases in libxfs_init
Quoted 5 lines · Christoph Hellwig
The only special handling for an XFS device on a regular file is that we skip the checks in
check_open. Simplify perform those conditionally instead of duplicating the entire sequence.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 94 lines
--- libxfs/init.c | 74 ++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 51 deletions(-)libxfs/init.c +23
-52@@ -313,59 +313,31 @@ libxfs_init(struct libxfs_init *a)radix_tree_init ();if (dname) { -if (a->disfile) { - a->ddev=libxfs_device_open (dname, a->dcreat, flags, - a->setblksize); - a->dfd =libxfs_device_to_fd (a->ddev); -platform_findsizes (dname, a->dfd, &a->dsize, - &a->dbsize); - }else { -if (!check_open (dname, flags)) - goto done; - a->ddev =libxfs_device_open (dname, - a->dcreat, flags, a->setblksize); - a->dfd =libxfs_device_to_fd (a->ddev); -platform_findsizes (dname, a->dfd, - &a->dsize, &a->dbsize); - } - }else - a->dsize =0 ; +if (!a->disfile && !check_open (dname, flags)) + goto done; + a->ddev =libxfs_device_open (dname, a->dcreat, flags, + a->setblksize); + a->dfd =libxfs_device_to_fd (a->ddev); +platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); + }if (logname) { -if (a->lisfile) { - a->logdev =libxfs_device_open (logname, - a->lcreat, flags, a->setblksize); - a->logfd =libxfs_device_to_fd (a->logdev); -platform_findsizes (dname, a->logfd, &a->logBBsize, - &a->lbsize); - }else { -if (!check_open (logname, flags)) - goto done; - a->logdev =libxfs_device_open (logname, - a->lcreat, flags, a->setblksize); - a->logfd =libxfs_device_to_fd (a->logdev); -platform_findsizes (logname, a->logfd, - &a->logBBsize, &a->lbsize); - } - }else - a->logBBsize =0 ; +if (!a->lisfile && !check_open (logname, flags)) + goto done; + a->logdev =libxfs_device_open (logname, a->lcreat, flags, + a->setblksize); + a->logfd =libxfs_device_to_fd (a->logdev); +platform_findsizes (logname, a->logfd, &a->logBBsize, + &a->lbsize); + }if (rtname) { -if (a->risfile) { - a->rtdev =libxfs_device_open (rtname, - a->rcreat, flags, a->setblksize); - a->rtfd =libxfs_device_to_fd (a->rtdev); -platform_findsizes (dname, a->rtfd, &a->rtsize, - &a->rtbsize); - }else { -if (!check_open (rtname, flags)) - goto done; - a->rtdev =libxfs_device_open (rtname, - a->rcreat, flags, a->setblksize); - a->rtfd =libxfs_device_to_fd (a->rtdev); -platform_findsizes (rtname, a->rtfd, - &a->rtsize, &a->rtbsize); - } - }else - a->rtsize =0 ; +if (a->risfile && !check_open (rtname, flags)) + goto done; + a->rtdev =libxfs_device_open (rtname, a->rcreat, flags, + a->setblksize); + a->rtfd =libxfs_device_to_fd (a->rtdev); +platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); + } +if (a->dsize <0 ) {fprintf (stderr,_ ("%s: can't get size for data subvolume\n" ), progname); --2.39.2
PATCH 14/23 libxfs: making passing flags to libxfs_init less confusing
In reply to Christoph HellwigThe libxfs_xinit stucture has four different ways to pass flags to libxfs_init:
- the isreadonly argument despite it's name contains various LIBXFS_ flags that go beyond just the readonly flag
- the isdirect flag contains a single LIBXFS_ flag from the same name
- the usebuflock is an integer used as bool
- the bcache_flags member is used to pass flags directly to cache_init() for the buffer cache
While there is good arguments for keeping the last one separate, all the others are rather confusing. Consolidate them into a single flags member using flags in the LIBXFS_* namespace.
--- copy/xfs_copy.c | 4 +--- db/crc.c | 2 +- db/fuzz.c | 2 +- db/init.c | 6 +++--- db/sb.c | 6 +++--- db/write.c | 2 +- growfs/xfs_growfs.c | 2 +- include/libxfs.h | 26 ++++++++++++++++++-------- libxfs/init.c | 17 +++++++---------- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 5 ++--- repair/init.c | 15 ++++++++------- 12 files changed, 47 insertions(+), 42 deletions(-)
copy/xfs_copy.c +1 -3
@@ -715,9 +715,7 @@ main(int argc, char **argv)/* prepare the libxfs_init structure */ memset (&xargs,0 ,sizeof (xargs)); - xargs.isdirect =LIBXFS_DIRECT ; - xargs.isreadonly =LIBXFS_ISREADONLY ; - + xargs.flags =LIBXFS_ISREADONLY |LIBXFS_DIRECT ; xargs.dname = source_name; xargs.disfile = source_is_file;
db/crc.c +1 -1
@@ -98,7 +98,7 @@ crc_f( }if ((invalidate || recalculate) && - ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode)) { + ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode)) {dbprintf (_ ("%s not in expert mode, writing disabled\n" ), progname);return 0 ;
db/fuzz.c +1 -1
@@ -77,7 +77,7 @@ fuzz_f(struct xfs_buf_ops local_ops;const struct xfs_buf_ops *stashed_ops =NULL ; -if (x.isreadonly &LIBXFS_ISREADONLY ) { +if (x.flags &LIBXFS_ISREADONLY ) {dbprintf (_ ("%s started in read only mode, fuzzing disabled\n" ), progname);return 0 ;
db/init.c +3 -3
@@ -67,13 +67,13 @@ init( force =1 ;break ;case 'i' : - x.isreadonly = (LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ); + x.flags =LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ;break ;case 'p' : progname = optarg;break ;case 'r' : - x.isreadonly =LIBXFS_ISREADONLY ; + x.flags =LIBXFS_ISREADONLY ;break ;case 'l' : x.logname = optarg;
@@ -92,7 +92,7 @@ init(usage (); x.dname = argv[optind]; - x.isdirect =LIBXFS_DIRECT ; + x.flags |=LIBXFS_DIRECT ; x.bcache_flags =CACHE_MISCOMPARE_PURGE ;if (!libxfs_init (&x)) {
db/sb.c +3 -3
@@ -374,7 +374,7 @@ uuid_f(if (argc ==2 ) {/* WRITE UUID */ -if ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode) { +if ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode) {dbprintf (_ ("%s: not in expert mode, writing disabled\n" ), progname);return 0 ;
@@ -542,7 +542,7 @@ label_f(if (argc ==2 ) {/* WRITE LABEL */ -if ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode) { +if ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode) {dbprintf (_ ("%s: not in expert mode, writing disabled\n" ), progname);return 0 ;
@@ -727,7 +727,7 @@ version_f(if (argc ==2 ) {/* WRITE VERSION */ -if ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode) { +if ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode) {dbprintf (_ ("%s: not in expert mode, writing disabled\n" ), progname);return 0 ;
db/write.c +1 -1
@@ -88,7 +88,7 @@ write_f(struct xfs_buf_ops local_ops;const struct xfs_buf_ops *stashed_ops =NULL ; -if (x.isreadonly &LIBXFS_ISREADONLY ) { +if (x.flags &LIBXFS_ISREADONLY ) {dbprintf (_ ("%s started in read only mode, writing disabled\n" ), progname);return 0 ;
growfs/xfs_growfs.c +1 -1
@@ -186,7 +186,7 @@ main(int argc, char **argv) xi.dname = datadev; xi.logname = logdev; xi.rtname = rtdev; - xi.isreadonly =LIBXFS_ISREADONLY ; + xi.flags =LIBXFS_ISREADONLY ;if (!libxfs_init (&xi))usage ();
include/libxfs.h +18 -8
@@ -97,8 +97,7 @@ struct libxfs_init {char *dname;/* pathname of data "subvolume" */ char *logname;/* pathname of log "subvolume" */ char *rtname;/* pathname of realtime "subvolume" */ -int isreadonly;/* filesystem is only read in applic */ -int isdirect;/* we can attempt to use direct I/O */ +unsigned flags;/* LIBXFS_* flags below */ int disfile;/* data "subvolume" is a regular file */ int dcreat;/* try to create data subvolume */ int lisfile;/* log "subvolume" is a regular file */
@@ -106,7 +105,6 @@ struct libxfs_init {int risfile;/* realtime "subvolume" is a reg file */ int rcreat;/* try to create realtime subvolume */ int setblksize;/* attempt to set device blksize */ -int usebuflock;/* lock xfs_buf's - for MT usage */ /* output results */ dev_t ddev;/* device for data subvolume */ dev_t logdev;/* device for log subvolume */
@@ -125,11 +123,23 @@ struct libxfs_init {int bcache_flags;/* cache init flags */ }; -#define LIBXFS_ISREADONLY 0x0002/* disallow all mounted filesystems */ -#define LIBXFS_ISINACTIVE 0x0004/* allow mounted only if mounted ro */ -#define LIBXFS_DANGEROUSLY 0x0008/* repairing a device mounted ro */ -#define LIBXFS_EXCLUSIVELY 0x0010/* disallow other accesses (O_EXCL) */ -#define LIBXFS_DIRECT 0x0020/* can use direct I/O, not buffered */ +/* disallow all mounted filesystems: */ +#define LIBXFS_ISREADONLY (1U << 0) + +/* allow mounted only if mounted ro: */ +#define LIBXFS_ISINACTIVE (1U << 1) + +/* repairing a device mounted ro: */ +#define LIBXFS_DANGEROUSLY (1U << 2) + +/* disallow other accesses (O_EXCL): */ +#define LIBXFS_EXCLUSIVELY (1U << 3) + +/* can use direct I/O, not buffered: */ +#define LIBXFS_DIRECT (1U << 4) + +/* lock xfs_buf's - for MT usage */ +#define LIBXFS_USEBUFLOCK (1U << 5)extern char *progname;extern xfs_lsn_t libxfs_max_lsn;
libxfs/init.c +7 -10
@@ -296,7 +296,6 @@ libxfs_init(struct libxfs_init *a)char *dname;char *logname;char *rtname; -int flags; dname = a->dname; logname = a->logname;
@@ -306,33 +305,31 @@ libxfs_init(struct libxfs_init *a) a->dsize = a->lbsize = a->rtbsize =0 ; a->dbsize = a->logBBsize = a->rtsize =0 ; - flags = (a->isreadonly | a->isdirect); -rcu_init ();rcu_register_thread ();radix_tree_init ();if (dname) { -if (!a->disfile && !check_open (dname, flags)) +if (!a->disfile && !check_open (dname, a->flags)) goto done; - a->ddev =libxfs_device_open (dname, a->dcreat, flags, + a->ddev =libxfs_device_open (dname, a->dcreat, a->flags, a->setblksize); a->dfd =libxfs_device_to_fd (a->ddev);platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); }if (logname) { -if (!a->lisfile && !check_open (logname, flags)) +if (!a->lisfile && !check_open (logname, a->flags)) goto done; - a->logdev =libxfs_device_open (logname, a->lcreat, flags, + a->logdev =libxfs_device_open (logname, a->lcreat, a->flags, a->setblksize); a->logfd =libxfs_device_to_fd (a->logdev);platform_findsizes (logname, a->logfd, &a->logBBsize, &a->lbsize); }if (rtname) { -if (a->risfile && !check_open (rtname, flags)) +if (a->risfile && !check_open (rtname, a->flags)) goto done; - a->rtdev =libxfs_device_open (rtname, a->rcreat, flags, + a->rtdev =libxfs_device_open (rtname, a->rcreat, a->flags, a->setblksize); a->rtfd =libxfs_device_to_fd (a->rtdev);platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize);
@@ -357,7 +354,7 @@ libxfs_init(struct libxfs_init *a) libxfs_bhash_size =LIBXFS_BHASHSIZE (sbp); libxfs_bcache =cache_init (a->bcache_flags, libxfs_bhash_size, &libxfs_bcache_operations); - use_xfs_buf_lock = a->usebuflock; + use_xfs_buf_lock = a->flags &LIBXFS_USEBUFLOCK ;xfs_dir_startup ();init_caches ();return 1 ;
logprint/logprint.c +1 -1
@@ -208,7 +208,7 @@ main(int argc, char **argv)if (x.dname ==NULL )usage (); - x.isreadonly =LIBXFS_ISINACTIVE ; + x.flags =LIBXFS_ISINACTIVE ;printf (_ ("xfs_logprint:\n" ));if (!libxfs_init (&x))exit (1 );
mkfs/xfs_mkfs.c +2 -3
@@ -1984,7 +1984,7 @@ validate_sectorsize(* host filesystem. */ if (cli->xi->disfile || cli->xi->lisfile || cli->xi->risfile) - cli->xi->isdirect =0 ; + cli->xi->flags &= ~LIBXFS_DIRECT ;memset (ft,0 ,sizeof (*ft));get_topology (cli->xi, ft, force_overwrite);
@@ -4057,8 +4057,7 @@ main(int worst_freelist =0 ;struct libxfs_init xi = { - .isdirect =LIBXFS_DIRECT , - .isreadonly =LIBXFS_EXCLUSIVELY , + .flags =LIBXFS_EXCLUSIVELY |LIBXFS_DIRECT , };struct xfs_mount mbuf = {};struct xfs_mount *mp = &mbuf;
repair/init.c +8 -7
@@ -72,21 +72,22 @@ xfs_init(struct libxfs_init *args)/* XXX assume data file also means rt file */ } - args->usebuflock = do_prefetch; args->setblksize =0 ; - args->isdirect =LIBXFS_DIRECT ;if (no_modify) - args->isreadonly = (LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ); + args->flags =LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ;else if (dangerously) - args->isreadonly = (LIBXFS_ISINACTIVE |LIBXFS_DANGEROUSLY ); + args->flags =LIBXFS_ISINACTIVE |LIBXFS_DANGEROUSLY ;else - args->isreadonly =LIBXFS_EXCLUSIVELY ; + args->flags =LIBXFS_EXCLUSIVELY ; + args->flags |=LIBXFS_DIRECT ; +if (do_prefetch) + args->flags |=LIBXFS_USEBUFLOCK ;if (!libxfs_init (args)) {/* would -d be an option? */ if (!no_modify && !dangerously) { - args->isreadonly = (LIBXFS_ISINACTIVE | -LIBXFS_DANGEROUSLY ); + args->flags &= ~LIBXFS_EXCLUSIVELY ; + args->flags |=LIBXFS_ISINACTIVE |LIBXFS_DANGEROUSLY ;if (libxfs_init (args))fprintf (stderr,_ ("Unmount or use the dangerous (-d) option to repair a read-only mounted filesystem\n" ));
Signature · 1 line
2.39.2
Re: [PATCH 14/23] libxfs: making passing flags to libxfs_init less confusing
Quoted 10 lines · Christoph Hellwig
The
libxfs_xinitstucture has four different ways to pass flags tolibxfs_init:- the isreadonly argument despite it's name contains various
LIBXFS_flags that go beyond just the readonly flag
- the isdirect flag contains a singleLIBXFS_flag from the same name
- the usebuflock is an integer used as bool
- thebcache_flagsmember is used to pass flags directly tocache_init()for the buffer cache
Quoted 3 lines
While there is good arguments for keeping the last one separate, all the others are rather confusing. Consolidate them into a single flags member using flags in the LIBXFS_* namespace.
Quoted 327 lines
--- copy/xfs_copy.c | 4 +--- db/crc.c | 2 +- db/fuzz.c | 2 +- db/init.c | 6 +++--- db/sb.c | 6 +++--- db/write.c | 2 +- growfs/xfs_growfs.c | 2 +- include/libxfs.h | 26 ++++++++++++++++++-------- libxfs/init.c | 17 +++++++---------- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 5 ++--- repair/init.c | 15 ++++++++------- 12 files changed, 47 insertions(+), 42 deletions(-)copy/xfs_copy.c +1
-3@@ -715,9 +715,7 @@ main(int argc, char **argv)/* prepare the libxfs_init structure */ memset (&xargs,0 ,sizeof (xargs)); - xargs.isdirect =LIBXFS_DIRECT ; - xargs.isreadonly =LIBXFS_ISREADONLY ; - + xargs.flags =LIBXFS_ISREADONLY |LIBXFS_DIRECT ; xargs.dname = source_name; xargs.disfile = source_is_file;db/crc.c +1
-1@@ -98,7 +98,7 @@ crc_f( }if ((invalidate || recalculate) && - ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode)) { + ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode)) {dbprintf (_ ("%s not in expert mode, writing disabled\n" ), progname);return 0 ;db/fuzz.c +1
-1@@ -77,7 +77,7 @@ fuzz_f(struct xfs_buf_ops local_ops;const struct xfs_buf_ops *stashed_ops =NULL ; -if (x.isreadonly &LIBXFS_ISREADONLY ) { +if (x.flags &LIBXFS_ISREADONLY ) {dbprintf (_ ("%s started in read only mode, fuzzing disabled\n" ), progname);return 0 ;db/init.c +3
-3@@ -67,13 +67,13 @@ init( force =1 ;break ;case 'i' : - x.isreadonly = (LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ); + x.flags =LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ;break ;case 'p' : progname = optarg;break ;case 'r' : - x.isreadonly =LIBXFS_ISREADONLY ; + x.flags =LIBXFS_ISREADONLY ;break ;case 'l' : x.logname = optarg;@@ -92,7 +92,7 @@ init(usage (); x.dname = argv[optind]; - x.isdirect =LIBXFS_DIRECT ; + x.flags |=LIBXFS_DIRECT ; x.bcache_flags =CACHE_MISCOMPARE_PURGE ;if (!libxfs_init (&x)) {db/sb.c +3
-3@@ -374,7 +374,7 @@ uuid_f(if (argc ==2 ) {/* WRITE UUID */ -if ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode) { +if ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode) {dbprintf (_ ("%s: not in expert mode, writing disabled\n" ), progname);return 0 ;@@ -542,7 +542,7 @@ label_f(if (argc ==2 ) {/* WRITE LABEL */ -if ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode) { +if ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode) {dbprintf (_ ("%s: not in expert mode, writing disabled\n" ), progname);return 0 ;@@ -727,7 +727,7 @@ version_f(if (argc ==2 ) {/* WRITE VERSION */ -if ((x.isreadonly &LIBXFS_ISREADONLY ) || !expert_mode) { +if ((x.flags &LIBXFS_ISREADONLY ) || !expert_mode) {dbprintf (_ ("%s: not in expert mode, writing disabled\n" ), progname);return 0 ;db/write.c +1
-1@@ -88,7 +88,7 @@ write_f(struct xfs_buf_ops local_ops;const struct xfs_buf_ops *stashed_ops =NULL ; -if (x.isreadonly &LIBXFS_ISREADONLY ) { +if (x.flags &LIBXFS_ISREADONLY ) {dbprintf (_ ("%s started in read only mode, writing disabled\n" ), progname);return 0 ;growfs/xfs_growfs.c +1
-1@@ -186,7 +186,7 @@ main(int argc, char **argv) xi.dname = datadev; xi.logname = logdev; xi.rtname = rtdev; - xi.isreadonly =LIBXFS_ISREADONLY ; + xi.flags =LIBXFS_ISREADONLY ;if (!libxfs_init (&xi))usage ();include/libxfs.h +18
-8@@ -97,8 +97,7 @@ struct libxfs_init {char *dname;/* pathname of data "subvolume" */ char *logname;/* pathname of log "subvolume" */ char *rtname;/* pathname of realtime "subvolume" */ -int isreadonly;/* filesystem is only read in applic */ -int isdirect;/* we can attempt to use direct I/O */ +unsigned flags;/* LIBXFS_* flags below */ int disfile;/* data "subvolume" is a regular file */ int dcreat;/* try to create data subvolume */ int lisfile;/* log "subvolume" is a regular file */ @@ -106,7 +105,6 @@ struct libxfs_init {int risfile;/* realtime "subvolume" is a reg file */ int rcreat;/* try to create realtime subvolume */ int setblksize;/* attempt to set device blksize */ -int usebuflock;/* lock xfs_buf's - for MT usage */ /* output results */ dev_t ddev;/* device for data subvolume */ dev_t logdev;/* device for log subvolume */ @@ -125,11 +123,23 @@ struct libxfs_init {int bcache_flags;/* cache init flags */ }; -#define LIBXFS_ISREADONLY 0x0002/* disallow all mounted filesystems */ -#define LIBXFS_ISINACTIVE 0x0004/* allow mounted only if mounted ro */ -#define LIBXFS_DANGEROUSLY 0x0008/* repairing a device mounted ro */ -#define LIBXFS_EXCLUSIVELY 0x0010/* disallow other accesses (O_EXCL) */ -#define LIBXFS_DIRECT 0x0020/* can use direct I/O, not buffered */ +/* disallow all mounted filesystems: */ +#define LIBXFS_ISREADONLY (1U << 0) + +/* allow mounted only if mounted ro: */ +#define LIBXFS_ISINACTIVE (1U << 1) + +/* repairing a device mounted ro: */ +#define LIBXFS_DANGEROUSLY (1U << 2) + +/* disallow other accesses (O_EXCL): */ +#define LIBXFS_EXCLUSIVELY (1U << 3) + +/* can use direct I/O, not buffered: */ +#define LIBXFS_DIRECT (1U << 4) + +/* lock xfs_buf's - for MT usage */ +#define LIBXFS_USEBUFLOCK (1U << 5)extern char *progname;extern xfs_lsn_t libxfs_max_lsn;libxfs/init.c +7
-10@@ -296,7 +296,6 @@ libxfs_init(struct libxfs_init *a)char *dname;char *logname;char *rtname; -int flags; dname = a->dname; logname = a->logname;@@ -306,33 +305,31 @@ libxfs_init(struct libxfs_init *a) a->dsize = a->lbsize = a->rtbsize =0 ; a->dbsize = a->logBBsize = a->rtsize =0 ; - flags = (a->isreadonly | a->isdirect); -rcu_init ();rcu_register_thread ();radix_tree_init ();if (dname) { -if (!a->disfile && !check_open (dname, flags)) +if (!a->disfile && !check_open (dname, a->flags)) goto done; - a->ddev =libxfs_device_open (dname, a->dcreat, flags, + a->ddev =libxfs_device_open (dname, a->dcreat, a->flags, a->setblksize); a->dfd =libxfs_device_to_fd (a->ddev);platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); }if (logname) { -if (!a->lisfile && !check_open (logname, flags)) +if (!a->lisfile && !check_open (logname, a->flags)) goto done; - a->logdev =libxfs_device_open (logname, a->lcreat, flags, + a->logdev =libxfs_device_open (logname, a->lcreat, a->flags, a->setblksize); a->logfd =libxfs_device_to_fd (a->logdev);platform_findsizes (logname, a->logfd, &a->logBBsize, &a->lbsize); }if (rtname) { -if (a->risfile && !check_open (rtname, flags)) +if (a->risfile && !check_open (rtname, a->flags)) goto done; - a->rtdev =libxfs_device_open (rtname, a->rcreat, flags, + a->rtdev =libxfs_device_open (rtname, a->rcreat, a->flags, a->setblksize); a->rtfd =libxfs_device_to_fd (a->rtdev);platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize);@@ -357,7 +354,7 @@ libxfs_init(struct libxfs_init *a) libxfs_bhash_size =LIBXFS_BHASHSIZE (sbp); libxfs_bcache =cache_init (a->bcache_flags, libxfs_bhash_size, &libxfs_bcache_operations); - use_xfs_buf_lock = a->usebuflock; + use_xfs_buf_lock = a->flags &LIBXFS_USEBUFLOCK ;xfs_dir_startup ();init_caches ();return 1 ;logprint/logprint.c +1
-1@@ -208,7 +208,7 @@ main(int argc, char **argv)if (x.dname ==NULL )usage (); - x.isreadonly =LIBXFS_ISINACTIVE ; + x.flags =LIBXFS_ISINACTIVE ;printf (_ ("xfs_logprint:\n" ));if (!libxfs_init (&x))exit (1 );mkfs/xfs_mkfs.c +2
-3@@ -1984,7 +1984,7 @@ validate_sectorsize(* host filesystem. */ if (cli->xi->disfile || cli->xi->lisfile || cli->xi->risfile) - cli->xi->isdirect =0 ; + cli->xi->flags &= ~LIBXFS_DIRECT ;memset (ft,0 ,sizeof (*ft));get_topology (cli->xi, ft, force_overwrite);@@ -4057,8 +4057,7 @@ main(int worst_freelist =0 ;struct libxfs_init xi = { - .isdirect =LIBXFS_DIRECT , - .isreadonly =LIBXFS_EXCLUSIVELY , + .flags =LIBXFS_EXCLUSIVELY |LIBXFS_DIRECT , };struct xfs_mount mbuf = {};struct xfs_mount *mp = &mbuf;repair/init.c +8
-8@@ -72,21 +72,22 @@ xfs_init(struct libxfs_init *args)/* XXX assume data file also means rt file */ } - args->usebuflock = do_prefetch; args->setblksize =0 ; - args->isdirect =LIBXFS_DIRECT ;if (no_modify) - args->isreadonly = (LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ); + args->flags =LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE ;else if (dangerously) - args->isreadonly = (LIBXFS_ISINACTIVE |LIBXFS_DANGEROUSLY ); + args->flags =LIBXFS_ISINACTIVE |LIBXFS_DANGEROUSLY ;else - args->isreadonly =LIBXFS_EXCLUSIVELY ; + args->flags =LIBXFS_EXCLUSIVELY ; + args->flags |=LIBXFS_DIRECT ; +if (do_prefetch) + args->flags |=LIBXFS_USEBUFLOCK ;if (!libxfs_init (args)) {/* would -d be an option? */ if (!no_modify && !dangerously) { - args->isreadonly = (LIBXFS_ISINACTIVE | -LIBXFS_DANGEROUSLY ); + args->flags &= ~LIBXFS_EXCLUSIVELY ; + args->flags |=LIBXFS_ISINACTIVE |LIBXFS_DANGEROUSLY ;if (libxfs_init (args))fprintf (stderr,_ ("Unmount or use the dangerous (-d) option to repair a read-only mounted filesystem\n" )); --2.39.2
Re: [PATCH 14/23] libxfs: making passing flags to libxfs_init less confusing
PATCH 15/23 libxfs: remove the setblksize == 1 case in libxfs_device_open
In reply to Christoph HellwigAll callers of libxfs_init always pass an actual sector size or zero in the setblksize member. Remove the unreachable setblksize == 1 case.
--- libxfs/init.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
libxfs/init.c +1 -4
@@ -125,10 +125,7 @@ retry: }if (!readonly && setblksize && (statb.st_mode &S_IFMT ) ==S_IFBLK ) { -if (setblksize ==1 ) { -/* use the default blocksize */ - (void )platform_set_blocksize (fd, path, statb.st_rdev,XFS_MIN_SECTORSIZE ,0 ); - }else if (dio) { +if (dio) {/* try to use the given explicit blocksize */ (void )platform_set_blocksize (fd, path, statb.st_rdev, setblksize,0 );
Signature · 1 line
2.39.2
Re: [PATCH 15/23] libxfs: remove the setblksize == 1 case in libxfs_device_open
Quoted 4 lines · Christoph Hellwig
All callers of
libxfs_initalways pass an actual sector size or zero in the setblksize member. Remove the unreachable setblksize == 1 case.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 23 lines
--- libxfs/init.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)libxfs/init.c +1
-5@@ -125,10 +125,7 @@ retry: }if (!readonly && setblksize && (statb.st_mode &S_IFMT ) ==S_IFBLK ) { -if (setblksize ==1 ) { -/* use the default blocksize */ - (void )platform_set_blocksize (fd, path, statb.st_rdev,XFS_MIN_SECTORSIZE ,0 ); - }else if (dio) { +if (dio) {/* try to use the given explicit blocksize */ (void )platform_set_blocksize (fd, path, statb.st_rdev, setblksize,0 ); --2.39.2
PATCH 16/23 libfrog: make platform_set_blocksize exit on fatal failure
In reply to Christoph Hellwigplatform_set_blocksize has a fatal argument that is currently only used to change the printed message. Make it actually fatal similar to other libfrog platform helpers to simplify the caller.
--- libfrog/linux.c | 27 +++++++++++++++------------ libfrog/platform.h | 4 ++-- libxfs/init.c | 15 ++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-)
libfrog/linux.c +15 -12
@@ -127,20 +127,23 @@ platform_check_iswritable(char *name, char *block, struct stat *s)return platform_check_mount (name, block, s, flags); } -int -platform_set_blocksize (int fd,char *path,dev_t device,int blocksize,int fatal) +void +platform_set_blocksize (int fd,char *path,dev_t device,int blocksize, +bool fatal) { -int error =0 ; - -if (major (device) !=RAMDISK_MAJOR ) { -if ((error =ioctl (fd,BLKBSZSET , &blocksize)) <0 ) { -fprintf (stderr,_ ("%s: %s - cannot set blocksize " -"%d on block device %s: %s\n" ), - progname, fatal ?"error" :"warning" , - blocksize, path,strerror (errno)); - } +int error; + +if (major (device) ==RAMDISK_MAJOR ) +return ; + error =ioctl (fd,BLKBSZSET , &blocksize); +if (error <0 ) { +fprintf (stderr,_ ("%s: %s - cannot set blocksize " +"%d on block device %s: %s\n" ), + progname, fatal ?"error" :"warning" , + blocksize, path,strerror (errno)); +if (fatal) +exit (1 ); } -return error; }/*
libfrog/platform.h +2 -2
@@ -10,8 +10,8 @@int platform_check_ismounted (char *path,char *block,struct stat *sptr,int verbose);int platform_check_iswritable (char *path,char *block,struct stat *sptr); -int platform_set_blocksize (int fd,char *path,dev_t device,int bsz, -int fatal); +void platform_set_blocksize (int fd,char *path,dev_t device,int bsz, +bool fatal);int platform_flush_device (int fd,dev_t device);int platform_direct_blockdev (void );int platform_align_blockdev (void );
libxfs/init.c +6 -9
@@ -125,15 +125,12 @@ retry: }if (!readonly && setblksize && (statb.st_mode &S_IFMT ) ==S_IFBLK ) { -if (dio) { -/* try to use the given explicit blocksize */ - (void )platform_set_blocksize (fd, path, statb.st_rdev, - setblksize,0 ); - }else { -/* given an explicit blocksize to use */ -if (platform_set_blocksize (fd, path, statb.st_rdev, setblksize,1 )) -exit (1 ); - } +/* +* Try to use the given explicit blocksize. Failure to set the +* block size is only fatal for direct I/O. +*/ +platform_set_blocksize (fd, path, statb.st_rdev, setblksize, + dio); }/*
Signature · 1 line
2.39.2
Re: [PATCH 16/23] libfrog: make platform_set_blocksize exit on fatal failure
Quoted 5 lines · Christoph Hellwig
platform_set_blocksizehas a fatal argument that is currently only used to change the printed message. Make it actually fatal similar to other libfrog platform helpers to simplify the caller.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 90 lines
--- libfrog/linux.c | 27 +++++++++++++++------------ libfrog/platform.h | 4 ++-- libxfs/init.c | 15 ++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-)libfrog/linux.c +15
-12@@ -127,20 +127,23 @@ platform_check_iswritable(char *name, char *block, struct stat *s)return platform_check_mount (name, block, s, flags); } -int -platform_set_blocksize (int fd,char *path,dev_t device,int blocksize,int fatal) +void +platform_set_blocksize (int fd,char *path,dev_t device,int blocksize, +bool fatal) { -int error =0 ; - -if (major (device) !=RAMDISK_MAJOR ) { -if ((error =ioctl (fd,BLKBSZSET , &blocksize)) <0 ) { -fprintf (stderr,_ ("%s: %s - cannot set blocksize " -"%d on block device %s: %s\n" ), - progname, fatal ?"error" :"warning" , - blocksize, path,strerror (errno)); - } +int error; + +if (major (device) ==RAMDISK_MAJOR ) +return ; + error =ioctl (fd,BLKBSZSET , &blocksize); +if (error <0 ) { +fprintf (stderr,_ ("%s: %s - cannot set blocksize " +"%d on block device %s: %s\n" ), + progname, fatal ?"error" :"warning" , + blocksize, path,strerror (errno)); +if (fatal) +exit (1 ); } -return error; }/* libfrog/platform.h +2
-2@@ -10,8 +10,8 @@int platform_check_ismounted (char *path,char *block,struct stat *sptr,int verbose);int platform_check_iswritable (char *path,char *block,struct stat *sptr); -int platform_set_blocksize (int fd,char *path,dev_t device,int bsz, -int fatal); +void platform_set_blocksize (int fd,char *path,dev_t device,int bsz, +bool fatal);int platform_flush_device (int fd,dev_t device);int platform_direct_blockdev (void );int platform_align_blockdev (void );libxfs/init.c +6
-10@@ -125,15 +125,12 @@ retry: }if (!readonly && setblksize && (statb.st_mode &S_IFMT ) ==S_IFBLK ) { -if (dio) { -/* try to use the given explicit blocksize */ - (void )platform_set_blocksize (fd, path, statb.st_rdev, - setblksize,0 ); - }else { -/* given an explicit blocksize to use */ -if (platform_set_blocksize (fd, path, statb.st_rdev, setblksize,1 )) -exit (1 ); - } +/* +* Try to use the given explicit blocksize. Failure to set the +* block size is only fatal for direct I/O. +*/ +platform_set_blocksize (fd, path, statb.st_rdev, setblksize, + dio); }/* -- 2.39.2
PATCH 17/23 libxfs: remove dead size < 0 checks in libxfs_init
In reply to Christoph Hellwiglibxfs_init initializes the device size to 0 at the start of the function and libxfs_open_device never sets the size to a negativ value. Remove these checks as they are dead code.
--- libxfs/init.c | 15 --------------- 1 file changed, 15 deletions(-)
libxfs/init.c +0 -15
@@ -329,21 +329,6 @@ libxfs_init(struct libxfs_init *a)platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); } -if (a->dsize <0 ) { -fprintf (stderr,_ ("%s: can't get size for data subvolume\n" ), - progname); - goto done; - } -if (a->logBBsize <0 ) { -fprintf (stderr,_ ("%s: can't get size for log subvolume\n" ), - progname); - goto done; - } -if (a->rtsize <0 ) { -fprintf (stderr,_ ("%s: can't get size for realtime subvolume\n" ), - progname); - goto done; - }if (!libxfs_bhash_size) libxfs_bhash_size =LIBXFS_BHASHSIZE (sbp); libxfs_bcache = cache_init(a->bcache_flags, libxfs_bhash_size,
Signature · 1 line
2.39.2
Re: [PATCH 17/23] libxfs: remove dead size < 0 checks in libxfs_init
Quoted 5 lines · Christoph Hellwig
libxfs_initinitializes the device size to 0 at the start of the function andlibxfs_open_devicenever sets the size to a negativ value. Remove these checks as they are dead code.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 33 lines
--- libxfs/init.c | 15 --------------- 1 file changed, 15 deletions(-)libxfs/init.c +0
-16@@ -329,21 +329,6 @@ libxfs_init(struct libxfs_init *a)platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); } -if (a->dsize <0 ) { -fprintf (stderr,_ ("%s: can't get size for data subvolume\n" ), - progname); - goto done; - } -if (a->logBBsize <0 ) { -fprintf (stderr,_ ("%s: can't get size for log subvolume\n" ), - progname); - goto done; - } -if (a->rtsize <0 ) { -fprintf (stderr,_ ("%s: can't get size for realtime subvolume\n" ), - progname); - goto done; - }if (!libxfs_bhash_size) libxfs_bhash_size =LIBXFS_BHASHSIZE (sbp); libxfs_bcache = cache_init(a->bcache_flags, libxfs_bhash_size, --2.39.2
PATCH 18/23 libxfs: mark libxfs_device_{open,close} static
In reply to Christoph Hellwiglibxfs_device_open and libxfs_device_close are only used in init.c.
--- include/libxfs.h | 2 -- libxfs/init.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-)
include/libxfs.h +0 -2
@@ -148,8 +148,6 @@ int libxfs_init(struct libxfs_init *);void libxfs_destroy (struct libxfs_init *li);extern int libxfs_device_to_fd (dev_t ); -extern dev_t libxfs_device_open (char *,int ,int ,int ); -extern void libxfs_device_close (dev_t );extern int libxfs_device_alignment (void );extern void libxfs_report (FILE *);
libxfs/init.c +2 -2
@@ -92,7 +92,7 @@ libxfs_device_to_fd(dev_t device)/* libxfs_device_open: * open a device and return its device number */ -dev_t +static dev_t libxfs_device_open (char *path,int creat,int xflags,int setblksize) {dev_t dev;
@@ -161,7 +161,7 @@ retry:/* NOTREACHED */ } -void +static void libxfs_device_close (dev_t dev) {int d;
Signature · 1 line
2.39.2
Re: [PATCH 18/23] libxfs: mark libxfs_device_{open,close} static
Quoted 3 lines · Christoph Hellwig
libxfs_device_openandlibxfs_device_closeare only used ininit.c.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 43 lines
--- include/libxfs.h | 2 -- libxfs/init.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-)include/libxfs.h +0
-2@@ -148,8 +148,6 @@ int libxfs_init(struct libxfs_init *);void libxfs_destroy (struct libxfs_init *li);extern int libxfs_device_to_fd (dev_t ); -extern dev_t libxfs_device_open (char *,int ,int ,int ); -extern void libxfs_device_close (dev_t );extern int libxfs_device_alignment (void );extern void libxfs_report (FILE *);libxfs/init.c +2
-3@@ -92,7 +92,7 @@ libxfs_device_to_fd(dev_t device)/* libxfs_device_open: * open a device and return its device number */ -dev_t +static dev_t libxfs_device_open (char *path,int creat,int xflags,int setblksize) {dev_t dev;@@ -161,7 +161,7 @@ retry:/* NOTREACHED */ } -void +static void libxfs_device_close (dev_t dev) {int d; --2.39.2
PATCH 19/23 libxfs: return the opened fd from libxfs_device_open
In reply to Christoph HellwigSo that the caller can stash it away without having to call xfs_device_to_fd.
--- libxfs/init.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
libxfs/init.c +5 -7
@@ -93,7 +93,7 @@ libxfs_device_to_fd(dev_t device)* open a device and return its device number */ static dev_t -libxfs_device_open (char *path,int creat,int xflags,int setblksize) +libxfs_device_open (char *path,int creat,int xflags,int setblksize,int *fdp) {dev_t dev;int fd, d, flags;
@@ -151,6 +151,7 @@ retry:if (!dev_map[d].dev) { dev_map[d].dev = dev; dev_map[d].fd = fd; + *fdp = fd;return dev; }
@@ -307,16 +308,14 @@ libxfs_init(struct libxfs_init *a)if (!a->disfile && !check_open (dname, a->flags)) goto done; a->ddev =libxfs_device_open (dname, a->dcreat, a->flags, - a->setblksize); - a->dfd =libxfs_device_to_fd (a->ddev); + a->setblksize, &a->dfd);platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); }if (logname) {if (!a->lisfile && !check_open (logname, a->flags)) goto done; a->logdev =libxfs_device_open (logname, a->lcreat, a->flags, - a->setblksize); - a->logfd =libxfs_device_to_fd (a->logdev); + a->setblksize, &a->logfd);platform_findsizes (logname, a->logfd, &a->logBBsize, &a->lbsize); }
@@ -324,8 +323,7 @@ libxfs_init(struct libxfs_init *a)if (a->risfile && !check_open (rtname, a->flags)) goto done; a->rtdev =libxfs_device_open (rtname, a->rcreat, a->flags, - a->setblksize); - a->rtfd =libxfs_device_to_fd (a->rtdev); + a->setblksize, &a->rtfd);platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); }
Signature · 1 line
2.39.2
Re: [PATCH 19/23] libxfs: return the opened fd from libxfs_device_open
Quoted 4 lines · Christoph Hellwig
So that the caller can stash it away without having to call
xfs_device_to_fd.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 58 lines
--- libxfs/init.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)libxfs/init.c +5
-8@@ -93,7 +93,7 @@ libxfs_device_to_fd(dev_t device)* open a device and return its device number */ static dev_t -libxfs_device_open (char *path,int creat,int xflags,int setblksize) +libxfs_device_open (char *path,int creat,int xflags,int setblksize,int *fdp) {dev_t dev;int fd, d, flags;@@ -151,6 +151,7 @@ retry:if (!dev_map[d].dev) { dev_map[d].dev = dev; dev_map[d].fd = fd; + *fdp = fd;return dev; }@@ -307,16 +308,14 @@ libxfs_init(struct libxfs_init *a)if (!a->disfile && !check_open (dname, a->flags)) goto done; a->ddev =libxfs_device_open (dname, a->dcreat, a->flags, - a->setblksize); - a->dfd =libxfs_device_to_fd (a->ddev); + a->setblksize, &a->dfd);platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); }if (logname) {if (!a->lisfile && !check_open (logname, a->flags)) goto done; a->logdev =libxfs_device_open (logname, a->lcreat, a->flags, - a->setblksize); - a->logfd =libxfs_device_to_fd (a->logdev); + a->setblksize, &a->logfd);platform_findsizes (logname, a->logfd, &a->logBBsize, &a->lbsize); }@@ -324,8 +323,7 @@ libxfs_init(struct libxfs_init *a)if (a->risfile && !check_open (rtname, a->flags)) goto done; a->rtdev =libxfs_device_open (rtname, a->rcreat, a->flags, - a->setblksize); - a->rtfd =libxfs_device_to_fd (a->rtdev); + a->setblksize, &a->rtfd);platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); } --2.39.2
PATCH 20/23 libxfs: pass the device fd to discard_blocks
In reply to Christoph HellwigNo need to do a dev_t to fd lookup when the caller already has the fd.
--- mkfs/xfs_mkfs.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
mkfs/xfs_mkfs.c +6 -10
@@ -1325,19 +1325,15 @@ done: }static void -discard_blocks (dev_t dev,uint64_t nsectors,int quiet) +discard_blocks (int fd,uint64_t nsectors,int quiet) { -int fd;uint64_t offset =0 ;/* Discard the device 2G at a time */ const uint64_t step =2ULL <<30 ;const uint64_t count =BBTOB (nsectors); - fd =libxfs_device_to_fd (dev); -if (fd <=0 ) -return ; - -/* The block discarding happens in smaller batches so it can be +/* +* The block discarding happens in smaller batches so it can be * interrupted prematurely */ while (offset < count) {
@@ -2875,11 +2871,11 @@ discard_devices(*/ if (!xi->disfile) -discard_blocks (xi->ddev, xi->dsize, quiet); +discard_blocks (xi->dfd, xi->dsize, quiet);if (xi->rtdev && !xi->risfile) -discard_blocks (xi->rtdev, xi->rtsize, quiet); +discard_blocks (xi->rtfd, xi->rtsize, quiet);if (xi->logdev && xi->logdev != xi->ddev && !xi->lisfile) -discard_blocks (xi->logdev, xi->logBBsize, quiet); +discard_blocks (xi->logfd, xi->logBBsize, quiet); } static void
Signature · 1 line
2.39.2
Re: [PATCH 20/23] libxfs: pass the device fd to discard_blocks
Quoted 3 lines · Christoph Hellwig
No need to do a
dev_tto fd lookup when the caller already has the fd.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 49 lines
--- mkfs/xfs_mkfs.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)mkfs/xfs_mkfs.c +6
-11@@ -1325,19 +1325,15 @@ done: }static void -discard_blocks (dev_t dev,uint64_t nsectors,int quiet) +discard_blocks (int fd,uint64_t nsectors,int quiet) { -int fd;uint64_t offset =0 ;/* Discard the device 2G at a time */ const uint64_t step =2ULL <<30 ;const uint64_t count =BBTOB (nsectors); - fd =libxfs_device_to_fd (dev); -if (fd <=0 ) -return ; - -/* The block discarding happens in smaller batches so it can be +/* +* The block discarding happens in smaller batches so it can be * interrupted prematurely */ while (offset < count) {@@ -2875,11 +2871,11 @@ discard_devices(*/ if (!xi->disfile) -discard_blocks (xi->ddev, xi->dsize, quiet); +discard_blocks (xi->dfd, xi->dsize, quiet);if (xi->rtdev && !xi->risfile) -discard_blocks (xi->rtdev, xi->rtsize, quiet); +discard_blocks (xi->rtfd, xi->rtsize, quiet);if (xi->logdev && xi->logdev != xi->ddev && !xi->lisfile) -discard_blocks (xi->logdev, xi->logBBsize, quiet); +discard_blocks (xi->logfd, xi->logBBsize, quiet); } static void --2.39.2
PATCH 21/23 xfs_repair: remove various libxfs_device_to_fd calls
In reply to Christoph HellwigA few places in xfs_repair call libxfs_device_to_fd to get the data device fd from the data device dev_t stored in the libxfs_init structure. Just use the file descriptor stored right there directly.
--- repair/xfs_repair.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
repair/xfs_repair.c +5 -8
@@ -724,13 +724,11 @@ static voidcheck_fs_vs_host_sectsize ( struct xfs_sb *sb) { -int fd, ret; +int ret;long old_flags;struct xfs_fsop_geom geom = {0 }; - fd =libxfs_device_to_fd (x.ddev); - - ret = -xfrog_geometry (fd, &geom); + ret = -xfrog_geometry (x.dfd, &geom);if (ret) { do_log(_("Cannot get host filesystem geometry.\n" "Repair may fail if there is a sector size mismatch between\n"
@@ -739,8 +737,8 @@ check_fs_vs_host_sectsize( }if (sb->sb_sectsize < geom.sectsize) { - old_flags =fcntl (fd,F_GETFL ,0 ); -if (fcntl (fd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) { + old_flags =fcntl (x.dfd,F_GETFL ,0 ); +if (fcntl (x.dfd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) {do_warn (_ ("Sector size on host filesystem larger than image sector size.\n" "Cannot turn off direct IO, so exiting.\n" ));
@@ -986,10 +984,9 @@ main(int argc, char **argv)/* -f forces this, but let's be nice and autodetect it, as well. */ if (!isa_file) { -int fd =libxfs_device_to_fd (x.ddev);struct stat statbuf; -if (fstat (fd, &statbuf) <0 ) +if (fstat (x.dfd, &statbuf) <0 )do_warn (_ ("%s: couldn't stat \"%s\"\n" ), progname, fs_name);else if (S_ISREG (statbuf.st_mode))
Signature · 1 line
2.39.2
Re: [PATCH 21/23] xfs_repair: remove various libxfs_device_to_fd calls
Quoted 5 lines · Christoph Hellwig
A few places in
xfs_repaircalllibxfs_device_to_fdto get the data device fd from the data devicedev_tstored in thelibxfs_initstructure. Just use the file descriptor stored right there directly.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 50 lines
--- repair/xfs_repair.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)repair/xfs_repair.c +5
-9@@ -724,13 +724,11 @@ static voidcheck_fs_vs_host_sectsize ( struct xfs_sb *sb) { -int fd, ret; +int ret;long old_flags;struct xfs_fsop_geom geom = {0 }; - fd =libxfs_device_to_fd (x.ddev); - - ret = -xfrog_geometry (fd, &geom); + ret = -xfrog_geometry (x.dfd, &geom);if (ret) { do_log(_("Cannot get host filesystem geometry.\n" "Repair may fail if there is a sector size mismatch between\n"@@ -739,8 +737,8 @@ check_fs_vs_host_sectsize( }if (sb->sb_sectsize < geom.sectsize) { - old_flags =fcntl (fd,F_GETFL ,0 ); -if (fcntl (fd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) { + old_flags =fcntl (x.dfd,F_GETFL ,0 ); +if (fcntl (x.dfd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) {do_warn (_ ("Sector size on host filesystem larger than image sector size.\n" "Cannot turn off direct IO, so exiting.\n" ));@@ -986,10 +984,9 @@ main(int argc, char **argv)/* -f forces this, but let's be nice and autodetect it, as well. */ if (!isa_file) { -int fd =libxfs_device_to_fd (x.ddev);struct stat statbuf; -if (fstat (fd, &statbuf) <0 ) +if (fstat (x.dfd, &statbuf) <0 )do_warn (_ ("%s: couldn't stat \"%s\"\n" ), progname, fs_name);else if (S_ISREG (statbuf.st_mode)) --2.39.2
PATCH 22/23 libxfs: stash away the device fd in struct xfs_buftarg
In reply to Christoph HellwigCache the open file descriptor for each device in the buftarg structure and remove the now unused dev_map infrastructure.
--- include/libxfs.h | 1 - libxfs/init.c | 108 +++++++++++---------------------------------- libxfs/libxfs_io.h | 1 + libxfs/rdwr.c | 16 +++---- repair/prefetch.c | 2 +- 5 files changed, 34 insertions(+), 94 deletions(-)
include/libxfs.h +0 -1
@@ -147,7 +147,6 @@ extern xfs_lsn_t libxfs_max_lsn;int libxfs_init (struct libxfs_init *);void libxfs_destroy (struct libxfs_init *li); -extern int libxfs_device_to_fd (dev_t );extern int libxfs_device_alignment (void );extern void libxfs_report (FILE *);
libxfs/init.c +25 -83
170 lines not on this page · raw message
libxfs/libxfs_io.h +1 -0
@@ -26,6 +26,7 @@ struct xfs_buftarg {pthread_mutex_t lock;unsigned long writes_left;dev_t bt_bdev; +int bt_bdev_fd;unsigned int flags; };
libxfs/rdwr.c +7 -9
@@ -62,13 +62,13 @@ static void libxfs_brelse(struct cache_node *node);int libxfs_device_zero (struct xfs_buftarg *btp,xfs_daddr_t start,uint len) { +int fd = btp->bt_bdev_fd;xfs_off_t start_offset, end_offset, offset;ssize_t zsize, bytes;size_t len_bytes;char *z; -int error, fd; +int error; - fd =libxfs_device_to_fd (btp->bt_bdev); start_offset =LIBXFS_BBTOOFF64 (start);/* try to use special zeroing methods, fall back to writes if needed */
@@ -598,7 +598,7 @@ int libxfs_readbufr(struct xfs_buftarg *btp, xfs_daddr_t blkno, struct xfs_buf *bp, int len, int flags) { - int fd = libxfs_device_to_fd(btp->bt_bdev); + int fd = btp->bt_bdev_fd;int bytes =BBTOB (len);int error;
@@ -631,12 +631,11 @@ libxfs_readbuf_verify(int libxfs_readbufr_map (struct xfs_buftarg *btp,struct xfs_buf *bp,int flags) { -int fd; +int fd = btp->bt_bdev_fd;int error =0 ;void *buf;int i; - fd =libxfs_device_to_fd (btp->bt_bdev); buf = bp->b_addr;for (i =0 ; i < bp->b_nmaps; i++) {off64_t offset =LIBXFS_BBTOOFF64 (bp->b_maps[i].bm_bn);
@@ -820,7 +819,7 @@ intlibxfs_bwrite ( struct xfs_buf *bp) { -int fd =libxfs_device_to_fd (bp->b_target->bt_bdev); +int fd = bp->b_target->bt_bdev_fd;/* * we never write buffers that are marked stale. This indicates they
@@ -1171,13 +1170,12 @@ intlibxfs_blkdev_issue_flush ( struct xfs_buftarg *btp) { -int fd, ret; +int ret;if (btp->bt_bdev ==0 )return 0 ; - fd =libxfs_device_to_fd (btp->bt_bdev); - ret =platform_flush_device (fd, btp->bt_bdev); + ret =platform_flush_device (btp->bt_bdev_fd, btp->bt_bdev);return ret ? -errno :0 ; }
repair/prefetch.c +1 -1
@@ -876,7 +876,7 @@ init_prefetch( xfs_mount_t *pmp) { mp = pmp; - mp_fd =libxfs_device_to_fd (mp->m_ddev_targp->bt_bdev); + mp_fd = mp->m_ddev_targp->bt_bdev_fd;; pf_max_bytes =sysconf (_SC_PAGE_SIZE) <<7 ; pf_max_bbs = pf_max_bytes >>BBSHIFT ; pf_max_fsbs = pf_max_bytes >> mp->m_sb.sb_blocklog;
Signature · 1 line
2.39.2
Re: [PATCH 22/23] libxfs: stash away the device fd in struct xfs_buftarg
Quoted 4 lines · Christoph Hellwig
Cache the open file descriptor for each device in the buftarg structure and remove the now unused
dev_mapinfrastructure.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 297 lines
--- include/libxfs.h | 1 - libxfs/init.c | 108 +++++++++++---------------------------------- libxfs/libxfs_io.h | 1 + libxfs/rdwr.c | 16 +++---- repair/prefetch.c | 2 +- 5 files changed, 34 insertions(+), 94 deletions(-)include/libxfs.h +0
-1@@ -147,7 +147,6 @@ extern xfs_lsn_t libxfs_max_lsn;int libxfs_init (struct libxfs_init *);void libxfs_destroy (struct libxfs_init *li); -extern int libxfs_device_to_fd (dev_t );extern int libxfs_device_alignment (void );extern void libxfs_report (FILE *);libxfs/init.c +25
-83@@ -36,15 +36,7 @@ int libxfs_bhash_size; /* #buckets in bcache */int use_xfs_buf_lock;/* global flag: use xfs_buf locks for MT */ -/* -* dev_map - map open devices to fd. -*/ -#define MAX_DEVS 10/* arbitary maximum */ static int nextfakedev =-1 ;/* device number to give to next fake device */ -static struct dev_to_fd { -dev_t dev; -int fd; -} dev_map[MAX_DEVS ]={{0 }};/* * Checks whether a given device has a mounted, writable @@ -70,33 +62,13 @@ check_isactive(char *name, char *block, int fatal)return 0 ; } -/* libxfs_device_to_fd: -* lookup a device number in the device map -* return the associated fd -*/ -int -libxfs_device_to_fd (dev_t device) -{ -int d; - -for (d =0 ; d <MAX_DEVS ; d++) -if (dev_map[d].dev == device) -return dev_map[d].fd; - -fprintf (stderr,_ ("%s: %s: device %lld is not open\n" ), - progname, __FUNCTION__, (long long )device); -exit (1 ); -/* NOTREACHED */ -} -/* libxfs_device_open: * open a device and return its device number */ static dev_t libxfs_device_open (char *path,int creat,int xflags,int setblksize,int *fdp) { -dev_t dev; -int fd, d, flags; +int fd, flags;int readonly, dio, excl;struct stat statb;@@ -134,61 +106,28 @@ retry: }/* -* Get the device number from the stat buf - unless -* we're not opening a real device, in which case -* choose a new fake device number. +* Get the device number from the stat buf - unless we're not opening a +* real device, in which case choose a new fake device number. */ - dev = (statb.st_rdev) ? (statb.st_rdev) : (nextfakedev--); - -for (d =0 ; d <MAX_DEVS ; d++) -if (dev_map[d].dev == dev) { -fprintf (stderr,_ ("%s: device %lld is already open\n" ), - progname, (long long )dev); -exit (1 ); - } - -for (d =0 ; d <MAX_DEVS ; d++) -if (!dev_map[d].dev) { - dev_map[d].dev = dev; - dev_map[d].fd = fd; - *fdp = fd; - -return dev; - } - -fprintf (stderr,_ ("%s: %s: too many open devices\n" ), - progname, __FUNCTION__); -exit (1 ); -/* NOTREACHED */ + *fdp = fd; +if (statb.st_rdev) +return statb.st_rdev; +return nextfakedev--; }static void -libxfs_device_close (dev_t dev) +libxfs_device_close (int fd,dev_t dev) { -int d; +int ret; -for (d =0 ; d <MAX_DEVS ; d++) -if (dev_map[d].dev == dev) { -int fd, ret; - - fd = dev_map[d].fd; - dev_map[d].dev = dev_map[d].fd =0 ; - - ret =platform_flush_device (fd, dev); -if (ret) { - ret = -errno; -fprintf (stderr, + ret =platform_flush_device (fd, dev); +if (ret) { + ret = -errno; +fprintf (stderr,_ ("%s: flush of device %lld failed, err=%d" ), - progname, (long long )dev, ret); - } -close (fd); - -return ; - } - -fprintf (stderr,_ ("%s: %s: device %lld is not open\n" ), - progname, __FUNCTION__, (long long )dev); -exit (1 ); + progname, (long long )dev, ret); + } +close (fd); } static int@@ -271,11 +210,11 @@ libxfs_close_devices( struct libxfs_init *li) {if (li->ddev) -libxfs_device_close (li->ddev); +libxfs_device_close (li->dfd, li->ddev);if (li->logdev && li->logdev != li->ddev) -libxfs_device_close (li->logdev); +libxfs_device_close (li->logfd, li->logdev);if (li->rtdev) -libxfs_device_close (li->rtdev); +libxfs_device_close (li->rtfd, li->rtdev); li->ddev = li->logdev = li->rtdev =0 ; li->dfd = li->logfd = li->rtfd =-1 ;@@ -514,6 +453,7 @@ static struct xfs_buftarg *libxfs_buftarg_alloc ( struct xfs_mount *mp, dev_t dev, + int fd, unsigned long write_fails) { struct xfs_buftarg *btp;@@ -526,6 +466,7 @@ libxfs_buftarg_alloc( } btp->bt_mount = mp; btp->bt_bdev = dev; + btp->bt_bdev_fd = fd; btp->flags =0 ;if (write_fails) { btp->writes_left = write_fails;@@ -629,13 +570,14 @@ libxfs_buftarg_init(return ; } - mp->m_ddev_targp =libxfs_buftarg_alloc (mp, xi->ddev, dfail); + mp->m_ddev_targp =libxfs_buftarg_alloc (mp, xi->ddev, xi->dfd, dfail);if (!xi->logdev || xi->logdev == xi->ddev) mp->m_logdev_targp = mp->m_ddev_targp;else mp->m_logdev_targp =libxfs_buftarg_alloc (mp, xi->logdev, - lfail); - mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, xi->rtdev, rfail); + xi->logfd, lfail); + mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, xi->rtdev, xi->rtfd, + rfail); }/* Compute maximum possible height for per-AG btree types for this fs. */ libxfs/libxfs_io.h +1
-0@@ -26,6 +26,7 @@ struct xfs_buftarg {pthread_mutex_t lock;unsigned long writes_left;dev_t bt_bdev; +int bt_bdev_fd;unsigned int flags; };libxfs/rdwr.c +7
-9@@ -62,13 +62,13 @@ static void libxfs_brelse(struct cache_node *node);int libxfs_device_zero (struct xfs_buftarg *btp,xfs_daddr_t start,uint len) { +int fd = btp->bt_bdev_fd;xfs_off_t start_offset, end_offset, offset;ssize_t zsize, bytes;size_t len_bytes;char *z; -int error, fd; +int error; - fd =libxfs_device_to_fd (btp->bt_bdev); start_offset =LIBXFS_BBTOOFF64 (start);/* try to use special zeroing methods, fall back to writes if needed */ @@ -598,7 +598,7 @@ int libxfs_readbufr(struct xfs_buftarg *btp, xfs_daddr_t blkno, struct xfs_buf *bp, int len, int flags) { - int fd = libxfs_device_to_fd(btp->bt_bdev); + int fd = btp->bt_bdev_fd;int bytes =BBTOB (len);int error;@@ -631,12 +631,11 @@ libxfs_readbuf_verify(int libxfs_readbufr_map (struct xfs_buftarg *btp,struct xfs_buf *bp,int flags) { -int fd; +int fd = btp->bt_bdev_fd;int error =0 ;void *buf;int i; - fd =libxfs_device_to_fd (btp->bt_bdev); buf = bp->b_addr;for (i =0 ; i < bp->b_nmaps; i++) {off64_t offset =LIBXFS_BBTOOFF64 (bp->b_maps[i].bm_bn);@@ -820,7 +819,7 @@ intlibxfs_bwrite ( struct xfs_buf *bp) { -int fd =libxfs_device_to_fd (bp->b_target->bt_bdev); +int fd = bp->b_target->bt_bdev_fd;/* * we never write buffers that are marked stale. This indicates they @@ -1171,13 +1170,12 @@ intlibxfs_blkdev_issue_flush ( struct xfs_buftarg *btp) { -int fd, ret; +int ret;if (btp->bt_bdev ==0 )return 0 ; - fd =libxfs_device_to_fd (btp->bt_bdev); - ret =platform_flush_device (fd, btp->bt_bdev); + ret =platform_flush_device (btp->bt_bdev_fd, btp->bt_bdev);return ret ? -errno :0 ; }repair/prefetch.c +1
-2@@ -876,7 +876,7 @@ init_prefetch( xfs_mount_t *pmp) { mp = pmp; - mp_fd =libxfs_device_to_fd (mp->m_ddev_targp->bt_bdev); + mp_fd = mp->m_ddev_targp->bt_bdev_fd;; pf_max_bytes =sysconf (_SC_PAGE_SIZE) <<7 ; pf_max_bbs = pf_max_bytes >>BBSHIFT ; pf_max_fsbs = pf_max_bytes >> mp->m_sb.sb_blocklog; --2.39.2
PATCH 23/23 libxfs: split out a libxfs_dev structure from struct libxfs_init
In reply to Christoph HellwigMost of the content of libxfs_init is members duplicated for each of the data, log and RT devices. Split those members into a separate libxfs_dev structure.
--- copy/xfs_copy.c | 4 +- db/info.c | 2 +- db/init.c | 12 +-- db/output.c | 2 +- db/sb.c | 8 +- growfs/xfs_growfs.c | 20 ++--- include/libxfs.h | 45 ++++------ libxfs/init.c | 210 +++++++++++++++++++++----------------------- libxfs/topology.c | 16 ++-- logprint/logprint.c | 40 ++++----- mkfs/xfs_mkfs.c | 158 ++++++++++++++++----------------- repair/init.c | 12 +-- repair/phase2.c | 4 +- repair/sb.c | 16 ++-- repair/xfs_repair.c | 8 +- 15 files changed, 265 insertions(+), 292 deletions(-)
copy/xfs_copy.c +2 -2
@@ -716,8 +716,8 @@ main(int argc, char **argv)memset (&xargs,0 ,sizeof (xargs)); xargs.flags =LIBXFS_ISREADONLY |LIBXFS_DIRECT ; - xargs.dname = source_name; - xargs.disfile = source_is_file; + xargs.data.name = source_name; + xargs.data.isfile = source_is_file;if (!libxfs_init (&xargs)) { do_log(_("%s: couldn't initialize XFS library\n"
db/info.c +1 -1
@@ -30,7 +30,7 @@ info_f(struct xfs_fsop_geom geo;libxfs_fs_geometry (mp, &geo,XFS_FS_GEOM_MAX_STRUCT_VER ); -xfs_report_geom (&geo, x.dname, x.logname, x.rtname); +xfs_report_geom (&geo, x.data.name, x.log.name, x.rt.name);return 0 ; }
db/init.c +6 -6
@@ -61,7 +61,7 @@ init( cmdline[ncmdline++] = optarg;break ;case 'f' : - x.disfile =1 ; + x.data.isfile =1 ;break ;case 'F' : force =1 ;
@@ -76,7 +76,7 @@ init( x.flags =LIBXFS_ISREADONLY ;break ;case 'l' : - x.logname = optarg; + x.log.name = optarg;break ;case 'x' : expert_mode =1 ;
@@ -91,7 +91,7 @@ init(if (optind +1 != argc)usage (); - x.dname = argv[optind]; + x.data.name = argv[optind]; x.flags |=LIBXFS_DIRECT ; x.bcache_flags =CACHE_MISCOMPARE_PURGE ;
@@ -111,7 +111,7 @@ init( 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL);if (error) {fprintf (stderr,_ ("%s: %s is invalid (cannot read first 512 " -"bytes)\n" ), progname, x.dname); +"bytes)\n" ), progname, x.data.name);exit (1 ); }
@@ -122,7 +122,7 @@ init( sbp = &xmount.m_sb;if (sbp->sb_magicnum !=XFS_SB_MAGIC ) {fprintf (stderr,_ ("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n" ), - progname, x.dname, sbp->sb_magicnum); + progname, x.data.name, sbp->sb_magicnum);if (!force) {fprintf (stderr,_ ("Use -F to force a read attempt.\n" ));exit (EXIT_FAILURE );
@@ -134,7 +134,7 @@ init(if (!mp) {fprintf (stderr,_ ("%s: device %s unusable (not an XFS filesystem?)\n" ), - progname, x.dname); + progname, x.data.name);exit (1 ); } mp->m_log = &xlog;
db/output.c +1 -1
@@ -34,7 +34,7 @@ dbprintf(const char *fmt, ...)blockint (); i =0 ;if (dbprefix) - i +=printf ("%s: " , x.dname); + i +=printf ("%s: " , x.data.name); i +=vprintf (fmt, ap);unblockint ();va_end (ap);
db/sb.c +4 -4
@@ -220,13 +220,13 @@ sb_logcheck(void)int dirty;if (mp->m_sb.sb_logstart) { -if (x.logdev && x.logdev != x.ddev) { +if (x.log.dev && x.log.dev != x.data.dev) {dbprintf (_ ("aborting - external log specified for FS " "with an internal log\n" ));return 0 ; } }else { -if (!x.logdev || (x.logdev == x.ddev)) { +if (!x.log.dev || (x.log.dev == x.data.dev)) {dbprintf (_ ("aborting - no external log specified for FS " "with an external log\n" ));return 0 ;
@@ -452,10 +452,10 @@ uuid_f( } }if (mp->m_sb.sb_logstart) { -if (x.logdev && x.logdev != x.ddev) +if (x.log.dev && x.log.dev != x.data.dev)dbprintf (_ ("warning - external log specified " "for FS with an internal log\n" )); - }else if (!x.logdev || (x.logdev == x.ddev)) { + }else if (!x.log.dev || (x.log.dev == x.data.dev)) {dbprintf (_ ("warning - no external log specified " "for FS with an external log\n" )); }
growfs/xfs_growfs.c +10 -10
@@ -183,26 +183,26 @@ main(int argc, char **argv)*/ memset (&xi,0 ,sizeof (xi)); - xi.dname = datadev; - xi.logname = logdev; - xi.rtname = rtdev; + xi.data.name = datadev; + xi.log.name = logdev; + xi.rt.name = rtdev; xi.flags =LIBXFS_ISREADONLY ;if (!libxfs_init (&xi))usage ();/* check we got the info for all the sections we are trying to modify */ -if (!xi.ddev) { +if (!xi.data.dev) {fprintf (stderr,_ ("%s: failed to access data device for %s\n" ), progname, fname);exit (1 ); } -if (lflag && !isint && !xi.logdev) { +if (lflag && !isint && !xi.log.dev) {fprintf (stderr,_ ("%s: failed to access external log for %s\n" ), progname, fname);exit (1 ); } -if (rflag && !xi.rtdev) { +if (rflag && !xi.rt.dev) {fprintf (stderr,_ ("%s: failed to access realtime device for %s\n" ), progname, fname);
@@ -211,10 +211,10 @@ main(int argc, char **argv)xfs_report_geom (&geo, datadev, logdev, rtdev); - ddsize = xi.dsize; - dlsize = ( xi.logBBsize? xi.logBBsize : + ddsize = xi.data.size; + dlsize = (xi.log.size ? xi.log.size : geo.logblocks * (geo.blocksize /BBSIZE ) ); - drsize = xi.rtsize; + drsize = xi.rt.size;/* * Ok, Linux only has a 1024-byte resolution on device _size_,
@@ -328,7 +328,7 @@ _("[EXPERIMENTAL] try to shrink unused space %lld, old size is %lld\n"),else if (xflag) in.isint =0 ;else - in.isint = xi.logBBsize ==0 ; + in.isint = xi.log.size ==0 ;if (lsize == geo.logblocks && (in.isint == isint)) {if (lflag) fprintf(stderr,
include/libxfs.h +19 -26
57 lines not on this page · raw message
libxfs/init.c +100 -110
318 lines not on this page · raw message
libxfs/topology.c +8 -8
@@ -299,34 +299,34 @@ get_topology(* to try to obtain the underlying filesystem's requirements * for direct IO; we'll set our sector size to that if possible. */ -if (xi->disfile || - (!stat (xi->dname, &statbuf) &&S_ISREG (statbuf.st_mode))) { +if (xi->data.isfile || + (!stat (xi->data.name, &statbuf) &&S_ISREG (statbuf.st_mode))) {int fd;int flags =O_RDONLY ;long long dummy;/* with xi->disfile we may not have the file yet! */ -if (xi->disfile) +if (xi->data.isfile) flags |=O_CREAT ; - fd =open (xi->dname, flags,0666 ); + fd =open (xi->data.name, flags,0666 );if (fd >=0 ) { -platform_findsizes (xi->dname, fd, &dummy, +platform_findsizes (xi->data.name, fd, &dummy, &ft->lsectorsize);close (fd); ft->psectorsize = ft->lsectorsize; }else ft->psectorsize = ft->lsectorsize =BBSIZE ; }else { -blkid_get_topology (xi->dname, &ft->dsunit, &ft->dswidth, +blkid_get_topology (xi->data.name, &ft->dsunit, &ft->dswidth, &ft->lsectorsize, &ft->psectorsize, force_overwrite); } -if (xi->rtname && !xi->risfile) { +if (xi->rt.name && !xi->rt.isfile) {int sunit, lsectorsize, psectorsize; -blkid_get_topology (xi->rtname, &sunit, &ft->rtswidth, +blkid_get_topology (xi->rt.name, &sunit, &ft->rtswidth, &lsectorsize, &psectorsize, force_overwrite); } }
logprint/logprint.c +20 -20
@@ -64,9 +64,9 @@ logstat(* filesystem. We need this to get the length of the * log. Otherwise we end up seeking forever. -- mkp */ -if ((fd =open (x.dname,O_RDONLY )) ==-1 ) { +if ((fd =open (x.data.name,O_RDONLY )) ==-1 ) {fprintf (stderr,_ (" Can't open device %s: %s\n" ), - x.dname,strerror (errno)); + x.data.name,strerror (errno));exit (1 ); }lseek (fd,0 ,SEEK_SET );
@@ -76,7 +76,7 @@ logstat( }close (fd); -if (!x.disfile) { +if (!x.data.isfile) {struct xfs_sb *sb = &mp->m_sb;/*
@@ -88,7 +88,7 @@ logstat(xlog_init (mp, log); -if (!x.logname && sb->sb_logstart ==0 ) { +if (!x.log.name && sb->sb_logstart ==0 ) {fprintf (stderr,_ (" external log device not specified\n\n" ));usage ();/*NOTREACHED*/
@@ -96,7 +96,7 @@ logstat( }else {struct stat s; -stat (x.dname, &s); +stat (x.data.name, &s); log->l_logBBsize = s.st_size >>9 ; log->l_logBBstart =0 ;
@@ -105,15 +105,15 @@ logstat( log->l_mp = mp; } -if (x.logname && *x.logname) {/* External log */ -if ((fd =open (x.logname,O_RDONLY )) ==-1 ) { +if (x.log.name && *x.log.name) {/* External log */ +if ((fd =open (x.log.name,O_RDONLY )) ==-1 ) {fprintf (stderr,_ ("Can't open file %s: %s\n" ), - x.logname,strerror (errno)); + x.log.name,strerror (errno));exit (1 ); }close (fd); }else {/* Internal log */ - x.logdev = x.ddev; + x.log.dev = x.data.dev; }return 0 ;
@@ -165,11 +165,11 @@ main(int argc, char **argv)break ;case 'f' : print_skip_uuid++; - x.disfile =1 ; + x.data.isfile =1 ;break ;case 'l' : - x.logname = optarg; - x.lisfile =1 ; + x.log.name = optarg; + x.log.isfile =1 ;break ;case 'i' : print_inode++;
@@ -203,9 +203,9 @@ main(int argc, char **argv)if (argc - optind !=1 )usage (); - x.dname = argv[optind]; + x.data.name = argv[optind]; -if (x.dname ==NULL ) +if (x.data.name ==NULL )usage (); x.flags =LIBXFS_ISINACTIVE ;
@@ -216,20 +216,20 @@ main(int argc, char **argv)libxfs_buftarg_init (&mount, &x);logstat (&mount, &log); - logfd = (x.logfd <0 ) ? x.dfd : x.logfd; + logfd = (x.log.fd <0 ) ? x.data.fd : x.log.fd; -printf (_ (" data device: 0x%llx\n" ), (unsigned long long )x.ddev); +printf (_ (" data device: 0x%llx\n" ), (unsigned long long )x.data.dev); -if (x.logname) { -printf (_ (" log file: \"%s\" " ), x.logname); +if (x.log.name) { +printf (_ (" log file: \"%s\" " ), x.log.name); }else { -printf (_ (" log device: 0x%llx " ), (unsigned long long )x.logdev); +printf (_ (" log device: 0x%llx " ), (unsigned long long )x.log.dev); }printf (_ ("daddr: %lld length: %lld\n\n" ), (long long )log.l_logBBstart, (long long )log.l_logBBsize); -ASSERT (log.l_logBBsize <=INT_MAX ); +ASSERT (x.log.size <=INT_MAX );switch (print_operation) {case OP_PRINT :
mkfs/xfs_mkfs.c +75 -83
412 lines not on this page · raw message
repair/init.c +6 -6
@@ -56,19 +56,19 @@ xfs_init(struct libxfs_init *args) {memset (args,0 ,sizeof (*args)); - args->dname = fs_name; - args->disfile = isa_file; + args->data.name = fs_name; + args->data.isfile = isa_file;if (log_spec) {/* External log specified */ - args->logname = log_name; - args->lisfile = (isa_file?1 :0 ); + args->log.name = log_name; + args->log.isfile = isa_file;/* XXX assume data file also means log file */ /* REVISIT: Need to do fs sanity / log validity checking */ }if (rt_spec) {/* RT device specified */ - args->rtname = rt_name; - args->risfile = (isa_file?1 :0 ); + args->rt.name = rt_name; + args->rt.isfile = isa_file;/* XXX assume data file also means rt file */ }
repair/phase2.c +2 -2
@@ -341,11 +341,11 @@ phase2(/* Check whether this fs has internal or external log */ if (mp->m_sb.sb_logstart ==0 ) { -if (!x.logname) +if (!x.log.name)do_error (_ ("This filesystem has an external log. " "Specify log device with the -l option.\n" )); -do_log (_ ("Phase 2 - using external log on %s\n" ), x.logname); +do_log (_ ("Phase 2 - using external log on %s\n" ), x.log.name); }else do_log (_ ("Phase 2 - using internal log\n" ));
repair/sb.c +7 -9
@@ -125,13 +125,11 @@ __find_secondary_sb(/* * read disk 1 MByte at a time. */ -if (lseek (x.dfd, off,SEEK_SET ) != off) { +if (lseek (x.data.fd, off,SEEK_SET ) != off) done =1 ; - } -if (!done && (bsize =read (x.dfd, sb,BSIZE )) <=0 ) { +if (!done && (bsize =read (x.data.fd, sb,BSIZE )) <=0 ) done =1 ; - }do_warn ("." );
@@ -192,7 +190,7 @@ guess_default_geometry(*/ blocklog =12 ; multidisk = ft.dswidth | ft.dsunit; - dblocks = x->dsize >> (blocklog -BBSHIFT ); + dblocks = x->data.size >> (blocklog -BBSHIFT );calc_default_ag_geometry (blocklog, dblocks, multidisk, agsize, agcount);
@@ -533,7 +531,7 @@ write_primary_sb(xfs_sb_t *sbp, int size) }memset (buf,0 , size); -if (lseek (x.dfd,0LL ,SEEK_SET ) !=0LL ) { +if (lseek (x.data.fd,0LL ,SEEK_SET ) !=0LL ) {free (buf);do_error (_ ("couldn't seek to offset 0 in filesystem\n" )); }
@@ -543,7 +541,7 @@ write_primary_sb(xfs_sb_t *sbp, int size)if (xfs_sb_version_hascrc (sbp))xfs_update_cksum ((char *)buf, size,XFS_SB_CRC_OFF ); -if (write (x.dfd, buf, size) != size) { +if (write (x.data.fd, buf, size) != size) {free (buf);do_error (_ ("primary superblock write failed!\n" )); }
@@ -572,7 +570,7 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno)/* try and read it first */ -if (lseek (x.dfd, off,SEEK_SET ) != off) { +if (lseek (x.data.fd, off,SEEK_SET ) != off) {do_warn (_ ("error reading superblock %u -- seek to offset %" PRId64" failed\n" ), agno, off);
@@ -580,7 +578,7 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno)return (XR_EOF ); } -if ((rval =read (x.dfd, buf, size)) != size) { +if ((rval =read (x.data.fd, buf, size)) != size) { error = errno; do_warn( _("superblock read failed, offset %" PRId64 ", size %d, ag %u, rval %d\n"),
repair/xfs_repair.c +4 -4
@@ -728,7 +728,7 @@ check_fs_vs_host_sectsize(long old_flags;struct xfs_fsop_geom geom = {0 }; - ret = -xfrog_geometry (x.dfd, &geom); + ret = -xfrog_geometry (x.data.fd, &geom);if (ret) { do_log(_("Cannot get host filesystem geometry.\n" "Repair may fail if there is a sector size mismatch between\n"
@@ -737,8 +737,8 @@ check_fs_vs_host_sectsize( }if (sb->sb_sectsize < geom.sectsize) { - old_flags =fcntl (x.dfd,F_GETFL ,0 ); -if (fcntl (x.dfd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) { + old_flags =fcntl (x.data.fd,F_GETFL ,0 ); +if (fcntl (x.data.fd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) {do_warn (_ ("Sector size on host filesystem larger than image sector size.\n" "Cannot turn off direct IO, so exiting.\n" ));
@@ -986,7 +986,7 @@ main(int argc, char **argv)if (!isa_file) {struct stat statbuf; -if (fstat (x.dfd, &statbuf) <0 ) +if (fstat (x.data.fd, &statbuf) <0 )do_warn (_ ("%s: couldn't stat \"%s\"\n" ), progname, fs_name);else if (S_ISREG (statbuf.st_mode))
Signature · 1 line
2.39.2
Re: [PATCH 23/23] libxfs: split out a libxfs_dev structure from struct libxfs_init
Quoted 5 lines · Christoph Hellwig
Most of the content of
libxfs_initis members duplicated for each of the data, log and RT devices. Split those members into a separatelibxfs_devstructure.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 1,359 lines
--- copy/xfs_copy.c | 4 +- db/info.c | 2 +- db/init.c | 12 +-- db/output.c | 2 +- db/sb.c | 8 +- growfs/xfs_growfs.c | 20 ++--- include/libxfs.h | 45 ++++------ libxfs/init.c | 210 +++++++++++++++++++++----------------------- libxfs/topology.c | 16 ++-- logprint/logprint.c | 40 ++++----- mkfs/xfs_mkfs.c | 158 ++++++++++++++++----------------- repair/init.c | 12 +-- repair/phase2.c | 4 +- repair/sb.c | 16 ++-- repair/xfs_repair.c | 8 +- 15 files changed, 265 insertions(+), 292 deletions(-)copy/xfs_copy.c +2
-2@@ -716,8 +716,8 @@ main(int argc, char **argv)memset (&xargs,0 ,sizeof (xargs)); xargs.flags =LIBXFS_ISREADONLY |LIBXFS_DIRECT ; - xargs.dname = source_name; - xargs.disfile = source_is_file; + xargs.data.name = source_name; + xargs.data.isfile = source_is_file;if (!libxfs_init (&xargs)) { do_log(_("%s: couldn't initialize XFS library\n"db/info.c +1
-1@@ -30,7 +30,7 @@ info_f(struct xfs_fsop_geom geo;libxfs_fs_geometry (mp, &geo,XFS_FS_GEOM_MAX_STRUCT_VER ); -xfs_report_geom (&geo, x.dname, x.logname, x.rtname); +xfs_report_geom (&geo, x.data.name, x.log.name, x.rt.name);return 0 ; }db/init.c +6
-6@@ -61,7 +61,7 @@ init( cmdline[ncmdline++] = optarg;break ;case 'f' : - x.disfile =1 ; + x.data.isfile =1 ;break ;case 'F' : force =1 ;@@ -76,7 +76,7 @@ init( x.flags =LIBXFS_ISREADONLY ;break ;case 'l' : - x.logname = optarg; + x.log.name = optarg;break ;case 'x' : expert_mode =1 ;@@ -91,7 +91,7 @@ init(if (optind +1 != argc)usage (); - x.dname = argv[optind]; + x.data.name = argv[optind]; x.flags |=LIBXFS_DIRECT ; x.bcache_flags =CACHE_MISCOMPARE_PURGE ;@@ -111,7 +111,7 @@ init( 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL);if (error) {fprintf (stderr,_ ("%s: %s is invalid (cannot read first 512 " -"bytes)\n" ), progname, x.dname); +"bytes)\n" ), progname, x.data.name);exit (1 ); }@@ -122,7 +122,7 @@ init( sbp = &xmount.m_sb;if (sbp->sb_magicnum !=XFS_SB_MAGIC ) {fprintf (stderr,_ ("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n" ), - progname, x.dname, sbp->sb_magicnum); + progname, x.data.name, sbp->sb_magicnum);if (!force) {fprintf (stderr,_ ("Use -F to force a read attempt.\n" ));exit (EXIT_FAILURE );@@ -134,7 +134,7 @@ init(if (!mp) {fprintf (stderr,_ ("%s: device %s unusable (not an XFS filesystem?)\n" ), - progname, x.dname); + progname, x.data.name);exit (1 ); } mp->m_log = &xlog;db/output.c +1
-1@@ -34,7 +34,7 @@ dbprintf(const char *fmt, ...)blockint (); i =0 ;if (dbprefix) - i +=printf ("%s: " , x.dname); + i +=printf ("%s: " , x.data.name); i +=vprintf (fmt, ap);unblockint ();va_end (ap);db/sb.c +4
-4@@ -220,13 +220,13 @@ sb_logcheck(void)int dirty;if (mp->m_sb.sb_logstart) { -if (x.logdev && x.logdev != x.ddev) { +if (x.log.dev && x.log.dev != x.data.dev) {dbprintf (_ ("aborting - external log specified for FS " "with an internal log\n" ));return 0 ; } }else { -if (!x.logdev || (x.logdev == x.ddev)) { +if (!x.log.dev || (x.log.dev == x.data.dev)) {dbprintf (_ ("aborting - no external log specified for FS " "with an external log\n" ));return 0 ;@@ -452,10 +452,10 @@ uuid_f( } }if (mp->m_sb.sb_logstart) { -if (x.logdev && x.logdev != x.ddev) +if (x.log.dev && x.log.dev != x.data.dev)dbprintf (_ ("warning - external log specified " "for FS with an internal log\n" )); - }else if (!x.logdev || (x.logdev == x.ddev)) { + }else if (!x.log.dev || (x.log.dev == x.data.dev)) {dbprintf (_ ("warning - no external log specified " "for FS with an external log\n" )); }growfs/xfs_growfs.c +10
-10@@ -183,26 +183,26 @@ main(int argc, char **argv)*/ memset (&xi,0 ,sizeof (xi)); - xi.dname = datadev; - xi.logname = logdev; - xi.rtname = rtdev; + xi.data.name = datadev; + xi.log.name = logdev; + xi.rt.name = rtdev; xi.flags =LIBXFS_ISREADONLY ;if (!libxfs_init (&xi))usage ();/* check we got the info for all the sections we are trying to modify */ -if (!xi.ddev) { +if (!xi.data.dev) {fprintf (stderr,_ ("%s: failed to access data device for %s\n" ), progname, fname);exit (1 ); } -if (lflag && !isint && !xi.logdev) { +if (lflag && !isint && !xi.log.dev) {fprintf (stderr,_ ("%s: failed to access external log for %s\n" ), progname, fname);exit (1 ); } -if (rflag && !xi.rtdev) { +if (rflag && !xi.rt.dev) {fprintf (stderr,_ ("%s: failed to access realtime device for %s\n" ), progname, fname);@@ -211,10 +211,10 @@ main(int argc, char **argv)xfs_report_geom (&geo, datadev, logdev, rtdev); - ddsize = xi.dsize; - dlsize = ( xi.logBBsize? xi.logBBsize : + ddsize = xi.data.size; + dlsize = (xi.log.size ? xi.log.size : geo.logblocks * (geo.blocksize /BBSIZE ) ); - drsize = xi.rtsize; + drsize = xi.rt.size;/* * Ok, Linux only has a 1024-byte resolution on device _size_, @@ -328,7 +328,7 @@ _("[EXPERIMENTAL] try to shrink unused space %lld, old size is %lld\n"),else if (xflag) in.isint =0 ;else - in.isint = xi.logBBsize ==0 ; + in.isint = xi.log.size ==0 ;if (lsize == geo.logblocks && (in.isint == isint)) {if (lflag) fprintf(stderr,include/libxfs.h +19
-26@@ -89,38 +89,31 @@ struct iomap;#define xfs_isset (a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY)))) +struct libxfs_dev { +/* input parameters */ +char *name;/* pathname of the device */ +bool isfile;/* is the device a file? */ +bool create;/* create file if it doesn't exist */ + +/* output parameters */ +dev_t dev;/* device name for the device */ +long long size;/* size of subvolume (BBs) */ +int bsize;/* device blksize */ +int fd;/* file descriptor */ +}; +/* * Argument structure for libxfs_init(). */ struct libxfs_init { -/* input parameters */ -char *dname;/* pathname of data "subvolume" */ -char *logname;/* pathname of log "subvolume" */ -char *rtname;/* pathname of realtime "subvolume" */ +struct libxfs_dev data; +struct libxfs_dev log; +struct libxfs_dev rt; + +/* input parameters */ unsigned flags;/* LIBXFS_* flags below */ -int disfile;/* data "subvolume" is a regular file */ -int dcreat;/* try to create data subvolume */ -int lisfile;/* log "subvolume" is a regular file */ -int lcreat;/* try to create log subvolume */ -int risfile;/* realtime "subvolume" is a reg file */ -int rcreat;/* try to create realtime subvolume */ -int setblksize;/* attempt to set device blksize */ -/* output results */ -dev_t ddev;/* device for data subvolume */ -dev_t logdev;/* device for log subvolume */ -dev_t rtdev;/* device for realtime subvolume */ -long long dsize;/* size of data subvolume (BBs) */ -long long logBBsize;/* size of log subvolume (BBs) */ -/* (blocks allocated for use as -* log is stored in mount structure) */ -long long rtsize;/* size of realtime subvolume (BBs) */ -int dbsize;/* data subvolume device blksize */ -int lbsize;/* log subvolume device blksize */ -int rtbsize;/* realtime subvolume device blksize */ -int dfd;/* data subvolume file descriptor */ -int logfd;/* log subvolume file descriptor */ -int rtfd;/* realtime subvolume file descriptor */ int bcache_flags;/* cache init flags */ +int setblksize;/* value to set device blksizes to */ };/* disallow all mounted filesystems: */ libxfs/init.c +100
-110@@ -62,93 +62,117 @@ check_isactive(char *name, char *block, int fatal)return 0 ; } -/* libxfs_device_open: -* open a device and return its device number -*/ -static dev_t -libxfs_device_open (char *path,int creat,int xflags,int setblksize,int *fdp) +static int +check_open ( +struct libxfs_init *xi, +struct libxfs_dev *dev) { -int fd, flags; -int readonly, dio, excl; -struct stat statb; +struct stat stbuf; - readonly = (xflags &LIBXFS_ISREADONLY ); - excl = (xflags &LIBXFS_EXCLUSIVELY ) && !creat; - dio = (xflags &LIBXFS_DIRECT ) && !creat &&platform_direct_blockdev (); +if (stat (dev->name, &stbuf) <0 ) { +perror (dev->name); +return 0 ; + } +if (!(xi->flags &LIBXFS_ISREADONLY ) && + !(xi->flags &LIBXFS_ISINACTIVE ) && +platform_check_ismounted (dev->name, dev->name,NULL ,1 )) +return 0 ; -retry: - flags = (readonly ?O_RDONLY :O_RDWR ) | \ - (creat ? (O_CREAT |O_TRUNC ) :0 ) | \ - (dio ?O_DIRECT :0 ) | \ - (excl ?O_EXCL :0 ); +if ((xi->flags &LIBXFS_ISINACTIVE ) && +check_isactive (dev->name, dev->name, !!(xi->flags & + (LIBXFS_ISREADONLY |LIBXFS_DANGEROUSLY )))) +return 0 ; + +return 1 ; +} + +static bool +libxfs_device_open ( +struct libxfs_init *xi, +struct libxfs_dev *dev) +{ +struct stat statb; +int flags; + + dev->fd =-1 ; + +if (!dev->name) +return true; +if (!dev->isfile && !check_open (xi, dev)) +return false; + +if (xi->flags &LIBXFS_ISREADONLY ) + flags =O_RDONLY ; +else + flags =O_RDWR ; -if ((fd =open (path, flags,0666 )) <0 ) { -if (errno ==EINVAL && --dio ==0 ) +if (dev->create) { + flags |=O_CREAT |O_TRUNC ; + }else { +if (xi->flags &LIBXFS_EXCLUSIVELY ) + flags |=O_EXCL ; +if ((xi->flags &LIBXFS_DIRECT ) &&platform_direct_blockdev ()) + flags |=O_DIRECT ; + } + +retry: + dev->fd =open (dev->name, flags,0666 ); +if (dev->fd <0 ) { +if (errno ==EINVAL && (flags &O_DIRECT )) { + flags &= ~O_DIRECT ; goto retry; + }fprintf (stderr,_ ("%s: cannot open %s: %s\n" ), - progname, path,strerror (errno)); + progname, dev->name,strerror (errno));exit (1 ); } -if (fstat (fd, &statb) <0 ) { +if (fstat (dev->fd, &statb) <0 ) {fprintf (stderr,_ ("%s: cannot stat %s: %s\n" ), - progname, path,strerror (errno)); + progname, dev->name,strerror (errno));exit (1 ); } -if (!readonly && setblksize && (statb.st_mode &S_IFMT ) ==S_IFBLK ) { +if (!(xi->flags &LIBXFS_ISREADONLY ) && + xi->setblksize && + (statb.st_mode &S_IFMT ) ==S_IFBLK ) {/* * Try to use the given explicit blocksize. Failure to set the * block size is only fatal for direct I/O. */ -platform_set_blocksize (fd, path, statb.st_rdev, setblksize, - dio); +platform_set_blocksize (dev->fd, dev->name, statb.st_rdev, + xi->setblksize, flags &O_DIRECT ); }/* * Get the device number from the stat buf - unless we're not opening a * real device, in which case choose a new fake device number. */ - *fdp = fd;if (statb.st_rdev) -return statb.st_rdev; -return nextfakedev--; + dev->dev = statb.st_rdev; +else + dev->dev = nextfakedev--; +platform_findsizes (dev->name, dev->fd, &dev->size, &dev->bsize); +return true; }static void -libxfs_device_close (int fd,dev_t dev) +libxfs_device_close ( +struct libxfs_dev *dev) { -int ret; +int ret; - ret =platform_flush_device (fd, dev); + ret =platform_flush_device (dev->fd, dev->dev);if (ret) { ret = -errno;fprintf (stderr,_ ("%s: flush of device %lld failed, err=%d" ), progname, (long long )dev, ret); } -close (fd); -} +close (dev->fd); -static int -check_open (char *path,int flags) -{ -int readonly = (flags &LIBXFS_ISREADONLY ); -int inactive = (flags &LIBXFS_ISINACTIVE ); -int dangerously = (flags &LIBXFS_DANGEROUSLY ); -struct stat stbuf; - -if (stat (path, &stbuf) <0 ) { -perror (path); -return 0 ; - } -if (!readonly && !inactive &&platform_check_ismounted (path, path,NULL ,1 )) -return 0 ; - -if (inactive &&check_isactive (path, path, ((readonly|dangerously)?1 :0 ))) -return 0 ; - -return 1 ; + dev->fd =-1 ; + dev->dev =0 ; }/* @@ -209,15 +233,12 @@ static voidlibxfs_close_devices ( struct libxfs_init *li) { -if (li->ddev) -libxfs_device_close (li->dfd, li->ddev); -if (li->logdev && li->logdev != li->ddev) -libxfs_device_close (li->logfd, li->logdev); -if (li->rtdev) -libxfs_device_close (li->rtfd, li->rtdev); - - li->ddev = li->logdev = li->rtdev =0 ; - li->dfd = li->logfd = li->rtfd =-1 ; +if (li->data.dev) +libxfs_device_close (&li->data); +if (li->log.dev && li->log.dev != li->data.dev) +libxfs_device_close (&li->log); +if (li->rt.dev) +libxfs_device_close (&li->rt); }/* @@ -227,44 +248,16 @@ libxfs_close_devices(int libxfs_init (struct libxfs_init *a) { -char *dname; -char *logname; -char *rtname; - - dname = a->dname; - logname = a->logname; - rtname = a->rtname; - a->dfd = a->logfd = a->rtfd =-1 ; - a->ddev = a->logdev = a->rtdev =0 ; - a->dsize = a->lbsize = a->rtbsize =0 ; - a->dbsize = a->logBBsize = a->rtsize =0 ; -rcu_init ();rcu_register_thread ();radix_tree_init (); -if (dname) { -if (!a->disfile && !check_open (dname, a->flags)) - goto done; - a->ddev =libxfs_device_open (dname, a->dcreat, a->flags, - a->setblksize, &a->dfd); -platform_findsizes (dname, a->dfd, &a->dsize, &a->dbsize); - } -if (logname) { -if (!a->lisfile && !check_open (logname, a->flags)) - goto done; - a->logdev =libxfs_device_open (logname, a->lcreat, a->flags, - a->setblksize, &a->logfd); -platform_findsizes (logname, a->logfd, &a->logBBsize, - &a->lbsize); - } -if (rtname) { -if (a->risfile && !check_open (rtname, a->flags)) - goto done; - a->rtdev =libxfs_device_open (rtname, a->rcreat, a->flags, - a->setblksize, &a->rtfd); -platform_findsizes (dname, a->rtfd, &a->rtsize, &a->rtbsize); - } +if (!libxfs_device_open (a, &a->data)) + goto done; +if (!libxfs_device_open (a, &a->log)) + goto done; +if (!libxfs_device_open (a, &a->rt)) + goto done;if (!libxfs_bhash_size) libxfs_bhash_size =LIBXFS_BHASHSIZE (sbp);@@ -452,8 +445,7 @@ xfs_set_inode_alloc(static struct xfs_buftarg *libxfs_buftarg_alloc (struct xfs_mount *mp, -dev_t dev, -int fd, +struct libxfs_dev *dev,unsigned long write_fails) {struct xfs_buftarg *btp;@@ -465,8 +457,8 @@ libxfs_buftarg_alloc(exit (1 ); } btp->bt_mount = mp; - btp->bt_bdev = dev; - btp->bt_bdev_fd = fd; + btp->bt_bdev = dev->dev; + btp->bt_bdev_fd = dev->fd; btp->flags =0 ;if (write_fails) { btp->writes_left = write_fails;@@ -538,29 +530,29 @@ libxfs_buftarg_init(if (mp->m_ddev_targp) {/* should already have all buftargs initialised */ -if (mp->m_ddev_targp->bt_bdev != xi->ddev || +if (mp->m_ddev_targp->bt_bdev != xi->data.dev || mp->m_ddev_targp->bt_mount != mp) {fprintf (stderr,_ ("%s: bad buftarg reinit, ddev\n" ), progname);exit (1 ); } -if (!xi->logdev || xi->logdev == xi->ddev) { +if (!xi->log.dev || xi->log.dev == xi->data.dev) {if (mp->m_logdev_targp != mp->m_ddev_targp) {fprintf (stderr,_ ("%s: bad buftarg reinit, ldev mismatch\n" ), progname);exit (1 ); } - }else if (mp->m_logdev_targp->bt_bdev != xi->logdev || + }else if (mp->m_logdev_targp->bt_bdev != xi->log.dev || mp->m_logdev_targp->bt_mount != mp) {fprintf (stderr,_ ("%s: bad buftarg reinit, logdev\n" ), progname);exit (1 ); } -if (xi->rtdev && - (mp->m_rtdev_targp->bt_bdev != xi->rtdev || +if (xi->rt.dev && + (mp->m_rtdev_targp->bt_bdev != xi->rt.dev || mp->m_rtdev_targp->bt_mount != mp)) { fprintf(stderr, _("%s: bad buftarg reinit, rtdev\n"),@@ -570,14 +562,12 @@ libxfs_buftarg_init(return ; } - mp->m_ddev_targp =libxfs_buftarg_alloc (mp, xi->ddev, xi->dfd, dfail); -if (!xi->logdev || xi->logdev == xi->ddev) + mp->m_ddev_targp =libxfs_buftarg_alloc (mp, &xi->data, dfail); +if (!xi->log.dev || xi->log.dev == xi->data.dev) mp->m_logdev_targp = mp->m_ddev_targp;else - mp->m_logdev_targp =libxfs_buftarg_alloc (mp, xi->logdev, - xi->logfd, lfail); - mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, xi->rtdev, xi->rtfd, - rfail); + mp->m_logdev_targp =libxfs_buftarg_alloc (mp, &xi->log, lfail); + mp->m_rtdev_targp =libxfs_buftarg_alloc (mp, &xi->rt, rfail); }/* Compute maximum possible height for per-AG btree types for this fs. */ @@ -711,7 +701,7 @@ libxfs_mount(/* Initialize the precomputed transaction reservations values */ xfs_trans_init (mp); -if (xi->ddev ==0 )/* maxtrres, we have no device so leave now */ +if (xi->data.dev ==0 )/* maxtrres, we have no device so leave now */ return mp;/* device size checks must pass unless we're a debugger. */ libxfs/topology.c +8
-8@@ -299,34 +299,34 @@ get_topology(* to try to obtain the underlying filesystem's requirements * for direct IO; we'll set our sector size to that if possible. */ -if (xi->disfile || - (!stat (xi->dname, &statbuf) &&S_ISREG (statbuf.st_mode))) { +if (xi->data.isfile || + (!stat (xi->data.name, &statbuf) &&S_ISREG (statbuf.st_mode))) {int fd;int flags =O_RDONLY ;long long dummy;/* with xi->disfile we may not have the file yet! */ -if (xi->disfile) +if (xi->data.isfile) flags |=O_CREAT ; - fd =open (xi->dname, flags,0666 ); + fd =open (xi->data.name, flags,0666 );if (fd >=0 ) { -platform_findsizes (xi->dname, fd, &dummy, +platform_findsizes (xi->data.name, fd, &dummy, &ft->lsectorsize);close (fd); ft->psectorsize = ft->lsectorsize; }else ft->psectorsize = ft->lsectorsize =BBSIZE ; }else { -blkid_get_topology (xi->dname, &ft->dsunit, &ft->dswidth, +blkid_get_topology (xi->data.name, &ft->dsunit, &ft->dswidth, &ft->lsectorsize, &ft->psectorsize, force_overwrite); } -if (xi->rtname && !xi->risfile) { +if (xi->rt.name && !xi->rt.isfile) {int sunit, lsectorsize, psectorsize; -blkid_get_topology (xi->rtname, &sunit, &ft->rtswidth, +blkid_get_topology (xi->rt.name, &sunit, &ft->rtswidth, &lsectorsize, &psectorsize, force_overwrite); } }logprint/logprint.c +20
-20@@ -64,9 +64,9 @@ logstat(* filesystem. We need this to get the length of the * log. Otherwise we end up seeking forever. -- mkp */ -if ((fd =open (x.dname,O_RDONLY )) ==-1 ) { +if ((fd =open (x.data.name,O_RDONLY )) ==-1 ) {fprintf (stderr,_ (" Can't open device %s: %s\n" ), - x.dname,strerror (errno)); + x.data.name,strerror (errno));exit (1 ); }lseek (fd,0 ,SEEK_SET );@@ -76,7 +76,7 @@ logstat( }close (fd); -if (!x.disfile) { +if (!x.data.isfile) {struct xfs_sb *sb = &mp->m_sb;/* @@ -88,7 +88,7 @@ logstat(xlog_init (mp, log); -if (!x.logname && sb->sb_logstart ==0 ) { +if (!x.log.name && sb->sb_logstart ==0 ) {fprintf (stderr,_ (" external log device not specified\n\n" ));usage ();/*NOTREACHED*/ @@ -96,7 +96,7 @@ logstat( }else {struct stat s; -stat (x.dname, &s); +stat (x.data.name, &s); log->l_logBBsize = s.st_size >>9 ; log->l_logBBstart =0 ;@@ -105,15 +105,15 @@ logstat( log->l_mp = mp; } -if (x.logname && *x.logname) {/* External log */ -if ((fd =open (x.logname,O_RDONLY )) ==-1 ) { +if (x.log.name && *x.log.name) {/* External log */ +if ((fd =open (x.log.name,O_RDONLY )) ==-1 ) {fprintf (stderr,_ ("Can't open file %s: %s\n" ), - x.logname,strerror (errno)); + x.log.name,strerror (errno));exit (1 ); }close (fd); }else {/* Internal log */ - x.logdev = x.ddev; + x.log.dev = x.data.dev; }return 0 ;@@ -165,11 +165,11 @@ main(int argc, char **argv)break ;case 'f' : print_skip_uuid++; - x.disfile =1 ; + x.data.isfile =1 ;break ;case 'l' : - x.logname = optarg; - x.lisfile =1 ; + x.log.name = optarg; + x.log.isfile =1 ;break ;case 'i' : print_inode++;@@ -203,9 +203,9 @@ main(int argc, char **argv)if (argc - optind !=1 )usage (); - x.dname = argv[optind]; + x.data.name = argv[optind]; -if (x.dname ==NULL ) +if (x.data.name ==NULL )usage (); x.flags =LIBXFS_ISINACTIVE ;@@ -216,20 +216,20 @@ main(int argc, char **argv)libxfs_buftarg_init (&mount, &x);logstat (&mount, &log); - logfd = (x.logfd <0 ) ? x.dfd : x.logfd; + logfd = (x.log.fd <0 ) ? x.data.fd : x.log.fd; -printf (_ (" data device: 0x%llx\n" ), (unsigned long long )x.ddev); +printf (_ (" data device: 0x%llx\n" ), (unsigned long long )x.data.dev); -if (x.logname) { -printf (_ (" log file: \"%s\" " ), x.logname); +if (x.log.name) { +printf (_ (" log file: \"%s\" " ), x.log.name); }else { -printf (_ (" log device: 0x%llx " ), (unsigned long long )x.logdev); +printf (_ (" log device: 0x%llx " ), (unsigned long long )x.log.dev); }printf (_ ("daddr: %lld length: %lld\n\n" ), (long long )log.l_logBBstart, (long long )log.l_logBBsize); -ASSERT (log.l_logBBsize <=INT_MAX ); +ASSERT (x.log.size <=INT_MAX );switch (print_operation) {case OP_PRINT :mkfs/xfs_mkfs.c +75
-83@@ -1092,37 +1092,35 @@ invalid_cfgfile_opt(static void check_device_type ( -const char *name, -int *isfile, -bool no_size, -bool no_name, -int *create, -const char *optname) +struct libxfs_dev *dev, +bool no_size, +bool dry_run, +const char *optname) {struct stat statbuf; -if (*isfile && (no_size || no_name)) { +if (dev->isfile && (no_size || !dev->name)) {fprintf (stderr,_ ("if -%s file then -%s name and -%s size are required\n" ), optname, optname, optname);usage (); } -if (!name) { +if (!dev->name) {fprintf (stderr,_ ("No device name specified\n" ));usage (); } -if (stat (name, &statbuf)) { -if (errno ==ENOENT && *isfile) { -if (create) - *create =1 ; +if (stat (dev->name, &statbuf)) { +if (errno ==ENOENT && dev->isfile) { +if (!dry_run) + dev->create =1 ;return ; }fprintf (stderr,_ ("Error accessing specified device %s: %s\n" ), - name,strerror (errno)); + dev->name,strerror (errno));usage ();return ; }@@ -1133,18 +1131,18 @@ check_device_type(* this case to trigger that behaviour. */ if (S_ISREG (statbuf.st_mode)) { -if (!*isfile) - *isfile =1 ; -else if (create) - *create =1 ; +if (!dev->isfile) + dev->isfile =1 ; +else if (!dry_run) + dev->create =1 ;return ; }if (S_ISBLK (statbuf.st_mode)) { -if (*isfile) { +if (dev->isfile) {fprintf (stderr,_ ("specified \"-%s file\" on a block device %s\n" ), - optname, name); + optname, dev->name);usage (); }return ;@@ -1152,7 +1150,7 @@ check_device_type(fprintf (stderr,_ ("specified device %s not a file or block device\n" ), - name); + dev->name);usage (); }@@ -1258,7 +1256,7 @@ zero_old_xfs_structures(/* * We open regular files with O_TRUNC|O_CREAT. Nothing to do here... */ -if (xi->disfile && xi->dcreat) +if (xi->data.isfile && xi->data.create)return ;/* @@ -1279,9 +1277,9 @@ zero_old_xfs_structures(* return zero bytes. It's not a failure we need to warn about in this * case. */ - off =pread (xi->dfd, buf, new_sb->sb_sectsize,0 ); + off =pread (xi->data.fd, buf, new_sb->sb_sectsize,0 );if (off != new_sb->sb_sectsize) { -if (!xi->disfile) +if (!xi->data.isfile)fprintf (stderr,_ ("error reading existing superblock: %s\n" ),strerror (errno));@@ -1316,7 +1314,7 @@ zero_old_xfs_structures( off =0 ;for (i =1 ; i < sb.sb_agcount; i++) { off += sb.sb_agblocks; -if (pwrite (xi->dfd, buf, new_sb->sb_sectsize, +if (pwrite (xi->data.fd, buf, new_sb->sb_sectsize, off << sb.sb_blocklog) ==-1 )break ; }@@ -1561,10 +1559,10 @@ data_opts_parser( cli->agsize =getstr (value, opts, subopt);break ;case D_FILE : - cli->xi->disfile =getnum (value, opts, subopt); + cli->xi->data.isfile =getnum (value, opts, subopt);break ;case D_NAME : - cli->xi->dname =getstr (value, opts, subopt); + cli->xi->data.name =getstr (value, opts, subopt);break ;case D_SIZE : cli->dsize =getstr (value, opts, subopt);@@ -1673,7 +1671,7 @@ log_opts_parser( cli->logagno =getnum (value, opts, subopt);break ;case L_FILE : - cli->xi->lisfile =getnum (value, opts, subopt); + cli->xi->log.isfile =getnum (value, opts, subopt);break ;case L_INTERNAL : cli->loginternal =getnum (value, opts, subopt);@@ -1686,7 +1684,7 @@ log_opts_parser(break ;case L_NAME :case L_DEV : - cli->xi->logname =getstr (value, opts, subopt); + cli->xi->log.name =getstr (value, opts, subopt); cli->loginternal =0 ;break ;case L_VERSION :@@ -1819,11 +1817,11 @@ rtdev_opts_parser( cli->rtextsize =getstr (value, opts, subopt);break ;case R_FILE : - cli->xi->risfile =getnum (value, opts, subopt); + cli->xi->rt.isfile =getnum (value, opts, subopt);break ;case R_NAME :case R_DEV : - cli->xi->rtname =getstr (value, opts, subopt); + cli->xi->rt.name =getstr (value, opts, subopt);break ;case R_SIZE : cli->rtsize =getstr (value, opts, subopt);@@ -1962,24 +1960,18 @@ validate_sectorsize(* Before anything else, verify that we are correctly operating on * files or block devices and set the control parameters correctly. */ -check_device_type (cli->xi->dname, &cli->xi->disfile, - !cli->dsize, !cli->xi->dname, - dry_run ?NULL : &cli->xi->dcreat,"d" ); +check_device_type (&cli->xi->data, !cli->dsize, dry_run,"d" );if (!cli->loginternal) -check_device_type (cli->xi->logname, &cli->xi->lisfile, - !cli->logsize, !cli->xi->logname, - dry_run ?NULL : &cli->xi->lcreat,"l" ); -if (cli->xi->rtname) -check_device_type (cli->xi->rtname, &cli->xi->risfile, - !cli->rtsize, !cli->xi->rtname, - dry_run ?NULL : &cli->xi->rcreat,"r" ); +check_device_type (&cli->xi->log, !cli->logsize, dry_run,"l" ); +if (cli->xi->rt.name) +check_device_type (&cli->xi->rt, !cli->rtsize, dry_run,"r" );/* * Explicitly disable direct IO for image files so we don't error out on * sector size mismatches between the new filesystem and the underlying * host filesystem. */ -if (cli->xi->disfile || cli->xi->lisfile || cli->xi->risfile) +if (cli->xi->data.isfile || cli->xi->log.isfile || cli->xi->rt.isfile) cli->xi->flags &= ~LIBXFS_DIRECT ;memset (ft,0 ,sizeof (*ft));@@ -2294,7 +2286,7 @@ _("inode btree counters not supported without finobt support\n")); cli->sb_feat.inobtcnt = false; } -if (cli->xi->rtname) { +if (cli->xi->rt.name) {if (cli->sb_feat.reflink &&cli_opt_set (&mopts,M_REFLINK )) {fprintf (stderr,_ ("reflink not supported with realtime devices\n" ));@@ -2461,8 +2453,8 @@ validate_rtextsize(*/ uint64_t rswidth; -if (!cfg->sb_feat.nortalign && !cli->xi->risfile && - !(!cli->rtsize && cli->xi->disfile)) +if (!cfg->sb_feat.nortalign && !cli->xi->rt.isfile && + !(!cli->rtsize && cli->xi->data.isfile)) rswidth = ft->rtswidth;else rswidth =0 ;@@ -2840,7 +2832,7 @@ open_devices( xi->setblksize = cfg->sectorsize;if (!libxfs_init (xi))usage (); -if (!xi->ddev) { +if (!xi->data.dev) {fprintf (stderr,_ ("no device name given in argument list\n" ));usage (); }@@ -2856,9 +2848,9 @@ open_devices(* multiple of the sector size, or 1024, whichever is larger. */ sector_mask = (uint64_t )-1 << (max (cfg->sectorlog,10 ) -BBSHIFT ); - xi->dsize &= sector_mask; - xi->rtsize &= sector_mask; - xi->logBBsize &= (uint64_t )-1 << (max (cfg->lsectorlog,10 ) -BBSHIFT ); + xi->data.size &= sector_mask; + xi->rt.size &= sector_mask; + xi->log.size &= (uint64_t )-1 << (max (cfg->lsectorlog,10 ) -BBSHIFT ); } static void@@ -2870,12 +2862,12 @@ discard_devices(* This function has to be called after libxfs has been initialized. */ -if (!xi->disfile) -discard_blocks (xi->dfd, xi->dsize, quiet); -if (xi->rtdev && !xi->risfile) -discard_blocks (xi->rtfd, xi->rtsize, quiet); -if (xi->logdev && xi->logdev != xi->ddev && !xi->lisfile) -discard_blocks (xi->logfd, xi->logBBsize, quiet); +if (!xi->data.isfile) +discard_blocks (xi->data.fd, xi->data.size, quiet); +if (xi->rt.dev && !xi->rt.isfile) +discard_blocks (xi->rt.fd, xi->rt.size, quiet); +if (xi->log.dev && xi->log.dev != xi->data.dev && !xi->log.isfile) +discard_blocks (xi->log.fd, xi->log.size, quiet); } static void@@ -2885,29 +2877,29 @@ validate_datadev( {struct libxfs_init *xi = cli->xi; -if (!xi->dsize) { +if (!xi->data.size) {/* * if the device is a file, we can't validate the size here. * Instead, the file will be truncated to the correct length * later on. if it's not a file, we've got a dud device. */ -if (!xi->disfile) { +if (!xi->data.isfile) {fprintf (stderr,_ ("can't get size of data subvolume\n" ));usage (); }ASSERT (cfg->dblocks); }else if (cfg->dblocks) {/* check the size fits into the underlying device */ -if (cfg->dblocks >DTOBT (xi->dsize, cfg->blocklog)) { +if (cfg->dblocks >DTOBT (xi->data.size, cfg->blocklog)) {fprintf (stderr,_ ("size %s specified for data subvolume is too large, maximum is %lld blocks\n" ), cli->dsize, - (long long )DTOBT (xi->dsize, cfg->blocklog)); + (long long )DTOBT (xi->data.size, cfg->blocklog));usage (); } }else {/* no user size, so use the full block device */ - cfg->dblocks =DTOBT (xi->dsize, cfg->blocklog); + cfg->dblocks =DTOBT (xi->data.size, cfg->blocklog); }if (cfg->dblocks <XFS_MIN_DATA_BLOCKS (cfg)) {@@ -2917,11 +2909,11 @@ _("size %lld of data subvolume is too small, minimum %lld blocks\n"),usage (); } -if (xi->dbsize > cfg->sectorsize) { +if (xi->data.bsize > cfg->sectorsize) {fprintf (stderr,_ ("Warning: the data subvolume sector size %u is less than the sector size \n\ reported by the device (%u).\n" ), - cfg->sectorsize, xi->dbsize); + cfg->sectorsize, xi->data.bsize); } }@@ -2961,31 +2953,31 @@ _("log size %lld too large for internal log\n"), }/* External/log subvolume checks */ -if (!*xi->logname || !xi->logdev) { +if (!*xi->log.name || !xi->log.dev) {fprintf (stderr,_ ("no log subvolume or external log.\n" ));usage (); }if (!cfg->logblocks) { -if (xi->logBBsize ==0 ) { +if (xi->log.size ==0 ) {fprintf (stderr,_ ("unable to get size of the log subvolume.\n" ));usage (); } - cfg->logblocks =DTOBT (xi->logBBsize, cfg->blocklog); - }else if (cfg->logblocks >DTOBT (xi->logBBsize, cfg->blocklog)) { + cfg->logblocks =DTOBT (xi->log.size, cfg->blocklog); + }else if (cfg->logblocks >DTOBT (xi->log.size, cfg->blocklog)) {fprintf (stderr,_ ("size %s specified for log subvolume is too large, maximum is %lld blocks\n" ), cli->logsize, - (long long )DTOBT (xi->logBBsize, cfg->blocklog)); + (long long )DTOBT (xi->log.size, cfg->blocklog));usage (); } -if (xi->lbsize > cfg->lsectorsize) { +if (xi->log.bsize > cfg->lsectorsize) {fprintf (stderr,_ ("Warning: the log subvolume sector size %u is less than the sector size\n\ reported by the device (%u).\n" ), - cfg->lsectorsize, xi->lbsize); + cfg->lsectorsize, xi->log.bsize); } }@@ -2996,7 +2988,7 @@ validate_rtdev( {struct libxfs_init *xi = cli->xi; -if (!xi->rtdev) { +if (!xi->rt.dev) {if (cli->rtsize) {fprintf (stderr,_ ("size specified for non-existent rt subvolume\n" ));@@ -3008,28 +3000,28 @@ _("size specified for non-existent rt subvolume\n")); cfg->rtbmblocks =0 ;return ; } -if (!xi->rtsize) { +if (!xi->rt.size) {fprintf (stderr,_ ("Invalid zero length rt subvolume found\n" ));usage (); }if (cli->rtsize) { -if (cfg->rtblocks >DTOBT (xi->rtsize, cfg->blocklog)) { +if (cfg->rtblocks >DTOBT (xi->rt.size, cfg->blocklog)) {fprintf (stderr,_ ("size %s specified for rt subvolume is too large, maxi->um is %lld blocks\n" ), cli->rtsize, - (long long )DTOBT (xi->rtsize, cfg->blocklog)); + (long long )DTOBT (xi->rt.size, cfg->blocklog));usage (); } -if (xi->rtbsize > cfg->sectorsize) { +if (xi->rt.bsize > cfg->sectorsize) {fprintf (stderr,_ ("Warning: the realtime subvolume sector size %u is less than the sector size\n\ reported by the device (%u).\n" ), - cfg->sectorsize, xi->rtbsize); + cfg->sectorsize, xi->rt.bsize); } }else {/* grab volume size */ - cfg->rtblocks =DTOBT (xi->rtsize, cfg->blocklog); + cfg->rtblocks =DTOBT (xi->rt.size, cfg->blocklog); } cfg->rtextents = cfg->rtblocks / cfg->rtextblocks;@@ -3770,9 +3762,9 @@ prepare_devices(* needed so that the reads for the end of the device in the mount code * will succeed. */ -if (xi->disfile && - xi->dsize * xi->dbsize < cfg->dblocks * cfg->blocksize) { -if (ftruncate (xi->dfd, cfg->dblocks * cfg->blocksize) <0 ) { +if (xi->data.isfile && + xi->data.size * xi->data.bsize < cfg->dblocks * cfg->blocksize) { +if (ftruncate (xi->data.fd, cfg->dblocks * cfg->blocksize) <0 ) {fprintf (stderr,_ ("%s: Growing the data section failed\n" ), progname);@@ -3780,7 +3772,7 @@ prepare_devices( }/* update size to be able to whack blocks correctly */ - xi->dsize =BTOBB (cfg->dblocks * cfg->blocksize); + xi->data.size =BTOBB (cfg->dblocks * cfg->blocksize); }/* @@ -3788,7 +3780,7 @@ prepare_devices(* the end of the device. (MD sb is ~64k from the end, take out a wider * swath to be sure) */ - buf =alloc_write_buf (mp->m_ddev_targp, (xi->dsize - whack_blks), + buf =alloc_write_buf (mp->m_ddev_targp, (xi->data.size - whack_blks), whack_blks);memset (buf->b_addr,0 ,WHACK_SIZE );libxfs_buf_mark_dirty (buf);@@ -4183,7 +4175,7 @@ main(fprintf (stderr,_ ("extra arguments\n" ));usage (); }else if (argc - optind ==1 ) { - xi.dname =getstr (argv[optind], &dopts,D_NAME ); + xi.data.name =getstr (argv[optind], &dopts,D_NAME ); }/* @@ -4236,7 +4228,7 @@ main(* Open and validate the device configurations */ open_devices (&cfg, &xi); -validate_overwrite (xi.dname, force_overwrite); +validate_overwrite (xi.data.name, force_overwrite);validate_datadev (&cfg, &cli);validate_logdev (&cfg, &cli);validate_rtdev (&cfg, &cli);@@ -4280,7 +4272,7 @@ main(struct xfs_fsop_geom geo;libxfs_fs_geometry (mp, &geo,XFS_FS_GEOM_MAX_STRUCT_VER ); -xfs_report_geom (&geo, xi.dname, xi.logname, xi.rtname); +xfs_report_geom (&geo, xi.data.name, xi.log.name, xi.rt.name);if (dry_run)exit (0 ); }repair/init.c +6
-6@@ -56,19 +56,19 @@ xfs_init(struct libxfs_init *args) {memset (args,0 ,sizeof (*args)); - args->dname = fs_name; - args->disfile = isa_file; + args->data.name = fs_name; + args->data.isfile = isa_file;if (log_spec) {/* External log specified */ - args->logname = log_name; - args->lisfile = (isa_file?1 :0 ); + args->log.name = log_name; + args->log.isfile = isa_file;/* XXX assume data file also means log file */ /* REVISIT: Need to do fs sanity / log validity checking */ }if (rt_spec) {/* RT device specified */ - args->rtname = rt_name; - args->risfile = (isa_file?1 :0 ); + args->rt.name = rt_name; + args->rt.isfile = isa_file;/* XXX assume data file also means rt file */ }repair/phase2.c +2
-2@@ -341,11 +341,11 @@ phase2(/* Check whether this fs has internal or external log */ if (mp->m_sb.sb_logstart ==0 ) { -if (!x.logname) +if (!x.log.name)do_error (_ ("This filesystem has an external log. " "Specify log device with the -l option.\n" )); -do_log (_ ("Phase 2 - using external log on %s\n" ), x.logname); +do_log (_ ("Phase 2 - using external log on %s\n" ), x.log.name); }else do_log (_ ("Phase 2 - using internal log\n" ));repair/sb.c +7
-9@@ -125,13 +125,11 @@ __find_secondary_sb(/* * read disk 1 MByte at a time. */ -if (lseek (x.dfd, off,SEEK_SET ) != off) { +if (lseek (x.data.fd, off,SEEK_SET ) != off) done =1 ; - } -if (!done && (bsize =read (x.dfd, sb,BSIZE )) <=0 ) { +if (!done && (bsize =read (x.data.fd, sb,BSIZE )) <=0 ) done =1 ; - }do_warn ("." );@@ -192,7 +190,7 @@ guess_default_geometry(*/ blocklog =12 ; multidisk = ft.dswidth | ft.dsunit; - dblocks = x->dsize >> (blocklog -BBSHIFT ); + dblocks = x->data.size >> (blocklog -BBSHIFT );calc_default_ag_geometry (blocklog, dblocks, multidisk, agsize, agcount);@@ -533,7 +531,7 @@ write_primary_sb(xfs_sb_t *sbp, int size) }memset (buf,0 , size); -if (lseek (x.dfd,0LL ,SEEK_SET ) !=0LL ) { +if (lseek (x.data.fd,0LL ,SEEK_SET ) !=0LL ) {free (buf);do_error (_ ("couldn't seek to offset 0 in filesystem\n" )); }@@ -543,7 +541,7 @@ write_primary_sb(xfs_sb_t *sbp, int size)if (xfs_sb_version_hascrc (sbp))xfs_update_cksum ((char *)buf, size,XFS_SB_CRC_OFF ); -if (write (x.dfd, buf, size) != size) { +if (write (x.data.fd, buf, size) != size) {free (buf);do_error (_ ("primary superblock write failed!\n" )); }@@ -572,7 +570,7 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno)/* try and read it first */ -if (lseek (x.dfd, off,SEEK_SET ) != off) { +if (lseek (x.data.fd, off,SEEK_SET ) != off) {do_warn (_ ("error reading superblock %u -- seek to offset %" PRId64" failed\n" ), agno, off);@@ -580,7 +578,7 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno)return (XR_EOF ); } -if ((rval =read (x.dfd, buf, size)) != size) { +if ((rval =read (x.data.fd, buf, size)) != size) { error = errno; do_warn( _("superblock read failed, offset %" PRId64 ", size %d, ag %u, rval %d\n"),repair/xfs_repair.c +4
-5@@ -728,7 +728,7 @@ check_fs_vs_host_sectsize(long old_flags;struct xfs_fsop_geom geom = {0 }; - ret = -xfrog_geometry (x.dfd, &geom); + ret = -xfrog_geometry (x.data.fd, &geom);if (ret) { do_log(_("Cannot get host filesystem geometry.\n" "Repair may fail if there is a sector size mismatch between\n"@@ -737,8 +737,8 @@ check_fs_vs_host_sectsize( }if (sb->sb_sectsize < geom.sectsize) { - old_flags =fcntl (x.dfd,F_GETFL ,0 ); -if (fcntl (x.dfd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) { + old_flags =fcntl (x.data.fd,F_GETFL ,0 ); +if (fcntl (x.data.fd,F_SETFL , old_flags & ~O_DIRECT ) <0 ) {do_warn (_ ("Sector size on host filesystem larger than image sector size.\n" "Cannot turn off direct IO, so exiting.\n" ));@@ -986,7 +986,7 @@ main(int argc, char **argv)if (!isa_file) {struct stat statbuf; -if (fstat (x.dfd, &statbuf) <0 ) +if (fstat (x.data.fd, &statbuf) <0 )do_warn (_ ("%s: couldn't stat \"%s\"\n" ), progname, fs_name);else if (S_ISREG (statbuf.st_mode)) --2.39.2
Darrick J. Wong
Reviewed-byQuoted 6 lines · Christoph Hellwig
Hi all,
this series how libxfs deals with the data, log and rt devices. A lot of it is just tidying up cruft old code, but it then introduces a
libxfs_devstructure that describes a single device to further simplify the code.
Yay! I'm glad the bizarre isreadonly == flags code is gone!
And all that weird dev_t -> fd translation weirdness, and the last of the irix stuff that makes no sense now.
--D
Quoted 35 lines
Diffstat:
copy/xfs_copy.c | 19 -- db/crc.c | 2 db/fuzz.c | 2 db/info.c | 2 db/init.c | 29 +-- db/init.h | 3 db/metadump.c | 4 db/output.c | 2 db/sb.c | 18 +- db/write.c | 2 growfs/xfs_growfs.c | 24 +-- include/libxfs.h | 87 +++++------ include/libxlog.h | 7 include/xfs_mount.h | 3 libfrog/linux.c | 39 +---- libfrog/platform.h | 6 libxfs/init.c | 398 +++++++++++++++------------------------------------- libxfs/libxfs_io.h | 5 libxfs/rdwr.c | 16 -- libxfs/topology.c | 23 +-- libxfs/topology.h | 4 libxlog/util.c | 49 +++--- logprint/logprint.c | 79 ++++------ mkfs/xfs_mkfs.c | 249 +++++++++++++------------------- repair/globals.h | 2 repair/init.c | 40 ++--- repair/phase2.c | 27 --- repair/prefetch.c | 2 repair/protos.h | 2 repair/sb.c | 18 +- repair/xfs_repair.c | 15 - 31 files changed, 453 insertions(+), 725 deletions(-)