aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore/xs.h
blob: ff9481c3a62dab381078457ec43468d245e22aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef _XS_H
#define _XS_H
/* 
    Xen Store Daemon providing simple tree-like database.
    Copyright (C) 2005 Rusty Russell IBM Corporation

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/* On failure, these routines set errno. */
#include "xs_lib.h"

struct xs_handle;

/* Connect to the xs daemon.
 * Returns a handle or NULL.
 */
struct xs_handle *xs_daemon_open(void);

/* Connect to the xs daemon (readonly for non-root clients).
 * Returns a handle or NULL.
 */
struct xs_handle *xs_daemon_open_readonly(void);

/* Close the connection to the xs daemon. */
void xs_daemon_close(struct xs_handle *);

/* Get contents of a directory.
 * Returns a malloced array: call free() on it after use.
 * Num indicates size.
 */
char **xs_directory(struct xs_handle *h, const char *path, unsigned int *num);

/* Get the value of a single file.
 * Returns a malloced value: call free() on it after use.
 * len indicates length in bytes.
 */
void *xs_read(struct xs_handle *h, const char *path, unsigned int *len);

/* Write the value of a single file.
 * Returns false on failure.  createflags can be 0, O_CREAT, or O_CREAT|O_EXCL.
 */
bool xs_write(struct xs_handle *h, const char *path, const void *data, unsigned int len,
	      int createflags);

/* Create a new directory.
 * Returns false on failure.
 */
bool xs_mkdir(struct xs_handle *h, const char *path);

/* Destroy a file or directory (and children).
 * Returns false on failure.
 */
bool xs_rm(struct xs_handle *h, const char *path);

/* Get permissions of node (first element is owner, first perms is "other").
 * Returns malloced array, or NULL: call free() after use.
 */
struct xs_permissions *xs_get_permissions(struct xs_handle *h,
					  const char *path,
					  unsigned int *num);

/* Set permissions of node (must be owner).
 * Returns false on failure.
 */
bool xs_set_permissions(struct xs_handle *h,
			const char *path,
			struct xs_permissions *perms,
			unsigned int num_perms);

/* Watch a node for changes (poll on fd to detect, or call read_watch()).
 * When the node (or any child) changes, fd will become readable.
 * Priority indicates order if multiple watchers: higher is first.
 * Returns false on failure.
 */
bool xs_watch(struct xs_handle *h, const char *path, unsigned int priority);

/* Return the FD to poll on to see if a watch has fired. */
int xs_fileno(struct xs_handle *h);

/* Find out what node change was on (will block if nothing pending).
 * Returns malloced path, or NULL: call free() after use.
 */
char *xs_read_watch(struct xs_handle *h);

/* Acknowledge watch on node.  Watches must be acknowledged before
 * any other watches can be read.
 * Returns false on failure.
 */
bool xs_acknowledge_watch(struct xs_handle *h);

/* Remove a watch on a node.
 * Returns false on failure (no watch on that node).
 */
bool xs_unwatch(struct xs_handle *h, const char *path);

/* Start a transaction: changes by others will not be seen during this
 * transaction, and changes will not be visible to others until end.
 * Transaction only applies to the given subtree.
 * You can only have one transaction at any time.
 * Returns false on failure.
 */
bool xs_transaction_start(struct xs_handle *h, const char *subtree);

/* End a transaction.
 * If abandon is true, transaction is discarded instead of committed.
 * Returns false on failure, which indicates an error: transactions will
 * not fail spuriously.
 */
bool xs_transaction_end(struct xs_handle *h, bool abort);

/* Introduce a new domain.
 * This tells the store daemon about a shared memory page, event channel
 * and store path associated with a domain: the domain uses these to communicate.
 */
bool xs_introduce_domain(struct xs_handle *h,
                         domid_t domid,
                         unsigned long mfn,
                         unsigned int eventchn,
                         const char *path);

/* Release a domain.
 * Tells the store domain to release the memory page to the domain.
 */
bool xs_release_domain(struct xs_handle *h, domid_t domid);

/* Only useful for DEBUG versions */
char *xs_debug_command(struct xs_handle *h, const char *cmd,
		       void *data, unsigned int len);

/* Shut down the daemon. */
bool xs_shutdown(struct xs_handle *h);

#endif /* _XS_H */