]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: ignore misaligned optimal I/O size
authorKarel Zak <kzak@redhat.com>
Thu, 18 Jun 2015 09:55:29 +0000 (11:55 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 18 Jun 2015 09:55:29 +0000 (11:55 +0200)
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>
libfdisk/src/alignment.c

index c658a5bee1584ac0d4b9397846fba110b0ab602c..1e1d07cfa7d880cd194a5ccdaef786636d99a71b 100644 (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;
 }