From d9ceaf48c61cfbe1c600804d6f840b21bc000a83 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Mon, 27 Apr 2020 14:53:12 +1000 Subject: [PATCH] LU-6142 osd-zfs: convert container_of0() to container_of() Every use of container_of0() in osd-zfs 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. in osd_internal.h), 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: I3f6d35c8b5beee09561e78c5eb20bb89d322590b Reviewed-on: https://review.whamcloud.com/38379 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Olaf Faaland-LLNL Reviewed-by: Oleg Drokin --- lustre/osd-zfs/osd_handler.c | 8 ++++---- lustre/osd-zfs/osd_index.c | 16 ++++++++-------- lustre/osd-zfs/osd_internal.h | 6 +++--- lustre/osd-zfs/osd_io.c | 12 ++++++------ lustre/osd-zfs/osd_object.c | 16 ++++++++-------- lustre/osd-zfs/osd_xattr.c | 8 ++++---- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index fb3e7de..f60f549 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -175,8 +175,8 @@ static void osd_trans_commit_cb(void *cb_data, int error) 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); @@ -200,7 +200,7 @@ static int osd_trans_start(const struct lu_env *env, struct dt_device *d, ENTRY; - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh); LASSERT(oh->ot_tx); @@ -285,7 +285,7 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt, int rc; ENTRY; - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); list_splice_init(&oh->ot_unlinked_list, &unlinked); osd_oti_get(env)->oti_ins_cache_depth--; diff --git a/lustre/osd-zfs/osd_index.c b/lustre/osd-zfs/osd_index.c index 226e304..f11a6e4 100644 --- a/lustre/osd-zfs/osd_index.c +++ b/lustre/osd-zfs/osd_index.c @@ -901,7 +901,7 @@ static int osd_declare_dir_insert(const struct lu_env *env, LASSERT(rec1->rec_type != 0); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); idc = osd_idc_find_or_init(env, osd, fid); if (IS_ERR(idc)) @@ -1015,7 +1015,7 @@ static int osd_dir_insert(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_invariant(parent)); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); idc = osd_idc_find(env, osd, fid); if (unlikely(idc == NULL)) { @@ -1122,7 +1122,7 @@ static int osd_declare_dir_delete(const struct lu_env *env, LASSERT(zap_dn != NULL); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); /* * In Orion . and .. were stored in the directory (not generated upon @@ -1161,7 +1161,7 @@ static int osd_dir_delete(const struct lu_env *env, struct dt_object *dt, LASSERT(zap_dn); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); /* * In Orion . and .. were stored in the directory (not generated upon @@ -1769,7 +1769,7 @@ static int osd_declare_index_insert(const struct lu_env *env, ENTRY; LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(obj->oo_dn); @@ -1798,7 +1798,7 @@ static int osd_index_insert(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_invariant(obj)); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); rc = osd_prepare_key_uint64(obj, k, key); @@ -1823,7 +1823,7 @@ static int osd_declare_index_delete(const struct lu_env *env, LASSERT(th != NULL); LASSERT(obj->oo_dn); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); /* do not specify the key as then DMU is trying to look it up * which is very expensive. usually the layers above lookup @@ -1846,7 +1846,7 @@ static int osd_index_delete(const struct lu_env *env, struct dt_object *dt, LASSERT(obj->oo_dn); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); rc = osd_prepare_key_uint64(obj, k, key); diff --git a/lustre/osd-zfs/osd_internal.h b/lustre/osd-zfs/osd_internal.h index dde36de..443a1ed 100644 --- a/lustre/osd-zfs/osd_internal.h +++ b/lustre/osd-zfs/osd_internal.h @@ -493,19 +493,19 @@ static inline int lu_device_is_osd(const struct lu_device *d) 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); + return container_of(o, struct osd_object, oo_dt.do_lu); } 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); + 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)); + return osd_dt_dev(container_of(d, struct dt_device, dd_lu_dev)); } static inline struct osd_object *osd_dt_obj(const struct dt_object *d) diff --git a/lustre/osd-zfs/osd_io.c b/lustre/osd-zfs/osd_io.c index 0117810..a4c5f35 100644 --- a/lustre/osd-zfs/osd_io.c +++ b/lustre/osd-zfs/osd_io.c @@ -174,7 +174,7 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt, uint64_t oid; ENTRY; - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); /* in some cases declare can race with creation (e.g. llog) * and we need to wait till object is initialized. notice @@ -219,7 +219,7 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt, LASSERT(obj->oo_dn); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); osd_dmu_write(osd, obj->oo_dn, offset, (uint64_t)buf->lb_len, buf->lb_buf, oh->ot_tx); @@ -647,7 +647,7 @@ static int osd_declare_write_commit(const struct lu_env *env, LASSERT(lnb); LASSERT(npages > 0); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); for (i = 0; i < npages; i++) { if (last_page && lnb[i].lnb_page->index != (last_page->index + 1)) @@ -833,7 +833,7 @@ static int osd_write_commit(const struct lu_env *env, struct dt_object *dt, LASSERT(obj->oo_dn); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); /* adjust block size. Assume the buffers are sorted. */ (void)osd_grow_blocksize(obj, oh, lnb[0].lnb_file_offset, @@ -1051,7 +1051,7 @@ static int osd_punch(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_invariant(obj)); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); write_lock(&obj->oo_attr_lock); /* truncate */ @@ -1083,7 +1083,7 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt, __u64 len; ENTRY; - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); read_lock(&obj->oo_attr_lock); if (end == OBD_OBJECT_EOF || end >= obj->oo_attr.la_size) diff --git a/lustre/osd-zfs/osd_object.c b/lustre/osd-zfs/osd_object.c index c41a42f..cc8f1da 100644 --- a/lustre/osd-zfs/osd_object.c +++ b/lustre/osd-zfs/osd_object.c @@ -759,7 +759,7 @@ static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt, LASSERT(th != NULL); LASSERT(dt_object_exists(dt)); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(oh->ot_tx != NULL); dmu_tx_mark_netfree(oh->ot_tx); @@ -825,7 +825,7 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt, LASSERT(obj->oo_dn != 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_tx != NULL); @@ -1119,7 +1119,7 @@ static int osd_declare_attr_set(const struct lu_env *env, LASSERT(handle != NULL); LASSERT(osd_invariant(obj)); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); down_read(&obj->oo_guard); if (unlikely(!dt_object_exists(dt) || obj->oo_destroyed)) @@ -1255,7 +1255,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_invariant(obj)); LASSERT(obj->oo_sa_hdl); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); /* Assert that the transaction has been assigned to a transaction group. */ LASSERT(oh->ot_tx->tx_txg != 0); @@ -1475,7 +1475,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_tx != NULL); /* this is the minimum set of EAs on every Lustre object */ @@ -1932,7 +1932,7 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt, LASSERT(dof != NULL); LASSERT(th != NULL); - oh = container_of0(th, struct osd_thandle, ot_super); + oh = container_of(th, struct osd_thandle, ot_super); LASSERT(obj->oo_dn == NULL); @@ -2054,7 +2054,7 @@ static int osd_ref_add(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_invariant(obj)); LASSERT(obj->oo_sa_hdl != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); write_lock(&obj->oo_attr_lock); nlink = ++obj->oo_attr.la_nlink; @@ -2096,7 +2096,7 @@ static int osd_ref_del(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_invariant(obj)); LASSERT(obj->oo_sa_hdl != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(!lu_object_is_dying(dt->do_lu.lo_header)); write_lock(&obj->oo_attr_lock); diff --git a/lustre/osd-zfs/osd_xattr.c b/lustre/osd-zfs/osd_xattr.c index 4683a17..0db69f3 100644 --- a/lustre/osd-zfs/osd_xattr.c +++ b/lustre/osd-zfs/osd_xattr.c @@ -414,7 +414,7 @@ int osd_declare_xattr_set(const struct lu_env *env, struct dt_object *dt, ENTRY; LASSERT(handle != NULL); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); down_read(&obj->oo_guard); __osd_xattr_declare_set(env, obj, buf->lb_len, name, oh); @@ -876,7 +876,7 @@ int osd_xattr_set(const struct lu_env *env, struct dt_object *dt, strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) RETURN(-EOPNOTSUPP); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); down_write(&obj->oo_guard); CDEBUG(D_INODE, "Setting xattr %s with size %d\n", @@ -946,7 +946,7 @@ int osd_declare_xattr_del(const struct lu_env *env, struct dt_object *dt, LASSERT(handle != NULL); 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_tx != NULL); LASSERT(obj->oo_dn != NULL); @@ -1032,7 +1032,7 @@ int osd_xattr_del(const struct lu_env *env, struct dt_object *dt, LASSERT(obj->oo_dn != NULL); LASSERT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); - oh = container_of0(handle, struct osd_thandle, ot_super); + oh = container_of(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_tx != NULL); if (!osd_obj2dev(obj)->od_posix_acl && -- 1.8.3.1