Whamcloud - gitweb
LU-6142 lustre: convert some container_of0 to container_of 83/38383/3
authorMr NeilBrown <neilb@suse.de>
Mon, 27 Apr 2020 05:38:49 +0000 (15:38 +1000)
committerOleg Drokin <green@whamcloud.com>
Wed, 27 May 2020 05:03:55 +0000 (05:03 +0000)
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:
lustre/fid/fid_store.c
lustre/lfsck/lfsck_layout.c
lustre/lfsck/lfsck_lib.c
lustre/lfsck/lfsck_namespace.c
lustre/llite/llite_nfs.c
lustre/lod/lod_internal.h
lustre/mdd/mdd_dir.c
lustre/mdd/mdd_internal.h
lustre/mgs/mgs_internal.h
lustre/mgs/mgs_llog.c
lustre/ofd/ofd_fs.c
lustre/ofd/ofd_internal.h
lustre/osp/osp_internal.h
lustre/osp/osp_sync.c
lustre/ptlrpc/nrs_tbf.c
lustre/target/tgt_lastrcvd.c
lustre/target/update_trans.c

index 1f7e767..f2bb8f3 100644 (file)
@@ -65,7 +65,7 @@ void seq_update_cb(struct lu_env *env, struct thandle *th,
 {
        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);
 
index 68ca022..9c0c865 100644 (file)
@@ -209,7 +209,7 @@ static void lfsck_layout_assistant_req_fini(const struct lu_env *env,
                                            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);
@@ -4302,7 +4302,7 @@ static int lfsck_layout_assistant_handler_p1(const struct lu_env *env,
                                             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);
index 4895b3b..fd161e8 100644 (file)
@@ -2392,8 +2392,8 @@ static int lfsck_async_interpret(const struct lu_env *env,
        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)
index cef0fe0..c722f42 100644 (file)
@@ -87,7 +87,7 @@ static void lfsck_namespace_assistant_req_fini(const struct lu_env *env,
                                               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);
@@ -5566,7 +5566,7 @@ static int lfsck_namespace_assistant_handler_p1(const struct lu_env *env,
        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;
index 4907d68..c51f5ef 100644 (file)
@@ -223,7 +223,13 @@ ll_nfs_get_name_filldir(struct dir_context *ctx, const char *name, int namelen,
         * 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);
index 8e36b08..a371216 100644 (file)
@@ -420,7 +420,7 @@ static inline struct obd_device *lod2obd(struct lod_device *d)
 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)
@@ -442,7 +442,7 @@ static inline const struct lu_fid *lod_object_fid(struct lod_object *obj)
 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)
@@ -452,8 +452,8 @@ 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)
 {
-       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)
index 7ebf57d..e985f2b 100644 (file)
@@ -800,7 +800,7 @@ int mdd_changelog_write_rec(const struct lu_env *env,
                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;
index 220bed9..0fc99bd 100644 (file)
@@ -478,8 +478,8 @@ static inline struct lu_object *mdd2lu_obj(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)
index 539b8d1..b062f91 100644 (file)
@@ -346,7 +346,7 @@ static inline struct lu_device *mgs2lu_dev(struct mgs_device *d)
 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)
@@ -363,7 +363,7 @@ static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj)
 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)
@@ -373,8 +373,8 @@ static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
 
 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);
 }
 
 struct mgs_direntry {
index b6fb67f..eb344a1 100644 (file)
@@ -4920,7 +4920,7 @@ static int mgs_xattr_del(const struct lu_env *env, struct dt_object *obj)
 
        ENTRY;
 
-       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));
index 7fbce7b..0235cd1 100644 (file)
@@ -320,7 +320,7 @@ void ofd_seqs_free(const struct lu_env *env, struct ofd_device *ofd)
        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);
        }
index ca2f8f7..bbe8cc2 100644 (file)
@@ -215,7 +215,7 @@ static inline struct dt_object *ofd_object_child(struct ofd_object *_obj)
 {
        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)
index 348c0d7..5aadd7b 100644 (file)
@@ -498,8 +498,8 @@ static inline struct osp_object *dt2osp_obj(const struct dt_object *d)
 
 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)
index 9eb38af..728c99e 100644 (file)
@@ -1599,7 +1599,7 @@ void osp_sync_local_commit_cb(struct lu_env *env, struct thandle *th,
        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,
index e15f54d..d28c11d 100644 (file)
@@ -630,7 +630,7 @@ nrs_tbf_jobid_hash_lookup(struct cfs_hash *hs,
        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;
@@ -713,8 +713,8 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
        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);
        }
@@ -1396,7 +1396,7 @@ nrs_tbf_cli_hash_lookup(struct cfs_hash *hs, struct cfs_hash_bd *bd,
        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;
@@ -1720,8 +1720,8 @@ nrs_tbf_cli_put(struct nrs_tbf_head *head, struct nrs_tbf_client *cli)
        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);
        }
index 0db82ed..aac5a6f 100644 (file)
@@ -529,7 +529,7 @@ static void tgt_cb_new_client(struct lu_env *env, struct thandle *th,
 {
        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);
 
@@ -867,7 +867,7 @@ static void tgt_cb_last_committed(struct lu_env *env, struct thandle *th,
 {
        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);
index 863d52f..2619f18 100644 (file)
@@ -1330,7 +1330,7 @@ static void distribute_txn_batchid_cb(struct lu_env *env,
        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",