Skip to content

Commit 0f9ca80

Browse files
npsingamsettyaxboe
authored andcommitted
fs: Add initial atomic write support info to statx
Extend statx system call to return additional info for atomic write support support for a file. Helper function generic_fill_statx_atomic_writes() can be used by FSes to fill in the relevant statx fields. For now atomic_write_segments_max will always be 1, otherwise some rules would need to be imposed on iovec length and alignment, which we don't want now. Signed-off-by: Prasad Singamsetty <[email protected]> jpg: relocate bdev support to another patch Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: John Garry <[email protected]> Acked-by: Darrick J. Wong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent c34fc6f commit 0f9ca80

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

fs/stat.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,37 @@ void generic_fill_statx_attr(struct inode *inode, struct kstat *stat)
8989
}
9090
EXPORT_SYMBOL(generic_fill_statx_attr);
9191

92+
/**
93+
* generic_fill_statx_atomic_writes - Fill in atomic writes statx attributes
94+
* @stat: Where to fill in the attribute flags
95+
* @unit_min: Minimum supported atomic write length in bytes
96+
* @unit_max: Maximum supported atomic write length in bytes
97+
*
98+
* Fill in the STATX{_ATTR}_WRITE_ATOMIC flags in the kstat structure from
99+
* atomic write unit_min and unit_max values.
100+
*/
101+
void generic_fill_statx_atomic_writes(struct kstat *stat,
102+
unsigned int unit_min,
103+
unsigned int unit_max)
104+
{
105+
/* Confirm that the request type is known */
106+
stat->result_mask |= STATX_WRITE_ATOMIC;
107+
108+
/* Confirm that the file attribute type is known */
109+
stat->attributes_mask |= STATX_ATTR_WRITE_ATOMIC;
110+
111+
if (unit_min) {
112+
stat->atomic_write_unit_min = unit_min;
113+
stat->atomic_write_unit_max = unit_max;
114+
/* Initially only allow 1x segment */
115+
stat->atomic_write_segments_max = 1;
116+
117+
/* Confirm atomic writes are actually supported */
118+
stat->attributes |= STATX_ATTR_WRITE_ATOMIC;
119+
}
120+
}
121+
EXPORT_SYMBOL_GPL(generic_fill_statx_atomic_writes);
122+
92123
/**
93124
* vfs_getattr_nosec - getattr without security checks
94125
* @path: file to get attributes from
@@ -659,6 +690,9 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer)
659690
tmp.stx_dio_mem_align = stat->dio_mem_align;
660691
tmp.stx_dio_offset_align = stat->dio_offset_align;
661692
tmp.stx_subvol = stat->subvol;
693+
tmp.stx_atomic_write_unit_min = stat->atomic_write_unit_min;
694+
tmp.stx_atomic_write_unit_max = stat->atomic_write_unit_max;
695+
tmp.stx_atomic_write_segments_max = stat->atomic_write_segments_max;
662696

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

include/linux/fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,6 +3235,9 @@ extern const struct inode_operations page_symlink_inode_operations;
32353235
extern void kfree_link(void *);
32363236
void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *);
32373237
void generic_fill_statx_attr(struct inode *inode, struct kstat *stat);
3238+
void generic_fill_statx_atomic_writes(struct kstat *stat,
3239+
unsigned int unit_min,
3240+
unsigned int unit_max);
32383241
extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int);
32393242
extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int);
32403243
void __inode_add_bytes(struct inode *inode, loff_t bytes);

include/linux/stat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ struct kstat {
5454
u32 dio_offset_align;
5555
u64 change_cookie;
5656
u64 subvol;
57+
u32 atomic_write_unit_min;
58+
u32 atomic_write_unit_max;
59+
u32 atomic_write_segments_max;
5760
};
5861

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

include/uapi/linux/stat.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,15 @@ 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 */
130129
/* 0xa0 */
131-
__u64 __spare3[11]; /* Spare space for future expansion */
130+
__u64 stx_subvol; /* Subvolume identifier */
131+
__u32 stx_atomic_write_unit_min; /* Min atomic write unit in bytes */
132+
__u32 stx_atomic_write_unit_max; /* Max atomic write unit in bytes */
133+
/* 0xb0 */
134+
__u32 stx_atomic_write_segments_max; /* Max atomic write segment count */
135+
__u32 __spare1[1];
136+
/* 0xb8 */
137+
__u64 __spare3[9]; /* Spare space for future expansion */
132138
/* 0x100 */
133139
};
134140

@@ -157,6 +163,7 @@ struct statx {
157163
#define STATX_DIOALIGN 0x00002000U /* Want/got direct I/O alignment info */
158164
#define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */
159165
#define STATX_SUBVOL 0x00008000U /* Want/got stx_subvol */
166+
#define STATX_WRITE_ATOMIC 0x00010000U /* Want/got atomic_write_* fields */
160167

161168
#define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */
162169

@@ -192,6 +199,7 @@ struct statx {
192199
#define STATX_ATTR_MOUNT_ROOT 0x00002000 /* Root of a mount */
193200
#define STATX_ATTR_VERITY 0x00100000 /* [I] Verity protected file */
194201
#define STATX_ATTR_DAX 0x00200000 /* File is currently in DAX state */
202+
#define STATX_ATTR_WRITE_ATOMIC 0x00400000 /* File supports atomic write operations */
195203

196204

197205
#endif /* _UAPI_LINUX_STAT_H */

0 commit comments

Comments
 (0)