Whamcloud - gitweb
EX-9029 lfs: not iterate compr_type_table using ARRAY_SIZE
authorBobi Jam <bobijam@whamcloud.com>
Wed, 24 Jan 2024 15:35:37 +0000 (23:35 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Mon, 29 Jan 2024 08:57:18 +0000 (08:57 +0000)
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 <bobijam@whamcloud.com>
Change-Id: I8e4988fd3a63c1cb66f75510d190c2ebc4f8f9be
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53808
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/obdclass/lustre_compr.c
lustre/utils/liblustreapi.c
lustre/utils/liblustreapi_layout.c

index 958b9c0..761cc70 100644 (file)
@@ -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)
index 5f090e5..616d411 100644 (file)
@@ -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;
 
index eae8d25..1370fd1 100644 (file)
@@ -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;
index d27582b..3c24a6f 100644 (file)
@@ -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].