2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef _LINUX_LIST_H_
29 #define _LINUX_LIST_H_
32 * Since LIST_HEAD conflicts with the linux definition we must include any
33 * FreeBSD header which requires it here so it is resolved with the correct
34 * definition prior to the undef.
36 #include <linux/compiler.h>
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/queue.h>
42 #include <sys/mutex.h>
44 #include <sys/vnode.h>
46 #include <sys/socket.h>
51 #include <net/if_types.h>
52 #include <net/if_media.h>
54 #include <netinet/in.h>
55 #include <netinet/in_pcb.h>
57 #include <netinet6/in6_var.h>
58 #include <netinet6/nd6.h>
61 #include <vm/vm_object.h>
66 struct list_head *next;
67 struct list_head *prev;
71 INIT_LIST_HEAD(struct list_head *list)
74 list->next = list->prev = list;
78 list_empty(const struct list_head *head)
81 return (head->next == head);
85 list_del(struct list_head *entry)
88 entry->next->prev = entry->prev;
89 entry->prev->next = entry->next;
92 static inline void list_replace(struct list_head *old,
93 struct list_head *new)
95 new->next = old->next;
96 new->next->prev = new;
97 new->prev = old->prev;
98 new->prev->next = new;
102 _list_add(struct list_head *new, struct list_head *prev,
103 struct list_head *next)
113 list_del_init(struct list_head *entry)
117 INIT_LIST_HEAD(entry);
120 #define list_entry(ptr, type, field) container_of(ptr, type, field)
122 #define list_first_entry(ptr, type, member) \
123 list_entry((ptr)->next, type, member)
125 #define list_for_each(p, head) \
126 for (p = (head)->next; p != (head); p = p->next)
128 #define list_for_each_safe(p, n, head) \
129 for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)
131 #define list_for_each_entry(p, h, field) \
132 for (p = list_entry((h)->next, typeof(*p), field); &p->field != (h); \
133 p = list_entry(p->field.next, typeof(*p), field))
135 #define list_for_each_entry_continue_reverse(pos, head, member) \
136 for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
137 &pos->member != (head); \
138 pos = list_entry(pos->member.prev, typeof(*pos), member))
140 #define list_for_each_entry_safe(p, n, h, field) \
141 for (p = list_entry((h)->next, typeof(*p), field), \
142 n = list_entry(p->field.next, typeof(*p), field); &p->field != (h);\
143 p = n, n = list_entry(n->field.next, typeof(*n), field))
145 #define list_for_each_entry_safe_from(pos, n, head, member) \
146 for (n = list_entry(pos->member.next, typeof(*pos), member); \
147 &pos->member != (head); \
148 pos = n, n = list_entry(n->member.next, typeof(*n), member))
150 #define list_for_each_entry_reverse(p, h, field) \
151 for (p = list_entry((h)->prev, typeof(*p), field); &p->field != (h); \
152 p = list_entry(p->field.prev, typeof(*p), field))
154 #define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev)
157 list_add(struct list_head *new, struct list_head *head)
160 _list_add(new, head, head->next);
164 list_add_tail(struct list_head *new, struct list_head *head)
167 _list_add(new, head->prev, head);
171 list_move(struct list_head *list, struct list_head *head)
175 list_add(list, head);
179 list_move_tail(struct list_head *entry, struct list_head *head)
183 list_add_tail(entry, head);
187 _list_splice(const struct list_head *list, struct list_head *prev,
188 struct list_head *next)
190 struct list_head *first;
191 struct list_head *last;
193 if (list_empty(list))
204 list_splice(const struct list_head *list, struct list_head *head)
207 _list_splice(list, head, head->next);
211 list_splice_tail(struct list_head *list, struct list_head *head)
214 _list_splice(list, head->prev, head);
218 list_splice_init(struct list_head *list, struct list_head *head)
221 _list_splice(list, head, head->next);
222 INIT_LIST_HEAD(list);
226 list_splice_tail_init(struct list_head *list, struct list_head *head)
229 _list_splice(list, head->prev, head);
230 INIT_LIST_HEAD(list);
233 #define DRM_LIST_HEAD(name) struct list_head name = { &(name), &(name) }
237 struct hlist_node *first;
241 struct hlist_node *next, **pprev;
244 #define HLIST_HEAD_INIT { }
245 #define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
246 #define INIT_HLIST_HEAD(head) (head)->first = NULL
247 #define INIT_HLIST_NODE(node) \
249 (node)->next = NULL; \
250 (node)->pprev = NULL; \
254 hlist_unhashed(const struct hlist_node *h)
261 hlist_empty(const struct hlist_head *h)
268 hlist_del(struct hlist_node *n)
272 n->next->pprev = n->pprev;
277 hlist_del_init(struct hlist_node *n)
280 if (hlist_unhashed(n))
287 hlist_add_head(struct hlist_node *n, struct hlist_head *h)
292 h->first->pprev = &n->next;
294 n->pprev = &h->first;
298 hlist_add_before(struct hlist_node *n, struct hlist_node *next)
301 n->pprev = next->pprev;
303 next->pprev = &n->next;
308 hlist_add_after(struct hlist_node *n, struct hlist_node *next)
311 next->next = n->next;
313 next->pprev = &n->next;
315 next->next->pprev = &next->next;
319 hlist_move_list(struct hlist_head *old, struct hlist_head *new)
322 new->first = old->first;
324 new->first->pprev = &new->first;
328 #define hlist_entry(ptr, type, field) container_of(ptr, type, field)
330 #define hlist_for_each(p, head) \
331 for (p = (head)->first; p; p = p->next)
333 #define hlist_for_each_safe(p, n, head) \
334 for (p = (head)->first; p && ({ n = p->next; 1; }); p = n)
336 #define hlist_for_each_entry(tp, p, head, field) \
337 for (p = (head)->first; \
338 p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
340 #define hlist_for_each_entry_continue(tp, p, field) \
341 for (p = (p)->next; \
342 p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
344 #define hlist_for_each_entry_from(tp, p, field) \
345 for (; p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
347 #define hlist_for_each_entry_safe(tp, p, n, head, field) \
348 for (p = (head)->first; p ? \
349 (n = p->next) | (tp = hlist_entry(p, typeof(*tp), field)) : \
352 void drm_list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv,
353 struct list_head *a, struct list_head *b));
355 #endif /* _LINUX_LIST_H_ */