linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: linux-nfs@vger.kernel.org
Cc: NeilBrown <neilb@suse.de>, Chuck Lever <chuck.lever@oracle.com>
Subject: [PATCH v1 08/17] llist: add interface to check if a node is on a list.
Date: Mon, 11 Sep 2023 10:39:24 -0400	[thread overview]
Message-ID: <169444316412.4327.17559564827280562621.stgit@bazille.1015granger.net> (raw)
In-Reply-To: <169444233785.4327.4365499966926096681.stgit@bazille.1015granger.net>

From: NeilBrown <neilb@suse.de>

With list.h lists, it is easy to test if a node is on a list, providing
it was initialised and that it is removed with list_del_init().

This patch provides similar functionality for llist.h lists.

 init_llist_node()
marks a node as being not-on-any-list be setting the ->next pointer to
the node itself.
 llist_on_list()
tests if the node is on any list.
 llist_del_first_init()
remove the first element from a llist, and marks it as being off-list.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 include/linux/llist.h |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/include/linux/llist.h b/include/linux/llist.h
index 85bda2d02d65..dcb91e3bac1c 100644
--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -73,6 +73,33 @@ static inline void init_llist_head(struct llist_head *list)
 	list->first = NULL;
 }
 
+/**
+ * init_llist_node - initialize lock-less list node
+ * @node:	the node to be initialised
+ *
+ * In cases where there is a need to test if a node is on
+ * a list or not, this initialises the node to clearly
+ * not be on any list.
+ */
+static inline void init_llist_node(struct llist_node *node)
+{
+	node->next = node;
+}
+
+/**
+ * llist_on_list - test if a lock-list list node is on a list
+ * @node:	the node to test
+ *
+ * When a node is on a list the ->next pointer will be NULL or
+ * some other node.  It can never point to itself.  We use that
+ * in init_llist_node() to record that a node is not on any list,
+ * and here to test whether it is on any list.
+ */
+static inline bool llist_on_list(const struct llist_node *node)
+{
+	return node->next != node;
+}
+
 /**
  * llist_entry - get the struct of this entry
  * @ptr:	the &struct llist_node pointer.
@@ -249,6 +276,21 @@ static inline struct llist_node *__llist_del_all(struct llist_head *head)
 
 extern struct llist_node *llist_del_first(struct llist_head *head);
 
+/**
+ * llist_del_first_init - delete first entry from lock-list and mark is as being off-list
+ * @head:	the head of lock-less list to delete from.
+ *
+ * This behave the same as llist_del_first() except that llist_init_node() is called
+ * on the returned node so that llist_on_list() will report false for the node.
+ */
+static inline struct llist_node *llist_del_first_init(struct llist_head *head)
+{
+	struct llist_node *n = llist_del_first(head);
+
+	if (n)
+		init_llist_node(n);
+	return n;
+}
 struct llist_node *llist_reverse_order(struct llist_node *head);
 
 #endif /* LLIST_H */



  parent reply	other threads:[~2023-09-11 22:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 14:38 [PATCH v1 00/17] RPC service thread improvements Chuck Lever
2023-09-11 14:38 ` [PATCH v1 01/17] SUNRPC: move all of xprt handling into svc_xprt_handle() Chuck Lever
2023-09-11 14:38 ` [PATCH v1 02/17] SUNRPC: rename and refactor svc_get_next_xprt() Chuck Lever
2023-09-11 14:38 ` [PATCH v1 03/17] SUNRPC: Clean up bc_svc_process() Chuck Lever
2023-09-11 14:38 ` [PATCH v1 04/17] SUNRPC: integrate back-channel processing with svc_recv() Chuck Lever
2023-09-11 14:39 ` [PATCH v1 05/17] SUNRPC: change how svc threads are asked to exit Chuck Lever
2023-09-11 14:39 ` [PATCH v1 06/17] SUNRPC: add list of idle threads Chuck Lever
2023-09-11 14:39 ` [PATCH v1 07/17] SUNRPC: discard SP_CONGESTED Chuck Lever
2023-09-11 14:39 ` Chuck Lever [this message]
2023-09-11 14:39 ` [PATCH v1 09/17] SUNRPC: change service idle list to be an llist Chuck Lever
2023-09-11 14:39 ` [PATCH v1 10/17] llist: add llist_del_first_this() Chuck Lever
2023-09-11 14:39 ` [PATCH v1 11/17] lib: add light-weight queuing mechanism Chuck Lever
2023-09-11 18:13   ` Andrew Morton
2023-09-11 20:30     ` Chuck Lever III
2023-09-11 21:04       ` Andrew Morton
2023-09-11 23:19         ` NeilBrown
2023-09-12  1:30           ` Andrew Morton
2023-09-14 14:05             ` Chuck Lever III
2023-09-15  1:51               ` NeilBrown
2023-09-15  2:22             ` [PATCH 11/17 SQUASH and replace commit message] " NeilBrown
2023-09-15 15:54               ` Chuck Lever III
2023-09-12  2:37   ` [PATCH v1 11/17] " Kees Cook
2023-09-12  4:08     ` NeilBrown
2023-09-11 14:39 ` [PATCH v1 12/17] SUNRPC: rename some functions from rqst_ to svc_thread_ Chuck Lever
2023-09-11 14:39 ` [PATCH v1 13/17] SUNRPC: only have one thread waking up at a time Chuck Lever
2023-09-11 14:40 ` [PATCH v1 14/17] SUNRPC: use lwq for sp_sockets - renamed to sp_xprts Chuck Lever
2023-09-11 14:40 ` [PATCH v1 15/17] SUNRPC: change sp_nrthreads to atomic_t Chuck Lever
2023-09-11 14:40 ` [PATCH v1 16/17] SUNRPC: discard sp_lock Chuck Lever
2023-09-11 14:40 ` [PATCH v1 17/17] SUNRPC: change the back-channel queue to lwq Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=169444316412.4327.17559564827280562621.stgit@bazille.1015granger.net \
    --to=cel@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).