All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@citrix.com>
To: "Jiang, Yunhong" <yunhong.jiang@intel.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	"gm281@cam.ac.uk" <gm281@cam.ac.uk>,
	"samuel.thibault@eu.citrix.com" <samuel.thibault@eu.citrix.com>
Subject: Re: Why xs_domain_open() in fs_backend
Date: Wed, 13 Oct 2010 13:57:07 +0100	[thread overview]
Message-ID: <1286974627.2003.3294.camel@zakaz.uk.xensource.com> (raw)
In-Reply-To: <789F9655DD1B8F43B48D77C5D30659732F9D7EBD@shsmsx501.ccr.corp.intel.com>

On Wed, 2010-10-13 at 08:19 +0100, Jiang, Yunhong wrote:
> the xenstore_client.c does not use watch feature at all.

I've occasionally thought that it might be useful to have a
xenstore-watch command for skanky scripting purposes so below is a patch
to add one.

I don't know how useful it is generally but it can be used to shows that
"xenstore-watch -s x" (i.e. xs_daemon_open) does appear to be broken.

Subject: xenstore: add xenstore-watch command line client

# xenstore-watch x | while read w ; do
> echo "watch fired on $w"
> echo "value" $(xenstore-read $w)
> echo
> done

# xenstore-write x/y/z 42

output from while loop:
        watch fired on x/t/z
        value 42

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 0b69bd41cf15 tools/xenstore/Makefile
--- a/tools/xenstore/Makefile	Wed Oct 13 13:47:32 2010 +0100
+++ b/tools/xenstore/Makefile	Wed Oct 13 13:56:08 2010 +0100
@@ -9,7 +9,7 @@ CFLAGS += $(CFLAGS_libxenctrl)
 CFLAGS += $(CFLAGS_libxenctrl)
 
 CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
-CLIENTS += xenstore-write xenstore-ls
+CLIENTS += xenstore-write xenstore-ls xenstore-watch
 
 XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
 
diff -r 0b69bd41cf15 tools/xenstore/xenstore_client.c
--- a/tools/xenstore/xenstore_client.c	Wed Oct 13 13:47:32 2010 +0100
+++ b/tools/xenstore/xenstore_client.c	Wed Oct 13 13:56:08 2010 +0100
@@ -36,6 +36,7 @@ enum mode {
     MODE_read,
     MODE_rm,
     MODE_write,
+    MODE_watch,
 };
 
 static char *output_buf = NULL;
@@ -95,6 +96,9 @@ usage(enum mode mode, int incl_mode, con
     case MODE_chmod:
 	mstr = incl_mode ? "chmod " : "";
 	errx(1, "Usage: %s %s[-h] [-u] [-r] [-s] key <mode [modes...]>", progname, mstr);
+    case MODE_watch:
+	mstr = incl_mode ? "watch " : "";
+	errx(1, "Usage: %s %s[-h] [-n NR] key", progname, mstr);
     }
 }
 
@@ -263,9 +267,28 @@ do_chmod(char *path, struct xs_permissio
     }
 }
 
+static void
+do_watch(struct xs_handle *xsh, int max_events)
+{
+    int count = 0;
+    char **vec = NULL;
+
+    for ( count = 0; max_events == -1 || count < max_events; count++ ) {
+	unsigned int num;
+
+	vec = xs_read_watch(xsh, &num);
+	if (vec == NULL)
+	    continue;
+
+	printf("%s\n", vec[XS_WATCH_PATH]);
+	fflush(stdout);
+	free(vec);
+    }
+}
+
 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)
+        xs_transaction_t xth, int prefix, int tidy, int upto, int recurse, int nr_watches)
 {
     switch (mode) {
     case MODE_ls:
@@ -428,6 +451,15 @@ perform(enum mode mode, int optind, int 
             do_chmod(path, perms, nperms, upto, recurse, xsh, xth);
             break;
         }
+        case MODE_watch: {
+            for (; argv[optind]; optind++) {
+                const char *w = argv[optind];
+
+                if (!xs_watch(xsh, w, w))
+                    errx(1, "Unable to add watch on %s\n", w);
+            }
+            do_watch(xsh, nr_watches);
+        }
         }
     }
 
@@ -452,6 +484,8 @@ static enum mode lookup_mode(const char 
 	return MODE_write;
     else if (strcmp(m, "read") == 0)
 	return MODE_read;
+    else if (strcmp(m, "watch") == 0)
+	return MODE_watch;
 
     errx(1, "unknown mode %s\n", m);
     return 0;
@@ -467,6 +501,7 @@ main(int argc, char **argv)
     int tidy = 0;
     int upto = 0;
     int recurse = 0;
+    int nr_watches = -1;
     int transaction;
     struct winsize ws;
     enum mode mode;
@@ -500,10 +535,11 @@ main(int argc, char **argv)
 	    {"tidy",    0, 0, 't'}, /* MODE_rm */
 	    {"upto",    0, 0, 'u'}, /* MODE_chmod */
 	    {"recurse", 0, 0, 'r'}, /* MODE_chmod */
+	    {"number",  1, 0, 'n'}, /* MODE_watch */
 	    {0, 0, 0, 0}
 	};
 
-	c = getopt_long(argc - switch_argv, argv + switch_argv, "hfsptur",
+	c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:",
 			long_options, &index);
 	if (c == -1)
 	    break;
@@ -548,6 +584,12 @@ main(int argc, char **argv)
 	    else
 		usage(mode, switch_argv, argv[0]);
 	    break;
+	case 'n':
+	    if ( mode == MODE_watch )
+		nr_watches = atoi(optarg);
+	    else
+		usage(mode, switch_argv, argv[0]);
+	    break;
 	}
     }
 
@@ -575,6 +617,7 @@ main(int argc, char **argv)
 	transaction = (argc - switch_argv - optind) > 2;
 	break;
     case MODE_ls:
+    case MODE_watch:
 	transaction = 0;
 	break;
     default:
@@ -601,7 +644,7 @@ again:
 	    errx(1, "couldn't start transaction");
     }
 
-    ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse);
+    ret = perform(mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse, nr_watches);
 
     if (transaction && !xs_transaction_end(xsh, xth, ret)) {
 	if (ret == 0 && errno == EAGAIN) {

  parent reply	other threads:[~2010-10-13 12:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-13  7:19 Why xs_domain_open() in fs_backend Jiang, Yunhong
2010-10-13  8:47 ` Tim Deegan
2010-10-13  9:13   ` Jiang, Yunhong
2010-10-13  9:24     ` Tim Deegan
2010-10-13 10:30       ` Stefano Stabellini
2010-10-13 12:20         ` Jiang, Yunhong
2010-10-13 13:53     ` Ian Campbell
2010-10-13 13:59       ` Jiang, Yunhong
2010-10-13 12:57 ` Ian Campbell [this message]
2010-10-13 13:18   ` Ian Campbell
2010-10-13 13:47     ` Ian Campbell
2010-10-13 14:04       ` Jiang, Yunhong
2010-10-13 15:34         ` Ian Campbell
2010-10-15  2:29           ` Jiang, Yunhong
2010-10-15  6:49             ` Ian Campbell
2010-10-15  6:55               ` Jiang, Yunhong
2010-10-21 16:57       ` Ian Jackson
2010-10-21 17:15   ` Ian Jackson

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=1286974627.2003.3294.camel@zakaz.uk.xensource.com \
    --to=ian.campbell@citrix.com \
    --cc=gm281@cam.ac.uk \
    --cc=samuel.thibault@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    --cc=yunhong.jiang@intel.com \
    /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.