Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

btrfs: send: make use of -fms-extensions for defining struct fs_path

The newly introduced -fms-extensions compiler flag allows defining
struct fs_path in such a way that inline_buf becomes a proper array
with a size known to the compiler.

This also makes the problem fixed by commit 8aec9dbf2db2 ("btrfs: send:
fix -Wflex-array-member-not-at-end warning in struct send_ctx") go away.
Whether cur_inode_path should be put back to its original place in
struct send_ctx I don't know, but at least the comment no longer
applies.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: David Sterba <dsterba@suse.com>
Link: https://patch.msgid.link/20251020142228.1819871-3-linux@rasmusvillemoes.dk
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nicolas Schier <nsc@kernel.org>

authored by

Rasmus Villemoes and committed by
Nicolas Schier
d599f571 9716818d

+20 -19
+20 -19
fs/btrfs/send.c
··· 47 47 * It allows fast adding of path elements on the right side (normal path) and 48 48 * fast adding to the left side (reversed path). A reversed path can also be 49 49 * unreversed if needed. 50 + * 51 + * The definition of struct fs_path relies on -fms-extensions to allow 52 + * including a tagged struct as an anonymous member. 50 53 */ 51 - struct fs_path { 52 - union { 53 - struct { 54 - char *start; 55 - char *end; 54 + struct __fs_path { 55 + char *start; 56 + char *end; 56 57 57 - char *buf; 58 - unsigned short buf_len:15; 59 - unsigned short reversed:1; 60 - char inline_buf[]; 61 - }; 62 - /* 63 - * Average path length does not exceed 200 bytes, we'll have 64 - * better packing in the slab and higher chance to satisfy 65 - * an allocation later during send. 66 - */ 67 - char pad[256]; 68 - }; 58 + char *buf; 59 + unsigned short buf_len:15; 60 + unsigned short reversed:1; 61 + }; 62 + static_assert(sizeof(struct __fs_path) < 256); 63 + struct fs_path { 64 + struct __fs_path; 65 + /* 66 + * Average path length does not exceed 200 bytes, we'll have 67 + * better packing in the slab and higher chance to satisfy 68 + * an allocation later during send. 69 + */ 70 + char inline_buf[256 - sizeof(struct __fs_path)]; 69 71 }; 70 72 #define FS_PATH_INLINE_SIZE \ 71 - (sizeof(struct fs_path) - offsetof(struct fs_path, inline_buf)) 73 + sizeof_field(struct fs_path, inline_buf) 72 74 73 75 74 76 /* reused for each extent */ ··· 307 305 struct btrfs_lru_cache dir_created_cache; 308 306 struct btrfs_lru_cache dir_utimes_cache; 309 307 310 - /* Must be last as it ends in a flexible-array member. */ 311 308 struct fs_path cur_inode_path; 312 309 }; 313 310