xref: /freebsd/sys/contrib/xen/io/xs_wire.h (revision a4128aad8503277614f2d214011ef60a19447b83)
1 /*
2  * Details of the "wire" protocol between Xen Store Daemon and client
3  * library or guest kernel.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Copyright (C) 2005 Rusty Russell IBM Corporation
24  */
25 
26 #ifndef _XS_WIRE_H
27 #define _XS_WIRE_H
28 
29 enum xsd_sockmsg_type
30 {
31     XS_CONTROL,
32 #define XS_DEBUG XS_CONTROL
33     XS_DIRECTORY,
34     XS_READ,
35     XS_GET_PERMS,
36     XS_WATCH,
37     XS_UNWATCH,
38     XS_TRANSACTION_START,
39     XS_TRANSACTION_END,
40     XS_INTRODUCE,
41     XS_RELEASE,
42     XS_GET_DOMAIN_PATH,
43     XS_WRITE,
44     XS_MKDIR,
45     XS_RM,
46     XS_SET_PERMS,
47     XS_WATCH_EVENT,
48     XS_ERROR,
49     XS_IS_DOMAIN_INTRODUCED,
50     XS_RESUME,
51     XS_SET_TARGET,
52     /* XS_RESTRICT has been removed */
53     XS_RESET_WATCHES = XS_SET_TARGET + 2,
54     XS_DIRECTORY_PART,
55 
56     XS_TYPE_COUNT,      /* Number of valid types. */
57 
58     XS_INVALID = 0xffff /* Guaranteed to remain an invalid type */
59 };
60 
61 #define XS_WRITE_NONE "NONE"
62 #define XS_WRITE_CREATE "CREATE"
63 #define XS_WRITE_CREATE_EXCL "CREATE|EXCL"
64 
65 /* We hand errors as strings, for portability. */
66 struct xsd_errors
67 {
68     int errnum;
69     const char *errstring;
70 };
71 #ifdef EINVAL
72 #define XSD_ERROR(x) { x, #x }
73 /* LINTED: static unused */
74 static struct xsd_errors xsd_errors[]
75 #if defined(__GNUC__)
76 __attribute__((unused))
77 #endif
78     = {
79     XSD_ERROR(EINVAL),
80     XSD_ERROR(EACCES),
81     XSD_ERROR(EEXIST),
82     XSD_ERROR(EISDIR),
83     XSD_ERROR(ENOENT),
84     XSD_ERROR(ENOMEM),
85     XSD_ERROR(ENOSPC),
86     XSD_ERROR(EIO),
87     XSD_ERROR(ENOTEMPTY),
88     XSD_ERROR(ENOSYS),
89     XSD_ERROR(EROFS),
90     XSD_ERROR(EBUSY),
91     XSD_ERROR(EAGAIN),
92     XSD_ERROR(EISCONN),
93     XSD_ERROR(E2BIG)
94 };
95 #endif
96 
97 struct xsd_sockmsg
98 {
99     uint32_t type;  /* XS_??? */
100     uint32_t req_id;/* Request identifier, echoed in daemon's response.  */
101     uint32_t tx_id; /* Transaction id (0 if not related to a transaction). */
102     uint32_t len;   /* Length of data following this. */
103 
104     /* Generally followed by nul-terminated string(s). */
105 };
106 
107 enum xs_watch_type
108 {
109     XS_WATCH_PATH = 0,
110     XS_WATCH_TOKEN
111 };
112 
113 /*
114  * `incontents 150 xenstore_struct XenStore wire protocol.
115  *
116  * Inter-domain shared memory communications. */
117 #define XENSTORE_RING_SIZE 1024
118 typedef uint32_t XENSTORE_RING_IDX;
119 #define MASK_XENSTORE_IDX(idx) ((idx) & (XENSTORE_RING_SIZE-1))
120 struct xenstore_domain_interface {
121     char req[XENSTORE_RING_SIZE]; /* Requests to xenstore daemon. */
122     char rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */
123     XENSTORE_RING_IDX req_cons, req_prod;
124     XENSTORE_RING_IDX rsp_cons, rsp_prod;
125     uint32_t server_features; /* Bitmap of features supported by the server */
126     uint32_t connection;
127 };
128 
129 /* Violating this is very bad.  See docs/misc/xenstore.txt. */
130 #define XENSTORE_PAYLOAD_MAX 4096
131 
132 /* Violating these just gets you an error back */
133 #define XENSTORE_ABS_PATH_MAX 3072
134 #define XENSTORE_REL_PATH_MAX 2048
135 
136 /* The ability to reconnect a ring */
137 #define XENSTORE_SERVER_FEATURE_RECONNECTION 1
138 
139 /* Valid values for the connection field */
140 #define XENSTORE_CONNECTED 0 /* the steady-state */
141 #define XENSTORE_RECONNECT 1 /* guest has initiated a reconnect */
142 
143 #endif /* _XS_WIRE_H */
144 
145 /*
146  * Local variables:
147  * mode: C
148  * c-file-style: "BSD"
149  * c-basic-offset: 4
150  * tab-width: 4
151  * indent-tabs-mode: nil
152  * End:
153  */
154