Whamcloud - gitweb
LU-9679 obdclass: use OBD_ALLOC_PTR_ARRAY() and others 21/38121/4
authorMr NeilBrown <neilb@suse.de>
Thu, 14 Nov 2019 03:20:01 +0000 (14:20 +1100)
committerOleg Drokin <green@whamcloud.com>
Thu, 14 May 2020 05:38:36 +0000 (05:38 +0000)
Use:
  OBD_ALLOC_PTR_ARRAY
  OBD_ALLOC_PTR_ARRAY_WAIT
  OBD_FREE_PTR_ARRAY
  OBD_ALLOC_PTR_ARRAY_LARGE
  OBD_FREE_PTR_ARRAY_LARGE

for allocating and freeing arrays in obdclass

Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I2ebf853769a9711f1f99431aa7f69a18ba2ea552
Reviewed-on: https://review.whamcloud.com/38121
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/obdclass/cl_object.c
lustre/obdclass/lu_object.c
lustre/obdclass/lustre_handles.c
lustre/obdclass/obd_mount.c

index 9844ed0..730deb9 100644 (file)
@@ -1074,7 +1074,7 @@ int cl_global_init(void)
 {
        int result;
 
-       OBD_ALLOC(cl_envs, sizeof(*cl_envs) * num_possible_cpus());
+       OBD_ALLOC_PTR_ARRAY(cl_envs, num_possible_cpus());
        if (cl_envs == NULL)
                GOTO(out, result = -ENOMEM);
 
@@ -1098,7 +1098,7 @@ out_keys:
 out_kmem:
        lu_kmem_fini(cl_object_caches);
 out_envs:
-       OBD_FREE(cl_envs, sizeof(*cl_envs) * num_possible_cpus());
+       OBD_FREE_PTR_ARRAY(cl_envs, num_possible_cpus());
 out:
        return result;
 }
@@ -1119,5 +1119,5 @@ void cl_global_fini(void)
        cl_env_percpu_fini();
        lu_context_key_degister(&cl_key);
        lu_kmem_fini(cl_object_caches);
-       OBD_FREE(cl_envs, sizeof(*cl_envs) * num_possible_cpus());
+       OBD_FREE_PTR_ARRAY(cl_envs, num_possible_cpus());
 }
index 916ad94..62d4521 100644 (file)
@@ -1157,7 +1157,7 @@ int lu_site_init(struct lu_site *s, struct lu_device *top)
        s->ls_bkt_cnt = max_t(long, 1 << LU_SITE_BKT_BITS,
                              2 * num_possible_cpus());
        s->ls_bkt_cnt = roundup_pow_of_two(s->ls_bkt_cnt);
-       OBD_ALLOC_LARGE(s->ls_bkts, s->ls_bkt_cnt * sizeof(*bkt));
+       OBD_ALLOC_PTR_ARRAY_LARGE(s->ls_bkts, s->ls_bkt_cnt);
        if (!s->ls_bkts) {
                cfs_hash_putref(s->ls_obj_hash);
                s->ls_obj_hash = NULL;
@@ -1171,14 +1171,14 @@ int lu_site_init(struct lu_site *s, struct lu_device *top)
                init_waitqueue_head(&bkt->lsb_waitq);
        }
 
-        s->ls_stats = lprocfs_alloc_stats(LU_SS_LAST_STAT, 0);
-        if (s->ls_stats == NULL) {
-               OBD_FREE_LARGE(s->ls_bkts, s->ls_bkt_cnt * sizeof(*bkt));
+       s->ls_stats = lprocfs_alloc_stats(LU_SS_LAST_STAT, 0);
+       if (s->ls_stats == NULL) {
+               OBD_FREE_PTR_ARRAY_LARGE(s->ls_bkts, s->ls_bkt_cnt);
                cfs_hash_putref(s->ls_obj_hash);
-                s->ls_obj_hash = NULL;
+               s->ls_obj_hash = NULL;
                s->ls_bkts = NULL;
-                return -ENOMEM;
-        }
+               return -ENOMEM;
+       }
 
         lprocfs_counter_init(s->ls_stats, LU_SS_CREATED,
                              0, "created", "created");
