Whamcloud - gitweb
LU-17784 build: improve wiretest for flexible arrays
authorShaun Tancheff <shaun.tancheff@hpe.com>
Fri, 26 Apr 2024 18:32:09 +0000 (11:32 -0700)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 27 Apr 2024 22:25:17 +0000 (22:25 +0000)
Flexible array checking can additionally probe that the size
of the array element is correct.

Lustre-change: https://review.whamcloud.com/54929
Lustre-commit: TBD (from a5cbf26e7985dfe60471d060439eb7cd90a17fc2)

Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: Ib7de3d156a2e77dfaf2e9ab1df8fab524c073610
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/54938
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/ptlrpc/wiretest.c
lustre/utils/wirecheck.c
lustre/utils/wiretest.c

index b1513b6..489b3a1 100644 (file)
@@ -2045,10 +2045,11 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct lov_comp_md_v1, lcm_padding2));
        LASSERTF((int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_padding2) == 8, "found %lld\n",
                 (long long)(int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_padding2));
-       LASSERTF((int)offsetof(struct lov_comp_md_v1, lcm_entries[0]) == 32, "found %lld\n",
-                (long long)(int)offsetof(struct lov_comp_md_v1, lcm_entries[0]));
-       LASSERTF((int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_entries[0]) == 48, "found %lld\n",
-                (long long)(int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_entries[0]));
+       LASSERTF((int)offsetof(struct lov_comp_md_v1, lcm_entries) == 32, "found %lld\n",
+                (long long)(int)offsetof(struct lov_comp_md_v1, lcm_entries));
+       LASSERTF((int)sizeof(*((struct lov_comp_md_v1 *)0)->lcm_entries) == 48, "found %lld\n",
+                (long long)(int)sizeof(*((struct lov_comp_md_v1 *)0)->lcm_entries));
+       BUILD_BUG_ON(offsetof(struct lov_comp_md_v1, lcm_entries) != sizeof(struct lov_comp_md_v1));
        BUILD_BUG_ON(LOV_MAGIC_COMP_V1 != (0x0BD60000 | 0x0BD0));
        LASSERTF(LCM_FL_NONE == 0, "found %lld\n",
                 (long long)LCM_FL_NONE);
@@ -4972,6 +4973,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct fiemap *)0)->fm_reserved));
        LASSERTF((int)offsetof(struct fiemap, fm_extents) == 32, "found %lld\n",
                 (long long)(int)offsetof(struct fiemap, fm_extents));
+       LASSERTF((int)sizeof(*((struct fiemap *)0)->fm_extents) == 56, "found %lld\n",
+                (long long)(int)sizeof(*((struct fiemap *)0)->fm_extents));
        BUILD_BUG_ON(offsetof(struct fiemap, fm_extents) != sizeof(struct fiemap));
        BUILD_BUG_ON(FIEMAP_FLAG_SYNC != 0x00000001);
        BUILD_BUG_ON(FIEMAP_FLAG_XATTR != 0x00000002);
@@ -5187,6 +5190,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct hsm_action_list *)0)->padding1));
        LASSERTF((int)offsetof(struct hsm_action_list, hal_fsname) == 32, "found %lld\n",
                 (long long)(int)offsetof(struct hsm_action_list, hal_fsname));
+       LASSERTF((int)sizeof(*((struct hsm_action_list *)0)->hal_fsname) == 1, "found %lld\n",
+                (long long)(int)sizeof(*((struct hsm_action_list *)0)->hal_fsname));
        BUILD_BUG_ON(offsetof(struct hsm_action_list, hal_fsname) != sizeof(struct hsm_action_list));
 
        /* Checks for struct hsm_progress */
@@ -5657,6 +5662,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_param *)0)->oup_padding2));
        LASSERTF((int)offsetof(struct object_update_param, oup_buf) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_param, oup_buf));
+       LASSERTF((int)sizeof(*((struct object_update_param *)0)->oup_buf) == 1, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_param *)0)->oup_buf));
        BUILD_BUG_ON(offsetof(struct object_update_param, oup_buf) != sizeof(struct object_update_param));
 
        /* Checks for struct object_update */
