All of lore.kernel.org
 help / color / mirror / Atom feed
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 v2 08/19] tools/xenstore: replace watch->relative_path with a prefix length
Date: Tue, 13 Dec 2022 17:00:34 +0100	[thread overview]
Message-ID: <20221213160045.28170-9-jgross@suse.com> (raw)
In-Reply-To: <20221213160045.28170-1-jgross@suse.com>

Instead of storing a pointer to the path which is prepended to
relative paths in struct watch, just use the length of the prepended
path.

It should be noted that the now removed special case of the
relative path being "" in get_watch_path() can't happen at all.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- don't open code get_watch_path() (Julien Grall)
---
 tools/xenstore/xenstored_watch.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_watch.c
index 75748ac109..5c0f764781 100644
--- a/tools/xenstore/xenstored_watch.c
+++ b/tools/xenstore/xenstored_watch.c
@@ -39,8 +39,8 @@ struct watch
 	/* Current outstanding events applying to this watch. */
 	struct list_head events;
 
-	/* Is this relative to connnection's implicit path? */
-	const char *relative_path;
+	/* Offset into path for skipping prefix (used for relative paths). */
+	unsigned int prefix_len;
 
 	char *token;
 	char *node;
@@ -66,15 +66,7 @@ static bool is_child(const char *child, const char *parent)
 
 static const char *get_watch_path(const struct watch *watch, const char *name)
 {
-	const char *path = name;
-
-	if (watch->relative_path) {
-		path += strlen(watch->relative_path);
-		if (*path == '/') /* Could be "" */
-			path++;
-	}
-
-	return path;
+	return name + watch->prefix_len;
 }
 
 /*
@@ -211,10 +203,7 @@ static struct watch *add_watch(struct connection *conn, char *path, char *token,
 			      no_quota_check))
 		goto nomem;
 
-	if (relative)
-		watch->relative_path = get_implicit_path(conn);
-	else
-		watch->relative_path = NULL;
+	watch->prefix_len = relative ? strlen(get_implicit_path(conn)) + 1 : 0;
 
 	INIT_LIST_HEAD(&watch->events);
 
@@ -313,19 +302,19 @@ const char *dump_state_watches(FILE *fp, struct connection *conn,
 			       unsigned int conn_id)
 {
 	const char *ret = NULL;
+	const char *watch_path;
 	struct watch *watch;
 	struct xs_state_watch sw;
 	struct xs_state_record_header head;
-	const char *path;
 
 	head.type = XS_STATE_TYPE_WATCH;
 
 	list_for_each_entry(watch, &conn->watches, list) {
 		head.length = sizeof(sw);
 
+		watch_path = get_watch_path(watch, watch->node);
 		sw.conn_id = conn_id;
-		path = get_watch_path(watch, watch->node);
-		sw.path_length = strlen(path) + 1;
+		sw.path_length = strlen(watch_path) + 1;
 		sw.token_length = strlen(watch->token) + 1;
 		head.length += sw.path_length + sw.token_length;
 		head.length = ROUNDUP(head.length, 3);
@@ -334,7 +323,7 @@ const char *dump_state_watches(FILE *fp, struct connection *conn,
 		if (fwrite(&sw, sizeof(sw), 1, fp) != 1)
 			return "Dump watch state error";
 
-		if (fwrite(path, sw.path_length, 1, fp) != 1)
+		if (fwrite(watch_path, sw.path_length, 1, fp) != 1)
 			return "Dump watch path error";
 		if (fwrite(watch->token, sw.token_length, 1, fp) != 1)
 			return "Dump watch token error";
-- 
2.35.3



  parent reply	other threads:[~2022-12-13 16:05 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-13 16:00 [PATCH v2 00/19] tools/xenstore: do some cleanup and fixes Juergen Gross
2022-12-13 16:00 ` [PATCH v2 01/19] tools/xenstore: let talloc_free() preserve errno Juergen Gross
2022-12-14  9:54   ` Jan Beulich
2022-12-14 10:08     ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 02/19] tools/xenstore: let tdb_logger() " Juergen Gross
2022-12-13 16:00 ` [PATCH v2 03/19] tools/xenstore: preserve errno across corrupt() Juergen Gross
2022-12-13 16:00 ` [PATCH v2 04/19] tools/xenstore: remove all watches when a domain has stopped Juergen Gross
2022-12-20 19:01   ` Julien Grall
2023-01-11  6:36     ` Juergen Gross
2023-01-11 17:45       ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 05/19] tools/xenstore: enhance hashtable implementation Juergen Gross
2022-12-13 16:00 ` [PATCH v2 06/19] tools/xenstore: add hashlist for finding struct domain by domid Juergen Gross
2022-12-20 19:09   ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 07/19] tools/xenstore: introduce dummy nodes for special watch paths Juergen Gross
2022-12-20 19:39   ` Julien Grall
2023-01-11  6:41     ` Juergen Gross
2023-01-11 17:46       ` Julien Grall
2022-12-13 16:00 ` Juergen Gross [this message]
2022-12-20 19:42   ` [PATCH v2 08/19] tools/xenstore: replace watch->relative_path with a prefix length Julien Grall
2023-01-11  6:48     ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 09/19] tools/xenstore: move changed domain handling Juergen Gross
2022-12-20 19:49   ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 10/19] tools/xenstore: change per-domain node accounting interface Juergen Gross
2022-12-20 20:15   ` Julien Grall
2023-01-11  8:59     ` Juergen Gross
2023-01-11 17:48       ` Julien Grall
2023-01-12  5:49         ` Juergen Gross
2023-01-13  9:53           ` Julien Grall
2023-01-13  9:57             ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 11/19] tools/xenstore: don't allow creating too many nodes in a transaction Juergen Gross
2022-12-20 20:18   ` Julien Grall
2023-01-11  9:07     ` Juergen Gross
2022-12-13 16:00 ` [PATCH v2 12/19] tools/xenstore: replace literal domid 0 with dom0_domid Juergen Gross
2022-12-13 16:00 ` [PATCH v2 13/19] tools/xenstore: make domain_is_unprivileged() an inline function Juergen Gross
2022-12-13 16:00 ` [PATCH v2 14/19] tools/xenstore: let chk_domain_generation() return a bool Juergen Gross
2022-12-13 16:00 ` [PATCH v2 15/19] tools/xenstore: switch hashtable to use the talloc framework Juergen Gross
2022-12-20 21:50   ` Julien Grall
2023-01-11  9:27     ` Juergen Gross
2023-01-11 17:50       ` Julien Grall
2022-12-13 16:00 ` [PATCH v2 16/19] tools/xenstore: make log macro globally available Juergen Gross
2022-12-13 16:00 ` [PATCH v2 17/19] tools/xenstore: introduce trace classes Juergen Gross
2022-12-13 16:00 ` [PATCH v2 18/19] tools/xenstore: let check_store() check the accounting data Juergen Gross
2022-12-13 16:00 ` [PATCH v2 19/19] tools/xenstore: make output of "xenstore-control help" more pretty Juergen Gross
2022-12-14 11:06 ` [PATCH v2 00/19] tools/xenstore: do some cleanup and fixes Jan Beulich

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=20221213160045.28170-9-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.