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 <tom.ty89@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2015-06-18 11:55:29 +02:00
parent 7f5769182f
commit acb7651f88
1 changed files with 12 additions and 3 deletions

View File

@ -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;
}