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

[Xen-devel] [PATCH v4 01/15] xenstore: add support for a retry open limit on xenstored



From: "Luis R. Rodriguez" <mcgrof@xxxxxxxx>

This adds support for a customizable retry limit on trying to open
the xenstored unix domain socket, each retry is separated by 1 second.
This should allow us to simplify both our LSB init scripts. For systemd
we'll use socket activation.

Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Jan RÄkorajski <baggins@xxxxxxxxxxxxx>
Cc: M A Young <m.a.young@xxxxxxxxxxxx>
Cc: Jacek Konieczny <jajcus@xxxxxxxxxx>
Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxx>
---
 docs/man/xenstore.pod.1          |  7 ++++++-
 tools/xenstore/xenstore_client.c | 40 +++++++++++++++++++++++++++++-----------
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/docs/man/xenstore.pod.1 b/docs/man/xenstore.pod.1
index 7417289..9647143 100644
--- a/docs/man/xenstore.pod.1
+++ b/docs/man/xenstore.pod.1
@@ -4,12 +4,17 @@ xenstore - interact with Xenstore
 
 =head1 SYNOPSIS
 
-B<xenstore> I<CMD> ...
+B<xenstore> I<CMD> I[ --retries <num_open_retries> ] ...
 
 =head1 DESCRIPTION
 
 A set of utilities for interacting with Xenstore.
 
+All xenstore-* commands support the --retries long option which
+can be used to try to opening the unix domain socket a certain
+number of retries before giving up. Each new try occurs every
+second.
+
 =over
 
 =item B<xenstore-chmod>(1)
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 0ec103f..0ab40f7 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -77,27 +77,28 @@ usage(enum mode mode, int incl_mode, const char *progname)
        errx(1, "Usage: %s <mode> [-h] [...]", progname);
     case MODE_read:
        mstr = incl_mode ? "read " : "";
-       errx(1, "Usage: %s %s[-h] [-p] [-s] key [...]", progname, mstr);
+       errx(1, "Usage: %s %s[-h] [ --retries <num_open_retries> ] [-p] [-s] 
key [...]",
+            progname, mstr);
     case MODE_write:
        mstr = incl_mode ? "write " : "";
-       errx(1, "Usage: %s %s[-h] [-s] key value [...]", progname, mstr);
+       errx(1, "Usage: %s %s[-h] [ --retries <num_open_retries> ] [-s] key 
value [...]", progname, mstr);
     case MODE_rm:
        mstr = incl_mode ? "rm " : "";
-       errx(1, "Usage: %s %s[-h] [-s] [-t] key [...]", progname, mstr);
+       errx(1, "Usage: %s %s[-h] [ --retries <num_open_retries> ] [-s] [-t] 
key [...]", progname, mstr);
     case MODE_exists:
        mstr = incl_mode ? "exists " : "";
     case MODE_list:
        mstr = mstr ? : incl_mode ? "list " : "";
-       errx(1, "Usage: %s %s[-h] [-p] [-s] key [...]", progname, mstr);
+       errx(1, "Usage: %s %s[-h] [ --retries <num_open_retries> ] [-p] [-s] 
key [...]", progname, mstr);
     case MODE_ls:
        mstr = mstr ? : incl_mode ? "ls " : "";
-       errx(1, "Usage: %s %s[-h] [-f] [-p] [-s] [path]", progname, mstr);
+       errx(1, "Usage: %s %s[-h] [ --retries <num_open_retries> ] [-f] [-p] 
[-s] [path]", progname, mstr);
     case MODE_chmod:
        mstr = incl_mode ? "chmod " : "";
-       errx(1, "Usage: %s %s[-h] [-u] [-r] [-s] key <mode [modes...]>", 
progname, mstr);
+       errx(1, "Usage: %s %s[-h] [ --retries <num_open_retries> ] [-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);
+       errx(1, "Usage: %s %s[-h] [ --retries <num_open_retries> ] [-n NR] 
key", progname, mstr);
     }
 }
 
@@ -493,9 +494,9 @@ static enum mode lookup_mode(const char *m)
 int
 main(int argc, char **argv)
 {
-    struct xs_handle *xsh;
+    struct xs_handle *xsh = NULL;
     xs_transaction_t xth = XBT_NULL;
-    int ret = 0, socket = 0;
+    int ret = 0, socket = 0, retries = 1;
     int prefix = 0;
     int tidy = 0;
     int upto = 0;
@@ -535,6 +536,7 @@ main(int argc, char **argv)
            {"upto",    0, 0, 'u'}, /* MODE_chmod */
            {"recurse", 0, 0, 'r'}, /* MODE_chmod */
            {"number",  1, 0, 'n'}, /* MODE_watch */
+           {"retries", 1, 0,  0 }, /* index 8 - MODE_* */
            {0, 0, 0, 0}
        };
 
@@ -544,6 +546,15 @@ main(int argc, char **argv)
            break;
 
        switch (c) {
+       case 0:
+           if (index == 8 && optarg) {
+               retries = atoi(optarg);
+               if (retries < 0) {
+                    retries = 1;
+                    usage(mode, switch_argv, argv[0]);
+               }
+           }
+           break;
        case 'h':
            usage(mode, switch_argv, argv[0]);
            /* NOTREACHED */
@@ -632,8 +643,15 @@ main(int argc, char **argv)
            max_width = ws.ws_col - 2;
     }
 
-    xsh = xs_open(socket ? XS_OPEN_SOCKETONLY : 0);
-    if (xsh == NULL) err(1, "xs_open");
+    while (retries--) {
+           xsh = xs_open(socket ? XS_OPEN_SOCKETONLY : 0);
+           if (xsh)
+                   break;
+           if (retries)
+                   sleep(1);
+    }
+    if (!xsh)
+           err(1, "xs_open");
 
 again:
     if (transaction) {
-- 
1.9.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

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