WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Adds an open xenstore connection function

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Adds an open xenstore connection function which tries to use the xenbus
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 23 Dec 2010 05:33:55 -0800
Delivery-date: Thu, 23 Dec 2010 05:38:29 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Stefano Stabellini <sstabellini@xxxxxxxxxxxxx>
# Date 1292260531 0
# Node ID a40455ae9ad3f1d0ff057fb61b833223c95fc762
# Parent  e5c48e0cd03d81e4e74952fe29fe3a7506e525a4
Adds an open xenstore connection function which tries to use the xenbus
interface (xs_domain_open) when the socket interface (xs_daemon_opn)
fails.

Signed-off-by: Mihir Nanavati <mihirn@xxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
committer: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 tools/xenstore/xs.c |   44 ++++++++++++++++++++++++++++++++++----------
 tools/xenstore/xs.h |   20 +++++++++++++++++++-
 2 files changed, 53 insertions(+), 11 deletions(-)

diff -r e5c48e0cd03d -r a40455ae9ad3 tools/xenstore/xs.c
--- a/tools/xenstore/xs.c       Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/xenstore/xs.c       Mon Dec 13 17:15:31 2010 +0000
@@ -182,12 +182,15 @@ error:
        return -1;
 }
 
-static int get_dev(const char *connect_to)
-{
-       return open(connect_to, O_RDWR);
-}
-
-static struct xs_handle *get_handle(const char *connect_to)
+static int get_dev(const char *connect_to, unsigned long flags)
+{
+       if (flags & XS_OPEN_READONLY)
+               return open(connect_to, O_RDONLY);
+       else
+               return open(connect_to, O_RDWR);
+}
+
+static struct xs_handle *get_handle(const char *connect_to, unsigned long 
flags)
 {
        struct stat buf;
        struct xs_handle *h = NULL;
@@ -199,7 +202,7 @@ static struct xs_handle *get_handle(cons
        if (S_ISSOCK(buf.st_mode))
                fd = get_socket(connect_to);
        else
-               fd = get_dev(connect_to);
+               fd = get_dev(connect_to, flags);
 
        if (fd == -1)
                return NULL;
@@ -237,17 +240,32 @@ static struct xs_handle *get_handle(cons
 
 struct xs_handle *xs_daemon_open(void)
 {
-       return get_handle(xs_daemon_socket());
+       return xs_open(0);
 }
 
 struct xs_handle *xs_daemon_open_readonly(void)
 {
-       return get_handle(xs_daemon_socket_ro());
+       return xs_open(XS_OPEN_READONLY);
 }
 
 struct xs_handle *xs_domain_open(void)
 {
-       return get_handle(xs_domain_dev());
+       return xs_open(0);
+}
+
+struct xs_handle *xs_open(unsigned long flags)
+{
+       struct xs_handle *xsh = NULL;
+
+       if (flags & XS_OPEN_READONLY)
+               xsh = get_handle(xs_daemon_socket_ro(), flags);
+       else
+               xsh = get_handle(xs_daemon_socket(), flags);
+
+       if (!xsh)
+               xsh = get_handle(xs_domain_dev(), flags);
+
+       return xsh;
 }
 
 static void close_free_msgs(struct xs_handle *h) {
@@ -301,6 +319,12 @@ void xs_daemon_close(struct xs_handle *h
        mutex_unlock(&h->watch_mutex);
 
         close_fds_free(h);
+}
+
+void xs_close(struct xs_handle* xsh)
+{
+       if (xsh)
+               xs_daemon_close(xsh);
 }
 
 static bool read_all(int fd, void *data, unsigned int len)
diff -r e5c48e0cd03d -r a40455ae9ad3 tools/xenstore/xs.h
--- a/tools/xenstore/xs.h       Thu Dec 02 12:49:00 2010 +0000
+++ b/tools/xenstore/xs.h       Mon Dec 13 17:15:31 2010 +0000
@@ -24,6 +24,8 @@
 
 #define XBT_NULL 0
 
+#define XS_OPEN_READONLY       1<<0
+
 struct xs_handle;
 typedef uint32_t xs_transaction_t;
 
@@ -34,18 +36,34 @@ typedef uint32_t xs_transaction_t;
 
 /* On failure, these routines set errno. */
 
+/* Open a connection to the xs daemon.
+ * Attempts to make a connection over the socket interface, 
+ * and if it fails, then over the  xenbus interface.
+ * Mode 0 specifies read-write access, XS_OPEN_READONLY for
+ * read-only access.
+ * Returns a handle or NULL.
+ */
+struct xs_handle *xs_open(unsigned long flags);
+
+/* Close the connection to the xs daemon. */
+void xs_close(struct xs_handle *xsh);
+
 /* Connect to the xs daemon.
  * Returns a handle or NULL.
+ * Deprecated, please use xs_open(0) instead
  */
 struct xs_handle *xs_daemon_open(void);
 struct xs_handle *xs_domain_open(void);
 
 /* Connect to the xs daemon (readonly for non-root clients).
  * Returns a handle or NULL.
+ * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
  */
 struct xs_handle *xs_daemon_open_readonly(void);
 
-/* Close the connection to the xs daemon. */
+/* Close the connection to the xs daemon.
+ * Deprecated, please use xs_close() instead
+ */
 void xs_daemon_close(struct xs_handle *);
 
 /* Throw away the connection to the xs daemon, for use after fork(). */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Adds an open xenstore connection function which tries to use the xenbus, Xen patchbot-unstable <=