From: Karel Zak Date: Thu, 18 Jun 2015 09:55:29 +0000 (+0200) Subject: libfdisk: ignore misaligned optimal I/O size X-Git-Tag: v2.27-rc1~137 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=acb7651f8897ae73d0f45dd75bc87630001c61b9;p=thirdparty%2Futil-linux.git libfdisk: ignore misaligned optimal I/O size For example: # modprobe scsi_debug dev_size_mb=1000 opt_blks=65535 physblk_exp=3 creates a disk with: Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 33553920 bytes where 33553920 % 4096 != 0, it means that use Optimal I/O size to align partition results that partition is not aligned to physical sector boundary. Reported-by: Tom Yan Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/alignment.c b/libfdisk/src/alignment.c index c658a5bee1..1e1d07cfa7 100644 --- a/libfdisk/src/alignment.c +++ b/libfdisk/src/alignment.c @@ -291,7 +291,7 @@ int fdisk_save_user_geometry(struct fdisk_context *cxt, * * Save user defined sector sizes to use it for partitioning. * - * The user properties are applied by fdisk_assign_device() or + * The user properties are applied by fdisk_assign_device() or * fdisk_reset_device_properties(). * * Returns: <0 on error, 0 on success. @@ -475,8 +475,17 @@ int fdisk_discover_topology(struct fdisk_context *cxt) /* I/O size used by fdisk */ cxt->io_size = cxt->optimal_io_size; if (!cxt->io_size) - /* optimal IO is optional, default to minimum IO */ + /* optimal I/O is optional, default to minimum IO */ cxt->io_size = cxt->min_io_size; + + /* ignore optimal I/O if not aligned to phy.sector size */ + if (cxt->io_size + && cxt->phy_sector_size + && (cxt->io_size % cxt->phy_sector_size) != 0) { + DBG(CXT, ul_debugobj(cxt, "ignore misaligned I/O size")); + cxt->io_size = cxt->phy_sector_size; + } + } } blkid_free_probe(pr); @@ -494,7 +503,7 @@ int fdisk_discover_topology(struct fdisk_context *cxt) DBG(CXT, ul_debugobj(cxt, "result: log/phy sector size: %ld/%ld", cxt->sector_size, cxt->phy_sector_size)); - DBG(CXT, ul_debugobj(cxt, "result: fdisk/min/optimal io: %ld/%ld/%ld", + DBG(CXT, ul_debugobj(cxt, "result: fdisk/optimal/minimal io: %ld/%ld/%ld", cxt->io_size, cxt->optimal_io_size, cxt->min_io_size)); return 0; }