[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 9/9] tools/xs-clients: support depth with xenstore-watch


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Juergen Gross <jgross@xxxxxxxx>
  • Date: Tue, 21 Apr 2026 09:42:11 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=susede1 header.d=suse.com header.i="@suse.com" header.h="From:Date:Message-ID:To:Cc:MIME-Version:Content-Transfer-Encoding:In-Reply-To:References"; dkim=pass header.s=susede1 header.d=suse.com header.i="@suse.com" header.h="From:Date:Message-ID:To:Cc:MIME-Version:Content-Transfer-Encoding:In-Reply-To:References"
  • Authentication-results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=IdV5N36U
  • Cc: Juergen Gross <jgross@xxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Tue, 21 Apr 2026 07:43:06 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add a "-d <depth>" parameter to xenstore-watch, allowing to specify
the depth parameter of the XS_WATCH command.

Using "-d" without support of depth by xenstored will refuse to set
the watch(es).

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
V2:
- add new flag to man page (Jason Andryuk)
---
 docs/man/xenstore-watch.1.pod      |  9 +++++++++
 tools/xs-clients/xenstore_client.c | 19 +++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/docs/man/xenstore-watch.1.pod b/docs/man/xenstore-watch.1.pod
index de28d380b7..716c5521bc 100644
--- a/docs/man/xenstore-watch.1.pod
+++ b/docs/man/xenstore-watch.1.pod
@@ -17,6 +17,15 @@ event happening.
 
 Show the usage information for xenstore-watch and exit the program.
 
+=item B<-d> B<depth>
+
+Limit the number of sub-directories below the specified I<PATH>s to be
+watched. A B<depth> of 0 will watch only the specified nodes, a B<depth>
+of 1 will watch the specified nodes and their direct children, etc.
+
+Using this option requires xenstored to support the Xenstore watch depth
+feature. In case it is not supported, the B<-d> usage will be rejected.
+
 =item B<-n> B<NR>
 
 Stop waiting after having received B<NR> watch events.
diff --git a/tools/xs-clients/xenstore_client.c 
b/tools/xs-clients/xenstore_client.c
index 9a25704b91..4a14cb334f 100644
--- a/tools/xs-clients/xenstore_client.c
+++ b/tools/xs-clients/xenstore_client.c
@@ -445,7 +445,7 @@ do_watch(struct xs_handle *xsh, int max_events)
 static int
 perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle 
*xsh,
         xs_transaction_t xth, int prefix, int tidy, int upto, int recurse, int 
nr_watches,
-        int raw)
+        int raw, int depth)
 {
     switch (mode) {
     case MODE_ls:
@@ -627,8 +627,11 @@ perform(enum mode mode, int optind, int argc, char **argv, 
struct xs_handle *xsh
             for (; argv[optind]; optind++) {
                 const char *w = argv[optind];
 
-                if (!xs_watch(xsh, w, w))
+                if (depth < 0 && !xs_watch(xsh, w, w))
                     errx(1, "Unable to add watch on %s\n", w);
+                if (depth >= 0 && !xs_watch_depth(xsh, w, w, depth))
+                    errx(1, "Unable to add watch on %s with depth %d\n", w,
+                         depth);
             }
             do_watch(xsh, nr_watches);
         }
@@ -676,6 +679,7 @@ main(int argc, char **argv)
     int nr_watches = -1;
     int transaction;
     int raw = 0;
+    int depth = -1;
     struct winsize ws;
     enum mode mode;
 
@@ -709,10 +713,11 @@ main(int argc, char **argv)
            {"recurse", 0, 0, 'r'}, /* MODE_chmod */
            {"number",  1, 0, 'n'}, /* MODE_watch */
            {"raw",     0, 0, 'R'}, /* MODE_read || MODE_write */
+           {"depth",   1, 0, 'd'}, /* MODE_watch */
            {0, 0, 0, 0}
        };
 
-       c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:R",
+       c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:Rd:",
                        long_options, &index);
        if (c == -1)
            break;
@@ -766,6 +771,12 @@ main(int argc, char **argv)
            else
                usage(1, mode, switch_argv, argv[0]);
            break;
+       case 'd':
+           if ( mode == MODE_watch )
+               depth = atoi(optarg);
+           else
+               usage(1, mode, switch_argv, argv[0]);
+           break;
        }
     }
 
@@ -819,7 +830,7 @@ again:
            errx(1, "couldn't start transaction");
     }
 
-    ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, 
xth, prefix, tidy, upto, recurse, nr_watches, raw);
+    ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, 
xth, prefix, tidy, upto, recurse, nr_watches, raw, depth);
 
     if (transaction && !xs_transaction_end(xsh, xth, ret)) {
        if (ret == 0 && errno == EAGAIN) {
-- 
2.53.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.