@@ -5692,6 +5699,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update *)0)->ou_fid));
        LASSERTF((int)offsetof(struct object_update, ou_params) == 40, "found %lld\n",
                 (long long)(int)offsetof(struct object_update, ou_params));
+       LASSERTF((int)sizeof(*((struct object_update *)0)->ou_params) == 8, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update *)0)->ou_params));
        BUILD_BUG_ON(offsetof(struct object_update, ou_params) != sizeof(struct object_update));
        BUILD_BUG_ON(UPDATE_FL_OST != 0x00000001);
        BUILD_BUG_ON(UPDATE_FL_SYNC != 0x00000002);
@@ -5715,6 +5724,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_request *)0)->ourq_padding));
        LASSERTF((int)offsetof(struct object_update_request, ourq_updates) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_request, ourq_updates));
+       LASSERTF((int)sizeof(*((struct object_update_request *)0)->ourq_updates) == 40, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_request *)0)->ourq_updates));
        BUILD_BUG_ON(offsetof(struct object_update_request, ourq_updates) != sizeof(struct object_update_request));
        BUILD_BUG_ON(UPDATE_REQUEST_MAGIC != 0xBDDE0002);
 
@@ -5735,6 +5746,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_result *)0)->our_padding));
        LASSERTF((int)offsetof(struct object_update_result, our_data) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_result, our_data));
+       LASSERTF((int)sizeof(*((struct object_update_result *)0)->our_data) == 4, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_result *)0)->our_data));
        BUILD_BUG_ON(offsetof(struct object_update_result, our_data) != sizeof(struct object_update_result));
 
        /* Checks for struct object_update_reply */
@@ -5754,6 +5767,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_reply *)0)->ourp_padding));
        LASSERTF((int)offsetof(struct object_update_reply, ourp_lens) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_reply, ourp_lens));
+       LASSERTF((int)sizeof(*((struct object_update_reply *)0)->ourp_lens) == 2, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_reply *)0)->ourp_lens));
        BUILD_BUG_ON(offsetof(struct object_update_reply, ourp_lens) != sizeof(struct object_update_reply));
        BUILD_BUG_ON(UPDATE_REPLY_MAGIC != 0x00BD0002);
 
@@ -5778,6 +5793,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct out_update_header *)0)->ouh_reply_size));
        LASSERTF((int)offsetof(struct out_update_header, ouh_inline_data) == 16, "found %lld\n",
                 (long long)(int)offsetof(struct out_update_header, ouh_inline_data));
+       LASSERTF((int)sizeof(*((struct out_update_header *)0)->ouh_inline_data) == 4, "found %lld\n",
+                (long long)(int)sizeof(*((struct out_update_header *)0)->ouh_inline_data));
        BUILD_BUG_ON(offsetof(struct out_update_header, ouh_inline_data) != sizeof(struct out_update_header));
        BUILD_BUG_ON(OUT_UPDATE_HEADER_MAGIC != 0xBDDF0001);
        BUILD_BUG_ON(OUT_UPDATE_MAX_INLINE_SIZE != 4096);
index 3c3fb79..e2bf937 100644 (file)
@@ -139,14 +139,20 @@ do {                                                              \
        CHECK_VALUE((int)sizeof(((struct s *)0)->m));           \
 } while(0)
 
+#define CHECK_MEMBER_SIZEOF_ARRAY_ELEMENT(s, m)                        \
+do {                                                           \
+       CHECK_VALUE((int)sizeof(*((struct s *)0)->m));          \
+} while(0)
+
 #define CHECK_MEMBER_SIZEOF_TYPEDEF(s, m)                      \
 do {                                                           \
        CHECK_VALUE((int)sizeof(((s *)0)->m));                  \
 } while(0)
 
