]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: support STATX_DIOALIGN for statx file
authorHongbo Li <lihongbo22@huawei.com>
Thu, 20 Jun 2024 13:21:12 +0000 (21:21 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 14 Jul 2024 23:00:16 +0000 (19:00 -0400)
Add support for STATX_DIOALIGN to bcachefs, so that direct I/O alignment
restrictions are exposed to userspace in a generic way.

[Before]
```
./statx_test /mnt/bcachefs/test
statx(/mnt/bcachefs/test) = 0
dio mem align:0
dio offset align:0
```

[After]
```
./statx_test /mnt/bcachefs/test
statx(/mnt/bcachefs/test) = 0
dio mem align:1
dio offset align:512
```

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c

index 3483d34c3be1fb881996e3f30fc4ebf84e81d91f..b734d91c44464d5be04ad043ea5fe0f1938e86dd 100644 (file)
@@ -895,6 +895,16 @@ static int bch2_getattr(struct mnt_idmap *idmap,
        stat->subvol    = inode->ei_subvol;
        stat->result_mask |= STATX_SUBVOL;
 
+       if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->v.i_mode)) {
+               stat->result_mask |= STATX_DIOALIGN;
+               /*
+                * this is incorrect; we should be tracking this in superblock,
+                * and checking the alignment of open devices
+                */
+               stat->dio_mem_align = SECTOR_SIZE;
+               stat->dio_offset_align = block_bytes(c);
+       }
+
        if (request_mask & STATX_BTIME) {
                stat->result_mask |= STATX_BTIME;
                stat->btime = bch2_time_to_timespec(c, inode->ei_inode.bi_otime);