On Mon, Nov 18, 2024 at 08:08:05AM +0100, Christoph Hellwig wrote: > On Wed, Nov 13, 2024 at 01:47:27AM -0800, Luis Chamberlain wrote: > > if (S_ISBLK(stat->mode)) > > - bdev_statx(path, stat, request_mask); > > + bdev_statx(path, stat, request_mask | STATX_DIOALIGN); > > And this is both unrelated and wrong. I knew this was an eyesore, but was not sure if we really wanted to go through the trouble of adding a new field for blksize alone, but come to think of it, with it at least userspace knows for sure its getting where as befault it was not. If we add it, and since it would be added post LBS support it could also signal that a kernel supports LBS. That may be a useful clue for default mkfs in case it is set and larger than today's 4k default. So how about: diff --git a/block/bdev.c b/block/bdev.c index 3a5fd65f6c8e..f5d7cda97616 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1277,7 +1277,8 @@ void bdev_statx(struct path *path, struct kstat *stat, struct inode *backing_inode; struct block_device *bdev; - if (!(request_mask & (STATX_DIOALIGN | STATX_WRITE_ATOMIC))) + if (!(request_mask & (STATX_DIOALIGN | STATX_WRITE_ATOMIC | + STATX_BLKSIZE))) return; backing_inode = d_backing_inode(path->dentry); @@ -1306,6 +1307,11 @@ void bdev_statx(struct path *path, struct kstat *stat, queue_atomic_write_unit_max_bytes(bd_queue)); } + if (request_mask & STATX_BLKSIZE) { + stat->blksize = (unsigned int) bdev_io_min(bdev); + stat->result_mask |= STATX_BLKSIZE; + } + blkdev_put_no_open(bdev); } diff --git a/fs/stat.c b/fs/stat.c index 41e598376d7e..d4cb2296b42d 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -268,7 +268,7 @@ static int vfs_statx_path(struct path *path, int flags, struct kstat *stat, * obtained from the bdev backing inode. */ if (S_ISBLK(stat->mode)) - bdev_statx(path, stat, request_mask); + bdev_statx(path, stat, request_mask | STATX_BLKSIZE); return error; } diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index 887a25286441..b7e180bf72b8 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -164,6 +164,7 @@ struct statx { #define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */ #define STATX_SUBVOL 0x00008000U /* Want/got stx_subvol */ #define STATX_WRITE_ATOMIC 0x00010000U /* Want/got atomic_write_* fields */ +#define STATX_BLKSIZE 0x00020000U /* Want/got stx_blksize */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */