fdisk: fix io_size usage in new API

properly implemented fdisk_dev_has_topology() requires optimal
I/O size to detect that the device provides topology.

Unfortunately, currently used cxt->io_size maybe overwritten in
__discover_topology() to min_io_size.

This patch introduces cxt->optimal_io_size and keeps it independent on
cxt->io_size. The cxt->io_size is I/O size used by fdisk for alignment
calculation.

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-06-06 11:03:23 +02:00
parent dde32b6ccd
commit df68ccd8b8
2 changed files with 10 additions and 7 deletions

View File

@ -107,10 +107,11 @@ struct fdisk_context {
char *dev_path; /* device path */
/* topology */
unsigned long io_size;
unsigned long min_io_size;
unsigned long phy_sector_size; /* physical size */
unsigned long sector_size; /* logical size */
unsigned long io_size; /* I/O size used by fdisk */
unsigned long optimal_io_size; /* optional I/O returned by device */
unsigned long min_io_size; /* minimal I/O size */
unsigned long phy_sector_size; /* physical size */
unsigned long sector_size; /* logical size */
unsigned long alignment_offset;
/* geometry */

View File

@ -61,10 +61,12 @@ static int __discover_topology(struct fdisk_context *cxt)
if (tp) {
cxt->min_io_size = blkid_topology_get_minimum_io_size(tp);
cxt->io_size = blkid_topology_get_optimal_io_size(tp);
cxt->optimal_io_size = blkid_topology_get_optimal_io_size(tp);
cxt->phy_sector_size = blkid_topology_get_physical_sector_size(tp);
cxt->alignment_offset = blkid_topology_get_alignment_offset(tp);
/* 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 */
cxt->io_size = cxt->min_io_size;
@ -110,8 +112,8 @@ int fdisk_dev_has_topology(struct fdisk_context *cxt)
* optimal_io_size is set or alignment_offset is set or
* minimum_io_size is not power of 2.
*/
if (cxt->io_size || cxt->alignment_offset ||
(cxt->min_io_size & (cxt->min_io_size - 1)))
if (cxt->optimal_io_size || cxt->alignment_offset ||
!is_power_of_2(cxt->min_io_size))
return 1;
return 0;
}