On 2025/5/6 13:47, Christoph Hellwig wrote: > On Mon, May 05, 2025 at 10:36:54PM -0700, Darrick J. Wong wrote: >> I think STATX_* (i.e. not STATX_ATTR_*) flags have two purposes: 1) to >> declare that specific fields in struct statx actually have meaning, most >> notably in scenarios where zeroes are valid field contents; and 2) if >> filling out the field is expensive, userspace can elect not to have it >> filled by leaving the bit unset. I don't know how userspace is supposed >> to figure out which fields are expensive. > > Yes. >
IIUC, it seems I was misled by STATX_ATTR_WRITE_ATOMIC, adding this STATX_ATTR_WRITE_ZEROES_UNMAP attribute flag is incorrect. The right approach should be to add STATX_WRITE_ZEROES_UNMAP, setting it in the result_mask if the request_mask includes this flag and bdev_write_zeroes_unmap(bdev) returns true. Something like below. Is my understanding right? diff --git a/block/bdev.c b/block/bdev.c index 4ba48b8735e7..e1367f30dbce 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1303,9 +1303,9 @@ void bdev_statx(const struct path *path, struct kstat *stat, u32 request_mask) queue_atomic_write_unit_max_bytes(bd_queue)); } + if (request_mask & STATX_WRITE_ZEROES_UNMAP && + bdev_write_zeroes_unmap(bdev)) + stat->result_mask |= STATX_WRITE_ZEROES_UNMAP; stat->blksize = bdev_io_min(bdev); Thanks, Yi.