From e85e6cea15a77795cd4d46452463641fd2948a8d Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Mon, 27 Apr 2020 14:47:39 +1000 Subject: [PATCH] LU-6142 osd-ldiskfs: convert container_of0() to container_of() Every use of container_of0() in osd-ldiskfs can safely use container_of() instead. Doing so makes the intent of the code clearer. In most cases, the pointer returned is later dereferenced without any subsequent checks. In a few cases (e.g. osd_obj()), the pointer passed in is dereferenced before the container_of() call. These patterns assure us that the pointer in valid (not NULL or an ERR_PTR), so container_of() is the correct interface to use. Signed-off-by: Mr NeilBrown Change-Id: I11cb51cd2dc459a3ab5c420ef7bf3324a28eeffc Reviewed-on: https://review.whamcloud.com/38378 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alexander Boyko Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/osd-ldiskfs/osd_handler.c | 50 +++++++++++++++++++-------------------- lustre/osd-ldiskfs/osd_internal.h | 12 +++++----- lustre/osd-ldiskfs/osd_io.c | 16 ++++++------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 8771715..027ded0 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -1712,7 +1712,7 @@ static int osd_param_is_not_sane(const struct osd_device *dev, static void osd_trans_commit_cb(struct super_block *sb, struct ldiskfs_journal_cb_entry *jcb, int error) { - struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb); + struct osd_thandle *oh = container_of(jcb, struct osd_thandle, ot_jcb); struct thandle *th = &oh->ot_super; struct lu_device *lud = &th->th_dev->dd_lu_dev; struct dt_txn_commit_cb *dcb, *tmp; @@ -1797,7 +1797,7 @@ void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th) struct osd_thread_info *oti = osd_oti_get(env); struct osd_thandle *oh; - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh != NULL); CWARN(" create: %u/%u/%u, destroy: %u/%u/%u\n", @@ -1856,7 +1856,7 @@ static int osd_trans_start(const struct lu_env *env, struct dt_device *d, LASSERT(current->journal_info == NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh != NULL); LASSERT(oh->ot_handle == NULL); @@ -1985,7 +1985,7 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, ENTRY; - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); remove_agents = oh->ot_remove_agents; @@ -2070,8 +2070,8 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb) { - struct osd_thandle *oh = container_of0(th, struct osd_thandle, - ot_super); + struct osd_thandle *oh = container_of(th, struct osd_thandle, + ot_super); LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC); LASSERT(&dcb->dcb_func != NULL); @@ -2793,7 +2793,7 @@ static int osd_declare_attr_set(const struct lu_env *env, obj = osd_dt_obj(dt); LASSERT(osd_invariant(obj)); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); osd_trans_declare_op(env, oh, OSD_OT_ATTR_SET, @@ -3059,7 +3059,7 @@ static int osd_attr_set(const struct lu_env *env, if (unlikely(ipd == NULL)) RETURN(-ENOMEM); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)fid1, (const struct iam_rec *)id, ipd); @@ -3453,7 +3453,7 @@ static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj, LASSERT(obj->oo_inode != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle); osd_trans_exec_op(env, th, OSD_OT_INSERT); @@ -3519,7 +3519,7 @@ static int osd_declare_create(const struct lu_env *env, struct dt_object *dt, LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); /* @@ -3577,7 +3577,7 @@ static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt, if (inode == NULL) RETURN(-ENOENT); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); osd_trans_declare_op(env, oh, OSD_OT_DESTROY, @@ -3628,7 +3628,7 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt, ENTRY; - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle); LASSERT(inode); LASSERT(!lu_object_is_dying(dt->do_lu.lo_header)); @@ -4087,7 +4087,7 @@ static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt, /* it's possible that object doesn't exist yet */ LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); osd_trans_declare_op(env, oh, OSD_OT_REF_ADD, @@ -4117,7 +4117,7 @@ static int osd_ref_add(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_is_write_locked(env, obj)); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle != NULL); osd_trans_exec_op(env, th, OSD_OT_REF_ADD); @@ -4165,7 +4165,7 @@ static int osd_declare_ref_del(const struct lu_env *env, struct dt_object *dt, LASSERT(!dt_object_remote(dt)); LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); osd_trans_declare_op(env, oh, OSD_OT_REF_DEL, @@ -4193,7 +4193,7 @@ static int osd_ref_del(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_is_write_locked(env, obj)); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle != NULL); osd_trans_exec_op(env, th, OSD_OT_REF_DEL); @@ -4344,7 +4344,7 @@ static int osd_declare_xattr_set(const struct lu_env *env, LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); if (strcmp(name, XATTR_NAME_LMA) == 0) { @@ -4563,7 +4563,7 @@ static int osd_xattr_handle_linkea(const struct lu_env *env, ENTRY; - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle != NULL); rc = linkea_init_with_rec(&ldata); @@ -4732,7 +4732,7 @@ static int osd_declare_xattr_del(const struct lu_env *env, LASSERT(!dt_object_remote(dt)); LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, @@ -5033,7 +5033,7 @@ static int osd_index_declare_iam_delete(const struct lu_env *env, { struct osd_thandle *oh; - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); /* Recycle may cause additional three blocks to be changed. */ @@ -5081,7 +5081,7 @@ static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt, if (unlikely(ipd == NULL)) RETURN(-ENOMEM); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle != NULL); LASSERT(oh->ot_handle->h_transaction != NULL); @@ -5112,7 +5112,7 @@ static int osd_index_declare_ea_delete(const struct lu_env *env, LASSERT(!dt_object_remote(dt)); LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); credits = osd_dto_credits_noquota[DTO_INDEX_DELETE]; @@ -5375,7 +5375,7 @@ static int osd_index_declare_iam_insert(const struct lu_env *env, LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); osd_trans_declare_op(env, oh, OSD_OT_INSERT, @@ -5425,7 +5425,7 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt, if (unlikely(ipd == NULL)) RETURN(-ENOMEM); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_handle != NULL); LASSERT(oh->ot_handle->h_transaction != NULL); if (S_ISDIR(obj->oo_inode->i_mode)) { @@ -6020,7 +6020,7 @@ static int osd_index_declare_ea_insert(const struct lu_env *env, LASSERT(fid != NULL); LASSERT(rec1->rec_type != 0); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_handle == NULL); credits = osd_dto_credits_noquota[DTO_INDEX_INSERT]; diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 8419834..0ebba32 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -1011,14 +1011,14 @@ static inline int lu_device_is_osd(const struct lu_device *d) static inline struct osd_device *osd_dt_dev(const struct dt_device *d) { - LASSERT(lu_device_is_osd(&d->dd_lu_dev)); - return container_of0(d, struct osd_device, od_dt_dev); + LASSERT(lu_device_is_osd(&d->dd_lu_dev)); + return container_of(d, struct osd_device, od_dt_dev); } static inline struct osd_device *osd_dev(const struct lu_device *d) { - LASSERT(lu_device_is_osd(d)); - return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev)); + LASSERT(lu_device_is_osd(d)); + return osd_dt_dev(container_of(d, struct dt_device, dd_lu_dev)); } static inline struct osd_device *osd_obj2dev(const struct osd_object *o) @@ -1059,8 +1059,8 @@ static inline int osd_object_is_root(const struct osd_object *obj) static inline struct osd_object *osd_obj(const struct lu_object *o) { - LASSERT(lu_device_is_osd(o->lo_dev)); - return container_of0(o, struct osd_object, oo_dt.do_lu); + LASSERT(lu_device_is_osd(o->lo_dev)); + return container_of(o, struct osd_object, oo_dt.do_lu); } static inline struct osd_object *osd_dt_obj(const struct dt_object *d) diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index b3e4c07..88b4c35 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -1120,13 +1120,13 @@ static int osd_declare_write_commit(const struct lu_env *env, enum osd_qid_declare_flags declare_flags = OSD_QID_BLK; ENTRY; - LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle == NULL); + LASSERT(handle != NULL); + oh = container_of(handle, struct osd_thandle, ot_super); + LASSERT(oh->ot_handle == NULL); - newblocks = npages; + newblocks = npages; - /* calculate number of extents (probably better to pass nb) */ + /* calculate number of extents (probably better to pass nb) */ for (i = 0; i < npages; i++) { if (i && lnb[i].lnb_file_offset != lnb[i - 1].lnb_file_offset + lnb[i - 1].lnb_len) @@ -1586,10 +1586,10 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt, ENTRY; LASSERT(buf != NULL); - LASSERT(handle != NULL); + LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle == NULL); + oh = container_of(handle, struct osd_thandle, ot_super); + LASSERT(oh->ot_handle == NULL); size = buf->lb_len; bits = sb->s_blocksize_bits; -- 1.8.3.1