From 56741b993f05b6b3dddadde190282ef3476baa24 Mon Sep 17 00:00:00 2001
From: Jesse Gross <jesse@nicira.com>
Date: Fri, 15 Mar 2013 09:18:20 -0700
Subject: [PATCH 1/5] datapath: Backport simplified hlist iterators.

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                     |  1 +
 datapath/linux/compat/include/linux/list.h    | 24 ++++++++++++++++++++++++
 datapath/linux/compat/include/linux/rculist.h |  8 ++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 datapath/linux/compat/include/linux/list.h

diff --git a/datapath/linux/Modules.mk b/datapath/linux/Modules.mk
index 60351ce..4324336 100644
--- a/datapath/linux/Modules.mk
+++ b/datapath/linux/Modules.mk
@@ -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
index 0000000..4446779
--- /dev/null
+++ b/datapath/linux/compat/include/linux/list.h
@@ -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
diff --git a/datapath/linux/compat/include/linux/rculist.h b/datapath/linux/compat/include/linux/rculist.h
index 64e3905..fd9bf10 100644
--- a/datapath/linux/compat/include/linux/rculist.h
+++ b/datapath/linux/compat/include/linux/rculist.h
@@ -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
-- 
1.8.3.2

