]> Gentwo Git Trees - linux/.git/commitdiff
btrfs: send: make use of -fms-extensions for defining struct fs_path
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Mon, 20 Oct 2025 14:22:28 +0000 (16:22 +0200)
committerNicolas Schier <nsc@kernel.org>
Sat, 8 Nov 2025 11:17:58 +0000 (12:17 +0100)
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>
fs/btrfs/send.c

index 6144e66661f583abefc105ae74823485855cd2ed..1fe4a06e6850d29d14925732e7b8e9a0887c5607 100644 (file)
  * It allows fast adding of path elements on the right side (normal path) and
  * fast adding to the left side (reversed path). A reversed path can also be
  * unreversed if needed.
+ *
+ * The definition of struct fs_path relies on -fms-extensions to allow
+ * including a tagged struct as an anonymous member.
  */
+struct __fs_path {
+       char *start;
+       char *end;
+
+       char *buf;
+       unsigned short buf_len:15;
+       unsigned short reversed:1;
+};
+static_assert(sizeof(struct __fs_path) < 256);
 struct fs_path {
-       union {
-               struct {
-                       char *start;
-                       char *end;
-
-                       char *buf;
-                       unsigned short buf_len:15;
-                       unsigned short reversed:1;
-                       char inline_buf[];
-               };
-               /*
-                * Average path length does not exceed 200 bytes, we'll have
-                * better packing in the slab and higher chance to satisfy
-                * an allocation later during send.
-                */
-               char pad[256];
-       };
+       struct __fs_path;
+       /*
+        * Average path length does not exceed 200 bytes, we'll have
+        * better packing in the slab and higher chance to satisfy
+        * an allocation later during send.
+        */
+       char inline_buf[256 - sizeof(struct __fs_path)];
 };
 #define FS_PATH_INLINE_SIZE \
-       (sizeof(struct fs_path) - offsetof(struct fs_path, inline_buf))
+       sizeof_field(struct fs_path, inline_buf)
 
 
 /* reused for each extent */
@@ -305,7 +307,6 @@ struct send_ctx {
        struct btrfs_lru_cache dir_created_cache;
        struct btrfs_lru_cache dir_utimes_cache;
 
-       /* Must be last as it ends in a flexible-array member. */
        struct fs_path cur_inode_path;
 };