tools/xs-clients: support depth with xenstore-watch

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@suse.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
This commit is contained in:
Juergen Gross authored and Jan Beulich committed 2026-04-22 08:59:03 +02:00
1 parent 7e7723ea07
commit 464b7f4f26
2 files changed
+24 -4

No files matched your search

+9
View File
@@ -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.
+15 -4
View File
@@ -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) {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.