Skip to content

Commit d599f57

Browse files
VillemoesNicolas Schier
authored andcommitted
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 8aec9db ("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>
1 parent 9716818 commit d599f57

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

fs/btrfs/send.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,30 @@
4747
* It allows fast adding of path elements on the right side (normal path) and
4848
* fast adding to the left side (reversed path). A reversed path can also be
4949
* 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.
5053
*/
54+
struct __fs_path {
55+
char *start;
56+
char *end;
57+
58+
char *buf;
59+
unsigned short buf_len:15;
60+
unsigned short reversed:1;
61+
};
62+
static_assert(sizeof(struct __fs_path) < 256);
5163
struct fs_path {
52-
union {
53-
struct {
54-
char *start;
55-
char *end;
56-
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-
};
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)];
6971
};
7072
#define FS_PATH_INLINE_SIZE \
71-
(sizeof(struct fs_path) - offsetof(struct fs_path, inline_buf))
73+
sizeof_field(struct fs_path, inline_buf)
7274

7375

7476
/* reused for each extent */
@@ -305,7 +307,6 @@ struct send_ctx {
305307
struct btrfs_lru_cache dir_created_cache;
306308
struct btrfs_lru_cache dir_utimes_cache;
307309

308-
/* Must be last as it ends in a flexible-array member. */
309310
struct fs_path cur_inode_path;
310311
};
311312

0 commit comments

Comments
 (0)