@@ -1224,7 +1224,7 @@ void lu_site_fini(struct lu_site *s)
                 s->ls_obj_hash = NULL;
         }
 
-       OBD_FREE_LARGE(s->ls_bkts, s->ls_bkt_cnt * sizeof(*s->ls_bkts));
+       OBD_FREE_PTR_ARRAY_LARGE(s->ls_bkts, s->ls_bkt_cnt);
 
         if (s->ls_top_dev != NULL) {
                 s->ls_top_dev->ld_site = NULL;
@@ -1700,7 +1700,7 @@ static void keys_fini(struct lu_context *ctx)
        for (i = 0; i < ARRAY_SIZE(lu_keys); ++i)
                key_fini(ctx, i);
 
-       OBD_FREE(ctx->lc_value, ARRAY_SIZE(lu_keys) * sizeof ctx->lc_value[0]);
+       OBD_FREE_PTR_ARRAY(ctx->lc_value, ARRAY_SIZE(lu_keys));
        ctx->lc_value = NULL;
 }
 
@@ -1768,7 +1768,7 @@ static int keys_fill(struct lu_context *ctx)
 
 static int keys_init(struct lu_context *ctx)
 {
-       OBD_ALLOC(ctx->lc_value, ARRAY_SIZE(lu_keys) * sizeof ctx->lc_value[0]);
+       OBD_ALLOC_PTR_ARRAY(ctx->lc_value, ARRAY_SIZE(lu_keys));
        if (likely(ctx->lc_value != NULL))
                return keys_fill(ctx);
 
index 27f6971..061090a 100644 (file)
@@ -166,7 +166,7 @@ int class_handle_init(void)
 
        LASSERT(handle_hash == NULL);
 
-       OBD_ALLOC_LARGE(handle_hash, sizeof(*bucket) * HANDLE_HASH_SIZE);
+       OBD_ALLOC_PTR_ARRAY_LARGE(handle_hash, HANDLE_HASH_SIZE);
        if (handle_hash == NULL)
                return -ENOMEM;
 
@@ -212,7 +212,7 @@ void class_handle_cleanup(void)
 
        count = cleanup_all_handles();
 
-       OBD_FREE_LARGE(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE);
+       OBD_FREE_PTR_ARRAY_LARGE(handle_hash, HANDLE_HASH_SIZE);
        handle_hash = NULL;
 
        if (count != 0)
index cd9c7d4..5edc929 100644 (file)
@@ -1033,7 +1033,7 @@ static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
        devmax = strlen(ptr) / 8 + 1;
 
        /* temp storage until we figure out how many we have */
-       OBD_ALLOC(exclude_list, sizeof(index) * devmax);
+       OBD_ALLOC_PTR_ARRAY(exclude_list, devmax);
        if (!exclude_list)
                RETURN(-ENOMEM);
 
@@ -1064,8 +1064,8 @@ static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
 
        if (lmd->lmd_exclude_count) {
                /* permanent, freed in lustre_free_lsi */
-               OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
-                         lmd->lmd_exclude_count);
+               OBD_ALLOC_PTR_ARRAY(lmd->lmd_exclude,
+                                   lmd->lmd_exclude_count);
                if (lmd->lmd_exclude) {
                        memcpy(lmd->lmd_exclude, exclude_list,
                               sizeof(index) * lmd->lmd_exclude_count);
@@ -1074,7 +1074,7 @@ static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
                        lmd->lmd_exclude_count = 0;
                }
        }
-       OBD_FREE(exclude_list, sizeof(index) * devmax);
+       OBD_FREE_PTR_ARRAY(exclude_list, devmax);
        RETURN(rc);
 }