From: Andrew Price Date: Thu, 26 Jan 2017 16:47:07 +0000 Subject: [Cluster-devel] [PATCH 4/5] mkfs.gfs2: Disregard device topology if zero-sized sectors reported In-Reply-To: <20170126164708.23807-1-anprice@redhat.com> References: <20170126164708.23807-1-anprice@redhat.com> Message-ID: <20170126164708.23807-5-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Guard against physical_sector_size or logical_sector_size being zero. Normally this isn't a problem as the kernel will report these values as the device sector size but the checks are useful for when zero values are passed to mkfs. Signed-off-by: Andrew Price --- gfs2/mkfs/main_mkfs.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c index e2c4a22..0801a4b 100644 --- a/gfs2/mkfs/main_mkfs.c +++ b/gfs2/mkfs/main_mkfs.c @@ -136,6 +136,7 @@ struct mkfs_opts { unsigned got_lockproto:1; unsigned got_locktable:1; unsigned got_device:1; + unsigned got_topol:1; unsigned override:1; unsigned quiet:1; @@ -304,7 +305,8 @@ static void opt_parse_extended(char *str, struct mkfs_opts *opts) } else if (strcmp("test_topology", key) == 0) { if (parse_topology(opts, val) != 0) exit(-1); - opts->dev.got_topol = 1; + opts->got_topol = (opts->dev.logical_sector_size != 0 && + opts->dev.physical_sector_size != 0); } else if (strcmp("help", key) == 0) { print_ext_opts(); exit(0); @@ -487,20 +489,21 @@ static unsigned choose_blocksize(struct mkfs_opts *opts) unsigned int x; unsigned int bsize = opts->bsize; struct mkfs_dev *dev = &opts->dev; + int got_topol = (dev->got_topol || opts->got_topol); - if (dev->got_topol && opts->debug) { + if (got_topol && opts->debug) { printf("alignment_offset: %lu\n", dev->alignment_offset); printf("logical_sector_size: %lu\n", dev->logical_sector_size); printf("minimum_io_size: %lu\n", dev->minimum_io_size); printf("optimal_io_size: %lu\n", dev->optimal_io_size); printf("physical_sector_size: %lu\n", dev->physical_sector_size); } - if (dev->got_topol && dev->alignment_offset != 0) { + if (got_topol && dev->alignment_offset != 0) { fprintf(stderr, _("Warning: device is not properly aligned. This may harm performance.\n")); dev->physical_sector_size = dev->logical_sector_size; } - if (!opts->got_bsize && dev->got_topol) { + if (!opts->got_bsize && got_topol) { if (dev->optimal_io_size <= getpagesize() && dev->optimal_io_size >= dev->minimum_io_size) bsize = dev->optimal_io_size; @@ -887,7 +890,8 @@ static int probe_contents(struct mkfs_dev *dev) dev->minimum_io_size = blkid_topology_get_minimum_io_size(tp); dev->optimal_io_size = blkid_topology_get_optimal_io_size(tp); dev->physical_sector_size = blkid_topology_get_physical_sector_size(tp); - dev->got_topol = 1; + dev->got_topol = (dev->logical_sector_size != 0 && + dev->physical_sector_size != 0); } } @@ -944,7 +948,7 @@ int main(int argc, char *argv[]) opts_get(argc, argv, &opts); opts_check(&opts); - open_dev(&opts.dev, !opts.dev.got_topol); + open_dev(&opts.dev, !opts.got_topol); bsize = choose_blocksize(&opts); if (S_ISREG(opts.dev.stat.st_mode)) { -- 2.9.3