improve the discard / reset zones code in mkfs
Hi all,
this series refactors the discard and reset zones code in mkfs a bit, and then allows discarding for the data device even when the RT devices sits on a zones where discard doesn't make much sense.
Note: this sits on top of the "improve a few messages in mkfs and xfs_copy" series sent a while ago.
PATCH 1/4 mkfs: move clearing LIBXFS_DIRECT into check_device_type
Keep it close to the block device vs regular file logic and remove the checks for each device in the caller.
--- mkfs/xfs_mkfs.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
mkfs/xfs_mkfs.c +14 -13
@@ -1330,6 +1330,7 @@ nr_cpus(void) static void check_device_type( + struct cli_params *cli, struct libxfs_dev *dev, bool no_size, bool dry_run,
@@ -1375,6 +1376,13 @@ check_device_type( dev->isfile =1 ; else if (!dry_run) dev->create = 1; + + /* + * 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. + */ + cli->xi->flags &= ~LIBXFS_DIRECT; return; }
@@ -2378,21 +2386,14 @@ 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->data, !cli->dsize, dry_run,"data" ,"d" ); +check_device_type (cli, &cli->xi->data, !cli->dsize, dry_run, +"data" ,"d" );if (!cli->loginternal) -check_device_type (&cli->xi->log, !cli->logsize, dry_run,"log" , -"l" ); +check_device_type (cli, &cli->xi->log, !cli->logsize, dry_run, +"log" ,"l" );if (cli->xi->rt.name) -check_device_type (&cli->xi->rt, !cli->rtsize, dry_run,"RT" , -"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->data.isfile || cli->xi->log.isfile || cli->xi->rt.isfile) - cli->xi->flags &= ~LIBXFS_DIRECT ; +check_device_type (cli, &cli->xi->rt, !cli->rtsize, dry_run, +"RT" ,"r" );memset (ft,0 ,sizeof (*ft));get_topology (cli->xi, ft, force_overwrite);
Signature · 1 line
2.47.3
Re: [PATCH 1/4] mkfs: move clearing LIBXFS_DIRECT into check_device_type
Quoted 4 lines · Christoph Hellwig
Keep it close to the block device vs regular file logic and remove the checks for each device in the caller.
Signed-off-by Christoph Hellwig <[email protected]>
I guess it makes sense to move the clearing of LIBXFS_DIRECT to where we determine that one of the device paths pointed to a regular file...
--D
Quoted 62 lines
--- mkfs/xfs_mkfs.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)mkfs/xfs_mkfs.c +14
-13@@ -1330,6 +1330,7 @@ nr_cpus(void) static void check_device_type( + struct cli_params *cli, struct libxfs_dev *dev, bool no_size, bool dry_run,@@ -1375,6 +1376,13 @@ check_device_type( dev->isfile =1 ; else if (!dry_run) dev->create = 1; + + /* + * 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. + */ + cli->xi->flags &= ~LIBXFS_DIRECT; return; }@@ -2378,21 +2386,14 @@ 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->data, !cli->dsize, dry_run,"data" ,"d" ); +check_device_type (cli, &cli->xi->data, !cli->dsize, dry_run, +"data" ,"d" );if (!cli->loginternal) -check_device_type (&cli->xi->log, !cli->logsize, dry_run,"log" , -"l" ); +check_device_type (cli, &cli->xi->log, !cli->logsize, dry_run, +"log" ,"l" );if (cli->xi->rt.name) -check_device_type (&cli->xi->rt, !cli->rtsize, dry_run,"RT" , -"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->data.isfile || cli->xi->log.isfile || cli->xi->rt.isfile) - cli->xi->flags &= ~LIBXFS_DIRECT ; +check_device_type (cli, &cli->xi->rt, !cli->rtsize, dry_run, +"RT" ,"r" );memset (ft,0 ,sizeof (*ft));get_topology (cli->xi, ft, force_overwrite);Signature · 1 line
2.47.3
PATCH 2/4 libxfs: cleanup get_topology
In reply to Christoph HellwigAdd a libxfs_ prefix to the name, clear the structure in the helper instead of in the callers, and use a bool to pass a boolean argument.
--- libxfs/topology.c | 9 +++++---- libxfs/topology.h | 7 ++----- mkfs/xfs_mkfs.c | 3 +-- repair/sb.c | 3 +-- 4 files changed, 9 insertions(+), 13 deletions(-)
libxfs/topology.c +5 -4
@@ -224,7 +224,7 @@ static voidblkid_get_topology ( const char *device, struct device_topology *dt, - int force_overwrite) + bool force_overwrite) { blkid_topology tp;blkid_probe pr;
@@ -317,7 +317,7 @@ static voidget_device_topology ( struct libxfs_dev *dev, struct device_topology *dt, - int force_overwrite) + bool force_overwrite) { struct stat st;
@@ -364,11 +364,12 @@ get_device_topology( }void -get_topology ( +libxfs_get_topology (struct libxfs_init *xi,struct fs_topology *ft, -int force_overwrite) +bool force_overwrite) { +memset (ft,0 ,sizeof (*ft));get_device_topology (&xi->data, &ft->data, force_overwrite);get_device_topology (&xi->rt, &ft->rt, force_overwrite);get_device_topology (&xi->log, &ft->log, force_overwrite);
libxfs/topology.h +2 -5
@@ -25,11 +25,8 @@ struct fs_topology {struct device_topology log; }; -void -get_topology ( -struct libxfs_init *xi, -struct fs_topology *ft, -int force_overwrite); +void libxfs_get_topology (struct libxfs_init *xi,struct fs_topology *ft, +bool force_overwrite);extern void calc_default_ag_geometry(
mkfs/xfs_mkfs.c +1 -2
@@ -2395,8 +2395,7 @@ validate_sectorsize(check_device_type (cli, &cli->xi->rt, !cli->rtsize, dry_run,"RT" ,"r" ); -memset (ft,0 ,sizeof (*ft)); -get_topology (cli->xi, ft, force_overwrite); +libxfs_get_topology (cli->xi, ft, force_overwrite);/* set configured sector sizes in preparation for checks */ if (!cli->sectorsize) {
repair/sb.c +1 -2
@@ -184,8 +184,7 @@ guess_default_geometry(uint64_t dblocks;int multidisk; -memset (&ft,0 ,sizeof (ft)); -get_topology (x, &ft,1 ); +libxfs_get_topology (x, &ft, true);/* * get geometry from get_topology result.
Signature · 1 line
2.47.3
Re: [PATCH 2/4] libxfs: cleanup get_topology
Quoted 4 lines · Christoph Hellwig
Add a
libxfs_prefix to the name, clear the structure in the helper instead of in the callers, and use a bool to pass a boolean argument.Signed-off-by Christoph Hellwig <[email protected]>
Looks good,
--D
Quoted 94 lines
--- libxfs/topology.c | 9 +++++---- libxfs/topology.h | 7 ++----- mkfs/xfs_mkfs.c | 3 +-- repair/sb.c | 3 +-- 4 files changed, 9 insertions(+), 13 deletions(-)libxfs/topology.c +5
-4@@ -224,7 +224,7 @@ static voidblkid_get_topology ( const char *device, struct device_topology *dt, - int force_overwrite) + bool force_overwrite) { blkid_topology tp;blkid_probe pr;@@ -317,7 +317,7 @@ static voidget_device_topology ( struct libxfs_dev *dev, struct device_topology *dt, - int force_overwrite) + bool force_overwrite) { struct stat st;@@ -364,11 +364,12 @@ get_device_topology( }void -get_topology ( +libxfs_get_topology (struct libxfs_init *xi,struct fs_topology *ft, -int force_overwrite) +bool force_overwrite) { +memset (ft,0 ,sizeof (*ft));get_device_topology (&xi->data, &ft->data, force_overwrite);get_device_topology (&xi->rt, &ft->rt, force_overwrite);get_device_topology (&xi->log, &ft->log, force_overwrite);libxfs/topology.h +2
-5@@ -25,11 +25,8 @@ struct fs_topology {struct device_topology log; }; -void -get_topology ( -struct libxfs_init *xi, -struct fs_topology *ft, -int force_overwrite); +void libxfs_get_topology (struct libxfs_init *xi,struct fs_topology *ft, +bool force_overwrite);extern void calc_default_ag_geometry(mkfs/xfs_mkfs.c +1
-2@@ -2395,8 +2395,7 @@ validate_sectorsize(check_device_type (cli, &cli->xi->rt, !cli->rtsize, dry_run,"RT" ,"r" ); -memset (ft,0 ,sizeof (*ft)); -get_topology (cli->xi, ft, force_overwrite); +libxfs_get_topology (cli->xi, ft, force_overwrite);/* set configured sector sizes in preparation for checks */ if (!cli->sectorsize) {repair/sb.c +1
-2@@ -184,8 +184,7 @@ guess_default_geometry(uint64_t dblocks;int multidisk; -memset (&ft,0 ,sizeof (ft)); -get_topology (x, &ft,1 ); +libxfs_get_topology (x, &ft, true);/* * get geometry from get_topology result. Signature · 1 line
2.47.3
PATCH 3/4 mkfs: remove duplicate struct libxfs_init arguments
In reply to Christoph HellwigThe libxfs_init structure instance is pointed to by cli_params, so use that were it already exists instead of passing an additional argument.
--- mkfs/xfs_mkfs.c | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-)
mkfs/xfs_mkfs.c +22 -27
@@ -4005,8 +4005,7 @@ ddev_is_solidstate(static void calc_concurrency_ag_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {uint64_t try_agsize;uint64_t def_agsize;
@@ -4074,11 +4073,10 @@ out:static void calculate_initial_ag_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {if (cli->data_concurrency >0 ) { -calc_concurrency_ag_geometry (cfg, cli, xi); +calc_concurrency_ag_geometry (cfg, cli); }else if (cli->agsize) {/* User-specified AG size */ cfg->agsize =getnum (cli->agsize, &dopts,D_AGSIZE );
@@ -4099,8 +4097,9 @@ _("agsize (%s) not a multiple of fs blk size (%d)\n"), cfg->agcount = cli->agcount; cfg->agsize = cfg->dblocks / cfg->agcount + (cfg->dblocks % cfg->agcount !=0 ); - }else if (cli->data_concurrency ==-1 &&ddev_is_solidstate (xi)) { -calc_concurrency_ag_geometry (cfg, cli, xi); + }else if (cli->data_concurrency ==-1 && +ddev_is_solidstate (cli->xi)) { +calc_concurrency_ag_geometry (cfg, cli); }else { calc_default_ag_geometry(cfg->blocklog, cfg->dblocks, cfg->dsunit, &cfg->agsize,
@@ -4360,8 +4359,7 @@ rtdev_is_solidstate(static void calc_concurrency_rtgroup_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {uint64_t try_rgsize;uint64_t def_rgsize;
@@ -4468,8 +4466,7 @@ _("realtime group count (%llu) must be less than the maximum (%u)\n"),static void calculate_rtgroup_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {if (!cli->sb_feat.metadir) { cfg->rgcount =0 ;
@@ -4510,8 +4507,9 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"), cfg->rgsize = cfg->rtblocks; cfg->rgcount =0 ; }else if (cli->rtvol_concurrency >0 || - (cli->rtvol_concurrency ==-1 &&rtdev_is_solidstate (xi))) { -calc_concurrency_rtgroup_geometry (cfg, cli, xi); + (cli->rtvol_concurrency ==-1 && +rtdev_is_solidstate (cli->xi))) { +calc_concurrency_rtgroup_geometry (cfg, cli); }else if (is_power_of_2 (cfg->rtextblocks)) { cfg->rgsize =calc_rgsize_extsize_power (cfg); cfg->rgcount = cfg->rtblocks / cfg->rgsize +
@@ -4538,7 +4536,6 @@ static voidadjust_nr_zones ( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, struct zone_topology *zt) { uint64_t new_rtblocks, slack;
@@ -4547,7 +4544,8 @@ adjust_nr_zones(if (zt->rt.nr_zones) max_zones = zt->rt.nr_zones;else - max_zones =DTOBT (xi->rt.size, cfg->blocklog) / cfg->rgsize; + max_zones =DTOBT (cli->xi->rt.size, cfg->blocklog) / + cfg->rgsize;if (!cli->rgcount) cfg->rgcount +=XFS_RESERVED_ZONES ;
@@ -4576,7 +4574,6 @@ static void calculate_zone_geometry( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, struct zone_topology *zt) { if (cfg->rtblocks == 0) {
@@ -4645,7 +4642,7 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"), }if (cli->rtsize || cli->rgcount) -adjust_nr_zones (cfg, cli, xi, zt); +adjust_nr_zones (cfg, cli, zt);if (cfg->rgcount <XFS_MIN_ZONES ) { fprintf(stderr,
@@ -4984,7 +4981,6 @@ static uint64_tcalc_concurrency_logblocks ( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, unsigned int max_tx_bytes) { uint64_t log_bytes;
@@ -4992,7 +4988,7 @@ calc_concurrency_logblocks(unsigned int new_logblocks;if (cli->log_concurrency <0 ) { -if (!ddev_is_solidstate (xi)) +if (!ddev_is_solidstate (cli->xi)) goto out; cli->log_concurrency =nr_cpus ();
@@ -5160,7 +5156,6 @@ static voidcalculate_log_size ( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, struct xfs_mount *mp) { struct xfs_sb *sbp = &mp->m_sb;
@@ -5225,8 +5220,8 @@ _("external log device size %lld blocks too small, must be at least %lld blocks\if (cfg->lsunit) {uint64_t max_logblocks; - max_logblocks =min (DTOBT (xi->log.size, cfg->blocklog), -XFS_MAX_LOG_BLOCKS ); + max_logblocks =min (XFS_MAX_LOG_BLOCKS , +DTOBT (cli->xi->log.size, cfg->blocklog));align_log_size (cfg, cfg->lsunit, max_logblocks); }
@@ -5261,7 +5256,7 @@ _("max log size %d smaller than min log size %d, filesystem is too small\n"),if (cli->log_concurrency !=0 ) cfg->logblocks =calc_concurrency_logblocks (cfg, cli, - xi, max_tx_bytes); + max_tx_bytes);/* But don't go below a reasonable size */ cfg->logblocks = max(cfg->logblocks,
@@ -6135,12 +6130,12 @@ main(* dependent on device sizes. Once calculated, make sure everything * aligns to device geometry correctly. */ -calculate_initial_ag_geometry (&cfg, &cli, &xi); +calculate_initial_ag_geometry (&cfg, &cli);align_ag_geometry (&cfg, &ft);if (cfg.sb_feat.zoned) -calculate_zone_geometry (&cfg, &cli, &xi, &zt); +calculate_zone_geometry (&cfg, &cli, &zt);else -calculate_rtgroup_geometry (&cfg, &cli, &xi); +calculate_rtgroup_geometry (&cfg, &cli);calculate_imaxpct (&cfg, &cli);
@@ -6164,7 +6159,7 @@ main(* With the mount set up, we can finally calculate the log size * constraints and do default size calculations and final validation */ -calculate_log_size (&cfg, &cli, &xi, mp); +calculate_log_size (&cfg, &cli, mp);finish_superblock_setup (&cfg, mp, sbp);
Signature · 1 line
2.47.3
Re: [PATCH 3/4] mkfs: remove duplicate struct libxfs_init arguments
Quoted 4 lines · Christoph Hellwig
The
libxfs_initstructure instance is pointed to bycli_params, so use that were it already exists instead of passing an additional argument.Signed-off-by Christoph Hellwig <[email protected]>
Yay fewer args,
--D
Quoted 185 lines
--- mkfs/xfs_mkfs.c | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-)mkfs/xfs_mkfs.c +22
-27@@ -4005,8 +4005,7 @@ ddev_is_solidstate(static void calc_concurrency_ag_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {uint64_t try_agsize;uint64_t def_agsize;@@ -4074,11 +4073,10 @@ out:static void calculate_initial_ag_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {if (cli->data_concurrency >0 ) { -calc_concurrency_ag_geometry (cfg, cli, xi); +calc_concurrency_ag_geometry (cfg, cli); }else if (cli->agsize) {/* User-specified AG size */ cfg->agsize =getnum (cli->agsize, &dopts,D_AGSIZE );@@ -4099,8 +4097,9 @@ _("agsize (%s) not a multiple of fs blk size (%d)\n"), cfg->agcount = cli->agcount; cfg->agsize = cfg->dblocks / cfg->agcount + (cfg->dblocks % cfg->agcount !=0 ); - }else if (cli->data_concurrency ==-1 &&ddev_is_solidstate (xi)) { -calc_concurrency_ag_geometry (cfg, cli, xi); + }else if (cli->data_concurrency ==-1 && +ddev_is_solidstate (cli->xi)) { +calc_concurrency_ag_geometry (cfg, cli); }else { calc_default_ag_geometry(cfg->blocklog, cfg->dblocks, cfg->dsunit, &cfg->agsize,@@ -4360,8 +4359,7 @@ rtdev_is_solidstate(static void calc_concurrency_rtgroup_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {uint64_t try_rgsize;uint64_t def_rgsize;@@ -4468,8 +4466,7 @@ _("realtime group count (%llu) must be less than the maximum (%u)\n"),static void calculate_rtgroup_geometry (struct mkfs_params *cfg, -struct cli_params *cli, -struct libxfs_init *xi) +struct cli_params *cli) {if (!cli->sb_feat.metadir) { cfg->rgcount =0 ;@@ -4510,8 +4507,9 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"), cfg->rgsize = cfg->rtblocks; cfg->rgcount =0 ; }else if (cli->rtvol_concurrency >0 || - (cli->rtvol_concurrency ==-1 &&rtdev_is_solidstate (xi))) { -calc_concurrency_rtgroup_geometry (cfg, cli, xi); + (cli->rtvol_concurrency ==-1 && +rtdev_is_solidstate (cli->xi))) { +calc_concurrency_rtgroup_geometry (cfg, cli); }else if (is_power_of_2 (cfg->rtextblocks)) { cfg->rgsize =calc_rgsize_extsize_power (cfg); cfg->rgcount = cfg->rtblocks / cfg->rgsize +@@ -4538,7 +4536,6 @@ static voidadjust_nr_zones ( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, struct zone_topology *zt) { uint64_t new_rtblocks, slack;@@ -4547,7 +4544,8 @@ adjust_nr_zones(if (zt->rt.nr_zones) max_zones = zt->rt.nr_zones;else - max_zones =DTOBT (xi->rt.size, cfg->blocklog) / cfg->rgsize; + max_zones =DTOBT (cli->xi->rt.size, cfg->blocklog) / + cfg->rgsize;if (!cli->rgcount) cfg->rgcount +=XFS_RESERVED_ZONES ;@@ -4576,7 +4574,6 @@ static void calculate_zone_geometry( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, struct zone_topology *zt) { if (cfg->rtblocks == 0) {@@ -4645,7 +4642,7 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"), }if (cli->rtsize || cli->rgcount) -adjust_nr_zones (cfg, cli, xi, zt); +adjust_nr_zones (cfg, cli, zt);if (cfg->rgcount <XFS_MIN_ZONES ) { fprintf(stderr,@@ -4984,7 +4981,6 @@ static uint64_tcalc_concurrency_logblocks ( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, unsigned int max_tx_bytes) { uint64_t log_bytes;@@ -4992,7 +4988,7 @@ calc_concurrency_logblocks(unsigned int new_logblocks;if (cli->log_concurrency <0 ) { -if (!ddev_is_solidstate (xi)) +if (!ddev_is_solidstate (cli->xi)) goto out; cli->log_concurrency =nr_cpus ();@@ -5160,7 +5156,6 @@ static voidcalculate_log_size ( struct mkfs_params *cfg, struct cli_params *cli, - struct libxfs_init *xi, struct xfs_mount *mp) { struct xfs_sb *sbp = &mp->m_sb;@@ -5225,8 +5220,8 @@ _("external log device size %lld blocks too small, must be at least %lld blocks\if (cfg->lsunit) {uint64_t max_logblocks; - max_logblocks =min (DTOBT (xi->log.size, cfg->blocklog), -XFS_MAX_LOG_BLOCKS ); + max_logblocks =min (XFS_MAX_LOG_BLOCKS , +DTOBT (cli->xi->log.size, cfg->blocklog));align_log_size (cfg, cfg->lsunit, max_logblocks); }@@ -5261,7 +5256,7 @@ _("max log size %d smaller than min log size %d, filesystem is too small\n"),if (cli->log_concurrency !=0 ) cfg->logblocks =calc_concurrency_logblocks (cfg, cli, - xi, max_tx_bytes); + max_tx_bytes);/* But don't go below a reasonable size */ cfg->logblocks = max(cfg->logblocks,@@ -6135,12 +6130,12 @@ main(* dependent on device sizes. Once calculated, make sure everything * aligns to device geometry correctly. */ -calculate_initial_ag_geometry (&cfg, &cli, &xi); +calculate_initial_ag_geometry (&cfg, &cli);align_ag_geometry (&cfg, &ft);if (cfg.sb_feat.zoned) -calculate_zone_geometry (&cfg, &cli, &xi, &zt); +calculate_zone_geometry (&cfg, &cli, &zt);else -calculate_rtgroup_geometry (&cfg, &cli, &xi); +calculate_rtgroup_geometry (&cfg, &cli);calculate_imaxpct (&cfg, &cli);@@ -6164,7 +6159,7 @@ main(* With the mount set up, we can finally calculate the log size * constraints and do default size calculations and final validation */ -calculate_log_size (&cfg, &cli, &xi, mp); +calculate_log_size (&cfg, &cli, mp);finish_superblock_setup (&cfg, mp, sbp);Signature · 1 line
2.47.3
PATCH 4/4 mkfs: split zone reset from discard
In reply to Christoph HellwigZone reset is a mandatory part of creating a file system on a zoned device, unlike discard, which can be skipped. It also is implemented a bit different, so just split the handling. This also means that we can now support the -K option to skip discard on the data section for zoned file systems.
--- mkfs/xfs_mkfs.c | 112 +++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 59 deletions(-)
mkfs/xfs_mkfs.c +53 -59
@@ -1607,34 +1607,6 @@ discard_blocks(int fd, uint64_t nsectors, int quiet)printf ("Done.\n" ); } -static void -reset_zones ( -struct mkfs_params *cfg, -int fd, -uint64_t start_sector, -uint64_t nsectors, -int quiet) -{ -struct blk_zone_range range = { - .sector = start_sector, - .nr_sectors = nsectors, - }; - -if (!quiet) { -printf ("Resetting zones..." ); -fflush (stdout); - } - -if (ioctl (fd,BLKRESETZONE , &range) <0 ) { -if (!quiet) -printf (" FAILED (%d)\n" , -errno); -exit (1 ); - } - -if (!quiet) -printf ("Done.\n" ); -} - static __attribute__((noreturn)) void illegal_option( const char *value,
@@ -3780,41 +3752,66 @@ discard_devices( struct zone_topology *zt, int quiet) { -/* -* This function has to be called after libxfs has been initialized. -*/ -if (!xi->data.isfile) {uint64_t nsectors = xi->data.size; -if (cfg->rtstart && zt->data.nr_zones) { -/* -* Note that the zone reset here includes the LBA range -* for the data device. -* -* This is because doing a single zone reset all on the -* entire device (which the kernel automatically does -* for us for a full device range) is a lot faster than -* resetting each zone individually and resetting -* the conventional zones used for the data device is a -* no-op. -*/ -reset_zones (cfg, xi->data.fd,0 , - cfg->rtstart + xi->rt.size, quiet); +if (cfg->rtstart && zt->data.nr_zones) nsectors -= cfg->rtstart; - }discard_blocks (xi->data.fd, nsectors, quiet); } -if (xi->rt.dev && !xi->rt.isfile) { -if (zt->rt.nr_zones) -reset_zones (cfg, xi->rt.fd,0 , xi->rt.size, quiet); -else -discard_blocks (xi->rt.fd, xi->rt.size, quiet); - } +if (xi->rt.dev && !xi->rt.isfile && !zt->rt.nr_zones) +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 +reset_zones ( +struct mkfs_params *cfg, +struct libxfs_dev *dev, +uint64_t size, +bool quiet) +{ +struct blk_zone_range range = { + .nr_sectors = size, + }; + +if (!quiet) { +printf ("Resetting zones..." ); +fflush (stdout); + } +if (ioctl (dev->fd,BLKRESETZONE , &range) <0 ) { +if (!quiet) +printf (" FAILED (%d)\n" , -errno); +exit (1 ); + } +if (!quiet) +printf ("Done.\n" ); +} + +static void +reset_devices ( +struct mkfs_params *cfg, +struct libxfs_init *xi, +struct zone_topology *zt, +int quiet) +{ +/* +* Note that the zone reset here includes the conventional zones used +* for the data device. +* +* It is done that way because doing a single zone reset all on the +* entire device (which the kernel automatically does for us for a full +* device range) is a lot faster than resetting each zone individually +* and resetting the conventional zones used for the data device is a +* no-op. +*/ +if (!xi->data.isfile && zt->data.nr_zones && cfg->rtstart) +reset_zones (cfg, &xi->data, cfg->rtstart + xi->rt.size, quiet); +if (xi->rt.dev && !xi->rt.isfile && zt->rt.nr_zones) +reset_zones (cfg, &xi->rt, xi->rt.size, quiet); +} + static void validate_datadev( struct mkfs_params *cfg,
@@ -6196,13 +6193,10 @@ main(/* * All values have been validated, discard the old device layout. */ -if (cli.sb_feat.zoned && !discard) { -fprintf (stderr, -_ ("-K not support for zoned file systems.\n" )); -return 1 ; - }if (discard && !dry_run) -discard_devices (&cfg, &xi, &zt, quiet); +discard_devices (&cfg, cli.xi, &zt, quiet); +if (cli.sb_feat.zoned && !dry_run) +reset_devices (&cfg, cli.xi, &zt, quiet);/* * we need the libxfs buffer cache from here on in.
Signature · 1 line
2.47.3
Re: [PATCH 4/4] mkfs: split zone reset from discard
Quoted 7 lines · Christoph Hellwig
Zone reset is a mandatory part of creating a file system on a zoned device, unlike discard, which can be skipped. It also is implemented a bit different, so just split the handling. This also means that we can now support the -K option to skip discard on the data section for zoned file systems.
Signed-off-by Christoph Hellwig <[email protected]>
Nice feature improvement! ;)
--D
Quoted 156 lines
--- mkfs/xfs_mkfs.c | 112 +++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 59 deletions(-)mkfs/xfs_mkfs.c +53
-59@@ -1607,34 +1607,6 @@ discard_blocks(int fd, uint64_t nsectors, int quiet)printf ("Done.\n" ); } -static void -reset_zones ( -struct mkfs_params *cfg, -int fd, -uint64_t start_sector, -uint64_t nsectors, -int quiet) -{ -struct blk_zone_range range = { - .sector = start_sector, - .nr_sectors = nsectors, - }; - -if (!quiet) { -printf ("Resetting zones..." ); -fflush (stdout); - } - -if (ioctl (fd,BLKRESETZONE , &range) <0 ) { -if (!quiet) -printf (" FAILED (%d)\n" , -errno); -exit (1 ); - } - -if (!quiet) -printf ("Done.\n" ); -} - static __attribute__((noreturn)) void illegal_option( const char *value,@@ -3780,41 +3752,66 @@ discard_devices( struct zone_topology *zt, int quiet) { -/* -* This function has to be called after libxfs has been initialized. -*/ -if (!xi->data.isfile) {uint64_t nsectors = xi->data.size; -if (cfg->rtstart && zt->data.nr_zones) { -/* -* Note that the zone reset here includes the LBA range -* for the data device. -* -* This is because doing a single zone reset all on the -* entire device (which the kernel automatically does -* for us for a full device range) is a lot faster than -* resetting each zone individually and resetting -* the conventional zones used for the data device is a -* no-op. -*/ -reset_zones (cfg, xi->data.fd,0 , - cfg->rtstart + xi->rt.size, quiet); +if (cfg->rtstart && zt->data.nr_zones) nsectors -= cfg->rtstart; - }discard_blocks (xi->data.fd, nsectors, quiet); } -if (xi->rt.dev && !xi->rt.isfile) { -if (zt->rt.nr_zones) -reset_zones (cfg, xi->rt.fd,0 , xi->rt.size, quiet); -else -discard_blocks (xi->rt.fd, xi->rt.size, quiet); - } +if (xi->rt.dev && !xi->rt.isfile && !zt->rt.nr_zones) +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 +reset_zones ( +struct mkfs_params *cfg, +struct libxfs_dev *dev, +uint64_t size, +bool quiet) +{ +struct blk_zone_range range = { + .nr_sectors = size, + }; + +if (!quiet) { +printf ("Resetting zones..." ); +fflush (stdout); + } +if (ioctl (dev->fd,BLKRESETZONE , &range) <0 ) { +if (!quiet) +printf (" FAILED (%d)\n" , -errno); +exit (1 ); + } +if (!quiet) +printf ("Done.\n" ); +} + +static void +reset_devices ( +struct mkfs_params *cfg, +struct libxfs_init *xi, +struct zone_topology *zt, +int quiet) +{ +/* +* Note that the zone reset here includes the conventional zones used +* for the data device. +* +* It is done that way because doing a single zone reset all on the +* entire device (which the kernel automatically does for us for a full +* device range) is a lot faster than resetting each zone individually +* and resetting the conventional zones used for the data device is a +* no-op. +*/ +if (!xi->data.isfile && zt->data.nr_zones && cfg->rtstart) +reset_zones (cfg, &xi->data, cfg->rtstart + xi->rt.size, quiet); +if (xi->rt.dev && !xi->rt.isfile && zt->rt.nr_zones) +reset_zones (cfg, &xi->rt, xi->rt.size, quiet); +} + static void validate_datadev( struct mkfs_params *cfg,@@ -6196,13 +6193,10 @@ main(/* * All values have been validated, discard the old device layout. */ -if (cli.sb_feat.zoned && !discard) { -fprintf (stderr, -_ ("-K not support for zoned file systems.\n" )); -return 1 ; - }if (discard && !dry_run) -discard_devices (&cfg, &xi, &zt, quiet); +discard_devices (&cfg, cli.xi, &zt, quiet); +if (cli.sb_feat.zoned && !dry_run) +reset_devices (&cfg, cli.xi, &zt, quiet);/* * we need the libxfs buffer cache from here on in. Signature · 1 line
2.47.3