From: Mr NeilBrown Date: Mon, 27 Apr 2020 05:42:38 +0000 (+1000) Subject: LU-6142 lustre: convert some container_of to *_safe X-Git-Tag: 2.13.55~186 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=46f1fc6c1ba493cd81e47917c413951a0f096d5e LU-6142 lustre: convert some container_of to *_safe Each of these uses of container_of0() cannot be determined from local inspection to always received a valid pointer, so container_of() cannot be used. So convert them to the upstream standard container_of_safe(). Signed-off-by: Mr NeilBrown Change-Id: I7d5551ae4d88bc931f7edbd3447b5bb2db8ce40c Reviewed-on: https://review.whamcloud.com/38384 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/lustre/lfsck/lfsck_internal.h b/lustre/lfsck/lfsck_internal.h index d491b2a..9292891 100644 --- a/lustre/lfsck/lfsck_internal.h +++ b/lustre/lfsck/lfsck_internal.h @@ -1109,7 +1109,8 @@ extern struct lu_context_key lfsck_thread_key; static inline struct dt_device *lfsck_obj2dev(struct dt_object *obj) { - return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev); + return container_of_safe(obj->do_lu.lo_dev, struct dt_device, + dd_lu_dev); } static inline struct lfsck_thread_info * diff --git a/lustre/llite/vvp_internal.h b/lustre/llite/vvp_internal.h index ce123d3..bb0d66e 100644 --- a/lustre/llite/vvp_internal.h +++ b/lustre/llite/vvp_internal.h @@ -260,22 +260,22 @@ static inline struct lu_device *vvp2lu_dev(struct vvp_device *vdv) static inline struct vvp_device *lu2vvp_dev(const struct lu_device *d) { - return container_of0(d, struct vvp_device, vdv_cl.cd_lu_dev); + return container_of_safe(d, struct vvp_device, vdv_cl.cd_lu_dev); } static inline struct vvp_device *cl2vvp_dev(const struct cl_device *d) { - return container_of0(d, struct vvp_device, vdv_cl); + return container_of_safe(d, struct vvp_device, vdv_cl); } static inline struct vvp_object *cl2vvp(const struct cl_object *obj) { - return container_of0(obj, struct vvp_object, vob_cl); + return container_of_safe(obj, struct vvp_object, vob_cl); } static inline struct vvp_object *lu2vvp(const struct lu_object *obj) { - return container_of0(obj, struct vvp_object, vob_cl.co_lu); + return container_of_safe(obj, struct vvp_object, vob_cl.co_lu); } static inline struct inode *vvp_object_inode(const struct cl_object *obj) diff --git a/lustre/lmv/lmv_internal.h b/lustre/lmv/lmv_internal.h index 340bd5a..c1b8a2a 100644 --- a/lustre/lmv/lmv_internal.h +++ b/lustre/lmv/lmv_internal.h @@ -66,7 +66,7 @@ int lmv_statfs_check_update(struct obd_device *obd, struct lmv_tgt_desc *tgt); static inline struct obd_device *lmv2obd_dev(struct lmv_obd *lmv) { - return container_of0(lmv, struct obd_device, u.lmv); + return container_of_safe(lmv, struct obd_device, u.lmv); } static inline struct lu_tgt_desc * diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index a371216..00fad0a 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -404,7 +404,7 @@ static inline int lu_device_is_lod(struct lu_device *d) static inline struct lod_device* lu2lod_dev(struct lu_device *d) { LASSERT(lu_device_is_lod(d)); - return container_of0(d, struct lod_device, lod_dt_dev.dd_lu_dev); + return container_of_safe(d, struct lod_device, lod_dt_dev.dd_lu_dev); } static inline struct lu_device *lod2lu_dev(struct lod_device *d) @@ -426,7 +426,7 @@ static inline struct lod_device *dt2lod_dev(struct dt_device *d) static inline struct lod_object *lu2lod_obj(struct lu_object *o) { LASSERT(ergo(o != NULL, lu_device_is_lod(o->lo_dev))); - return container_of0(o, struct lod_object, ldo_obj.do_lu); + return container_of_safe(o, struct lod_object, ldo_obj.do_lu); } static inline struct lu_object *lod2lu_obj(struct lod_object *obj) diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index 0fc99bd..a5bc753 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -440,8 +440,8 @@ static inline int lu_device_is_mdd(struct lu_device *d) static inline struct mdd_device *lu2mdd_dev(struct lu_device *d) { - LASSERT(lu_device_is_mdd(d)); - return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev); + LASSERT(lu_device_is_mdd(d)); + return container_of_safe(d, struct mdd_device, mdd_md_dev.md_lu_dev); } static inline struct lu_device *mdd2lu_dev(struct mdd_device *mdd) @@ -451,18 +451,19 @@ static inline struct lu_device *mdd2lu_dev(struct mdd_device *mdd) static inline struct mdd_object *lu2mdd_obj(struct lu_object *o) { - LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev))); - return container_of0(o, struct mdd_object, mod_obj.mo_lu); + LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev))); + return container_of_safe(o, struct mdd_object, + mod_obj.mo_lu); } static inline struct mdd_device *mdo2mdd(struct md_object *mdo) { - return lu2mdd_dev(mdo->mo_lu.lo_dev); + return lu2mdd_dev(mdo->mo_lu.lo_dev); } static inline struct mdd_object *md2mdd_obj(struct md_object *mdo) { - return container_of0(mdo, struct mdd_object, mod_obj); + return container_of_safe(mdo, struct mdd_object, mod_obj); } static inline const diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 99320fc..b9d32d6 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -916,12 +916,12 @@ int mdt_pack_secctx_in_reply(struct mdt_thread_info *info, static inline struct mdt_device *mdt_dev(struct lu_device *d) { - return container_of0(d, struct mdt_device, mdt_lu_dev); + return container_of_safe(d, struct mdt_device, mdt_lu_dev); } static inline struct mdt_object *mdt_obj(struct lu_object *o) { - return container_of0(o, struct mdt_object, mot_obj); + return container_of_safe(o, struct mdt_object, mot_obj); } static inline struct dt_object *mdt_obj2dt(struct mdt_object *mo) diff --git a/lustre/mdt/mdt_mds.c b/lustre/mdt/mdt_mds.c index 860cdf9..1c06518 100644 --- a/lustre/mdt/mdt_mds.c +++ b/lustre/mdt/mdt_mds.c @@ -567,7 +567,7 @@ err_mds_svc: static inline struct mds_device *mds_dev(struct lu_device *d) { - return container_of0(d, struct mds_device, mds_md_dev.md_lu_dev); + return container_of_safe(d, struct mds_device, mds_md_dev.md_lu_dev); } static struct lu_device *mds_device_fini(const struct lu_env *env, diff --git a/lustre/mgs/mgs_internal.h b/lustre/mgs/mgs_internal.h index b062f91..793f178 100644 --- a/lustre/mgs/mgs_internal.h +++ b/lustre/mgs/mgs_internal.h @@ -330,7 +330,7 @@ static inline int lu_device_is_mgs(struct lu_device *d) static inline struct mgs_device* lu2mgs_dev(struct lu_device *d) { LASSERT(lu_device_is_mgs(d)); - return container_of0(d, struct mgs_device, mgs_dt_dev.dd_lu_dev); + return container_of_safe(d, struct mgs_device, mgs_dt_dev.dd_lu_dev); } static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp) @@ -352,7 +352,7 @@ static inline struct mgs_device *dt2mgs_dev(struct dt_device *d) static inline struct mgs_object *lu2mgs_obj(struct lu_object *o) { LASSERT(ergo(o != NULL, lu_device_is_mgs(o->lo_dev))); - return container_of0(o, struct mgs_object, mgo_obj.do_lu); + return container_of_safe(o, struct mgs_object, mgo_obj.do_lu); } static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj) diff --git a/lustre/obdecho/echo.c b/lustre/obdecho/echo.c index f0978ad..e31d048 100644 --- a/lustre/obdecho/echo.c +++ b/lustre/obdecho/echo.c @@ -68,7 +68,7 @@ struct echo_srv_device { static inline struct echo_srv_device *echo_srv_dev(struct lu_device *d) { - return container_of0(d, struct echo_srv_device, esd_dev); + return container_of_safe(d, struct echo_srv_device, esd_dev); } static inline struct obd_device *echo_srv_obd(struct echo_srv_device *esd) diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index e25cae0..19e522a 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -135,7 +135,7 @@ static int echo_client_cleanup(struct obd_device *obd); */ static inline struct echo_device *cl2echo_dev(const struct cl_device *dev) { - return container_of0(dev, struct echo_device, ed_cl); + return container_of_safe(dev, struct echo_device, ed_cl); } static inline struct cl_device *echo_dev2cl(struct echo_device *d) @@ -193,7 +193,8 @@ struct echo_object_conf *cl2echo_conf(const struct cl_object_conf *c) #ifdef HAVE_SERVER_SUPPORT static inline struct echo_md_device *lu2emd_dev(struct lu_device *d) { - return container_of0(d, struct echo_md_device, emd_md_dev.md_lu_dev); + return container_of_safe(d, struct echo_md_device, + emd_md_dev.md_lu_dev); } static inline struct lu_device *emd2lu_dev(struct echo_md_device *d) diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index bbe8cc2..9d06085 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -166,7 +166,7 @@ struct ofd_device { static inline struct ofd_device *ofd_dev(struct lu_device *d) { - return container_of0(d, struct ofd_device, ofd_dt_dev.dd_lu_dev); + return container_of_safe(d, struct ofd_device, ofd_dt_dev.dd_lu_dev); } static inline struct obd_device *ofd_obd(struct ofd_device *ofd) @@ -195,7 +195,7 @@ struct ofd_object { static inline struct ofd_object *ofd_obj(struct lu_object *o) { - return container_of0(o, struct ofd_object, ofo_obj.do_lu); + return container_of_safe(o, struct ofd_object, ofo_obj.do_lu); } static inline int ofd_object_exists(struct ofd_object *obj) diff --git a/lustre/osp/lwp_dev.c b/lustre/osp/lwp_dev.c index 6fdf950..d8c83aa 100644 --- a/lustre/osp/lwp_dev.c +++ b/lustre/osp/lwp_dev.c @@ -56,7 +56,7 @@ struct lwp_device { static inline struct lwp_device *lu2lwp_dev(struct lu_device *d) { - return container_of0(d, struct lwp_device, lpd_dev); + return container_of_safe(d, struct lwp_device, lpd_dev); } static inline struct lu_device *lwp2lu_dev(struct lwp_device *d) diff --git a/lustre/osp/osp_internal.h b/lustre/osp/osp_internal.h index 5aadd7b..7246cd2 100644 --- a/lustre/osp/osp_internal.h +++ b/lustre/osp/osp_internal.h @@ -460,7 +460,7 @@ static inline int lu_device_is_osp(struct lu_device *d) static inline struct osp_device *lu2osp_dev(struct lu_device *d) { LASSERT(lu_device_is_osp(d)); - return container_of0(d, struct osp_device, opd_dt_dev.dd_lu_dev); + return container_of_safe(d, struct osp_device, opd_dt_dev.dd_lu_dev); } static inline struct lu_device *osp2lu_dev(struct osp_device *d) @@ -471,13 +471,13 @@ static inline struct lu_device *osp2lu_dev(struct osp_device *d) static inline struct osp_device *dt2osp_dev(struct dt_device *d) { LASSERT(lu_device_is_osp(&d->dd_lu_dev)); - return container_of0(d, struct osp_device, opd_dt_dev); + return container_of_safe(d, struct osp_device, opd_dt_dev); } static inline struct osp_object *lu2osp_obj(struct lu_object *o) { LASSERT(ergo(o != NULL, lu_device_is_osp(o->lo_dev))); - return container_of0(o, struct osp_object, opo_obj.do_lu); + return container_of_safe(o, struct osp_object, opo_obj.do_lu); } static inline struct lu_object *osp2lu_obj(struct osp_object *obj) @@ -488,7 +488,7 @@ static inline struct lu_object *osp2lu_obj(struct osp_object *obj) static inline struct osp_object *osp_obj(const struct lu_object *o) { LASSERT(lu_device_is_osp(o->lo_dev)); - return container_of0(o, struct osp_object, opo_obj.do_lu); + return container_of_safe(o, struct osp_object, opo_obj.do_lu); } static inline struct osp_object *dt2osp_obj(const struct dt_object *d) diff --git a/lustre/quota/qmt_internal.h b/lustre/quota/qmt_internal.h index 423cda6..ba72a1e 100644 --- a/lustre/quota/qmt_internal.h +++ b/lustre/quota/qmt_internal.h @@ -301,7 +301,7 @@ struct qmt_thread_info *qmt_info(const struct lu_env *env) /* helper routine to convert a lu_device into a qmt_device */ static inline struct qmt_device *lu2qmt_dev(struct lu_device *ld) { - return container_of0(lu2dt_dev(ld), struct qmt_device, qmt_dt_dev); + return container_of_safe(lu2dt_dev(ld), struct qmt_device, qmt_dt_dev); } /* helper routine to convert a qmt_device into lu_device */