1 /*
2  * Details of the "wire" protocol between Xen Store Daemon and client
3  * library or guest kernel.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Copyright (C) 2005 Rusty Russell IBM Corporation
8  */
9 
10 #ifndef _XS_WIRE_H
11 #define _XS_WIRE_H
12 
13 enum xsd_sockmsg_type
14 {
15     XS_DEBUG,
16     XS_DIRECTORY,
17     XS_READ,
18     XS_GET_PERMS,
19     XS_WATCH,
20     XS_UNWATCH,
21     XS_TRANSACTION_START,
22     XS_TRANSACTION_END,
23     XS_INTRODUCE,
24     XS_RELEASE,
25     XS_GET_DOMAIN_PATH,
26     XS_WRITE,
27     XS_MKDIR,
28     XS_RM,
29     XS_SET_PERMS,
30     XS_WATCH_EVENT,
31     XS_ERROR,
32     XS_IS_DOMAIN_INTRODUCED,
33     XS_RESUME,
34     XS_SET_TARGET,
35     XS_RESTRICT,
36     XS_RESET_WATCHES,
37 
38     XS_INVALID = 0xffff /* Guaranteed to remain an invalid type */
39 };
40 
41 #define XS_WRITE_NONE "NONE"
42 #define XS_WRITE_CREATE "CREATE"
43 #define XS_WRITE_CREATE_EXCL "CREATE|EXCL"
44 
45 /* We hand errors as strings, for portability. */
46 struct xsd_errors
47 {
48     INT32 errnum;
49     const CHAR8 *errstring;
50 };
51 #ifdef EINVAL
52 #define XSD_ERROR(x) { x, #x }
53 /* LINTED: static unused */
54 static struct xsd_errors xsd_errors[]
55 #if defined(__GNUC__)
56 __attribute__((unused))
57 #endif
58     = {
59     XSD_ERROR(EINVAL),
60     XSD_ERROR(EACCES),
61     XSD_ERROR(EEXIST),
62     XSD_ERROR(EISDIR),
63     XSD_ERROR(ENOENT),
64     XSD_ERROR(ENOMEM),
65     XSD_ERROR(ENOSPC),
66     XSD_ERROR(EIO),
67     XSD_ERROR(ENOTEMPTY),
68     XSD_ERROR(ENOSYS),
69     XSD_ERROR(EROFS),
70     XSD_ERROR(EBUSY),
71     XSD_ERROR(EAGAIN),
72     XSD_ERROR(EISCONN),
73     XSD_ERROR(E2BIG)
74 };
75 #endif
76 
77 struct xsd_sockmsg
78 {
79     UINT32 type;  /* XS_??? */
80     UINT32 req_id;/* Request identifier, echoed in daemon's response.  */
81     UINT32 tx_id; /* Transaction id (0 if not related to a transaction). */
82     UINT32 len;   /* Length of data following this. */
83 
84     /* Generally followed by nul-terminated string(s). */
85 };
86 
87 enum xs_watch_type
88 {
89     XS_WATCH_PATH = 0,
90     XS_WATCH_TOKEN
91 };
92 
93 /*
94  * `incontents 150 xenstore_struct XenStore wire protocol.
95  *
96  * Inter-domain shared memory communications. */
97 #define XENSTORE_RING_SIZE 1024
98 typedef UINT32 XENSTORE_RING_IDX;
99 #define MASK_XENSTORE_IDX(idx) ((idx) & (XENSTORE_RING_SIZE-1))
100 struct xenstore_domain_interface {
101     CHAR8 req[XENSTORE_RING_SIZE]; /* Requests to xenstore daemon. */
102     CHAR8 rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */
103     XENSTORE_RING_IDX req_cons, req_prod;
104     XENSTORE_RING_IDX rsp_cons, rsp_prod;
105     UINT32 server_features; /* Bitmap of features supported by the server */
106     UINT32 connection;
107 };
108 
109 /* Violating this is very bad.  See docs/misc/xenstore.txt. */
110 #define XENSTORE_PAYLOAD_MAX 4096
111 
112 /* Violating these just gets you an error back */
113 #define XENSTORE_ABS_PATH_MAX 3072
114 #define XENSTORE_REL_PATH_MAX 2048
115 
116 /* The ability to reconnect a ring */
117 #define XENSTORE_SERVER_FEATURE_RECONNECTION 1
118 
119 /* Valid values for the connection field */
120 #define XENSTORE_CONNECTED 0 /* the steady-state */
121 #define XENSTORE_RECONNECT 1 /* guest has initiated a reconnect */
122 
123 #endif /* _XS_WIRE_H */
124 
125 /*
126  * Local variables:
127  * mode: C
128  * c-file-style: "BSD"
129  * c-basic-offset: 4
130  * tab-width: 4
131  * indent-tabs-mode: nil
132  * End:
133  */
134