datapath: Backport simplified hlist iterators.
authorJesse Gross <jesse@nicira.com>
Fri, 15 Mar 2013 16:18:20 +0000 (09:18 -0700)
committerJesse Gross <jesse@nicira.com>
Fri, 15 Mar 2013 16:31:40 +0000 (09:31 -0700)
The hlist iterator macros were simplified upstream to remove the
need for a scratch pointer.  This backports those versions, which
don't otherwise touch anything else about the data structures.

Signed-off-by: Jesse Gross <jesse@nicira.com>
datapath/linux/Modules.mk
datapath/linux/compat/include/linux/list.h [new file with mode: 0644]
datapath/linux/compat/include/linux/rculist.h

index 60351ce..4324336 100644 (file)
@@ -35,6 +35,7 @@ openvswitch_headers += \
        linux/compat/include/linux/jiffies.h \
        linux/compat/include/linux/kernel.h \
        linux/compat/include/linux/kobject.h \
+       linux/compat/include/linux/list.h \
        linux/compat/include/linux/lockdep.h \
        linux/compat/include/linux/log2.h \
        linux/compat/include/linux/mutex.h \
diff --git a/datapath/linux/compat/include/linux/list.h b/datapath/linux/compat/include/linux/list.h
new file mode 100644 (file)
index 0000000..4446779
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __LINUX_LIST_WRAPPER_H
+#define __LINUX_LIST_WRAPPER_H 1
+
+#include_next <linux/list.h>
+
+#ifndef hlist_entry_safe
+#define hlist_entry_safe(ptr, type, member) \
+       (ptr) ? hlist_entry(ptr, type, member) : NULL
+
+#undef hlist_for_each_entry
+#define hlist_for_each_entry(pos, head, member)                                \
+       for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
+            pos;                                                       \
+            pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
+
+#undef hlist_for_each_entry_safe
+#define hlist_for_each_entry_safe(pos, n, head, member)                \
+       for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
+            pos && ({ n = pos->member.next; 1; });                     \
+            pos = hlist_entry_safe(n, typeof(*pos), member))
+
+#endif
+
+#endif
index 64e3905..fd9bf10 100644 (file)
@@ -20,4 +20,12 @@ static inline void hlist_del_init_rcu(struct hlist_node *n)
 }
 #endif
 
+#undef hlist_for_each_entry_rcu
+#define hlist_for_each_entry_rcu(pos, head, member)                    \
+       for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\
+                       typeof(*(pos)), member);                        \
+               pos;                                                    \
+               pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\
+                       &(pos)->member)), typeof(*(pos)), member))
+
 #endif