From 339b585c257d7f47d0c9b74f9d940fd20b8c04a3 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Fri, 26 Apr 2024 18:24:34 +0700 Subject: [PATCH] LU-17784 build: improve wiretest for flexible arrays Flexible array checking can additionally probe that the size of the array element is correct. Signed-off-by: Shaun Tancheff Change-Id: Ib7de3d156a2e77dfaf2e9ab1df8fab524c073610 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54929 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/ptlrpc/wiretest.c | 25 +++++++++++++++++++++---- lustre/utils/wirecheck.c | 10 ++++++++-- lustre/utils/wiretest.c | 24 +++++++++++++++++++++--- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/lustre/ptlrpc/wiretest.c b/lustre/ptlrpc/wiretest.c index 8ed8574..c85dc3b 100644 --- a/lustre/ptlrpc/wiretest.c +++ b/lustre/ptlrpc/wiretest.c @@ -2019,10 +2019,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); @@ -4995,6 +4996,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); @@ -5210,6 +5213,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 */ @@ -5680,6 +5685,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 */ @@ -5715,6 +5722,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); @@ -5738,6 +5747,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); @@ -5758,6 +5769,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 */ @@ -5777,6 +5790,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); @@ -5801,6 +5816,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); diff --git a/lustre/utils/wirecheck.c b/lustre/utils/wirecheck.c index 1e0c0d6..e427c56 100644 --- a/lustre/utils/wirecheck.c +++ b/lustre/utils/wirecheck.c @@ -141,14 +141,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) @@ -960,7 +966,7 @@ check_lov_comp_md_v1(void) CHECK_MEMBER(lov_comp_md_v1, lcm_padding3); 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); diff --git a/lustre/utils/wiretest.c b/lustre/utils/wiretest.c index f881309..42c4154 100644 --- a/lustre/utils/wiretest.c +++ b/lustre/utils/wiretest.c @@ -1657,7 +1657,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); @@ -2044,8 +2044,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", @@ -5019,6 +5021,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); @@ -5234,6 +5238,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 */ @@ -5704,6 +5710,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 */ @@ -5739,6 +5747,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); @@ -5762,6 +5772,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); @@ -5782,6 +5794,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 */ @@ -5801,6 +5815,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); @@ -5825,6 +5841,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); -- 1.8.3.1