Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blockdev: query physical sector size, not logical
When determining whether to install the 512b or 4k image, we should be comparing against the physical sector size of the drive, not its logical sector size. Some 4k drives report themselves as having a logical sector size of 512 bytes for backwards compatibility with OSes and software that can't do 4k blocks (these are also called "512e" drives). However, actually using the drive as a 512b one provides reduced performance because the drive needs to translate all requests. For comparison, `mkfs.xfs` will use a sector size of 4096 on 512e drives: https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/tree/mkfs/xfs_mkfs.c?id=3498b68025ce#n1932 One can also experimentally verify this: ``` $ qemu-img create -f qcow2 storage-512.qcow2 1G $ qemu-img create -f qcow2 storage-512e.qcow2 1G $ qemu-img create -f qcow2 storage-4kn.qcow2 1G $ cosa run -- \ -drive if=none,id=storage-512,format=qcow2,file=storage-512.qcow2 \ -device virtio-blk,drive=storage-512,physical_block_size=512,logical_block_size=512,serial=storage-512 \ -drive if=none,id=storage-512e,format=qcow2,file=storage-512e.qcow2 \ -device virtio-blk,drive=storage-512e,physical_block_size=4096,logical_block_size=512,serial=storage-512e \ -drive if=none,id=storage-4kn,format=qcow2,file=storage-4kn.qcow2 \ -device virtio-blk,drive=storage-4kn,physical_block_size=4096,logical_block_size=4096,serial=storage-4kn [core@cosa-devsh ~]$ sudo mkfs.xfs /dev/disk/by-id/virtio-storage-512 | grep sectsz = sectsz=512 attr=2, projid32bit=1 = sectsz=512 sunit=0 blks, lazy-count=1 [core@cosa-devsh ~]$ sudo mkfs.xfs /dev/disk/by-id/virtio-storage-512e | grep sectsz = sectsz=4096 attr=2, projid32bit=1 = sectsz=4096 sunit=1 blks, lazy-count=1 [core@cosa-devsh ~]$ sudo mkfs.xfs /dev/disk/by-id/virtio-storage-4kn | grep sectsz = sectsz=4096 attr=2, projid32bit=1 = sectsz=4096 sunit=1 blks, lazy-count=1 ``` To match this, we only need to change `get_sector_size_for_path` to use `BLKPBSZGET` instead of `BLKSSZGET`.
- Loading branch information