-#define CHECK_MEMBER_IS_FLEXIBLE(s, m)                 \
+#define CHECK_MEMBER_IS_FLEXIBLE(s, m)                                 \
 do {                                                                   \
        CHECK_MEMBER_OFFSET(s, m);                                      \
+       CHECK_MEMBER_SIZEOF_ARRAY_ELEMENT(s, m);                        \
        CHECK_BUILD_TEST(offsetof(struct s, m) != sizeof(struct s));    \
 } while (0)
 
@@ -976,7 +982,7 @@ check_lov_comp_md_v1(void)
        CHECK_MEMBER(lov_comp_md_v1, lcm_mirror_count);
        CHECK_MEMBER(lov_comp_md_v1, lcm_padding1);
        CHECK_MEMBER(lov_comp_md_v1, lcm_padding2);
-       CHECK_MEMBER(lov_comp_md_v1, lcm_entries[0]);
+       CHECK_MEMBER_IS_FLEXIBLE(lov_comp_md_v1, lcm_entries);
 
        CHECK_CDEFINE(LOV_MAGIC_COMP_V1);
 
index 8be26b1..254976d 100644 (file)
@@ -1708,7 +1708,7 @@ void lustre_assert_wire_constants(void)
                 OBD_MD_FLGID);
        LASSERTF(OBD_MD_FLFLAGS == (0x00000800ULL), "found 0x%.16llxULL\n",
                 OBD_MD_FLFLAGS);
-       LASSERTF(OBD_MD_DOM_SIZE == (0X00001000ULL), "found 0x%.16llxULL\n",
+       LASSERTF(OBD_MD_DOM_SIZE == (0x00001000ULL), "found 0x%.16llxULL\n",
                 OBD_MD_DOM_SIZE);
        LASSERTF(OBD_MD_FLNLINK == (0x00002000ULL), "found 0x%.16llxULL\n",
                 OBD_MD_FLNLINK);
@@ -2080,8 +2080,10 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct lov_comp_md_v1, lcm_padding2));
        LASSERTF((int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_padding2) == 8, "found %lld\n",
                 (long long)(int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_padding2));
-       LASSERTF((int)offsetof(struct lov_comp_md_v1, lcm_entries[0]) == 32, "found %lld\n",
-                (long long)(int)offsetof(struct lov_comp_md_v1, lcm_entries[0]));
+       LASSERTF((int)offsetof(struct lov_comp_md_v1, lcm_entries) == 32, "found %lld\n",
+                (long long)(int)offsetof(struct lov_comp_md_v1, lcm_entries));
+       LASSERTF((int)sizeof(*((struct lov_comp_md_v1 *)0)->lcm_entries) == 48, "found %lld\n",
+                (long long)(int)sizeof(*((struct lov_comp_md_v1 *)0)->lcm_entries));
        BUILD_BUG_ON(offsetof(struct lov_comp_md_v1, lcm_entries) != sizeof(struct lov_comp_md_v1));
        BUILD_BUG_ON(LOV_MAGIC_COMP_V1 != (0x0BD60000 | 0x0BD0));
        LASSERTF(LCM_FL_NONE == 0, "found %lld\n",
@@ -5006,6 +5008,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct fiemap *)0)->fm_reserved));
        LASSERTF((int)offsetof(struct fiemap, fm_extents) == 32, "found %lld\n",
                 (long long)(int)offsetof(struct fiemap, fm_extents));
+       LASSERTF((int)sizeof(*((struct fiemap *)0)->fm_extents) == 56, "found %lld\n",
+                (long long)(int)sizeof(*((struct fiemap *)0)->fm_extents));
        BUILD_BUG_ON(offsetof(struct fiemap, fm_extents) != sizeof(struct fiemap));
        BUILD_BUG_ON(FIEMAP_FLAG_SYNC != 0x00000001);
        BUILD_BUG_ON(FIEMAP_FLAG_XATTR != 0x00000002);
@@ -5221,6 +5225,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct hsm_action_list *)0)->padding1));
        LASSERTF((int)offsetof(struct hsm_action_list, hal_fsname) == 32, "found %lld\n",
                 (long long)(int)offsetof(struct hsm_action_list, hal_fsname));
