Whamcloud - gitweb
LU-9679 osd: use OBD_ALLOC_PTR_ARRAY() and others 52/38252/3
authorMr NeilBrown <neilb@suse.de>
Thu, 14 Nov 2019 03:20:01 +0000 (14:20 +1100)
committerOleg Drokin <green@whamcloud.com>
Thu, 7 May 2020 05:42:51 +0000 (05:42 +0000)
Use:
  OBD_ALLOC_PTR_ARRAY
  OBD_FREE_PTR_ARRAY
  OBD_ALLOC_PTR_ARRAY_LARGE
  OBD_FREE_PTR_ARRAY_LARGE

for allocating and freeing arrays in osd-ldiskfs and osd-zfs.

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Iec2ec54e0b87aeefb42d5b4ab802c564850f6edd
Reviewed-on: https://review.whamcloud.com/38252
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/osd-ldiskfs/osd_compat.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_io.c
lustre/osd-ldiskfs/osd_oi.c
lustre/osd-zfs/osd_handler.c
lustre/osd-zfs/osd_oi.c

index 2150f28..8b70faf 100644 (file)
@@ -546,8 +546,8 @@ static void osd_seq_free(struct osd_obj_seq *osd_seq)
                        if (osd_seq->oos_dirs[j])
                                dput(osd_seq->oos_dirs[j]);
                }
-               OBD_FREE(osd_seq->oos_dirs,
-                        sizeof(struct dentry *) * osd_seq->oos_subdir_count);
+               OBD_FREE_PTR_ARRAY(osd_seq->oos_dirs,
+                                  osd_seq->oos_subdir_count);
        }
 
        if (osd_seq->oos_root)
@@ -972,8 +972,7 @@ static int osd_seq_load_locked(struct osd_thread_info *info,
        osd_seq->oos_root = seq_dir;
 
        LASSERT(osd_seq->oos_dirs == NULL);
-       OBD_ALLOC(osd_seq->oos_dirs,
-                 sizeof(seq_dir) * osd_seq->oos_subdir_count);
+       OBD_ALLOC_PTR_ARRAY(osd_seq->oos_dirs, osd_seq->oos_subdir_count);
        if (osd_seq->oos_dirs == NULL)
                GOTO(out_put, rc = -ENOMEM);
 
@@ -1000,8 +999,8 @@ out_free:
                        if (osd_seq->oos_dirs[i] != NULL)
                                dput(osd_seq->oos_dirs[i]);
                }
-               OBD_FREE(osd_seq->oos_dirs,
-                        sizeof(seq_dir) * osd_seq->oos_subdir_count);
+               OBD_FREE_PTR_ARRAY(osd_seq->oos_dirs,
+                                  osd_seq->oos_subdir_count);
 out_put:
                dput(seq_dir);
                osd_seq->oos_root = NULL;
index 8d8d8b4..62df1ef 100644 (file)
@@ -209,14 +209,14 @@ osd_idc_add(const struct lu_env *env, struct osd_device *osd,
                i = oti->oti_ins_cache_size * 2;
                if (i == 0)
                        i = OSD_INS_CACHE_SIZE;
-               OBD_ALLOC(idc, sizeof(*idc) * i);
+               OBD_ALLOC_PTR_ARRAY(idc, i);
                if (idc == NULL)
                        return ERR_PTR(-ENOMEM);
                if (oti->oti_ins_cache != NULL) {
                        memcpy(idc, oti->oti_ins_cache,
                               oti->oti_ins_cache_used * sizeof(*idc));
-                       OBD_FREE(oti->oti_ins_cache,
-                                oti->oti_ins_cache_used * sizeof(*idc));
+                       OBD_FREE_PTR_ARRAY(oti->oti_ins_cache,
+                                          oti->oti_ins_cache_used);
                }
                oti->oti_ins_cache = idc;
                oti->oti_ins_cache_size = i;
@@ -7374,8 +7374,7 @@ static void osd_key_fini(const struct lu_context *ctx,
                                __free_page(page);
                        }
                }
