mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
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:
1 parent
7e7723ea07
commit
464b7f4f26
2 files changed
+24
-4
No files matched your search
@@ -17,6 +17,15 @@ event happening.
|
|||||||
|
|
||||||
Show the usage information for xenstore-watch and exit the program.
|
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>
|
=item B<-n> B<NR>
|
||||||
|
|
||||||
Stop waiting after having received B<NR> watch events.
|
Stop waiting after having received B<NR> watch events.
|
||||||
|
|||||||
@@ -445,7 +445,7 @@ do_watch(struct xs_handle *xsh, int max_events)
|
|||||||
static int
|
static int
|
||||||
perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xsh,
|
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,
|
xs_transaction_t xth, int prefix, int tidy, int upto, int recurse, int nr_watches,
|
||||||
int raw)
|
int raw, int depth)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case MODE_ls:
|
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++) {
|
for (; argv[optind]; optind++) {
|
||||||
const char *w = argv[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);
|
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);
|
do_watch(xsh, nr_watches);
|
||||||
}
|
}
|
||||||
@@ -676,6 +679,7 @@ main(int argc, char **argv)
|
|||||||
int nr_watches = -1;
|
int nr_watches = -1;
|
||||||
int transaction;
|
int transaction;
|
||||||
int raw = 0;
|
int raw = 0;
|
||||||
|
int depth = -1;
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
enum mode mode;
|
enum mode mode;
|
||||||
|
|
||||||
@@ -709,10 +713,11 @@ main(int argc, char **argv)
|
|||||||
{"recurse", 0, 0, 'r'}, /* MODE_chmod */
|
{"recurse", 0, 0, 'r'}, /* MODE_chmod */
|
||||||
{"number", 1, 0, 'n'}, /* MODE_watch */
|
{"number", 1, 0, 'n'}, /* MODE_watch */
|
||||||
{"raw", 0, 0, 'R'}, /* MODE_read || MODE_write */
|
{"raw", 0, 0, 'R'}, /* MODE_read || MODE_write */
|
||||||
|
{"depth", 1, 0, 'd'}, /* MODE_watch */
|
||||||
{0, 0, 0, 0}
|
{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);
|
long_options, &index);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
@@ -766,6 +771,12 @@ main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
usage(1, mode, switch_argv, argv[0]);
|
usage(1, mode, switch_argv, argv[0]);
|
||||||
break;
|
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");
|
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 (transaction && !xs_transaction_end(xsh, xth, ret)) {
|
||||||
if (ret == 0 && errno == EAGAIN) {
|
if (ret == 0 && errno == EAGAIN) {
|
||||||
|
|||||||