Debian Codegraph @

tools/xenstored/xenstore_state.h

raw
1 /*
2 * Xenstore internal state dump definitions.
3 * Copyright (C) Juergen Gross, SUSE Software Solutions Germany GmbH
4 *
5 * Used for live-update and migration, possibly across Xenstore implementations.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef XENSTORE_STATE_H
22 #define XENSTORE_STATE_H
23
24 #include INCLUDE_ENDIAN_H
25 #include <sys/types.h>
26
27 #ifndef htobe32
28 #if __BYTE_ORDER == __LITTLE_ENDIAN
29 #define htobe32(x) __builtin_bswap32(x)
30 #else
31 #define htobe32(x) (x)
32 #endif
33 #endif
34
35 struct xs_state_preamble {
36 char ident[8];
37 #define XS_STATE_IDENT "xenstore" /* To be used without the NUL byte. */
38 uint32_t version; /* Version in big endian format. */
39 #define XS_STATE_VERSION 0x00000001
40 uint32_t flags; /* Endianess. */
41 #if __BYTE_ORDER == __LITTLE_ENDIAN
42 #define XS_STATE_FLAGS 0x00000000 /* Little endian. */
43 #else
44 #define XS_STATE_FLAGS 0x00000001 /* Big endian. */
45 #endif
46 };
47
48 /*
49 * Each record is starting with xs_state_record_header.
50 * All records have a length of a multiple of 8 bytes.
51 */
52
53 /* Common record layout: */
54 struct xs_state_record_header {
55 uint32_t type;
56 #define XS_STATE_TYPE_END 0x00000000
57 #define XS_STATE_TYPE_GLOBAL 0x00000001
58 #define XS_STATE_TYPE_CONN 0x00000002
59 #define XS_STATE_TYPE_WATCH 0x00000003
60 #define XS_STATE_TYPE_TA 0x00000004
61 #define XS_STATE_TYPE_NODE 0x00000005
62 uint32_t length; /* Length of record in bytes. */
63 };
64
65 /* Global state of Xenstore: */
66 struct xs_state_global {
67 int32_t socket_fd; /* File descriptor for socket connections or -1. */
68 int32_t evtchn_fd; /* File descriptor for event channel operations. */
69 };
70
71 /* Connection to Xenstore: */
72 struct xs_state_connection {
73 uint32_t conn_id; /* Used as reference in watch and TA records. */
74 uint16_t conn_type;
75 #define XS_STATE_CONN_TYPE_RING 0
76 #define XS_STATE_CONN_TYPE_SOCKET 1
77 uint16_t pad;
78 union {
79 struct {
80 uint16_t domid; /* Domain-Id. */
81 uint16_t tdomid; /* Id of target domain or DOMID_INVALID. */
82 uint32_t evtchn; /* Event channel port. */
83 } ring;
84 int32_t socket_fd; /* File descriptor for socket connections. */
85 } spec;
86 uint16_t data_in_len; /* Number of unprocessed bytes read from conn. */
87 uint16_t data_resp_len; /* Size of partial response pending for conn. */
88 uint32_t data_out_len; /* Number of bytes not yet written to conn. */
89 uint8_t data[]; /* Pending data (read, written) + 0-7 pad bytes. */
90 };
91
92 /* Watch: */
93 struct xs_state_watch {
94 uint32_t conn_id; /* Connection this watch is associated with. */
95 uint16_t path_length; /* Number of bytes of path watched (incl. 0). */
96 uint16_t token_length; /* Number of bytes of watch token (incl. 0). */
97 uint8_t data[]; /* Path bytes, token bytes, 0-7 pad bytes. */
98 };
99
100 /* Transaction: */
101 struct xs_state_transaction {
102 uint32_t conn_id; /* Connection this TA is associated with. */
103 uint32_t ta_id; /* Transaction Id. */
104 };
105
106 /* Node (either XS_STATE_TYPE_NODE or XS_STATE_TYPE_TANODE[_MOD]): */
107 struct xs_state_node_perm {
108 uint8_t access; /* Access rights. */
109 #define XS_STATE_NODE_PERM_NONE 'n'
110 #define XS_STATE_NODE_PERM_READ 'r'
111 #define XS_STATE_NODE_PERM_WRITE 'w'
112 #define XS_STATE_NODE_PERM_BOTH 'b'
113 uint8_t flags;
114 #define XS_STATE_NODE_PERM_IGNORE 0x01 /* Stale permission, ignore for check. */
115 uint16_t domid; /* Domain-Id. */
116 };
117 struct xs_state_node {
118 uint32_t conn_id; /* Connection in case of transaction or 0. */
119 uint32_t ta_id; /* Transaction Id or 0. */
120 uint16_t path_len; /* Length of path string including NUL byte. */
121 uint16_t data_len; /* Length of node data. */
122 uint16_t ta_access;
123 #define XS_STATE_NODE_TA_DELETED 0x0000
124 #define XS_STATE_NODE_TA_READ 0x0001
125 #define XS_STATE_NODE_TA_WRITTEN 0x0002
126 uint16_t perm_n; /* Number of permissions (0 in TA: node deleted). */
127 /* Permissions (first is owner, has full access). */
128 struct xs_state_node_perm perms[];
129 /* Path and data follows, plus 0-7 pad bytes. */
130 };
131 #endif /* XENSTORE_STATE_H */