From 464b7f4f267f978302f2758bb6dad3f56fef30d3 Mon Sep 17 00:00:00 2001 From: Juergen Gross Date: Tue, 21 Apr 2026 09:42:11 +0200 Subject: [PATCH] tools/xs-clients: support depth with xenstore-watch Add a "-d " 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 Reviewed-by: 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 + +Limit the number of sub-directories below the specified Is to be +watched. A B of 0 will watch only the specified nodes, a B +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 Stop waiting after having received B 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) {