From a9cfa645d9b940b6a1c6688422aba7084101b2ad Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Wed, 24 Jan 2024 23:35:37 +0800 Subject: [PATCH] EX-9029 lfs: not iterate compr_type_table using ARRAY_SIZE EX-8311 patch modifies compr_type_table to contain NULL fields in the array, so iterate over the array should not use ARRAY_SIZE, but skip those elements with NULL compression type name. Fixes: ec5814c9a7 ("EX-8311 csdc: allow specify 'fast'/'best' compression type") Signed-off-by: Bobi Jam Change-Id: I8e4988fd3a63c1cb66f75510d190c2ebc4f8f9be Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53808 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/include/uapi/linux/lustre/lustre_user.h | 10 +++++++--- lustre/obdclass/lustre_compr.c | 4 +++- lustre/utils/liblustreapi.c | 10 ++++++++-- lustre/utils/liblustreapi_layout.c | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 958b9c0..761cc70 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -3088,9 +3088,11 @@ static const struct compr_type_name { static inline const char *compress_type_2str(__u8 compr_type) { bool found = false; - int i = 0; + int i; - for (i = 0; compr_type_table[i].ctn_name != NULL; i++) { + for (i = LL_COMPR_TYPE_NONE; i < LL_COMPR_TYPE_MAX; i++) { + if (compr_type_table[i].ctn_name == NULL) + continue; if (compr_type == compr_type_table[i].ctn_compr_type) { found = true; break; @@ -3107,7 +3109,9 @@ static inline int mapback_compress_level(enum ll_compr_type type, __u8 level) int i; bool known_type = false; - for (i = 0; compr_type_table[i].ctn_name != NULL; i++) { + for (i = LL_COMPR_TYPE_NONE; i < LL_COMPR_TYPE_MAX; i++) { + if (compr_type_table[i].ctn_name == NULL) + continue; if (compr_type_table[i].ctn_compr_type == type) { known_type = true; if (compr_type_table[i].ctn_to_compr_level != NULL) diff --git a/lustre/obdclass/lustre_compr.c b/lustre/obdclass/lustre_compr.c index 5f090e5..616d411 100644 --- a/lustre/obdclass/lustre_compr.c +++ b/lustre/obdclass/lustre_compr.c @@ -493,7 +493,9 @@ int compress_str2type(char *s_type, enum ll_compr_type *type, int i; int rc = 0; - for (i = 0; compr_type_table[i].ctn_name != NULL; i++) { + for (i = LL_COMPR_TYPE_NONE; i < LL_COMPR_TYPE_MAX; i++) { + if (compr_type_table[i].ctn_name == NULL) + continue; if (strcmp(s_type, compr_type_table[i].ctn_name) == 0) { *type = compr_type_table[i].ctn_compr_type; diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index eae8d25..1370fd1 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4371,7 +4371,10 @@ static int find_check_compress(struct find_param *param) found_type = true; if (param->fp_check_compr_lvl) { - for (j = 0; j < ARRAY_SIZE(compr_type_table); j++) { + for (j = LL_COMPR_TYPE_NONE; + j < LL_COMPR_TYPE_MAX; j++) { + if (compr_type_table[j].ctn_name == NULL) + continue; if (compr_type_table[j].ctn_compr_type != entry->lcme_compr_type) continue; @@ -4394,7 +4397,10 @@ static int find_check_compress(struct find_param *param) } if (param->fp_check_compr_chunk) { - for (j = 0; j < ARRAY_SIZE(compr_type_table); j++) { + for (j = LL_COMPR_TYPE_NONE; + j < LL_COMPR_TYPE_MAX; j++) { + if (compr_type_table[j].ctn_name == NULL) + continue; if (compr_type_table[j].ctn_compr_type != entry->lcme_compr_type) continue; diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index d27582b..3c24a6f 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -1550,7 +1550,9 @@ int llapi_parse_compress_type(const char *optarg, unsigned int *type, *sign = '\0'; } - for (i = 0; i < ARRAY_SIZE(compr_type_table); i++) { + for (i = LL_COMPR_TYPE_NONE; i < LL_COMPR_TYPE_MAX; i++) { + if (compr_type_table[i].ctn_name == NULL) + continue; if (strcmp(argbuf, compr_type_table[i].ctn_name) == 0) { *type = compr_type_table[i].ctn_compr_type; found = true; @@ -1617,7 +1619,9 @@ int llapi_layout_compress_set(struct llapi_layout *layout, printed = true; } - for (i = 0; i < ARRAY_SIZE(compr_type_table); i++) { + for (i = LL_COMPR_TYPE_NONE; i < LL_COMPR_TYPE_MAX; i++) { + if (compr_type_table[i].ctn_name == NULL) + continue; if (compr_type_table[i].ctn_compr_type == type) { if (compr_type_table[i].ctn_from_compr_level != NULL) { comp->llc_compr_lvl = compr_type_table[i]. -- 1.8.3.1