From 29285b6286493965a36ae3eff5983457f85cd087 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Fri, 15 Mar 2013 09:18:20 -0700 Subject: [PATCH] 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 --- 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 60351ce9a..432433675 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 000000000..44467794b --- /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 + +#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 64e390591..fd9bf10ed 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 -- 2.43.0