Bug 1684078

Summary: blockdev –-getbsz forever return 4096.
Product: [Fedora] Fedora Reporter: izyk <linux>
Component: util-linuxAssignee: Karel Zak <kzak>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: rawhideCC: jcall, jonathan, kzak, yaneti
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-02-28 13:00:46 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description izyk 2019-02-28 11:23:15 UTC
Description of problem:
“blockdev –-getbsz” forever return 4096.

Version-Release number of selected component (if applicable):
All.

How reproducible:
Run:
smartctl -i /dev/sda; blockdev --getbsz --getpbsz /dev/sda

Steps to Reproduce:
smartctl --getbsz /dev/sda

Actual results:
4096

Expected results:
512

Additional info:
This utility get me the strange
results (output reduced):

 smartctl -i /dev/sda; blockdev --getbsz --getpbsz /dev/sda
Device Model:     INTEL SSDSC2KB480G8
User Capacity:    480,103,981,056 bytes [480 GB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    Solid State Device
4096
4096

 smartctl -i /dev/sdb; blockdev --getbsz --getpbsz /dev/sdb
Device Model:     HGST HUS722T2TALA604
User Capacity:    2,000,398,934,016 bytes [2.00 TB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
4096
512

As you can see “-–getbsz” forever 4096.
But I think it must be forever 512.

Thank you.
Ilia.

Comment 1 Karel Zak 2019-02-28 13:00:46 UTC
Linux kernel provides three basic ioctls:

        case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
                return put_int(arg, block_size(bdev));
        case BLKSSZGET: /* get block device logical block size */
                return put_int(arg, bdev_logical_block_size(bdev));
        case BLKPBSZGET: /* get block device physical block size */

--getbsz means BLKBSZGET. 

This size does not describes the device from "topology" point of view (like logical or physical sector), but it's block used internally by kernel for the device. 

It's for example on the fly modified by filesystem. See "mkfs.ext4 -b <size>" (default is 4KiB). You can also change from userspace by --setbsz (but the setting is valid only for the open descriptor). I'll add more information to the upstream blockdev.8 man page to make it more obvios.

So, not a bug. Although at first glance it seems strange :-)

Comment 2 Karel Zak 2019-02-28 13:06:24 UTC
Example:

# mkfs.ext4 -b $((2 * 1024)) /dev/sdc
# blockdev --getbsz /dev/sdc
4096

# mount /dev/sdc /mnt/test
# blockdev --getbsz /dev/sdc
2048

# umount /mnt/test
# blockdev --getbsz /dev/sdc
4096

Note that the default is usually 4096 due to system PAGE_SIZE.

Comment 3 izyk 2019-02-28 13:27:46 UTC
Oh.
Maybe you can add new parameter for more obvious.

--getlbsz - Get logical block (sector) size. Physical disk. See BLKSSZGET
analog of:
--getpbsz - Get physical block (sector) size.  Physical disk. See BLKPBSZGET
--getbsz  - Print blocksize in bytes. Used inside kernel. See BLKBSZGET

Or something similar.
Thank you.