Each of these calls to container_of0() can be determined from local
context to be passed a valid pointer, so it is best to use
container_of() directly to make this clear.
Either:
- the returned pointer is dereferenced with out be tests, or
- the passed-in pointer is dereferened before the call, or
- the passed-in pointer cannot be NULL, such as when
it is a '.next' of a list_head or returned by lu_obecjt_next()
So convert all of these to container_of()
... except one which *should* be container_of(), but cannot
be as it won't compile cleanly on older kernels. Change
that one to container_of_safe() with a big comment.
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Idcd954f89ed366882563810ce042a5ddaba5a1e5
Reviewed-on: https://review.whamcloud.com/38383
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yingjin Qian <qian@ddn.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
17 files changed:
{
struct seq_update_callback *ccb;
{
struct seq_update_callback *ccb;
- ccb = container_of0(cb, struct seq_update_callback, suc_cb);
+ ccb = container_of(cb, struct seq_update_callback, suc_cb);
LASSERT(ccb->suc_seq != NULL);
LASSERT(ccb->suc_seq != NULL);
struct lfsck_assistant_req *lar)
{
struct lfsck_layout_req *llr =
struct lfsck_assistant_req *lar)
{
struct lfsck_layout_req *llr =
- container_of0(lar, struct lfsck_layout_req, llr_lar);
+ container_of(lar, struct lfsck_layout_req, llr_lar);
lfsck_object_put(env, llr->llr_child);
lfsck_assistant_object_put(env, lar->lar_parent);
lfsck_object_put(env, llr->llr_child);
lfsck_assistant_object_put(env, lar->lar_parent);
struct lfsck_assistant_req *lar)
{
struct lfsck_layout_req *llr =
struct lfsck_assistant_req *lar)
{
struct lfsck_layout_req *llr =
- container_of0(lar, struct lfsck_layout_req, llr_lar);
+ container_of(lar, struct lfsck_layout_req, llr_lar);
struct lfsck_assistant_object *lso = lar->lar_parent;
struct lfsck_layout *lo = com->lc_file_ram;
struct lfsck_thread_info *info = lfsck_env_info(env);
struct lfsck_assistant_object *lso = lar->lar_parent;
struct lfsck_layout *lo = com->lc_file_ram;
struct lfsck_thread_info *info = lfsck_env_info(env);
struct lfsck_async_interpret_args *laia = args;
struct lfsck_instance *lfsck;
struct lfsck_async_interpret_args *laia = args;
struct lfsck_instance *lfsck;
- lfsck = container_of0(laia->laia_ltds, struct lfsck_instance,
- li_mdt_descs);
+ lfsck = container_of(laia->laia_ltds, struct lfsck_instance,
+ li_mdt_descs);
lfsck_interpret(env, lfsck, req, laia, rc);
lfsck_tgt_put(laia->laia_ltd);
if (rc != 0 && laia->laia_result != -EALREADY)
lfsck_interpret(env, lfsck, req, laia, rc);
lfsck_tgt_put(laia->laia_ltd);
if (rc != 0 && laia->laia_result != -EALREADY)
struct lfsck_assistant_req *lar)
{
struct lfsck_namespace_req *lnr =
struct lfsck_assistant_req *lar)
{
struct lfsck_namespace_req *lnr =
- container_of0(lar, struct lfsck_namespace_req, lnr_lar);
+ container_of(lar, struct lfsck_namespace_req, lnr_lar);
if (lnr->lnr_lmv != NULL)
lfsck_lmv_put(env, lnr->lnr_lmv);
if (lnr->lnr_lmv != NULL)
lfsck_lmv_put(env, lnr->lnr_lmv);
const struct lu_name *cname;
struct thandle *handle = NULL;
struct lfsck_namespace_req *lnr =
const struct lu_name *cname;
struct thandle *handle = NULL;
struct lfsck_namespace_req *lnr =
- container_of0(lar, struct lfsck_namespace_req, lnr_lar);
+ container_of(lar, struct lfsck_namespace_req, lnr_lar);
struct dt_object *dir = NULL;
struct dt_object *obj = NULL;
struct lfsck_assistant_object *lso = lar->lar_parent;
struct dt_object *dir = NULL;
struct dt_object *obj = NULL;
struct lfsck_assistant_object *lso = lar->lar_parent;
* so must appear to be a non-const pointer to an empty array.
*/
char (*n)[0] = (void *)name;
* so must appear to be a non-const pointer to an empty array.
*/
char (*n)[0] = (void *)name;
- struct lu_dirent *lde = container_of0(n, struct lu_dirent, lde_name);
+ /* NOTE: This should be container_of(). However container_of() in
+ * kernels earlier than v4.13-rc1~37^2~94 cause this to generate a
+ * warning, which fails when we compile with -Werror. Those earlier
+ * kernels don't have container_of_safe, calling that instead will use
+ * the lustre-local version which doesn't generate the warning.
+ */
+ struct lu_dirent *lde = container_of_safe(n, struct lu_dirent, lde_name);
struct lu_fid fid;
fid_le_to_cpu(&fid, &lde->lde_fid);
struct lu_fid fid;
fid_le_to_cpu(&fid, &lde->lde_fid);
static inline struct lod_device *dt2lod_dev(struct dt_device *d)
{
LASSERT(lu_device_is_lod(&d->dd_lu_dev));
static inline struct lod_device *dt2lod_dev(struct dt_device *d)
{
LASSERT(lu_device_is_lod(&d->dd_lu_dev));
- return container_of0(d, struct lod_device, lod_dt_dev);
+ return container_of(d, struct lod_device, lod_dt_dev);
}
static inline struct lod_object *lu2lod_obj(struct lu_object *o)
}
static inline struct lod_object *lu2lod_obj(struct lu_object *o)
static inline struct lod_object *lod_obj(const struct lu_object *o)
{
LASSERT(lu_device_is_lod(o->lo_dev));
static inline struct lod_object *lod_obj(const struct lu_object *o)
{
LASSERT(lu_device_is_lod(o->lo_dev));
- return container_of0(o, struct lod_object, ldo_obj.do_lu);
+ return container_of(o, struct lod_object, ldo_obj.do_lu);
}
static inline struct lod_object *lod_dt_obj(const struct dt_object *d)
}
static inline struct lod_object *lod_dt_obj(const struct dt_object *d)
static inline struct dt_object* lod_object_child(struct lod_object *o)
{
static inline struct dt_object* lod_object_child(struct lod_object *o)
{
- return container_of0(lu_object_next(lod2lu_obj(o)),
- struct dt_object, do_lu);
+ return container_of(lu_object_next(lod2lu_obj(o)),
+ struct dt_object, do_lu);
}
static inline bool lod_obj_is_striped(struct dt_object *dt)
}
static inline bool lod_obj_is_striped(struct dt_object *dt)
struct llog_changelog_rec *rec;
mdd = lu2mdd_dev(loghandle->lgh_ctxt->loc_obd->obd_lu_dev);
struct llog_changelog_rec *rec;
mdd = lu2mdd_dev(loghandle->lgh_ctxt->loc_obd->obd_lu_dev);
- rec = container_of0(r, struct llog_changelog_rec, cr_hdr);
+ rec = container_of(r, struct llog_changelog_rec, cr_hdr);
spin_lock(&mdd->mdd_cl.mc_lock);
rec->cr.cr_index = mdd->mdd_cl.mc_index + 1;
spin_lock(&mdd->mdd_cl.mc_lock);
rec->cr.cr_index = mdd->mdd_cl.mc_index + 1;
static inline struct dt_object *mdd_object_child(struct mdd_object *obj)
{
static inline struct dt_object *mdd_object_child(struct mdd_object *obj)
{
- return container_of0(lu_object_next(mdd2lu_obj(obj)),
- struct dt_object, do_lu);
+ return container_of(lu_object_next(mdd2lu_obj(obj)),
+ struct dt_object, do_lu);
}
static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
}
static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
{
LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
{
LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
- return container_of0(d, struct mgs_device, mgs_dt_dev);
+ return container_of(d, struct mgs_device, mgs_dt_dev);
}
static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
}
static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
static inline struct mgs_object *mgs_obj(const struct lu_object *o)
{
LASSERT(lu_device_is_mgs(o->lo_dev));
static inline struct mgs_object *mgs_obj(const struct lu_object *o)
{
LASSERT(lu_device_is_mgs(o->lo_dev));
- return container_of0(o, struct mgs_object, mgo_obj.do_lu);
+ return container_of(o, struct mgs_object, mgo_obj.do_lu);
}
static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
}
static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
static inline struct dt_object* mgs_object_child(struct mgs_object *o)
{
static inline struct dt_object* mgs_object_child(struct mgs_object *o)
{
- return container_of0(lu_object_next(mgs2lu_obj(o)),
- struct dt_object, do_lu);
+ return container_of(lu_object_next(mgs2lu_obj(o)),
+ struct dt_object, do_lu);
- dev = container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
+ dev = container_of(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
th = dt_trans_create(env, dev);
if (IS_ERR(th))
RETURN(PTR_ERR(th));
th = dt_trans_create(env, dev);
if (IS_ERR(th))
RETURN(PTR_ERR(th));
write_unlock(&ofd->ofd_seq_list_lock);
while (!list_empty(&dispose)) {
write_unlock(&ofd->ofd_seq_list_lock);
while (!list_empty(&dispose)) {
- oseq = container_of0(dispose.next, struct ofd_seq, os_list);
+ oseq = container_of(dispose.next, struct ofd_seq, os_list);
list_del_init(&oseq->os_list);
ofd_seq_put(env, oseq);
}
list_del_init(&oseq->os_list);
ofd_seq_put(env, oseq);
}
{
struct lu_object *lu = &(_obj)->ofo_obj.do_lu;
{
struct lu_object *lu = &(_obj)->ofo_obj.do_lu;
- return container_of0(lu_object_next(lu), struct dt_object, do_lu);
+ return container_of(lu_object_next(lu), struct dt_object, do_lu);
}
static inline struct ofd_device *ofd_obj2dev(const struct ofd_object *fo)
}
static inline struct ofd_device *ofd_obj2dev(const struct ofd_object *fo)
static inline struct dt_object *osp_object_child(struct osp_object *o)
{
static inline struct dt_object *osp_object_child(struct osp_object *o)
{
- return container_of0(lu_object_next(osp2lu_obj(o)),
- struct dt_object, do_lu);
+ return container_of(lu_object_next(osp2lu_obj(o)),
+ struct dt_object, do_lu);
}
static inline struct seq_server_site *osp_seq_site(struct osp_device *osp)
}
static inline struct seq_server_site *osp_seq_site(struct osp_device *osp)
struct osp_last_committed_cb *cb;
struct osp_device *d;
struct osp_last_committed_cb *cb;
struct osp_device *d;
- cb = container_of0(dcb, struct osp_last_committed_cb, ospc_cb);
+ cb = container_of(dcb, struct osp_last_committed_cb, ospc_cb);
d = cb->ospc_dev;
CDEBUG(D_HA, "%s: %llu committed\n", d->opd_obd->obd_name,
d = cb->ospc_dev;
CDEBUG(D_HA, "%s: %llu committed\n", d->opd_obd->obd_name,
if (hnode == NULL)
return NULL;
if (hnode == NULL)
return NULL;
- cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
+ cli = container_of(hnode, struct nrs_tbf_client, tc_hnode);
if (!list_empty(&cli->tc_lru))
list_del_init(&cli->tc_lru);
return cli;
if (!list_empty(&cli->tc_lru))
list_del_init(&cli->tc_lru);
return cli;
cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
while (!list_empty(&zombies)) {
cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
while (!list_empty(&zombies)) {
- cli = container_of0(zombies.next,
- struct nrs_tbf_client, tc_lru);
+ cli = container_of(zombies.next,
+ struct nrs_tbf_client, tc_lru);
list_del_init(&cli->tc_lru);
nrs_tbf_cli_fini(cli);
}
list_del_init(&cli->tc_lru);
nrs_tbf_cli_fini(cli);
}
if (hnode == NULL)
return NULL;
if (hnode == NULL)
return NULL;
- cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
+ cli = container_of(hnode, struct nrs_tbf_client, tc_hnode);
if (!list_empty(&cli->tc_lru))
list_del_init(&cli->tc_lru);
return cli;
if (!list_empty(&cli->tc_lru))
list_del_init(&cli->tc_lru);
return cli;
cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
while (!list_empty(&zombies)) {
cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
while (!list_empty(&zombies)) {
- cli = container_of0(zombies.next,
- struct nrs_tbf_client, tc_lru);
+ cli = container_of(zombies.next,
+ struct nrs_tbf_client, tc_lru);
list_del_init(&cli->tc_lru);
nrs_tbf_cli_fini(cli);
}
list_del_init(&cli->tc_lru);
nrs_tbf_cli_fini(cli);
}
{
struct tgt_new_client_callback *ccb;
{
struct tgt_new_client_callback *ccb;
- ccb = container_of0(cb, struct tgt_new_client_callback, lncc_cb);
+ ccb = container_of(cb, struct tgt_new_client_callback, lncc_cb);
LASSERT(ccb->lncc_exp->exp_obd);
LASSERT(ccb->lncc_exp->exp_obd);
{
struct tgt_last_committed_callback *ccb;
{
struct tgt_last_committed_callback *ccb;
- ccb = container_of0(cb, struct tgt_last_committed_callback, llcc_cb);
+ ccb = container_of(cb, struct tgt_last_committed_callback, llcc_cb);
LASSERT(ccb->llcc_exp);
LASSERT(ccb->llcc_tgt != NULL);
LASSERT(ccb->llcc_exp);
LASSERT(ccb->llcc_tgt != NULL);
struct distribute_txn_bid_data *dtbd = NULL;
struct target_distribute_txn_data *tdtd;
struct distribute_txn_bid_data *dtbd = NULL;
struct target_distribute_txn_data *tdtd;
- dtbd = container_of0(cb, struct distribute_txn_bid_data, dtbd_cb);
+ dtbd = container_of(cb, struct distribute_txn_bid_data, dtbd_cb);
tdtd = dtbd->dtbd_tdtd;
CDEBUG(D_HA, "%s: %llu batchid updated\n",
tdtd = dtbd->dtbd_tdtd;
CDEBUG(D_HA, "%s: %llu batchid updated\n",