]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkzone: fix whole device detection
authorKarel Zak <kzak@redhat.com>
Fri, 8 Jun 2018 09:37:55 +0000 (11:37 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Jul 2018 14:09:12 +0000 (16:09 +0200)
Matias Bjørling wrote:
  The current detection code for chunk size assumes that the
  underlying device is a device that uses the minor device id
  as the partition id, and that the whole device has minor id 0.
  This is not true for example null_blk and nvme device drivers.

Let's use sysfs_devno_to_wholedisk() to get whole-disk devno.

Addresses: https://github.com/karelzak/util-linux/pull/646
Reported-by: Matias Bjørling matias.bjorling@wdc.com
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/blkzone.c

index 6d837ff289ed4c9ad453efcdc769502d0eb2a796..9c6dda0116bea01ddac14eb35b4bfd51ebfe1fe5 100644 (file)
@@ -116,8 +116,7 @@ static unsigned long blkdev_chunk_sectors(const char *dname)
 {
        struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY;
        dev_t devno = sysfs_devname_to_devno(dname, NULL);
-       int major_no = major(devno);
-       int block_no = minor(devno) & ~0x0f;
+       dev_t disk;
        uint64_t sz;
        int rc;
 
@@ -126,8 +125,10 @@ static unsigned long blkdev_chunk_sectors(const char *dname)
         * This method masks off the partition specified by the minor device
         * component.
         */
-       devno = makedev(major_no, block_no);
-       if (sysfs_init(&cxt, devno, NULL))
+       if (sysfs_devno_to_wholedisk(devno, NULL, 0, &disk) != 0)
+               return 0;
+
+       if (sysfs_init(&cxt, disk, NULL))
                return 0;
 
        rc = sysfs_read_u64(&cxt, "queue/chunk_sectors", &sz);