From 0d7d9aedaf4f85d97cf82888b2a5beab9dcd65c3 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Fri, 26 Apr 2024 22:25:19 +0700 Subject: [PATCH] LU-17657 build: gcc 13 stricter enum checking gcc 13 does not allow mixing of enum and integer types between function declaration and implementation. Cleanup a couple of instances where an enum is treated as an uint32_t / __u32 and treat it as an enum type. lustre/lov/lov_ea.c: In function 'lsme_unpack_comp': lustre/lov/lov_ea.c:531:21: error: array subscript 'struct lov_stripe_md_entry[0]' is partly outside array bounds of 'struct lov_stripe_md_entry[0]' [-Werror=array-bounds=] 531 | lsme->lsme_magic = magic; Signed-off-by: Shaun Tancheff Change-Id: I8e2ef989ecbdebe5e13bcea0fbb210c4a14eb45e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54468 Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: Yang Sheng Reviewed-by: James Simmons Tested-by: jenkins Tested-by: Maloo --- lustre/include/lustre/lustreapi.h | 6 +++++- lustre/include/lustre_net.h | 5 +++-- lustre/lov/lov_ea.c | 13 ++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index f5e921e..876dce6 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -1249,6 +1249,9 @@ enum llapi_layout_comp_use { LLAPI_LAYOUT_COMP_USE_LAST = 2, LLAPI_LAYOUT_COMP_USE_NEXT = 3, LLAPI_LAYOUT_COMP_USE_PREV = 4, + + /* ensure -fshort-enums keeps u32 size for interop */ + _LLAPI_LAYOUT_COMP_TYPE_SIZE = (__u32)-1, }; /** @@ -1258,7 +1261,8 @@ int llapi_layout_comp_use_id(struct llapi_layout *layout, uint32_t id); /** * Select the currently active component at the specified position. */ -int llapi_layout_comp_use(struct llapi_layout *layout, uint32_t pos); +int llapi_layout_comp_use(struct llapi_layout *layout, + enum llapi_layout_comp_use pos); /** * Add layout components to an existing file. */ diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index 7cdd4c6..762556e 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -2291,7 +2291,8 @@ int ptlrpc_reconnect_import(struct obd_import *imp); int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len); int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len); -int lustre_msg_check_version(struct lustre_msg *msg, __u32 version); +int lustre_msg_check_version(struct lustre_msg *msg, + enum lustre_msg_version version); void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens, char **bufs); int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count, @@ -2319,7 +2320,7 @@ __u32 lustre_msg_buflen(struct lustre_msg *m, __u32 n); void lustre_msg_set_buflen(struct lustre_msg *m, __u32 n, __u32 len); __u32 lustre_msg_bufcount(struct lustre_msg *m); char *lustre_msg_string(struct lustre_msg *m, __u32 n, __u32 max_len); -__u32 lustre_msghdr_get_flags(struct lustre_msg *msg); +enum lustre_msghdr lustre_msghdr_get_flags(struct lustre_msg *msg); void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags); __u32 lustre_msg_get_flags(struct lustre_msg *msg); void lustre_msg_add_flags(struct lustre_msg *msg, __u32 flags); diff --git a/lustre/lov/lov_ea.c b/lustre/lov/lov_ea.c index 45a1a65..d572e47 100644 --- a/lustre/lov/lov_ea.c +++ b/lustre/lov/lov_ea.c @@ -525,11 +525,18 @@ lsme_unpack_comp(struct lov_obd *lov, struct lov_mds_md *lmm, magic = le32_to_cpu(lmm->lmm_magic); if (!lov_supported_comp_magic(magic)) { struct lov_stripe_md_entry *lsme; + size_t lsme_sz = offsetof(typeof(*lsme), lsme_oinfo[0]); + struct lov_stripe_md_entry lsme_init = { + .lsme_pattern = le32_to_cpu(lmm->lmm_pattern), + .lsme_magic = magic, + }; /* allocate a lsme holder for invalid magic lmm */ - OBD_ALLOC_LARGE(lsme, offsetof(typeof(*lsme), lsme_oinfo[0])); - lsme->lsme_magic = magic; - lsme->lsme_pattern = le32_to_cpu(lmm->lmm_pattern); + OBD_ALLOC_LARGE(lsme, lsme_sz); + if (!lsme) + return ERR_PTR(-ENOMEM); + + memcpy(lsme, &lsme_init, lsme_sz); return lsme; } -- 1.8.3.1