2 * Xenstore internal state dump definitions.
3 * Copyright (C) Juergen Gross, SUSE Software Solutions Germany GmbH
5 * Used for live-update and migration, possibly across Xenstore implementations.
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.
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.
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/>.
21 #ifndef XENSTORE_STATE_H
22 #define XENSTORE_STATE_H
24 #if defined(__FreeBSD__) || defined(__NetBSD__)
25 #include <sys/endian.h>
29 #include <sys/types.h>
32 #if __BYTE_ORDER == __LITTLE_ENDIAN
33 #define htobe32(x) __builtin_bswap32(x)
35 #define htobe32(x) (x)
39 struct xs_state_preamble {
41 #define XS_STATE_IDENT "xenstore" /* To be used without the NUL byte. */
42 uint32_t version; /* Version in big endian format. */
43 #define XS_STATE_VERSION 0x00000001
44 uint32_t flags; /* Endianess. */
45 #if __BYTE_ORDER == __LITTLE_ENDIAN
46 #define XS_STATE_FLAGS 0x00000000 /* Little endian. */
48 #define XS_STATE_FLAGS 0x00000001 /* Big endian. */
53 * Each record is starting with xs_state_record_header.
54 * All records have a length of a multiple of 8 bytes.
57 /* Common record layout: */
58 struct xs_state_record_header {
60 #define XS_STATE_TYPE_END 0x00000000
61 #define XS_STATE_TYPE_GLOBAL 0x00000001
62 #define XS_STATE_TYPE_CONN 0x00000002
63 #define XS_STATE_TYPE_WATCH 0x00000003
64 #define XS_STATE_TYPE_TA 0x00000004
65 #define XS_STATE_TYPE_NODE 0x00000005
66 uint32_t length; /* Length of record in bytes. */
69 /* Global state of Xenstore: */
70 struct xs_state_global {
71 int32_t socket_fd; /* File descriptor for socket connections or -1. */
72 int32_t evtchn_fd; /* File descriptor for event channel operations. */
75 /* Connection to Xenstore: */
76 struct xs_state_connection {
77 uint32_t conn_id; /* Used as reference in watch and TA records. */
79 #define XS_STATE_CONN_TYPE_RING 0
80 #define XS_STATE_CONN_TYPE_SOCKET 1
84 uint16_t domid; /* Domain-Id. */
85 uint16_t tdomid; /* Id of target domain or DOMID_INVALID. */
86 uint32_t evtchn; /* Event channel port. */
88 int32_t socket_fd; /* File descriptor for socket connections. */
90 uint16_t data_in_len; /* Number of unprocessed bytes read from conn. */
91 uint16_t data_resp_len; /* Size of partial response pending for conn. */
92 uint32_t data_out_len; /* Number of bytes not yet written to conn. */
93 uint8_t data[]; /* Pending data (read, written) + 0-7 pad bytes. */
97 struct xs_state_watch {
98 uint32_t conn_id; /* Connection this watch is associated with. */
99 uint16_t path_length; /* Number of bytes of path watched (incl. 0). */
100 uint16_t token_length; /* Number of bytes of watch token (incl. 0). */
101 uint8_t data[]; /* Path bytes, token bytes, 0-7 pad bytes. */
105 struct xs_state_transaction {
106 uint32_t conn_id; /* Connection this TA is associated with. */
107 uint32_t ta_id; /* Transaction Id. */
110 /* Node (either XS_STATE_TYPE_NODE or XS_STATE_TYPE_TANODE[_MOD]): */
111 struct xs_state_node_perm {
112 uint8_t access; /* Access rights. */
113 #define XS_STATE_NODE_PERM_NONE 'n'
114 #define XS_STATE_NODE_PERM_READ 'r'
115 #define XS_STATE_NODE_PERM_WRITE 'w'
116 #define XS_STATE_NODE_PERM_BOTH 'b'
118 #define XS_STATE_NODE_PERM_IGNORE 0x01 /* Stale permission, ignore for check. */
119 uint16_t domid; /* Domain-Id. */
121 struct xs_state_node {
122 uint32_t conn_id; /* Connection in case of transaction or 0. */
123 uint32_t ta_id; /* Transaction Id or 0. */
124 uint16_t path_len; /* Length of path string including NUL byte. */
125 uint16_t data_len; /* Length of node data. */
127 #define XS_STATE_NODE_TA_DELETED 0x0000
128 #define XS_STATE_NODE_TA_READ 0x0001
129 #define XS_STATE_NODE_TA_WRITTEN 0x0002
130 uint16_t perm_n; /* Number of permissions (0 in TA: node deleted). */
131 /* Permissions (first is owner, has full access). */
132 struct xs_state_node_perm perms[];
133 /* Path and data follows, plus 0-7 pad bytes. */
135 #endif /* XENSTORE_STATE_H */