naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0183-include-add-linked-list-implementation-from-kernel.patch

049c96
From 48a71ae76f5b7535f787a34b34162c2235550261 Mon Sep 17 00:00:00 2001
049c96
From: Phil Sutter <psutter@redhat.com>
049c96
Date: Sat, 9 Jul 2016 11:31:01 +0200
049c96
Subject: [PATCH] include: add linked list implementation from kernel
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1342515
049c96
Upstream Status: iproute2.git commit 4952b45946d73
049c96
Conflicts: Dropped changes in tc/tc_class.c since commit d954b34a1f8d8
049c96
           ("tc class: Show classes as ASCII graph") is missing.
049c96
049c96
commit 4952b45946d73a4e5dd673928cf50327251de1de
049c96
Author: Jiri Pirko <jiri@mellanox.com>
049c96
Date:   Tue Mar 22 10:02:20 2016 +0100
049c96
049c96
    include: add linked list implementation from kernel
049c96
049c96
    Rename hlist.h to list.h while adding it to be aligned with kernel
049c96
049c96
    Signed-off-by: Jiri Pirko <jiri@mellanox.com>
049c96
---
049c96
 include/hlist.h |  56 ----------------------------
049c96
 include/list.h  | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
049c96
 ip/ipnetns.c    |   2 +-
049c96
 lib/ll_map.c    |   2 +-
049c96
 4 files changed, 114 insertions(+), 58 deletions(-)
049c96
 delete mode 100644 include/hlist.h
049c96
 create mode 100644 include/list.h
