Skip to content

Commit 2a82bb0

Browse files
Kent Overstreetbrauner
authored andcommitted
statx: stx_subvol
Add a new statx field for (sub)volume identifiers, as implemented by btrfs and bcachefs. This includes bcachefs support; we'll definitely want btrfs support as well. Link: https://lore.kernel.org/linux-fsdevel/2uvhm6gweyl7iyyp2xpfryvcu2g3padagaeqcbiavjyiis6prl@yjm725bizncq/ Signed-off-by: Kent Overstreet <[email protected]> Cc: Josef Bacik <[email protected]> Cc: Miklos Szeredi <[email protected]> Cc: Christian Brauner <[email protected]> Cc: David Howells <[email protected]> Signed-off-by: Kent Overstreet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 4cece76 commit 2a82bb0

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

fs/bcachefs/fs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ static int bch2_getattr(struct mnt_idmap *idmap,
841841
stat->blksize = block_bytes(c);
842842
stat->blocks = inode->v.i_blocks;
843843

844+
stat->subvol = inode->ei_subvol;
845+
stat->result_mask |= STATX_SUBVOL;
846+
844847
if (request_mask & STATX_BTIME) {
845848
stat->result_mask |= STATX_BTIME;
846849
stat->btime = bch2_time_to_timespec(c, inode->ei_inode.bi_otime);

fs/btrfs/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8779,6 +8779,9 @@ static int btrfs_getattr(struct mnt_idmap *idmap,
87798779
generic_fillattr(idmap, request_mask, inode, stat);
87808780
stat->dev = BTRFS_I(inode)->root->anon_dev;
87818781

8782+
stat->subvol = BTRFS_I(inode)->root->root_key.objectid;
8783+
stat->result_mask |= STATX_SUBVOL;
8784+
87828785
spin_lock(&BTRFS_I(inode)->lock);
87838786
delalloc_bytes = BTRFS_I(inode)->new_delalloc_bytes;
87848787
inode_bytes = inode_get_bytes(inode);

fs/stat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer)
658658
tmp.stx_mnt_id = stat->mnt_id;
659659
tmp.stx_dio_mem_align = stat->dio_mem_align;
660660
tmp.stx_dio_offset_align = stat->dio_offset_align;
661+
tmp.stx_subvol = stat->subvol;
661662

662663
return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0;
663664
}

include/linux/stat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct kstat {
5353
u32 dio_mem_align;
5454
u32 dio_offset_align;
5555
u64 change_cookie;
56+
u64 subvol;
5657
};
5758

5859
/* These definitions are internal to the kernel for now. Mainly used by nfsd. */

include/uapi/linux/stat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ struct statx {
126126
__u64 stx_mnt_id;
127127
__u32 stx_dio_mem_align; /* Memory buffer alignment for direct I/O */
128128
__u32 stx_dio_offset_align; /* File offset alignment for direct I/O */
129+
__u64 stx_subvol; /* Subvolume identifier */
129130
/* 0xa0 */
130-
__u64 __spare3[12]; /* Spare space for future expansion */
131+
__u64 __spare3[11]; /* Spare space for future expansion */
131132
/* 0x100 */
132133
};
133134

@@ -155,6 +156,7 @@ struct statx {
155156
#define STATX_MNT_ID 0x00001000U /* Got stx_mnt_id */
156157
#define STATX_DIOALIGN 0x00002000U /* Want/got direct I/O alignment info */
157158
#define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */
159+
#define STATX_SUBVOL 0x00008000U /* Want/got stx_subvol */
158160

159161
#define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */
160162

0 commit comments

Comments
 (0)