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