]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: fix io_size usage in new API
authorKarel Zak <kzak@redhat.com>
Wed, 6 Jun 2012 09:03:23 +0000 (11:03 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Jun 2012 09:03:23 +0000 (11:03 +0200)
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>
fdisk/fdisk.h
fdisk/utils.c

index d5d66d3cfc863f23d90563229215cac39b1215d5..c645b24d559737bc9953200692c81b55d86bada3 100644 (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 */
index 4d838412c8971b8c83daf409ac8b0c370925fbe1..352a9346b1d1eeb7e17707acd45a0b27ae445c62 100644 (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;
 }