Blame SOURCES/autofs-5.1.6-update-list_h.patch

49b67f
autofs-5.1.6 - update list.h
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Update autofs include/list.h mostly to include the hlist
49b67f
implementation but also to simplify bits of it.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG      |    1 
49b67f
 include/list.h |  402 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
49b67f
 2 files changed, 378 insertions(+), 25 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -116,6 +116,7 @@ xx/xx/2018 autofs-5.1.5
49b67f
 - fix additional typing errors.
49b67f
 - make bind mounts propagation slave by default.
49b67f
 - fix browse dir not re-created on symlink expire.
49b67f
+- update list.h.
49b67f
 
49b67f
 19/12/2017 autofs-5.1.4
49b67f
 - fix spec file url.
49b67f
--- autofs-5.1.4.orig/include/list.h
49b67f
+++ autofs-5.1.4/include/list.h
49b67f
@@ -1,6 +1,27 @@
49b67f
 #ifndef _LINUX_LIST_H
49b67f
 #define _LINUX_LIST_H
49b67f
 
49b67f
+#include <stddef.h>
49b67f
+
49b67f
+/*
49b67f
+ * Casts a member of a structure out to the containing structure
49b67f
+ * @param ptr        the pointer to the member.
49b67f
+ * @param type       the type of the container struct this is embedded in.
49b67f
+ * @param member     the name of the member within the struct.
49b67f
+ *
49b67f
+ */
49b67f
+#define container_of(ptr, type, member) ({                      \
49b67f
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
49b67f
+        (type *)( (char *)__mptr - offsetof(type,member) );})
49b67f
+
49b67f
+/*
49b67f
+ * These are non-NULL pointers that will result in page faults
49b67f
+ * under normal circumstances, used to verify that nobody uses
49b67f
+ * non-initialized list entries.
49b67f
+ */
49b67f
+#define LIST_POISON1  ((void *) 0x00100100)
49b67f
+#define LIST_POISON2  ((void *) 0x00200200)
49b67f
+
49b67f
 /*
49b67f
  * Simple doubly linked list implementation.
49b67f
  *
49b67f
@@ -25,14 +46,14 @@ struct list_head {
49b67f
 } while (0)
49b67f
 
49b67f
 /*
49b67f
- * Insert a new entry between two known consecutive entries. 
49b67f
+ * Insert a new entry between two known consecutive entries.
49b67f
  *
49b67f
  * This is only for internal list manipulation where we know
49b67f
  * the prev/next entries already!
49b67f
  */
