Whamcloud - gitweb
LU-6142 all: use list_first_entry() where appropriate. 26/50826/2
authorMr NeilBrown <neilb@suse.de>
Wed, 6 Nov 2019 21:58:04 +0000 (08:58 +1100)
committerOleg Drokin <green@whamcloud.com>
Wed, 31 May 2023 19:03:31 +0000 (19:03 +0000)
Lustre already uses list_first_entry() in many places, but
it is not consistent.  Let's make it consistent.
The patch was generated with

 sed -i 's/list_entry(([^,]*)->next,/list_first_entry(1,/'
     `git grep -l 'list_entry(.*->next' lustre/ lnet/ libcfs/ `

followed by some manual cleanup of indents, and adding
list_first_entry() to libcfs/include/libcfs/util/list.h

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Id646fba1faf40282e66ede07c88c8db5ffadc211
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50826
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
15 files changed:
libcfs/include/libcfs/util/list.h
libcfs/libcfs/libcfs_string.c
libcfs/libcfs/util/nidstrings.c
libcfs/libcfs/util/string.c
lnet/lnet/lib-move.c
lnet/selftest/rpc.c
lnet/selftest/timer.c
lnet/utils/lnetconfig/cyaml.c
lnet/utils/lst.c
lustre/fld/fld_request.c
lustre/ldlm/ldlm_inodebits.c
lustre/ldlm/ldlm_lockd.c
lustre/lfsck/lfsck_engine.c
lustre/obdclass/scrub.c
lustre/osd-zfs/osd_handler.c