+       LASSERTF((int)sizeof(*((struct hsm_action_list *)0)->hal_fsname) == 1, "found %lld\n",
+                (long long)(int)sizeof(*((struct hsm_action_list *)0)->hal_fsname));
        BUILD_BUG_ON(offsetof(struct hsm_action_list, hal_fsname) != sizeof(struct hsm_action_list));
 
        /* Checks for struct hsm_progress */
@@ -5691,6 +5697,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_param *)0)->oup_padding2));
        LASSERTF((int)offsetof(struct object_update_param, oup_buf) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_param, oup_buf));
+       LASSERTF((int)sizeof(*((struct object_update_param *)0)->oup_buf) == 1, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_param *)0)->oup_buf));
        BUILD_BUG_ON(offsetof(struct object_update_param, oup_buf) != sizeof(struct object_update_param));
 
        /* Checks for struct object_update */
@@ -5726,6 +5734,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update *)0)->ou_fid));
        LASSERTF((int)offsetof(struct object_update, ou_params) == 40, "found %lld\n",
                 (long long)(int)offsetof(struct object_update, ou_params));
+       LASSERTF((int)sizeof(*((struct object_update *)0)->ou_params) == 8, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update *)0)->ou_params));
        BUILD_BUG_ON(offsetof(struct object_update, ou_params) != sizeof(struct object_update));
        BUILD_BUG_ON(UPDATE_FL_OST != 0x00000001);
        BUILD_BUG_ON(UPDATE_FL_SYNC != 0x00000002);
@@ -5749,6 +5759,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_request *)0)->ourq_padding));
        LASSERTF((int)offsetof(struct object_update_request, ourq_updates) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_request, ourq_updates));
+       LASSERTF((int)sizeof(*((struct object_update_request *)0)->ourq_updates) == 40, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_request *)0)->ourq_updates));
        BUILD_BUG_ON(offsetof(struct object_update_request, ourq_updates) != sizeof(struct object_update_request));
        BUILD_BUG_ON(UPDATE_REQUEST_MAGIC != 0xBDDE0002);
 
@@ -5769,6 +5781,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_result *)0)->our_padding));
        LASSERTF((int)offsetof(struct object_update_result, our_data) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_result, our_data));
+       LASSERTF((int)sizeof(*((struct object_update_result *)0)->our_data) == 4, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_result *)0)->our_data));
        BUILD_BUG_ON(offsetof(struct object_update_result, our_data) != sizeof(struct object_update_result));
 
        /* Checks for struct object_update_reply */
@@ -5788,6 +5802,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct object_update_reply *)0)->ourp_padding));
        LASSERTF((int)offsetof(struct object_update_reply, ourp_lens) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct object_update_reply, ourp_lens));
+       LASSERTF((int)sizeof(*((struct object_update_reply *)0)->ourp_lens) == 2, "found %lld\n",
+                (long long)(int)sizeof(*((struct object_update_reply *)0)->ourp_lens));
        BUILD_BUG_ON(offsetof(struct object_update_reply, ourp_lens) != sizeof(struct object_update_reply));
        BUILD_BUG_ON(UPDATE_REPLY_MAGIC != 0x00BD0002);
 
@@ -5812,6 +5828,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(((struct out_update_header *)0)->ouh_reply_size));
        LASSERTF((int)offsetof(struct out_update_header, ouh_inline_data) == 16, "found %lld\n",
                 (long long)(int)offsetof(struct out_update_header, ouh_inline_data));
+       LASSERTF((int)sizeof(*((struct out_update_header *)0)->ouh_inline_data) == 4, "found %lld\n",
+                (long long)(int)sizeof(*((struct out_update_header *)0)->ouh_inline_data));
        BUILD_BUG_ON(offsetof(struct out_update_header, ouh_inline_data) != sizeof(struct out_update_header));
        BUILD_BUG_ON(OUT_UPDATE_HEADER_MAGIC != 0xBDDF0001);
        BUILD_BUG_ON(OUT_UPDATE_MAX_INLINE_SIZE != 4096);