49b67f
-static __inline__ void __list_add(struct list_head * new,
49b67f
-	struct list_head * prev,
49b67f
-	struct list_head * next)
49b67f
+static inline void __list_add(struct list_head *new,
49b67f
+			      struct list_head *prev,
49b67f
+			      struct list_head *next)
49b67f
 {
49b67f
 	next->prev = new;
49b67f
 	new->next = next;
49b67f
@@ -48,7 +69,7 @@ static __inline__ void __list_add(struct
49b67f
  * Insert a new entry after the specified head.
49b67f
  * This is good for implementing stacks.
49b67f
  */
49b67f
-static __inline__ void list_add(struct list_head *new, struct list_head *head)
49b67f
+static inline void list_add(struct list_head *new, struct list_head *head)
49b67f
 {
49b67f
 	__list_add(new, head, head->next);
49b67f
 }
49b67f
@@ -61,7 +82,7 @@ static __inline__ void list_add(struct l
49b67f
  * Insert a new entry before the specified head.
49b67f
  * This is useful for implementing queues.
49b67f
  */
49b67f
-static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
49b67f
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
49b67f
 {
49b67f
 	__list_add(new, head->prev, head);
49b67f
 }
49b67f
@@ -73,8 +94,7 @@ static __inline__ void list_add_tail(str
49b67f
  * This is only for internal list manipulation where we know
49b67f
  * the prev/next entries already!
49b67f
  */
49b67f
-static __inline__ void __list_del(struct list_head * prev,
49b67f
-				  struct list_head * next)
49b67f
+static inline void __list_del(struct list_head * prev, struct list_head * next)
49b67f
 {
49b67f
 	next->prev = prev;
49b67f
 	prev->next = next;
49b67f
@@ -83,50 +103,96 @@ static __inline__ void __list_del(struct
49b67f
 /**
49b67f
  * list_del - deletes entry from list.
49b67f
  * @entry: the element to delete from the list.
49b67f
- * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
49b67f
+ * Note: list_empty on entry does not return true after this, the entry is
49b67f
+ * in an undefined state.
49b67f
  */
49b67f
-static __inline__ void list_del(struct list_head *entry)
49b67f
+static inline void list_del(struct list_head *entry)
49b67f
 {
49b67f
 	__list_del(entry->prev, entry->next);
49b67f
+	entry->next = LIST_POISON1;
49b67f
+	entry->prev = LIST_POISON2;
49b67f
 }
49b67f
 
49b67f
 /**
49b67f
  * list_del_init - deletes entry from list and reinitialize it.
49b67f
  * @entry: the element to delete from the list.
49b67f
  */
49b67f
-static __inline__ void list_del_init(struct list_head *entry)
49b67f
+static inline void list_del_init(struct list_head *entry)
49b67f
 {
49b67f
 	__list_del(entry->prev, entry->next);
49b67f
-	INIT_LIST_HEAD(entry); 
49b67f
+	INIT_LIST_HEAD(entry);
49b67f
+}
49b67f
+
49b67f
+/*
49b67f
+ * list_move - delete from one list and add as another's head
49b67f
+ * @list: the entry to move
49b67f
+ * @head: the head that will precede our entry
49b67f
+ */
49b67f
+static inline void list_move(struct list_head *list, struct list_head *head)
49b67f
+{
49b67f
+        __list_del(list->prev, list->next);
49b67f
+        list_add(list, head);
49b67f
+}
49b67f
+
49b67f
+/**
49b67f
+ * list_move_tail - delete from one list and add as another's tail
49b67f
+ * @list: the entry to move
49b67f
+ * @head: the head that will follow our entry
49b67f
+ */
49b67f
+static inline void list_move_tail(struct list_head *list,
49b67f
+				  struct list_head *head)
49b67f
+{
49b67f
+        __list_del(list->prev, list->next);
49b67f
+        list_add_tail(list, head);
49b67f
 }
49b67f
 
49b67f
 /**
49b67f
  * list_empty - tests whether a list is empty
49b67f
  * @head: the list to test.
49b67f
  */
49b67f
-static __inline__ int list_empty(struct list_head *head)
49b67f
+static inline int list_empty(const struct list_head *head)
49b67f
 {
49b67f
 	return head->next == head;
49b67f
 }
49b67f
 
49b67f
+static inline void __list_splice(struct list_head *list,
49b67f
+				 struct list_head *head)
49b67f
+{
49b67f
+	struct list_head *first = list->next;
49b67f
+	struct list_head *last = list->prev;
49b67f
+	struct list_head *at = head->next;
49b67f
+
49b67f
+	first->prev = head;
49b67f
+	head->next = first;
49b67f
+
49b67f
+	last->next = at;
49b67f
+	at->prev = last;
49b67f
+}
49b67f
+
49b67f
 /**
49b67f
  * list_splice - join two lists
49b67f
  * @list: the new list to add.
49b67f
  * @head: the place to add it in the first list.
49b67f
  */
49b67f
-static __inline__ void list_splice(struct list_head *list, struct list_head *head)
49b67f
+static inline void list_splice(struct list_head *list, struct list_head *head)
49b67f
 {
49b67f
-	struct list_head *first = list->next;
49b67f
-
49b67f
-	if (first != list) {
49b67f
-		struct list_head *last = list->prev;
49b67f
-		struct list_head *at = head->next;
49b67f
-
49b67f
-		first->prev = head;
49b67f
-		head->next = first;
49b67f
+	if (!list_empty(list))
49b67f
+		__list_splice(list, head);
49b67f
+}
49b67f
 
49b67f
-		last->next = at;
49b67f
-		at->prev = last;
49b67f
+/**
49b67f
+ * list_splice_init - join two lists and reinitialise the emptied list.
49b67f
+ * @list: the new list to add.
49b67f
+ * @head: the place to add it in the first list.
49b67f
+ *
49b67f
+ * The list at @list is reinitialised
49b67f
+ */
49b67f
+static inline void list_splice_init(struct list_head *list,
49b67f
+				    struct list_head *head)
49b67f
+{
49b67f
+	if (!list_empty(list)) {
49b67f
+		__list_splice(list, head);
49b67f
+		INIT_LIST_HEAD(list);
49b67f
 	}
49b67f
 }
49b67f
 
49b67f
@@ -137,7 +203,45 @@ static __inline__ void list_splice(struc
49b67f
  * @member:	the name of the list_struct within the struct.
49b67f
  */
49b67f
 #define list_entry(ptr, type, member) \
49b67f
-	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
49b67f
+	container_of(ptr, type, member)
49b67f
+
49b67f
+/**
49b67f
+ * list_first_entry - get the first element from a list
49b67f
+ * @ptr:        the list head to take the element from.
49b67f
+ * @type:       the type of the struct this is embedded in.
49b67f
+ * @member:     the name of the list_head within the struct.
49b67f
+ *
49b67f
+ * Note, that list is expected to be not empty.
49b67f
+ */
49b67f
+#define list_first_entry(ptr, type, member) \
49b67f
+        list_entry((ptr)->next, type, member)
49b67f
+
49b67f
+/**
49b67f
+ * list_last_entry - get the last element from a list
49b67f
+ * @ptr:        the list head to take the element from.
49b67f
+ * @type:       the type of the struct this is embedded in.
49b67f
+ * @member:     the name of the list_head within the struct.
49b67f
+ *
49b67f
+ * Note, that list is expected to be not empty.
49b67f
+ */
49b67f
+#define list_last_entry(ptr, type, member) \
49b67f
+        list_entry((ptr)->prev, type, member)
49b67f
+
49b67f
+/**
49b67f
+ * list_next_entry - get the next element in list
49b67f
+ * @pos:        the type * to cursor
49b67f
+ * @member:     the name of the list_head within the struct.
49b67f
+ */
49b67f
+#define list_next_entry(pos, member) \
49b67f
+	list_entry((pos)->member.next, typeof(*(pos)), member)
49b67f
+
49b67f
+/**
49b67f
+ * list_prev_entry - get the prev element in list
49b67f
+ * @pos:        the type * to cursor
49b67f
+ * @member:     the name of the list_head within the struct.
49b67f
+ */
49b67f
+#define list_prev_entry(pos, member) \
49b67f
+	list_entry((pos)->member.prev, typeof(*(pos)), member)
49b67f
 
49b67f
 /**
49b67f
  * list_for_each	-	iterate over a list
49b67f
@@ -155,4 +259,252 @@ static __inline__ void list_splice(struc
49b67f
 #define list_for_each_prev(pos, head) \
49b67f
 	for (pos = (head)->prev; pos != (head); pos = pos->prev)
49b67f
 
49b67f
+/**
49b67f
+ * list_for_each_safe	-	iterate over a list safe against removal of list entry
49b67f
+ * @pos:	the &struct list_head to use as a loop counter.
49b67f
+ * @n:		another &struct list_head to use as temporary storage
49b67f
+ * @head:	the head for your list.
49b67f
+ */
49b67f
+#define list_for_each_safe(pos, n, head) \
49b67f
+	for (pos = (head)->next, n = pos->next; pos != (head); \
49b67f
+		pos = n, n = pos->next)
49b67f
+
49b67f
+/**
49b67f
+ * list_for_each_entry	-	iterate over list of given type
49b67f
+ * @pos:	the type * to use as a loop counter.
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the list_struct within the struct.
49b67f
+ */
49b67f
+#define list_for_each_entry(pos, head, member)				\
49b67f
+	for (pos = list_entry((head)->next, typeof(*pos), member);	\
49b67f
+	     &pos->member != (head);					\
49b67f
+	     pos = list_next_entry(pos, member))
49b67f
+
49b67f
+/**
49b67f
+ * list_for_each_entry_reverse - iterate backwards over list of given type.
49b67f
+ * @pos:	the type * to use as a loop counter.
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the list_struct within the struct.
49b67f
+ */
49b67f
+#define list_for_each_entry_reverse(pos, head, member)			\
49b67f
+	for (pos = list_last_entry(head, typeof(*pos), member);	\
49b67f
+	     &pos->member != (head); 	\
49b67f
+	     pos = list_prev_entry(pos, member))
49b67f
+
49b67f
+/**
49b67f
+ * list_prepare_entry - prepare a pos entry for use as a start point in
49b67f
+ *			list_for_each_entry_continue
49b67f
+ * @pos:	the type * to use as a start point
49b67f
+ * @head:	the head of the list
49b67f
+ * @member:	the name of the list_struct within the struct.
49b67f
+ */
49b67f
+#define list_prepare_entry(pos, head, member) \
49b67f
+	((pos) ? : list_entry(head, typeof(*pos), member))
49b67f
+
49b67f
+/**
49b67f
+ * list_for_each_entry_continue -	iterate over list of given type
49b67f
+ *			continuing after existing point
49b67f
+ * @pos:	the type * to use as a loop counter.
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the list_struct within the struct.
49b67f
+ */
49b67f
+#define list_for_each_entry_continue(pos, head, member) 		\
49b67f
+	for (pos = list_next_entry(pos, member);			\
49b67f
+	     &pos->member != (head);					\
49b67f
+	     pos = list_next_entry(pos, member))
49b67f
+
49b67f
+/**
49b67f
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
49b67f
+ * @pos:	the type * to use as a loop counter.
49b67f
+ * @n:		another type * to use as temporary storage
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the list_struct within the struct.
49b67f
+ */
49b67f
+#define list_for_each_entry_safe(pos, n, head, member)			\
49b67f
+	for (pos = list_first_entry(head, typeof(*pos), member),	\
49b67f
+		n = list_next_entry(pos, member);			\
49b67f
+	     &pos->member != (head); 					\
49b67f
+	     pos = n, n = list_next_entry(n, member))
49b67f
+
49b67f
+/**
49b67f
+ * list_for_each_entry_safe_continue -	iterate over list of given type
49b67f
+ *			continuing after existing point safe against removal of list entry
49b67f
+ * @pos:	the type * to use as a loop counter.
49b67f
+ * @n:		another type * to use as temporary storage
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the list_struct within the struct.
49b67f
+ */
49b67f
+#define list_for_each_entry_safe_continue(pos, n, head, member) 		\
49b67f
+	for (pos = list_next_entry(pos, member),				\
49b67f
+	     n = list_next_entry(pos, member);					\
49b67f
+	     &pos->member != (head);						\
49b67f
+	     pos = n, n = list_next_entry(n, member))
49b67f
+
49b67f
+/**
49b67f
+ * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
49b67f
+ *				      removal of list entry
49b67f
+ * @pos:	the type * to use as a loop counter.
49b67f
+ * @n:		another type * to use as temporary storage
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the list_struct within the struct.
49b67f
+ */
49b67f
+#define list_for_each_entry_safe_reverse(pos, n, head, member)		\
49b67f
+	for (pos = list_last_entry(head, typeof(*pos), member),		\
49b67f
+	     n = list_prev_entry(pos, member);				\
49b67f
+	     &pos->member != (head); 					\
49b67f
+	     pos = n, n = list_prev_entry(n, member))
49b67f
+
49b67f
+
49b67f
+
49b67f
+
49b67f
+/*
49b67f
+ * Double linked lists with a single pointer list head.
49b67f
+ * Mostly useful for hash tables where the two pointer list head is
49b67f
+ * too wasteful.
49b67f
+ * You lose the ability to access the tail in O(1).
49b67f
+ */
49b67f
+
49b67f
+struct hlist_head {
49b67f
+	struct hlist_node *first;
49b67f
+};
49b67f
+
49b67f
+struct hlist_node {
49b67f
+	struct hlist_node *next, **pprev;
49b67f
+};
49b67f
+
49b67f
+#define HLIST_HEAD_INIT { .first = NULL }
49b67f
+#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
49b67f
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
49b67f
+#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
49b67f
+
49b67f
+static inline int hlist_unhashed(const struct hlist_node *h)
49b67f
+{
49b67f
+	return !h->pprev;
49b67f
+}
49b67f
+
49b67f
+static inline int hlist_empty(const struct hlist_head *h)
49b67f
+{
49b67f
+	return !h->first;
49b67f
+}
49b67f
+
49b67f
+static inline void __hlist_del(struct hlist_node *n)
49b67f
+{
49b67f
+	struct hlist_node *next = n->next;
49b67f
+	struct hlist_node **pprev = n->pprev;
49b67f
+	*pprev = next;
49b67f
+	if (next)
49b67f
+		next->pprev = pprev;
49b67f
+}
49b67f
+
49b67f
+static inline void hlist_del(struct hlist_node *n)
49b67f
+{
49b67f
+	__hlist_del(n);
49b67f
+	n->next = LIST_POISON1;
49b67f
+	n->pprev = LIST_POISON2;
49b67f
+}
49b67f
+
49b67f
+
49b67f
+static inline void hlist_del_init(struct hlist_node *n)
49b67f
+{
49b67f
+	if (n->pprev)  {
49b67f
+		__hlist_del(n);
49b67f
+		INIT_HLIST_NODE(n);
49b67f
+	}
49b67f
+}
49b67f
+
49b67f
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
49b67f
+{
49b67f
+	struct hlist_node *first = h->first;
49b67f
+	n->next = first;
49b67f
+	if (first)
49b67f
+		first->pprev = &n->next;
49b67f
+	h->first = n;
49b67f
+	n->pprev = &h->first;
49b67f
+}
49b67f
+
49b67f
+
49b67f
+
49b67f
+/* next must be != NULL */
49b67f
+static inline void hlist_add_before(struct hlist_node *n,
49b67f
+					struct hlist_node *next)
49b67f
+{
49b67f
+	n->pprev = next->pprev;
49b67f
+	n->next = next;
49b67f
+	next->pprev = &n->next;
49b67f
+	*(n->pprev) = n;
49b67f
+}
49b67f
+
49b67f
+static inline void hlist_add_after(struct hlist_node *n,
49b67f
+					struct hlist_node *next)
49b67f
+{
49b67f
+	next->next = n->next;
49b67f
+	n->next = next;
49b67f
+	next->pprev = &n->next;
49b67f
+
49b67f
+	if(next->next)
49b67f
+		next->next->pprev  = &next->next;
49b67f
+}
49b67f
+
49b67f
+
49b67f
+
49b67f
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
49b67f
+
49b67f
+#define hlist_for_each(pos, head) \
49b67f
+	for (pos = (head)->first; pos; pos = pos->next)
49b67f
+
49b67f
+#define hlist_for_each_safe(pos, n, head) \
49b67f
+	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
49b67f
+	     pos = n)
49b67f
+
49b67f
+#define hlist_entry_safe(ptr, type, member) \
49b67f
+        ({ typeof(ptr) ____ptr = (ptr); \
49b67f
+           ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
49b67f
+        })
49b67f
+
49b67f
+/**
49b67f
+ * hlist_for_each_entry	- iterate over list of given type
49b67f
+ * @tpos:	the type * to use as a loop counter.
49b67f
+ * @pos:	the &struct hlist_node to use as a loop counter.
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the hlist_node within the struct.
49b67f
+ */
49b67f
+#define hlist_for_each_entry(pos, head, member)				\
49b67f
+	for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
49b67f
+	     pos;							\
49b67f
+	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
49b67f
+
49b67f
+/**
49b67f
+ * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
49b67f
+ * @tpos:	the type * to use as a loop counter.
49b67f
+ * @pos:	the &struct hlist_node to use as a loop counter.
49b67f
+ * @member:	the name of the hlist_node within the struct.
49b67f
+ */
49b67f
+#define hlist_for_each_entry_continue(pos, member)			\
49b67f
+	for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\
49b67f
+	     pos;							\
49b67f
+	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
49b67f
+
49b67f
+/**
49b67f
+ * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
49b67f
+ * @tpos:	the type * to use as a loop counter.
49b67f
+ * @pos:	the &struct hlist_node to use as a loop counter.
49b67f
+ * @member:	the name of the hlist_node within the struct.
49b67f
+ */
49b67f
+#define hlist_for_each_entry_from(pos, member)				\
49b67f
+	for (; pos;							\
49b67f
+	     pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
49b67f
+
49b67f
+/**
49b67f
+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
49b67f
+ * @tpos:	the type * to use as a loop counter.
49b67f
+ * @pos:	the &struct hlist_node to use as a loop counter.
49b67f
+ * @n:		another &struct hlist_node to use as temporary storage
49b67f
+ * @head:	the head for your list.
49b67f
+ * @member:	the name of the hlist_node within the struct.
49b67f
+ */
49b67f
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member)		\
49b67f
+	for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
49b67f
+	     pos && ({ n = pos->next; 1; }) &&				\
49b67f
+	     pos = hlist_entry_safe(n, typeof(*pos), member))
49b67f
+
49b67f
 #endif