index ef69efe..b7e808c 100644 (file)
@@ -239,6 +239,17 @@ static inline void list_splice_init(struct list_head *list,
        ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
 
 /**
+ * list_first_entry - get the first element from a list
+ * \param ptr   the list head to take the element from.
+ * \param type  the type of the struct this is embedded in.
+ * \param member the name of the list_head within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+       list_entry((ptr)->next, type, member)
+
+/**
  * Iterate over a list
  * \param pos  the iterator
  * \param head the list to iterate over
@@ -453,7 +464,7 @@ static inline void hlist_add_after(struct hlist_node *n,
  * \param member     the name of the list_struct within the struct.
  */
 #define list_for_each_entry(pos, head, member)                          \
-       for (pos = list_entry((head)->next, typeof(*pos), member),      \
+       for (pos = list_first_entry((head), typeof(*pos), member),      \
                     prefetch(pos->member.next);                            \
             &pos->member != (head);                                        \
             pos = list_entry(pos->member.next, typeof(*pos), member),  \
@@ -478,7 +489,7 @@ static inline void hlist_add_after(struct hlist_node *n,
  * \param member     the name of the list_struct within the struct.
  */
 #define list_for_each_entry_safe(pos, n, head, member)                   \
-       for (pos = list_entry((head)->next, typeof(*pos), member),       \
+       for (pos = list_first_entry((head), typeof(*pos), member),       \
                n = list_entry(pos->member.next, typeof(*pos), member);  \
             &pos->member != (head);                                         \
             pos = n, n = list_entry(n->member.next, typeof(*n), member))
index a3ff59c..be88452 100644 (file)
@@ -552,8 +552,8 @@ cfs_expr_list_free_list(struct list_head *list)
        struct cfs_expr_list *el;
 
        while (!list_empty(list)) {
-               el = list_entry(list->next,
-                                   struct cfs_expr_list, el_link);
+               el = list_first_entry(list,
+                                     struct cfs_expr_list, el_link);
                list_del(&el->el_link);
                cfs_expr_list_free(el);
        }
index 88f668a..dfcd8c4 100644 (file)
@@ -460,7 +460,7 @@ cfs_ip_addr_range_gen(__u32 *ip_list, int count, struct list_head *ip_addr_expr)
        struct cfs_expr_list *octet_el;
        int idx = count - 1;
 
-       octet_el = list_entry(ip_addr_expr->next, typeof(*octet_el), el_link);
+       octet_el = list_first_entry(ip_addr_expr, typeof(*octet_el), el_link);
 
        (void) cfs_ip_addr_range_gen_recurse(ip_list, &idx, 3, 0, &octet_el->el_link, octet_el);
 
@@ -561,7 +561,7 @@ libcfs_num_match(__u32 addr, struct list_head *numaddr)
        struct cfs_expr_list *el;
 
        assert(!list_empty(numaddr));
-       el = list_entry(numaddr->next, struct cfs_expr_list, el_link);
+       el = list_first_entry(numaddr, struct cfs_expr_list, el_link);
 
        return cfs_expr_list_match(addr, el);
 }
@@ -1320,7 +1320,7 @@ free_addrranges(struct list_head *list)
        while (!list_empty(list)) {
                struct addrrange *ar;
 
-               ar = list_entry(list->next, struct addrrange, ar_link);
+               ar = list_first_entry(list, struct addrrange, ar_link);
 
                cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
                list_del(&ar->ar_link);
@@ -1649,7 +1649,7 @@ int cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
        char max_addr_str[IPSTRING_LENGTH];
        int rc;
 
-       first_nidrange = list_entry(nidlist->next, struct nidrange, nr_link);
+       first_nidrange = list_first_entry(nidlist, struct nidrange, nr_link);
 
        netnum = first_nidrange->nr_netnum;
        nf = first_nidrange->nr_netstrfns;
index 700f002..f957db6 100644 (file)
@@ -438,8 +438,8 @@ cfs_expr_list_free_list(struct list_head *list)
        struct cfs_expr_list *el;
 
        while (!list_empty(list)) {
-               el = list_entry(list->next,
-                                   struct cfs_expr_list, el_link);
+               el = list_first_entry(list,
+                                     struct cfs_expr_list, el_link);
                list_del(&el->el_link);
                cfs_expr_list_free(el);
        }
index d513caa..de5f10a 100644 (file)
@@ -3407,8 +3407,8 @@ lnet_resend_pending_msgs_locked(struct list_head *resendq, int cpt)
        while (!list_empty(resendq)) {
                struct lnet_peer_ni *lpni;
 
-               msg = list_entry(resendq->next, struct lnet_msg,
-                                msg_list);
+               msg = list_first_entry(resendq, struct lnet_msg,
+                                      msg_list);
 
                list_del_init(&msg->msg_list);
 
index 5a43ee7..4326c7b 100644 (file)
@@ -229,9 +229,9 @@ srpc_service_fini(struct srpc_service *svc)
                                break;
 
                        while (!list_empty(q)) {
-                               buf = list_entry(q->next,
-                                                struct srpc_buffer,
-                                                buf_list);
+                               buf = list_first_entry(q,
+                                                      struct srpc_buffer,
+                                                      buf_list);
                                list_del(&buf->buf_list);
                                LIBCFS_FREE(buf, sizeof(*buf));
                        }
index 8a35334..7f82941 100644 (file)
@@ -124,7 +124,7 @@ stt_expire_list(struct list_head *slot, time64_t now)
        struct stt_timer *timer;
 
        while (!list_empty(slot)) {
-               timer = list_entry(slot->next, struct stt_timer, stt_list);
+               timer = list_first_entry(slot, struct stt_timer, stt_list);
 
                if (timer->stt_expires > now)
                        break;
index f11a4f8..3466ca7 100644 (file)
@@ -242,7 +242,7 @@ static struct cYAML *cYAML_ll_pop(struct list_head *list,
        struct cYAML *obj = NULL;
 
        if (!list_empty(list)) {
-               pop = list_entry(list->next, struct cYAML_ll, list);
+               pop = list_first_entry(list, struct cYAML_ll, list);
 
                obj = pop->obj;
                if (print_info != NULL)
index 3d6cebe..4b66984 100644 (file)
@@ -407,7 +407,7 @@ lst_free_rpcent(struct list_head *head)
        struct lstcon_rpc_ent *ent;
 
        while (!list_empty(head)) {
-               ent = list_entry(head->next, struct lstcon_rpc_ent, rpe_link);
+               ent = list_first_entry(head, struct lstcon_rpc_ent, rpe_link);
 
                list_del(&ent->rpe_link);
                free(ent);
index fecf82d..28dee3d 100644 (file)
@@ -488,8 +488,9 @@ again:
                 * the target. Else retreive the next target entry.
                 */
                if (target->ft_chain.next == &fld->lcf_targets)
-                       target = list_entry(target->ft_chain.next->next,
-                                           struct lu_fld_target, ft_chain);
+                       target = list_first_entry(target->ft_chain.next,
+                                                 struct lu_fld_target,
+                                                 ft_chain);
                else
                        target = list_entry(target->ft_chain.next,
                                                 struct lu_fld_target,
index 41257a9..42640f1 100644 (file)
@@ -106,8 +106,8 @@ restart:
                if (list_empty(head) || !(mask & (1 << i)))
                        continue;
 
-               node = list_entry(head->next, struct ldlm_ibits_node,
-                                 lin_link[i]);
+               node = list_first_entry(head, struct ldlm_ibits_node,
+                                       lin_link[i]);
 
                pending = node->lock;
                LDLM_DEBUG(pending, "Reprocessing lock from queue %d", i);
index 440049e..ddf11e5 100644 (file)
@@ -204,8 +204,8 @@ static int expired_lock_main(void *arg)
                        struct obd_export *export;
                        struct ldlm_lock *lock;
 
-                       lock = list_entry(expired->next, struct ldlm_lock,
-                                         l_pending_chain);
+                       lock = list_first_entry(expired, struct ldlm_lock,
+                                               l_pending_chain);
                        if ((void *)lock < LP_POISON + PAGE_SIZE &&
                            (void *)lock >= LP_POISON) {
                                spin_unlock_bh(&waiting_locks_spinlock);
index 49e1303..29b6b44 100644 (file)
@@ -1197,15 +1197,15 @@ again:
                __u32            *gen;
 
                if (com->lc_type == LFSCK_TYPE_LAYOUT) {
-                       ltd = list_entry(phase_head->next,
-                                        struct lfsck_tgt_desc,
-                                        ltd_layout_phase_list);
+                       ltd = list_first_entry(phase_head,
+                                              struct lfsck_tgt_desc,
+                                              ltd_layout_phase_list);
                        phase_list = &ltd->ltd_layout_phase_list;
                        gen = &ltd->ltd_layout_gen;
                } else {
-                       ltd = list_entry(phase_head->next,
-                                        struct lfsck_tgt_desc,
-                                        ltd_namespace_phase_list);
+                       ltd = list_first_entry(phase_head,
+                                              struct lfsck_tgt_desc,
+                                              ltd_namespace_phase_list);
                        phase_list = &ltd->ltd_namespace_phase_list;
                        gen = &ltd->ltd_namespace_gen;
                }
@@ -1428,17 +1428,17 @@ again:
                spin_lock(&ltds->ltd_lock);
                while (!list_empty(phase_head)) {
                        if (com->lc_type == LFSCK_TYPE_LAYOUT) {
-                               ltd = list_entry(phase_head->next,
-                                                struct lfsck_tgt_desc,
-                                                ltd_layout_list);
+                               ltd = list_first_entry(phase_head,
+                                                      struct lfsck_tgt_desc,
+                                                      ltd_layout_list);
                                if (!list_empty(&ltd->ltd_layout_phase_list))
                                        list_del_init(
                                                &ltd->ltd_layout_phase_list);
                                list_del_init(&ltd->ltd_layout_list);
                        } else {
-                               ltd = list_entry(phase_head->next,
-                                                struct lfsck_tgt_desc,
-                                                ltd_namespace_list);
+                               ltd = list_first_entry(phase_head,
+                                                      struct lfsck_tgt_desc,
+                                                      ltd_namespace_list);
                                if (!list_empty(&ltd->ltd_namespace_phase_list))
                                        list_del_init(
                                                &ltd->ltd_namespace_phase_list);
index f1da24c..daf44e3 100644 (file)
@@ -1086,8 +1086,9 @@ void lustre_index_backup(const struct lu_env *env, struct dt_device *dev,
 scan:
        spin_lock(lock);
        while (!list_empty(head)) {
-               libu = list_entry(head->next,
-                                 struct lustre_index_backup_unit, libu_link);
+               libu = list_first_entry(head,
+                                       struct lustre_index_backup_unit,
+                                       libu_link);
                list_del_init(&libu->libu_link);
                spin_unlock(lock);
 
index 2730788..d2db32a 100644 (file)
@@ -241,8 +241,8 @@ static void osd_unlinked_list_emptify(const struct lu_env *env,
        uint64_t           oid;
 
        while (!list_empty(list)) {
-               obj = list_entry(list->next,
-                                struct osd_object, oo_unlinked_linkage);
+               obj = list_first_entry(list,
+                                      struct osd_object, oo_unlinked_linkage);
                LASSERT(obj->oo_dn != NULL);
                oid = obj->oo_dn->dn_object;