blob: 3ed7fd57333983b88b33be0c96f4f00ab0d09ee2 [file] [log] [blame]
Oleksandr Andrushchenko60e49ff2020-08-06 12:42:53 +03001/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef XENBUS_H__
4#define XENBUS_H__
5
6#include <xen/interface/xen.h>
7#include <xen/interface/io/xenbus.h>
8
9typedef unsigned long xenbus_transaction_t;
10#define XBT_NIL ((xenbus_transaction_t)0)
11
12extern u32 xenbus_evtchn;
13
14/* Initialize the XenBus system. */
15void init_xenbus(void);
16/* Finalize the XenBus system. */
17void fini_xenbus(void);
18
19/**
20 * xenbus_read() - Read the value associated with a path.
21 *
22 * Returns a malloc'd error string on failure and sets *value to NULL.
23 * On success, *value is set to a malloc'd copy of the value.
24 */
25char *xenbus_read(xenbus_transaction_t xbt, const char *path, char **value);
26
27char *xenbus_wait_for_state_change(const char *path, XenbusState *state);
28char *xenbus_switch_state(xenbus_transaction_t xbt, const char *path,
29 XenbusState state);
30
31/**
32 * xenbus_write() - Associates a value with a path.
33 *
34 * Returns a malloc'd error string on failure.
35 */
36char *xenbus_write(xenbus_transaction_t xbt, const char *path,
37 const char *value);
38
39/**
40 * xenbus_rm() - Removes the value associated with a path.
41 *
42 * Returns a malloc'd error string on failure.
43 */
44char *xenbus_rm(xenbus_transaction_t xbt, const char *path);
45
46/**
47 * xenbus_ls() - List the contents of a directory.
48 *
49 * Returns a malloc'd error string on failure and sets *contents to NULL.
50 * On success, *contents is set to a malloc'd array of pointers to malloc'd
51 * strings. The array is NULL terminated. May block.
52 */
53char *xenbus_ls(xenbus_transaction_t xbt, const char *prefix, char ***contents);
54
55/**
56 * xenbus_get_perms() - Reads permissions associated with a path.
57 *
58 * Returns a malloc'd error string on failure and sets *value to NULL.
59 * On success, *value is set to a malloc'd copy of the value.
60 */
61char *xenbus_get_perms(xenbus_transaction_t xbt, const char *path, char **value);
62
63/**
64 * xenbus_set_perms() - Sets the permissions associated with a path.
65 *
66 * Returns a malloc'd error string on failure.
67 */
68char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t dom,
69 char perm);
70
71/**
72 * xenbus_transaction_start() - Start a xenbus transaction.
73 *
74 * Returns the transaction in xbt on success or a malloc'd error string
75 * otherwise.
76 */
77char *xenbus_transaction_start(xenbus_transaction_t *xbt);
78
79/**
80 * xenbus_transaction_end() - End a xenbus transaction.
81 *
82 * Returns a malloc'd error string if it fails. Abort says whether the
83 * transaction should be aborted.
84 * Returns 1 in *retry if the transaction should be retried.
85 */
86char *xenbus_transaction_end(xenbus_transaction_t xbt, int abort,
87 int *retry);
88
89/**
90 * xenbus_read_integer() - Read path and parse it as an integer.
91 *
92 * Returns -1 on error.
93 */
94int xenbus_read_integer(const char *path);
95
96/**
97 * xenbus_read_uuid() - Read path and parse it as 16 byte uuid.
98 *
99 * Returns 1 if read and parsing were successful, 0 if not
100 */
101int xenbus_read_uuid(const char *path, unsigned char uuid[16]);
102
103/**
104 * xenbus_printf() - Contraction of snprintf and xenbus_write(path/node).
105 */
106char *xenbus_printf(xenbus_transaction_t xbt,
107 const char *node, const char *path,
108 const char *fmt, ...)
109 __attribute__((__format__(printf, 4, 5)));
110
111/**
112 * xenbus_get_self_id() - Utility function to figure out our domain id
113 */
114domid_t xenbus_get_self_id(void);
115
116#endif /* XENBUS_H__ */