-               OBD_FREE(info->oti_dio_pages,
-                        sizeof(struct page *) * PTLRPC_MAX_BRW_PAGES);
+               OBD_FREE_PTR_ARRAY(info->oti_dio_pages, PTLRPC_MAX_BRW_PAGES);
        }
 
        if (info->oti_inode != NULL)
@@ -7389,7 +7388,7 @@ static void osd_key_fini(const struct lu_context *ctx,
        lu_buf_free(&info->oti_big_buf);
        if (idc != NULL) {
                LASSERT(info->oti_ins_cache_size > 0);
-               OBD_FREE(idc, sizeof(*idc) * info->oti_ins_cache_size);
+               OBD_FREE_PTR_ARRAY(idc, info->oti_ins_cache_size);
                info->oti_ins_cache = NULL;
                info->oti_ins_cache_size = 0;
        }
index ce2af33..c3df4cc 100644 (file)
@@ -857,8 +857,7 @@ static int osd_bufs_get(const struct lu_env *env, struct dt_object *dt,
 
 bypass_checks:
        if (!cache && unlikely(!oti->oti_dio_pages)) {
-               OBD_ALLOC(oti->oti_dio_pages,
-                         sizeof(struct page *) * PTLRPC_MAX_BRW_PAGES);
+               OBD_ALLOC_PTR_ARRAY(oti->oti_dio_pages, PTLRPC_MAX_BRW_PAGES);
                if (!oti->oti_dio_pages)
                        return -ENOMEM;
        }
index 1b132ad..f87d107 100644 (file)
@@ -406,7 +406,7 @@ int osd_oi_init(struct osd_thread_info *info, struct osd_device *osd,
                        RETURN(rc);
        }
 
-       OBD_ALLOC(oi, sizeof(*oi) * OSD_OI_FID_NR_MAX);
+       OBD_ALLOC_PTR_ARRAY(oi, OSD_OI_FID_NR_MAX);
        if (oi == NULL)
                RETURN(-ENOMEM);
 
@@ -490,7 +490,7 @@ create:
 
 out:
        if (rc < 0) {
-               OBD_FREE(oi, sizeof(*oi) * OSD_OI_FID_NR_MAX);
+               OBD_FREE_PTR_ARRAY(oi, OSD_OI_FID_NR_MAX);
        } else {
                LASSERTF((rc & (rc - 1)) == 0, "Invalid OI count %d\n", rc);
 
@@ -501,7 +501,7 @@ out:
                        rc = scrub_file_store(info->oti_env, scrub);
                        if (rc < 0) {
                                osd_oi_table_put(info, oi, count);
-                               OBD_FREE(oi, sizeof(*oi) * OSD_OI_FID_NR_MAX);
+                               OBD_FREE_PTR_ARRAY(oi, OSD_OI_FID_NR_MAX);
                        }
                } else {
                        rc = 0;
@@ -518,8 +518,7 @@ void osd_oi_fini(struct osd_thread_info *info, struct osd_device *osd)
 
        osd_oi_table_put(info, osd->od_oi_table, osd->od_oi_count);
 
-       OBD_FREE(osd->od_oi_table,
-                sizeof(*(osd->od_oi_table)) * OSD_OI_FID_NR_MAX);
+       OBD_FREE_PTR_ARRAY(osd->od_oi_table, OSD_OI_FID_NR_MAX);
        osd->od_oi_table = NULL;
 }
 
index 1b9d0f4..fb3e7de 100644 (file)
@@ -743,7 +743,7 @@ static void osd_key_fini(const struct lu_context *ctx,
 
        if (idc != NULL) {
                LASSERT(info->oti_ins_cache_size > 0);
-               OBD_FREE_LARGE(idc, sizeof(*idc) * info->oti_ins_cache_size);
+               OBD_FREE_PTR_ARRAY_LARGE(idc, info->oti_ins_cache_size);
                info->oti_ins_cache = NULL;
                info->oti_ins_cache_size = 0;
        }
index f62a68c..5a21b3f 100644 (file)
@@ -388,8 +388,7 @@ static struct osd_seq *osd_find_or_add_seq(const struct lu_env *env,
        /* Init subdir count to be 32, but each seq can have
         * different subdir count */
        osd_seq->os_subdir_count = OSD_OST_MAP_SIZE;
-       OBD_ALLOC(osd_seq->os_compat_dirs,
-                 sizeof(uint64_t) * osd_seq->os_subdir_count);
+       OBD_ALLOC_PTR_ARRAY(osd_seq->os_compat_dirs, osd_seq->os_subdir_count);
        if (osd_seq->os_compat_dirs == NULL)
                GOTO(out, rc = -ENOMEM);
 
@@ -421,8 +420,8 @@ out:
        up(&seq_list->osl_seq_init_sem);
        if (rc != 0) {
                if (osd_seq != NULL && osd_seq->os_compat_dirs != NULL)
-                       OBD_FREE(osd_seq->os_compat_dirs,
-                                sizeof(uint64_t) * osd_seq->os_subdir_count);
+                       OBD_FREE_PTR_ARRAY(osd_seq->os_compat_dirs,
+                                          osd_seq->os_subdir_count);
                if (osd_seq != NULL)
                        OBD_FREE_PTR(osd_seq);
                osd_seq = ERR_PTR(rc);
@@ -782,8 +781,8 @@ static void osd_ost_seq_fini(const struct lu_env *env, struct osd_device *osd)
        list_for_each_entry_safe(osd_seq, tmp, &osl->osl_seq_list,
                                 os_seq_list) {
                list_del(&osd_seq->os_seq_list);
-               OBD_FREE(osd_seq->os_compat_dirs,
-                        sizeof(uint64_t) * osd_seq->os_subdir_count);
+               OBD_FREE_PTR_ARRAY(osd_seq->os_compat_dirs,
+                                  osd_seq->os_subdir_count);
                OBD_FREE(osd_seq, sizeof(*osd_seq));
        }
        write_unlock(&osl->osl_seq_list_lock);
@@ -922,7 +921,7 @@ int osd_oi_init(const struct lu_env *env, struct osd_device *o)
 open:
        LASSERT((count & (count - 1)) == 0);
        o->od_oi_count = count;
-       OBD_ALLOC(o->od_oi_table, sizeof(*o->od_oi_table) * count);
+       OBD_ALLOC_PTR_ARRAY(o->od_oi_table, count);
        if (o->od_oi_table == NULL)
                GOTO(out, rc = -ENOMEM);
 
@@ -935,8 +934,7 @@ out:
                osd_ost_seq_fini(env, o);
 
                if (o->od_oi_table) {
-                       OBD_FREE(o->od_oi_table,
-                                sizeof(struct osd_oi *) * count);
+                       OBD_FREE_PTR_ARRAY(o->od_oi_table, count);
                        o->od_oi_table = NULL;
                }
        }
@@ -952,8 +950,7 @@ void osd_oi_fini(const struct lu_env *env, struct osd_device *o)
 
        if (o->od_oi_table != NULL) {
                (void) osd_oi_close_table(env, o);
-               OBD_FREE(o->od_oi_table,
-                        sizeof(struct osd_oi *) * o->od_oi_count);
+               OBD_FREE_PTR_ARRAY(o->od_oi_table, o->od_oi_count);
                o->od_oi_table = NULL;
                o->od_oi_count = 0;
        }
@@ -1013,14 +1010,14 @@ struct osd_idmap_cache *osd_idc_add(const struct lu_env *env,
                i = oti->oti_ins_cache_size * 2;
                if (i == 0)
                        i = OSD_INS_CACHE_SIZE;
-               OBD_ALLOC_LARGE(idc, sizeof(*idc) * i);
+               OBD_ALLOC_PTR_ARRAY_LARGE(idc, i);
                if (idc == NULL)
                        return ERR_PTR(-ENOMEM);
                if (oti->oti_ins_cache != NULL) {
                        memcpy(idc, oti->oti_ins_cache,
                               oti->oti_ins_cache_used * sizeof(*idc));
-                       OBD_FREE_LARGE(oti->oti_ins_cache,
-                                oti->oti_ins_cache_used * sizeof(*idc));
+                       OBD_FREE_PTR_ARRAY_LARGE(oti->oti_ins_cache,
+                                                oti->oti_ins_cache_used);
                }
                oti->oti_ins_cache = idc;
                oti->oti_ins_cache_size = i;