049c96
049c96
diff --git a/include/hlist.h b/include/hlist.h
049c96
deleted file mode 100644
049c96
index 4e8de9e..0000000
049c96
--- a/include/hlist.h
049c96
+++ /dev/null
049c96
@@ -1,56 +0,0 @@
049c96
-#ifndef __HLIST_H__
049c96
-#define __HLIST_H__ 1
049c96
-/* Hash list stuff from kernel */
049c96
-
049c96
-#include <stddef.h>
049c96
-
049c96
-#define container_of(ptr, type, member) ({			\
049c96
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
049c96
-	(type *)( (char *)__mptr - offsetof(type,member) );})
049c96
-
049c96
-struct hlist_head {
049c96
-	struct hlist_node *first;
049c96
-};
049c96
-
049c96
-struct hlist_node {
049c96
-	struct hlist_node *next, **pprev;
049c96
-};
049c96
-
049c96
-static inline void hlist_del(struct hlist_node *n)
049c96
-{
049c96
-	struct hlist_node *next = n->next;
049c96
-	struct hlist_node **pprev = n->pprev;
049c96
-	*pprev = next;
049c96
-	if (next)
049c96
-		next->pprev = pprev;
049c96
-}
049c96
-
049c96
-static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
049c96
-{
049c96
-	struct hlist_node *first = h->first;
049c96
-	n->next = first;
049c96
-	if (first)
049c96
-		first->pprev = &n->next;
049c96
-	h->first = n;
049c96
-	n->pprev = &h->first;
049c96
-}
049c96
-
049c96
-#define hlist_for_each(pos, head) \
049c96
-	for (pos = (head)->first; pos ; pos = pos->next)
049c96
-
049c96
-
049c96
-#define hlist_for_each_safe(pos, n, head) \
049c96
-	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
049c96
-	     pos = n)
049c96
-
049c96
-#define hlist_entry_safe(ptr, type, member) \
049c96
-	({ typeof(ptr) ____ptr = (ptr); \
049c96
-	   ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
049c96
-	})
049c96
-
049c96
-#define hlist_for_each_entry(pos, head, member)				\
049c96
-	for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
049c96
-	     pos;							\
049c96
-	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
049c96
-
049c96
-#endif /* __HLIST_H__ */
049c96
diff --git a/include/list.h b/include/list.h
049c96
new file mode 100644
049c96
index 0000000..cdebe4d
049c96
--- /dev/null
049c96
+++ b/include/list.h
049c96
@@ -0,0 +1,112 @@
049c96
+#ifndef __LIST_H__
049c96
+#define __LIST_H__ 1
049c96
+/* List and hash list stuff from kernel */
049c96
+
049c96
+#include <stddef.h>
049c96
+
049c96
+#define container_of(ptr, type, member) ({			\
049c96
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
049c96
+	(type *)( (char *)__mptr - offsetof(type,member) );})
049c96
+
049c96
+struct list_head {
049c96
+	struct list_head *next, *prev;
049c96
+};
049c96
+
049c96
+static inline void INIT_LIST_HEAD(struct list_head *list)
049c96
+{
049c96
+	list->next = list;
049c96
+	list->prev = list;
049c96
+}
049c96
+
049c96
+static inline void __list_add(struct list_head *new,
049c96
+			      struct list_head *prev,
049c96
+			      struct list_head *next)
049c96
+{
049c96
+	next->prev = new;
049c96
+	new->next = next;
049c96
+	new->prev = prev;
049c96
+	prev->next = new;
049c96
+}
049c96
+
049c96
+static inline void list_add(struct list_head *new, struct list_head *head)
049c96
+{
049c96
+	__list_add(new, head, head->next);
049c96
+}
049c96
+
049c96
+static inline void __list_del(struct list_head *prev, struct list_head *next)
049c96
+{
049c96
+	next->prev = prev;
049c96
+	prev->next = next;
049c96
+}
049c96
+
049c96
+static inline void list_del(struct list_head *entry)
049c96
+{
049c96
+	__list_del(entry->prev, entry->next);
049c96
+}
049c96
+
049c96
+#define list_entry(ptr, type, member) \
049c96
+	container_of(ptr, type, member)
049c96
+
049c96
+#define list_first_entry(ptr, type, member) \
049c96
+	list_entry((ptr)->next, type, member)
049c96
+
049c96
+#define list_next_entry(pos, member) \
049c96
+	list_entry((pos)->member.next, typeof(*(pos)), member)
049c96
+
049c96
+#define list_for_each_entry(pos, head, member)				\
049c96
+	for (pos = list_first_entry(head, typeof(*pos), member);	\
049c96
+	     &pos->member != (head);					\
049c96
+	     pos = list_next_entry(pos, member))
049c96
+
049c96
+#define list_for_each_entry_safe(pos, n, head, member)			\
049c96
+	for (pos = list_first_entry(head, typeof(*pos), member),	\
049c96
+		n = list_next_entry(pos, member);			\
049c96
+	     &pos->member != (head);					\
049c96
+	     pos = n, n = list_next_entry(n, member))
049c96
+
049c96
+struct hlist_head {
049c96
+	struct hlist_node *first;
049c96
+};
049c96
+
049c96
+struct hlist_node {
049c96
+	struct hlist_node *next, **pprev;
049c96
+};
049c96
+
049c96
+static inline void hlist_del(struct hlist_node *n)
049c96
+{
049c96
+	struct hlist_node *next = n->next;
049c96
+	struct hlist_node **pprev = n->pprev;
049c96
+	*pprev = next;
049c96
+	if (next)
049c96
+		next->pprev = pprev;
049c96
+}
049c96
+
049c96
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
049c96
+{
049c96
+	struct hlist_node *first = h->first;
049c96
+	n->next = first;
049c96
+	if (first)
049c96
+		first->pprev = &n->next;
049c96
+	h->first = n;
049c96
+	n->pprev = &h->first;
049c96
+}
049c96
+
049c96
+#define hlist_for_each(pos, head) \
049c96
+	for (pos = (head)->first; pos ; pos = pos->next)
049c96
+
049c96
+
049c96
+#define hlist_for_each_safe(pos, n, head) \
049c96
+	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
049c96
+	     pos = n)
049c96
+
049c96
+#define hlist_entry_safe(ptr, type, member) \
049c96
+	({ typeof(ptr) ____ptr = (ptr); \
049c96
+	   ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
049c96
+	})
049c96
+
049c96
+#define hlist_for_each_entry(pos, head, member)				\
049c96
+	for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
049c96
+	     pos;							\
049c96
+	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
049c96
+
049c96
+#endif /* __LIST_H__ */
049c96
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
049c96
index 2c848bc..ef05ff3 100644
049c96
--- a/ip/ipnetns.c
049c96
+++ b/ip/ipnetns.c
049c96
@@ -19,7 +19,7 @@
049c96
 #include <linux/net_namespace.h>
049c96
 
049c96
 #include "utils.h"
049c96
-#include "hlist.h"
049c96
+#include "list.h"
049c96
 #include "ip_common.h"
049c96
 #include "namespace.h"
049c96
 
049c96
diff --git a/lib/ll_map.c b/lib/ll_map.c
049c96
index c6f7027..fa14a77 100644
049c96
--- a/lib/ll_map.c
049c96
+++ b/lib/ll_map.c
049c96
@@ -22,7 +22,7 @@
049c96
 
049c96
 #include "libnetlink.h"
049c96
 #include "ll_map.h"
049c96
-#include "hlist.h"
049c96
+#include "list.h"
049c96
 
049c96
 struct ll_cache {
049c96
 	struct hlist_node idx_hash;
049c96
-- 
049c96
1.8.3.1
049c96