Whamcloud - gitweb
LU-2446 build: Update Whamcloud copyright messages for Intel
[fs/lustre-release.git] / libcfs / include / libcfs / list.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22
23 #ifndef __LIBCFS_LIST_H__
24 #define __LIBCFS_LIST_H__
25
26 #if defined (__linux__) && defined(__KERNEL__)
27
28 #include <linux/list.h>
29
30 typedef struct list_head cfs_list_t;
31
32 #define __cfs_list_add(new, prev, next)      __list_add(new, prev, next)
33 #define cfs_list_add(new, head)              list_add(new, head)
34
35 #define cfs_list_add_tail(new, head)         list_add_tail(new, head)
36
37 #define __cfs_list_del(prev, next)           __list_del(prev, next)
38 #define cfs_list_del(entry)                  list_del(entry)
39 #define cfs_list_del_init(entry)             list_del_init(entry)
40
41 #define cfs_list_move(list, head)            list_move(list, head)
42 #define cfs_list_move_tail(list, head)       list_move_tail(list, head)
43
44 #define cfs_list_empty(head)                 list_empty(head)
45 #define cfs_list_empty_careful(head)         list_empty_careful(head)
46
47 #define __cfs_list_splice(list, head)        __list_splice(list, head)
48 #define cfs_list_splice(list, head)          list_splice(list, head)
49
50 #define cfs_list_splice_init(list, head)     list_splice_init(list, head)
51
52 #define cfs_list_entry(ptr, type, member)    list_entry(ptr, type, member)
53 #define cfs_list_for_each(pos, head)         list_for_each(pos, head)
54 #define cfs_list_for_each_safe(pos, n, head) list_for_each_safe(pos, n, head)
55 #define cfs_list_for_each_prev(pos, head)    list_for_each_prev(pos, head)
56 #define cfs_list_for_each_entry(pos, head, member) \
57         list_for_each_entry(pos, head, member)
58 #define cfs_list_for_each_entry_reverse(pos, head, member) \
59         list_for_each_entry_reverse(pos, head, member)
60 #define cfs_list_for_each_entry_safe_reverse(pos, n, head, member) \
61         list_for_each_entry_safe_reverse(pos, n, head, member)
62 #define cfs_list_for_each_entry_safe(pos, n, head, member) \
63         list_for_each_entry_safe(pos, n, head, member)
64 #ifdef list_for_each_entry_safe_from
65 #define cfs_list_for_each_entry_safe_from(pos, n, head, member) \
66         list_for_each_entry_safe_from(pos, n, head, member)
67 #endif /* list_for_each_entry_safe_from */
68 #define cfs_list_for_each_entry_continue(pos, head, member) \
69         list_for_each_entry_continue(pos, head, member)
70
71 #define CFS_LIST_HEAD_INIT(n)                LIST_HEAD_INIT(n)
72 #define CFS_LIST_HEAD(n)                     LIST_HEAD(n)
73 #define CFS_INIT_LIST_HEAD(p)                INIT_LIST_HEAD(p)
74
75 typedef struct hlist_head cfs_hlist_head_t;
76 typedef struct hlist_node cfs_hlist_node_t;
77
78 #define cfs_hlist_unhashed(h)              hlist_unhashed(h)
79
80 #define cfs_hlist_empty(h)                 hlist_empty(h)
81
82 #define __cfs_hlist_del(n)                 __hlist_del(n)
83 #define cfs_hlist_del(n)                   hlist_del(n)
84 #define cfs_hlist_del_init(n)              hlist_del_init(n)
85
86 #define cfs_hlist_add_head(n, next)        hlist_add_head(n, next)
87 #define cfs_hlist_add_before(n, next)      hlist_add_before(n, next)
88 #define cfs_hlist_add_after(n, next)       hlist_add_after(n, next)
89
90 #define cfs_hlist_entry(ptr, type, member) hlist_entry(ptr, type, member)
91 #define cfs_hlist_for_each(pos, head)      hlist_for_each(pos, head)
92 #define cfs_hlist_for_each_safe(pos, n, head) \
93         hlist_for_each_safe(pos, n, head)
94 #define cfs_hlist_for_each_entry(tpos, pos, head, member) \
95         hlist_for_each_entry(tpos, pos, head, member)
96 #define cfs_hlist_for_each_entry_continue(tpos, pos, member) \
97         hlist_for_each_entry_continue(tpos, pos, member)
98 #define cfs_hlist_for_each_entry_from(tpos, pos, member) \
99         hlist_for_each_entry_from(tpos, pos, member)
100 #define cfs_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
101         hlist_for_each_entry_safe(tpos, pos, n, head, member)
102
103 #define CFS_HLIST_HEAD_INIT                HLIST_HEAD_INIT
104 #define CFS_HLIST_HEAD(n)                  HLIST_HEAD(n)
105 #define CFS_INIT_HLIST_HEAD(p)             INIT_HLIST_HEAD(p)
106 #define CFS_INIT_HLIST_NODE(p)             INIT_HLIST_NODE(p)
107
108 #else /* !defined (__linux__) || !defined(__KERNEL__) */
109
110 /*
111  * Simple doubly linked list implementation.
112  *
113  * Some of the internal functions ("__xxx") are useful when
114  * manipulating whole lists rather than single entries, as
115  * sometimes we already know the next/prev entries and we can
116  * generate better code by using them directly rather than
117  * using the generic single-entry routines.
118  */
119
120 #define prefetch(a) ((void)a)
121
122 struct cfs_list_head {
123         struct cfs_list_head *next, *prev;
124 };
125
126 typedef struct cfs_list_head cfs_list_t;
127
128 #define CFS_LIST_HEAD_INIT(name) { &(name), &(name) }
129
130 #define CFS_LIST_HEAD(name) \
131         cfs_list_t name = CFS_LIST_HEAD_INIT(name)
132
133 #define CFS_INIT_LIST_HEAD(ptr) do { \
134         (ptr)->next = (ptr); (ptr)->prev = (ptr); \
135 } while (0)
136
137 /**
138  * Insert a new entry between two known consecutive entries.
139  *
140  * This is only for internal list manipulation where we know
141  * the prev/next entries already!
142  */
143 static inline void __cfs_list_add(cfs_list_t * new,
144                                   cfs_list_t * prev,
145                                   cfs_list_t * next)
146 {
147         next->prev = new;
148         new->next = next;
149         new->prev = prev;
150         prev->next = new;
151 }
152
153 /**
154  * Insert an entry at the start of a list.
155  * \param new  new entry to be inserted
156  * \param head list to add it to
157  *
158  * Insert a new entry after the specified head.
159  * This is good for implementing stacks.
160  */
161 static inline void cfs_list_add(cfs_list_t *new,
162                                 cfs_list_t *head)
163 {
164         __cfs_list_add(new, head, head->next);
165 }
166
167 /**
168  * Insert an entry at the end of a list.
169  * \param new  new entry to be inserted
170  * \param head list to add it to
171  *
172  * Insert a new entry before the specified head.
173  * This is useful for implementing queues.
174  */
175 static inline void cfs_list_add_tail(cfs_list_t *new,
176                                      cfs_list_t *head)
177 {
178         __cfs_list_add(new, head->prev, head);
179 }
180
181 /*
182  * Delete a list entry by making the prev/next entries
183  * point to each other.
184  *
185  * This is only for internal list manipulation where we know
186  * the prev/next entries already!
187  */
188 static inline void __cfs_list_del(cfs_list_t *prev,
189                                   cfs_list_t *next)
190 {
191         next->prev = prev;
192         prev->next = next;
193 }
194
195 /**
196  * Remove an entry from the list it is currently in.
197  * \param entry the entry to remove
198  * Note: list_empty(entry) does not return true after this, the entry is in an
199  * undefined state.
200  */
201 static inline void cfs_list_del(cfs_list_t *entry)
202 {
203         __cfs_list_del(entry->prev, entry->next);
204 }
205
206 /**
207  * Remove an entry from the list it is currently in and reinitialize it.
208  * \param entry the entry to remove.
209  */
210 static inline void cfs_list_del_init(cfs_list_t *entry)
211 {
212         __cfs_list_del(entry->prev, entry->next);
213         CFS_INIT_LIST_HEAD(entry);
214 }
215
216 /**
217  * Remove an entry from the list it is currently in and insert it at the start
218  * of another list.
219  * \param list the entry to move
220  * \param head the list to move it to
221  */
222 static inline void cfs_list_move(cfs_list_t *list,
223                                  cfs_list_t *head)
224 {
225         __cfs_list_del(list->prev, list->next);
226         cfs_list_add(list, head);
227 }
228
229 /**
230  * Remove an entry from the list it is currently in and insert it at the end of
231  * another list.
232  * \param list the entry to move
233  * \param head the list to move it to
234  */
235 static inline void cfs_list_move_tail(cfs_list_t *list,
236                                       cfs_list_t *head)
237 {
238         __cfs_list_del(list->prev, list->next);
239         cfs_list_add_tail(list, head);
240 }
241
242 /**
243  * Test whether a list is empty
244  * \param head the list to test.
245  */
246 static inline int cfs_list_empty(cfs_list_t *head)
247 {
248         return head->next == head;
249 }
250
251 /**
252  * Test whether a list is empty and not being modified
253  * \param head the list to test
254  *
255  * Tests whether a list is empty _and_ checks that no other CPU might be
256  * in the process of modifying either member (next or prev)
257  *
258  * NOTE: using cfs_list_empty_careful() without synchronization
259  * can only be safe if the only activity that can happen
260  * to the list entry is cfs_list_del_init(). Eg. it cannot be used
261  * if another CPU could re-list_add() it.
262  */
263 static inline int cfs_list_empty_careful(const cfs_list_t *head)
264 {
265         cfs_list_t *next = head->next;
266         return (next == head) && (next == head->prev);
267 }
268
269 static inline void __cfs_list_splice(cfs_list_t *list,
270                                      cfs_list_t *head)
271 {
272         cfs_list_t *first = list->next;
273         cfs_list_t *last = list->prev;
274         cfs_list_t *at = head->next;
275
276         first->prev = head;
277         head->next = first;
278
279         last->next = at;
280         at->prev = last;
281 }
282
283 /**
284  * Join two lists
285  * \param list the new list to add.
286  * \param head the place to add it in the first list.
287  *
288  * The contents of \a list are added at the start of \a head.  \a list is in an
289  * undefined state on return.
290  */
291 static inline void cfs_list_splice(cfs_list_t *list,
292                                    cfs_list_t *head)
293 {
294         if (!cfs_list_empty(list))
295                 __cfs_list_splice(list, head);
296 }
297
298 /**
299  * Join two lists and reinitialise the emptied list.
300  * \param list the new list to add.
301  * \param head the place to add it in the first list.
302  *
303  * The contents of \a list are added at the start of \a head.  \a list is empty
304  * on return.
305  */
306 static inline void cfs_list_splice_init(cfs_list_t *list,
307                                         cfs_list_t *head)
308 {
309         if (!cfs_list_empty(list)) {
310                 __cfs_list_splice(list, head);
311                 CFS_INIT_LIST_HEAD(list);
312         }
313 }
314
315 /**
316  * Get the container of a list
317  * \param ptr    the embedded list.
318  * \param type   the type of the struct this is embedded in.
319  * \param member the member name of the list within the struct.
320  */
321 #define cfs_list_entry(ptr, type, member) \
322         ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
323
324 /**
325  * Iterate over a list
326  * \param pos   the iterator
327  * \param head  the list to iterate over
328  *
329  * Behaviour is undefined if \a pos is removed from the list in the body of the
330  * loop.
331  */
332 #define cfs_list_for_each(pos, head) \
333         for (pos = (head)->next, prefetch(pos->next); pos != (head); \
334                 pos = pos->next, prefetch(pos->next))
335
336 /**
337  * Iterate over a list safely
338  * \param pos   the iterator
339  * \param n     temporary storage
340  * \param head  the list to iterate over
341  *
342  * This is safe to use if \a pos could be removed from the list in the body of
343  * the loop.
344  */
345 #define cfs_list_for_each_safe(pos, n, head) \
346         for (pos = (head)->next, n = pos->next; pos != (head); \
347                 pos = n, n = pos->next)
348
349 /**
350  * Iterate over a list continuing after existing point
351  * \param pos    the type * to use as a loop counter
352  * \param head   the list head
353  * \param member the name of the list_struct within the struct  
354  */
355 #define cfs_list_for_each_entry_continue(pos, head, member)                 \
356         for (pos = cfs_list_entry(pos->member.next, typeof(*pos), member);  \
357              prefetch(pos->member.next), &pos->member != (head);            \
358              pos = cfs_list_entry(pos->member.next, typeof(*pos), member))
359
360 /**
361  * \defgroup hlist Hash List
362  * Double linked lists with a single pointer list head.
363  * Mostly useful for hash tables where the two pointer list head is too
364  * wasteful.  You lose the ability to access the tail in O(1).
365  * @{
366  */
367
368 typedef struct cfs_hlist_node {
369         struct cfs_hlist_node *next, **pprev;
370 } cfs_hlist_node_t;
371
372 typedef struct cfs_hlist_head {
373         cfs_hlist_node_t *first;
374 } cfs_hlist_head_t;
375
376 /* @} */
377
378 /*
379  * "NULL" might not be defined at this point
380  */
381 #ifdef NULL
382 #define NULL_P NULL
383 #else
384 #define NULL_P ((void *)0)
385 #endif
386
387 /**
388  * \addtogroup hlist
389  * @{
390  */
391
392 #define CFS_HLIST_HEAD_INIT { NULL_P }
393 #define CFS_HLIST_HEAD(name) cfs_hlist_head_t name = { NULL_P }
394 #define CFS_INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL_P)
395 #define CFS_INIT_HLIST_NODE(ptr) ((ptr)->next = NULL_P, (ptr)->pprev = NULL_P)
396
397 static inline int cfs_hlist_unhashed(const cfs_hlist_node_t *h)
398 {
399         return !h->pprev;
400 }
401
402 static inline int cfs_hlist_empty(const cfs_hlist_head_t *h)
403 {
404         return !h->first;
405 }
406
407 static inline void __cfs_hlist_del(cfs_hlist_node_t *n)
408 {
409         cfs_hlist_node_t *next = n->next;
410         cfs_hlist_node_t **pprev = n->pprev;
411         *pprev = next;
412         if (next)
413                 next->pprev = pprev;
414 }
415
416 static inline void cfs_hlist_del(cfs_hlist_node_t *n)
417 {
418         __cfs_hlist_del(n);
419 }
420
421 static inline void cfs_hlist_del_init(cfs_hlist_node_t *n)
422 {
423         if (n->pprev)  {
424                 __cfs_hlist_del(n);
425                 CFS_INIT_HLIST_NODE(n);
426         }
427 }
428
429 static inline void cfs_hlist_add_head(cfs_hlist_node_t *n,
430                                       cfs_hlist_head_t *h)
431 {
432         cfs_hlist_node_t *first = h->first;
433         n->next = first;
434         if (first)
435                 first->pprev = &n->next;
436         h->first = n;
437         n->pprev = &h->first;
438 }
439
440 /* next must be != NULL */
441 static inline void cfs_hlist_add_before(cfs_hlist_node_t *n,
442                                         cfs_hlist_node_t *next)
443 {
444         n->pprev = next->pprev;
445         n->next = next;
446         next->pprev = &n->next;
447         *(n->pprev) = n;
448 }
449
450 static inline void cfs_hlist_add_after(cfs_hlist_node_t *n,
451                                        cfs_hlist_node_t *next)
452 {
453         next->next = n->next;
454         n->next = next;
455         next->pprev = &n->next;
456
457         if(next->next)
458                 next->next->pprev  = &next->next;
459 }
460
461 #define cfs_hlist_entry(ptr, type, member) container_of(ptr,type,member)
462
463 #define cfs_hlist_for_each(pos, head) \
464         for (pos = (head)->first; pos && (prefetch(pos->next), 1); \
465              pos = pos->next)
466
467 #define cfs_hlist_for_each_safe(pos, n, head) \
468         for (pos = (head)->first; pos && (n = pos->next, 1); \
469              pos = n)
470
471 /**
472  * Iterate over an hlist of given type
473  * \param tpos   the type * to use as a loop counter.
474  * \param pos    the &struct hlist_node to use as a loop counter.
475  * \param head   the head for your list.
476  * \param member the name of the hlist_node within the struct.
477  */
478 #define cfs_hlist_for_each_entry(tpos, pos, head, member)                    \
479         for (pos = (head)->first;                                            \
480              pos && ({ prefetch(pos->next); 1;}) &&                          \
481                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
482              pos = pos->next)
483
484 /**
485  * Iterate over an hlist continuing after existing point
486  * \param tpos   the type * to use as a loop counter.
487  * \param pos    the &struct hlist_node to use as a loop counter.
488  * \param member the name of the hlist_node within the struct.
489  */
490 #define cfs_hlist_for_each_entry_continue(tpos, pos, member)                 \
491         for (pos = (pos)->next;                                              \
492              pos && ({ prefetch(pos->next); 1;}) &&                          \
493                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
494              pos = pos->next)
495
496 /**
497  * Iterate over an hlist continuing from an existing point
498  * \param tpos   the type * to use as a loop counter.
499  * \param pos    the &struct hlist_node to use as a loop counter.
500  * \param member the name of the hlist_node within the struct.
501  */
502 #define cfs_hlist_for_each_entry_from(tpos, pos, member)                         \
503         for (; pos && ({ prefetch(pos->next); 1;}) &&                        \
504                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
505              pos = pos->next)
506
507 /**
508  * Iterate over an hlist of given type safe against removal of list entry
509  * \param tpos   the type * to use as a loop counter.
510  * \param pos    the &struct hlist_node to use as a loop counter.
511  * \param n      another &struct hlist_node to use as temporary storage
512  * \param head   the head for your list.
513  * \param member the name of the hlist_node within the struct.
514  */
515 #define cfs_hlist_for_each_entry_safe(tpos, pos, n, head, member)            \
516         for (pos = (head)->first;                                            \
517              pos && ({ n = pos->next; 1; }) &&                               \
518                 ({ tpos = cfs_hlist_entry(pos, typeof(*tpos), member); 1;}); \
519              pos = n)
520
521 /* @} */
522
523 #endif /* __linux__ && __KERNEL__ */
524
525 #ifndef cfs_list_for_each_prev
526 /**
527  * Iterate over a list in reverse order
528  * \param pos   the &struct list_head to use as a loop counter.
529  * \param head  the head for your list.
530  */
531 #define cfs_list_for_each_prev(pos, head) \
532         for (pos = (head)->prev, prefetch(pos->prev); pos != (head);     \
533                 pos = pos->prev, prefetch(pos->prev))
534
535 #endif /* cfs_list_for_each_prev */
536
537 #ifndef cfs_list_for_each_entry
538 /**
539  * Iterate over a list of given type
540  * \param pos        the type * to use as a loop counter.
541  * \param head       the head for your list.
542  * \param member     the name of the list_struct within the struct.
543  */
544 #define cfs_list_for_each_entry(pos, head, member)                          \
545         for (pos = cfs_list_entry((head)->next, typeof(*pos), member),      \
546                      prefetch(pos->member.next);                            \
547              &pos->member != (head);                                        \
548              pos = cfs_list_entry(pos->member.next, typeof(*pos), member),  \
549              prefetch(pos->member.next))
550 #endif /* cfs_list_for_each_entry */
551
552 #ifndef cfs_list_for_each_entry_rcu
553 #define cfs_list_for_each_entry_rcu(pos, head, member) \
554        list_for_each_entry(pos, head, member)
555 #endif
556
557 #ifndef cfs_list_for_each_entry_rcu
558 #define cfs_list_for_each_entry_rcu(pos, head, member) \
559        list_for_each_entry(pos, head, member)
560 #endif
561
562 #ifndef cfs_list_for_each_entry_reverse
563 /**
564  * Iterate backwards over a list of given type.
565  * \param pos        the type * to use as a loop counter.
566  * \param head       the head for your list.
567  * \param member     the name of the list_struct within the struct.
568  */
569 #define cfs_list_for_each_entry_reverse(pos, head, member)                  \
570         for (pos = cfs_list_entry((head)->prev, typeof(*pos), member);      \
571              prefetch(pos->member.prev), &pos->member != (head);            \
572              pos = cfs_list_entry(pos->member.prev, typeof(*pos), member))
573 #endif /* cfs_list_for_each_entry_reverse */
574
575 #ifndef cfs_list_for_each_entry_safe
576 /**
577  * Iterate over a list of given type safe against removal of list entry
578  * \param pos        the type * to use as a loop counter.
579  * \param n          another type * to use as temporary storage
580  * \param head       the head for your list.
581  * \param member     the name of the list_struct within the struct.
582  */
583 #define cfs_list_for_each_entry_safe(pos, n, head, member)                   \
584         for (pos = cfs_list_entry((head)->next, typeof(*pos), member),       \
585                 n = cfs_list_entry(pos->member.next, typeof(*pos), member);  \
586              &pos->member != (head);                                         \
587              pos = n, n = cfs_list_entry(n->member.next, typeof(*n), member))
588
589 #endif /* cfs_list_for_each_entry_safe */
590
591 #ifndef cfs_list_for_each_entry_safe_from
592 /**
593  * Iterate over a list continuing from an existing point
594  * \param pos        the type * to use as a loop cursor.
595  * \param n          another type * to use as temporary storage
596  * \param head       the head for your list.
597  * \param member     the name of the list_struct within the struct.
598  *
599  * Iterate over list of given type from current point, safe against
600  * removal of list entry.
601  */
602 #define cfs_list_for_each_entry_safe_from(pos, n, head, member)             \
603         for (n = cfs_list_entry(pos->member.next, typeof(*pos), member);    \
604              &pos->member != (head);                                        \
605              pos = n, n = cfs_list_entry(n->member.next, typeof(*n), member))
606 #endif /* cfs_list_for_each_entry_safe_from */
607
608 #define cfs_list_for_each_entry_typed(pos, head, type, member)          \
609         for (pos = cfs_list_entry((head)->next, type, member),          \
610                      prefetch(pos->member.next);                        \
611              &pos->member != (head);                                    \
612              pos = cfs_list_entry(pos->member.next, type, member),      \
613              prefetch(pos->member.next))
614
615 #define cfs_list_for_each_entry_reverse_typed(pos, head, type, member)  \
616         for (pos = cfs_list_entry((head)->prev, type, member);          \
617              prefetch(pos->member.prev), &pos->member != (head);        \
618              pos = cfs_list_entry(pos->member.prev, type, member))
619
620 #define cfs_list_for_each_entry_safe_typed(pos, n, head, type, member)  \
621     for (pos = cfs_list_entry((head)->next, type, member),              \
622                 n = cfs_list_entry(pos->member.next, type, member);     \
623              &pos->member != (head);                                    \
624              pos = n, n = cfs_list_entry(n->member.next, type, member))
625
626 #define cfs_list_for_each_entry_safe_from_typed(pos, n, head, type, member)  \
627         for (n = cfs_list_entry(pos->member.next, type, member);             \
628              &pos->member != (head);                                         \
629              pos = n, n = cfs_list_entry(n->member.next, type, member))
630
631 #define cfs_hlist_for_each_entry_typed(tpos, pos, head, type, member)   \
632         for (pos = (head)->first;                                       \
633              pos && (prefetch(pos->next), 1) &&                         \
634                 (tpos = cfs_hlist_entry(pos, type, member), 1);         \
635              pos = pos->next)
636
637 #define cfs_hlist_for_each_entry_safe_typed(tpos, pos, n, head, type, member) \
638         for (pos = (head)->first;                                             \
639              pos && (n = pos->next, 1) &&                                     \
640                 (tpos = cfs_hlist_entry(pos, type, member), 1);               \
641              pos = n)
642
643 #endif /* __LIBCFS_LUSTRE_LIST_H__ */