aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore
diff options
context:
space:
mode:
authorStefano Stabellini <sstabellini@xensource.com>2010-12-13 17:15:31 +0000
committerStefano Stabellini <sstabellini@xensource.com>2010-12-13 17:15:31 +0000
commit999241f7aa459cfa20c6b122374eb4c62c10c5a9 (patch)
tree3b27625788039716621ee426c912d916cebabd60 /tools/xenstore
parent2610f0b28d31a6fd19c271f229189c68d14ad54f (diff)
downloadxen-999241f7aa459cfa20c6b122374eb4c62c10c5a9.tar.gz
xen-999241f7aa459cfa20c6b122374eb4c62c10c5a9.tar.bz2
xen-999241f7aa459cfa20c6b122374eb4c62c10c5a9.zip
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@cs.ubc.ca> Acked-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Diffstat (limited to 'tools/xenstore')
-rw-r--r--tools/xenstore/xs.c38
-rw-r--r--tools/xenstore/xs.h20
2 files changed, 50 insertions, 8 deletions
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 112feec8a5..f3532b03c1 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -182,12 +182,15 @@ error:
return -1;
}
-static int get_dev(const char *connect_to)
+static int get_dev(const char *connect_to, unsigned long flags)
{
- return open(connect_to, O_RDWR);
+ 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)
+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(const char *connect_to)
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(const char *connect_to)
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) {
@@ -303,6 +321,12 @@ void xs_daemon_close(struct xs_handle *h)
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)
{
while (len) {
diff --git a/tools/xenstore/xs.h b/tools/xenstore/xs.h
index 4806f1e240..1e28849eac 100644
--- a/tools/xenstore/xs.h
+++ b/tools/xenstore/xs.h
@@ -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(). */