From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>, Wei Liu <wl@xen.org>,
Julien Grall <julien@xen.org>,
Anthony PERARD <anthony.perard@citrix.com>
Subject: [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h
Date: Tue, 30 May 2023 10:54:12 +0200 [thread overview]
Message-ID: <20230530085418.5417-11-jgross@suse.com> (raw)
In-Reply-To: <20230530085418.5417-1-jgross@suse.com>
Replace the usage of the xenstore private list.h header with the
common xen_list.h one.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V3:
- new patch
---
tools/libs/store/xs.c | 56 +++++++++++++++++++++----------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c
index 7a9a8b1656..3813b69ae2 100644
--- a/tools/libs/store/xs.c
+++ b/tools/libs/store/xs.c
@@ -35,13 +35,13 @@
#include <errno.h>
#include "xenstore.h"
#include "xs_lib.h"
-#include "list.h"
#include "utils.h"
#include <xentoolcore_internal.h>
+#include <xen_list.h>
struct xs_stored_msg {
- struct list_head list;
+ XEN_TAILQ_ENTRY(struct xs_stored_msg) list;
struct xsd_sockmsg hdr;
char *body;
};
@@ -70,7 +70,7 @@ struct xs_handle {
* A list of fired watch messages, protected by a mutex. Users can
* wait on the conditional variable until a watch is pending.
*/
- struct list_head watch_list;
+ XEN_TAILQ_HEAD(, struct xs_stored_msg) watch_list;
pthread_mutex_t watch_mutex;
pthread_cond_t watch_condvar;
@@ -84,7 +84,7 @@ struct xs_handle {
* because we serialise requests. The requester can wait on the
* conditional variable for its response.
*/
- struct list_head reply_list;
+ XEN_TAILQ_HEAD(, struct xs_stored_msg) reply_list;
pthread_mutex_t reply_mutex;
pthread_cond_t reply_condvar;
@@ -133,8 +133,8 @@ static void *read_thread(void *arg);
struct xs_handle {
int fd;
Xentoolcore__Active_Handle tc_ah; /* for restrict */
- struct list_head reply_list;
- struct list_head watch_list;
+ XEN_TAILQ_HEAD(, struct xs_stored_msg) reply_list;
+ XEN_TAILQ_HEAD(, struct xs_stored_msg) watch_list;
/* Clients can select() on this pipe to wait for a watch to fire. */
int watch_pipe[2];
/* Filtering watch event in unwatch function? */
@@ -180,7 +180,7 @@ int xs_fileno(struct xs_handle *h)
if ((h->watch_pipe[0] == -1) && (pipe(h->watch_pipe) != -1)) {
/* Kick things off if the watch list is already non-empty. */
- if (!list_empty(&h->watch_list))
+ if (!XEN_TAILQ_EMPTY(&h->watch_list))
while (write(h->watch_pipe[1], &c, 1) != 1)
continue;
}
@@ -262,8 +262,8 @@ static struct xs_handle *get_handle(const char *connect_to)
if (h->fd == -1)
goto err;
- INIT_LIST_HEAD(&h->reply_list);
- INIT_LIST_HEAD(&h->watch_list);
+ XEN_TAILQ_INIT(&h->reply_list);
+ XEN_TAILQ_INIT(&h->watch_list);
/* Watch pipe is allocated on demand in xs_fileno(). */
h->watch_pipe[0] = h->watch_pipe[1] = -1;
@@ -329,12 +329,12 @@ struct xs_handle *xs_open(unsigned long flags)
static void close_free_msgs(struct xs_handle *h) {
struct xs_stored_msg *msg, *tmsg;
- list_for_each_entry_safe(msg, tmsg, &h->reply_list, list) {
+ XEN_TAILQ_FOREACH_SAFE(msg, &h->reply_list, list, tmsg) {
free(msg->body);
free(msg);
}
- list_for_each_entry_safe(msg, tmsg, &h->watch_list, list) {
+ XEN_TAILQ_FOREACH_SAFE(msg, &h->watch_list, list, tmsg) {
free(msg->body);
free(msg);
}
@@ -459,17 +459,17 @@ static void *read_reply(
mutex_lock(&h->reply_mutex);
#ifdef USE_PTHREAD
- while (list_empty(&h->reply_list) && read_from_thread && h->fd != -1)
+ while (XEN_TAILQ_EMPTY(&h->reply_list) && read_from_thread && h->fd != -1)
condvar_wait(&h->reply_condvar, &h->reply_mutex);
#endif
- if (list_empty(&h->reply_list)) {
+ if (XEN_TAILQ_EMPTY(&h->reply_list)) {
mutex_unlock(&h->reply_mutex);
errno = EINVAL;
return NULL;
}
- msg = list_top(&h->reply_list, struct xs_stored_msg, list);
- list_del(&msg->list);
- assert(list_empty(&h->reply_list));
+ msg = XEN_TAILQ_FIRST(&h->reply_list);
+ XEN_TAILQ_REMOVE(&h->reply_list, msg, list);
+ assert(XEN_TAILQ_EMPTY(&h->reply_list));
mutex_unlock(&h->reply_mutex);
*type = msg->hdr.type;
@@ -883,7 +883,7 @@ static void xs_maybe_clear_watch_pipe(struct xs_handle *h)
{
char c;
- if (list_empty(&h->watch_list) && (h->watch_pipe[0] != -1))
+ if (XEN_TAILQ_EMPTY(&h->watch_list) && (h->watch_pipe[0] != -1))
while (read(h->watch_pipe[0], &c, 1) != 1)
continue;
}
@@ -907,7 +907,7 @@ static char **read_watch_internal(struct xs_handle *h, unsigned int *num,
* we haven't called xs_watch. Presumably the application
* will do so later; in the meantime we just block.
*/
- while (list_empty(&h->watch_list) && h->fd != -1) {
+ while (XEN_TAILQ_EMPTY(&h->watch_list) && h->fd != -1) {
if (nonblocking) {
mutex_unlock(&h->watch_mutex);
errno = EAGAIN;
@@ -925,13 +925,13 @@ static char **read_watch_internal(struct xs_handle *h, unsigned int *num,
#endif /* !defined(USE_PTHREAD) */
- if (list_empty(&h->watch_list)) {
+ if (XEN_TAILQ_EMPTY(&h->watch_list)) {
mutex_unlock(&h->watch_mutex);
errno = EINVAL;
return NULL;
}
- msg = list_top(&h->watch_list, struct xs_stored_msg, list);
- list_del(&msg->list);
+ msg = XEN_TAILQ_FIRST(&h->watch_list);
+ XEN_TAILQ_REMOVE(&h->watch_list, msg, list);
xs_maybe_clear_watch_pipe(h);
mutex_unlock(&h->watch_mutex);
@@ -1007,12 +1007,12 @@ bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)
/* Filter the watch list to remove potential message */
mutex_lock(&h->watch_mutex);
- if (list_empty(&h->watch_list)) {
+ if (XEN_TAILQ_EMPTY(&h->watch_list)) {
mutex_unlock(&h->watch_mutex);
return res;
}
- list_for_each_entry_safe(msg, tmsg, &h->watch_list, list) {
+ XEN_TAILQ_FOREACH_SAFE(msg, &h->watch_list, list, tmsg) {
assert(msg->hdr.type == XS_WATCH_EVENT);
s = msg->body;
@@ -1034,7 +1034,7 @@ bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)
if (l_token && !strcmp(token, l_token) &&
l_path && xs_path_is_subpath(path, l_path)) {
- list_del(&msg->list);
+ XEN_TAILQ_REMOVE(&h->watch_list, msg, list);
free(msg);
}
}
@@ -1290,12 +1290,12 @@ static int read_message(struct xs_handle *h, int nonblocking)
cleanup_push(pthread_mutex_unlock, &h->watch_mutex);
/* Kick users out of their select() loop. */
- if (list_empty(&h->watch_list) &&
+ if (XEN_TAILQ_EMPTY(&h->watch_list) &&
(h->watch_pipe[1] != -1))
while (write(h->watch_pipe[1], body, 1) != 1) /* Cancellation point */
continue;
- list_add_tail(&msg->list, &h->watch_list);
+ XEN_TAILQ_INSERT_TAIL(&h->watch_list, msg, list);
condvar_signal(&h->watch_condvar);
@@ -1304,13 +1304,13 @@ static int read_message(struct xs_handle *h, int nonblocking)
mutex_lock(&h->reply_mutex);
/* There should only ever be one response pending! */
- if (!list_empty(&h->reply_list)) {
+ if (!XEN_TAILQ_EMPTY(&h->reply_list)) {
mutex_unlock(&h->reply_mutex);
saved_errno = EEXIST;
goto error_freebody;
}
- list_add_tail(&msg->list, &h->reply_list);
+ XEN_TAILQ_INSERT_TAIL(&h->reply_list, msg, list);
condvar_signal(&h->reply_condvar);
mutex_unlock(&h->reply_mutex);
--
2.35.3
next prev parent reply other threads:[~2023-05-30 8:55 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 8:54 [PATCH v3 00/16] tools/xenstore: more cleanups Juergen Gross
2023-05-30 8:54 ` [PATCH v3 01/16] tools/xenstore: verify command line parameters better Juergen Gross
2023-05-30 8:54 ` [PATCH v3 02/16] tools/xenstore: do some cleanup of hashtable.c Juergen Gross
2023-05-30 8:54 ` [PATCH v3 03/16] tools/xenstore: modify interface of create_hashtable() Juergen Gross
2023-06-09 17:52 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 04/16] tools/xenstore: rename hashtable_insert() and let it return 0 on success Juergen Gross
2023-06-09 17:56 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 05/16] tools/xenstore: make some write limit functions static Juergen Gross
2023-06-09 18:00 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 06/16] tools/xenstore: switch write limiting to use millisecond time base Juergen Gross
2023-06-09 18:02 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 07/16] tools/xenstore: remove stale TODO file Juergen Gross
2023-05-30 8:54 ` [PATCH v3 08/16] tools/xenstore: remove unused events list Juergen Gross
2023-05-30 8:54 ` [PATCH v3 09/16] tools/xenstore: remove support of file backed data base Juergen Gross
2023-06-09 18:04 ` Julien Grall
2023-05-30 8:54 ` Juergen Gross [this message]
2023-06-09 18:09 ` [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h Julien Grall
2023-06-12 7:02 ` Juergen Gross
2023-06-12 10:34 ` Julien Grall
2023-06-12 10:37 ` Juergen Gross
2023-06-12 10:39 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 11/16] tools/libs/store: make libxenstore independent of utils.h Juergen Gross
2023-06-09 18:10 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 12/16] tools/xenstore: remove no longer needed functions from xs_lib.c Juergen Gross
2023-06-15 21:00 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 13/16] tools/xenstore: replace xs_lib.c with a header Juergen Gross
2023-06-15 21:03 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 14/16] tools/xenstore: split out environment specific live update code Juergen Gross
2023-06-19 17:55 ` Julien Grall
2023-06-20 8:22 ` Juergen Gross
2023-05-30 8:54 ` [PATCH v3 15/16] tools/xenstore: split out rest of live update control code Juergen Gross
2023-06-19 18:03 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 16/16] tools/xenstore: remove unused stuff from list.h Juergen Gross
2023-06-19 18:04 ` Julien Grall
2023-06-09 18:46 ` [PATCH v3 00/16] tools/xenstore: more cleanups Julien Grall
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=20230530085418.5417-11-jgross@suse.com \
--to=jgross@suse.com \
--cc=anthony.perard@citrix.com \
--cc=julien@xen.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/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).