fix log sector size detection v3
Hi all,
this series cleans up the libxfs toplogy code and then fixes detection of the log sector size in mkfs.xfs, so that it doesn't create smaller than possible log sectors by default on > 512 byte sector size devices.
Note that this doesn't cleanup the types of the topology members, as that creeps all the way into platform_findsize. Which has a lot more cruft that should be dealth with and is worth it's own series.
Changes since v2:
- rebased to the lastest for-next branch
Changes since v1:
- fix a spelling mistake
- add a few more cleanups
PATCH 1/5 libxfs: remove the unused fs_topology_t typedef
--- libxfs/topology.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libxfs/topology.h +2 -2
@@ -10,13 +10,13 @@/* * Device topology information. */ -typedef struct fs_topology { +struct fs_topology {int dsunit;/* stripe unit - data subvolume */ int dswidth;/* stripe width - data subvolume */ int rtswidth;/* stripe width - rt subvolume */ int lsectorsize;/* logical sector size &*/ int psectorsize;/* physical sector size */ -}fs_topology_t ; +};void get_topology(
Signature · 1 line
2.39.2
PATCH 2/5 libxfs: refactor the fs_topology structure
In reply to Christoph Hellwigfs_topology is a mess that mixes up data and RT device reporting, and to make things worse reuses lsectorsize for the logical sector size while other parts of xfsprogs use it for the log sector size.
Split out a device_topology structure that reports the topology for one device and embedded two of them into the fs_topology struture, and pass them directly to blkid_get_topology.
Rename the sector size members to be more explicit, and move some of the sanity checking from mkfs into the topology helpers.
--- libxfs/topology.c | 99 +++++++++++++++++++++++++---------------------- libxfs/topology.h | 14 ++++--- mkfs/xfs_mkfs.c | 64 ++++++++++++++---------------- repair/sb.c | 2 +- 4 files changed, 92 insertions(+), 87 deletions(-)
libxfs/topology.c +53 -46
@@ -170,18 +170,14 @@ out:return ret; } -static void blkid_get_topology ( -const char *device, -int *sunit, -int *swidth, -int *lsectorsize, -int *psectorsize, -int force_overwrite) +static void +blkid_get_topology ( +const char *device, +struct device_topology *dt, +int force_overwrite) { -blkid_topology tp;blkid_probe pr; -unsigned long val;struct stat statbuf;/* can't get topology info from a file */
@@ -200,31 +196,28 @@ static void blkid_get_topology(if (!tp) goto out_free_probe; - val =blkid_topology_get_logical_sector_size (tp); - *lsectorsize = val; - val =blkid_topology_get_physical_sector_size (tp); - *psectorsize = val; - val =blkid_topology_get_minimum_io_size (tp); - *sunit = val; - val =blkid_topology_get_optimal_io_size (tp); - *swidth = val; + dt->logical_sector_size =blkid_topology_get_logical_sector_size (tp); + dt->physical_sector_size =blkid_topology_get_physical_sector_size (tp); + dt->sunit =blkid_topology_get_minimum_io_size (tp); + dt->swidth =blkid_topology_get_optimal_io_size (tp);/* * If the reported values are the same as the physical sector size * do not bother to report anything. It will only cause warnings * if people specify larger stripe units or widths manually. */ -if (*sunit == *psectorsize || *swidth == *psectorsize) { - *sunit =0 ; - *swidth =0 ; +if (dt->sunit == dt->physical_sector_size || + dt->swidth == dt->physical_sector_size) { + dt->sunit =0 ; + dt->swidth =0 ; }/* * Blkid reports the information in terms of bytes, but we want it in * terms of 512 bytes blocks (only to convert it to bytes later..) */ - *sunit = *sunit >>9 ; - *swidth = *swidth >>9 ; + dt->sunit >>=9 ; + dt->swidth >>=9 ;if (blkid_topology_get_alignment_offset (tp) !=0 ) { fprintf(stderr,
@@ -238,7 +231,7 @@ static void blkid_get_topology(exit (EXIT_FAILURE ); }/* Do not use physical sector size if the device is misaligned */ - *psectorsize = *lsectorsize; + dt->physical_sector_size = dt->logical_sector_size; }blkid_free_probe (pr);
@@ -251,47 +244,61 @@ out_free_probe: device); } -void -get_topology ( -struct libxfs_init *xi, -struct fs_topology *ft, +static void +get_device_topology ( +struct libxfs_dev *dev, +struct device_topology *dt,int force_overwrite) { -struct stat statbuf; +struct stat st; + +/* +* Nothing to do if this particular subvolume doesn't exist. +*/ +if (!dev->name) +return ;/* * If our target is a regular file, use platform_findsizes * to try to obtain the underlying filesystem's requirements * for direct IO; we'll set our sector size to that if possible. */ -if (xi->data.isfile || - (!stat (xi->data.name, &statbuf) &&S_ISREG (statbuf.st_mode))) { -int fd; +if (dev->isfile || (!stat (dev->name, &st) &&S_ISREG (st.st_mode))) {int flags =O_RDONLY ;long long dummy; +int fd;/* with xi->disfile we may not have the file yet! */ -if (xi->data.isfile) +if (dev->isfile) flags |=O_CREAT ; - fd =open (xi->data.name, flags,0666 ); + fd =open (dev->name, flags,0666 );if (fd >=0 ) { -platform_findsizes (xi->data.name, fd, &dummy, - &ft->lsectorsize); +platform_findsizes (dev->name, fd, &dummy, + &dt->logical_sector_size);close (fd); - ft->psectorsize = ft->lsectorsize; - }else - ft->psectorsize = ft->lsectorsize =BBSIZE ; + }else { + dt->logical_sector_size =BBSIZE ; + } }else { -blkid_get_topology (xi->data.name, &ft->dsunit, &ft->dswidth, - &ft->lsectorsize, &ft->psectorsize, - force_overwrite); +blkid_get_topology (dev->name, dt, force_overwrite); } -if (xi->rt.name && !xi->rt.isfile) { -int sunit, lsectorsize, psectorsize; +ASSERT (dt->logical_sector_size); -blkid_get_topology (xi->rt.name, &sunit, &ft->rtswidth, - &lsectorsize, &psectorsize, force_overwrite); - } +/* +* Older kernels may not have physical/logical distinction. +*/ +if (!dt->physical_sector_size) + dt->physical_sector_size = dt->logical_sector_size; +} + +void +get_topology ( +struct libxfs_init *xi, +struct fs_topology *ft, +int force_overwrite) +{ +get_device_topology (&xi->data, &ft->data, force_overwrite); +get_device_topology (&xi->rt, &ft->rt, force_overwrite); }
libxfs/topology.h +9 -5
@@ -10,12 +10,16 @@/* * Device topology information. */ +struct device_topology { +int logical_sector_size;/* logical sector size */ +int physical_sector_size;/* physical sector size */ +int sunit;/* stripe unit */ +int swidth;/* stripe width */ +}; +struct fs_topology { -int dsunit;/* stripe unit - data subvolume */ -int dswidth;/* stripe width - data subvolume */ -int rtswidth;/* stripe width - rt subvolume */ -int lsectorsize;/* logical sector size &*/ -int psectorsize;/* physical sector size */ +struct device_topology data; +struct device_topology rt; };void
mkfs/xfs_mkfs.c +29 -35
118 lines not on this page · raw message
repair/sb.c +1 -1
@@ -189,7 +189,7 @@ guess_default_geometry(* Use default block size (2^12) */ blocklog =12 ; - multidisk = ft.dswidth | ft.dsunit; + multidisk = ft.data.swidth | ft.data.sunit; dblocks = x->data.size >> (blocklog -BBSHIFT );calc_default_ag_geometry (blocklog, dblocks, multidisk, agsize, agcount);
Signature · 1 line
2.39.2
PATCH 3/5 libxfs: remove the S_ISREG check from blkid_get_topology
In reply to Christoph HellwigThe only caller already performs the exact same check.
--- libxfs/topology.c | 9 --------- 1 file changed, 9 deletions(-)
libxfs/topology.c +0 -9
@@ -178,15 +178,6 @@ blkid_get_topology( {blkid_topology tp;blkid_probe pr; -struct stat statbuf; - -/* can't get topology info from a file */ -if (!stat (device, &statbuf) &&S_ISREG (statbuf.st_mode)) { -fprintf (stderr, -_ ("%s: Warning: trying to probe topology of a file %s!\n" ), - progname, device); -return ; - } pr =blkid_new_probe_from_filename (device);if (!pr)
Signature · 1 line
2.39.2
PATCH 4/5 libxfs: also query log device topology in get_topology
In reply to Christoph HellwigAlso query the log device topology in get_topology, which we'll need in mkfs in a bit.
--- libxfs/topology.c | 1 + libxfs/topology.h | 1 + 2 files changed, 2 insertions(+)
libxfs/topology.c +1 -0
@@ -292,4 +292,5 @@ get_topology( {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 +1 -0
@@ -20,6 +20,7 @@ struct device_topology {struct fs_topology {struct device_topology data;struct device_topology rt; +struct device_topology log; };void
Signature · 1 line
2.39.2
PATCH 5/5 mkfs: use a sensible log sector size default
In reply to Christoph HellwigCurrently the XFS log sector size defaults to the 512 bytes unless explicitly overriden. Default to the device logical block size queried by get_topology instead. If that is also 512 nothing changes, and if the device logical block size is larger this prevents a mkfs failure because the libxfs buffer cache blows up and as we obviously can't use a smaller than hardware supported sector size. This fixes xfs/157 with a 4k block size device.
--- mkfs/xfs_mkfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
mkfs/xfs_mkfs.c +4 -3
@@ -2075,7 +2075,8 @@ static void validate_log_sectorsize( struct mkfs_params *cfg, struct cli_params *cli, - struct mkfs_default_params *dft) + struct mkfs_default_params *dft, + struct fs_topology *ft) { if (cli->loginternal && cli->lsectorsize &&
@@ -2090,7 +2091,7 @@ _("Can't change sector size on internal log!\n"));else if (cli->loginternal) cfg->lsectorsize = cfg->sectorsize;else - cfg->lsectorsize = dft->sectorsize; + cfg->lsectorsize = ft->log.logical_sector_size; cfg->lsectorlog =libxfs_highbit32 (cfg->lsectorsize); if (cfg->lsectorsize < XFS_MIN_SECTORSIZE ||
@@ -4196,7 +4197,7 @@ main( blocksize = cfg.blocksize; sectorsize = cfg.sectorsize; -validate_log_sectorsize (&cfg, &cli, &dft); +validate_log_sectorsize (&cfg, &cli, &dft, &ft);validate_sb_features (&cfg, &cli);/*
Signature · 1 line
2.39.2