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 #define be32toh(x) __builtin_bswap32(x)
31 #else
32 #define htobe32(x) (x)
33 #define be32toh(x) (x)
34 #endif
35 #endif
36 
37 struct xs_state_preamble {
38     char ident[8];
39 #define XS_STATE_IDENT    "xenstore"  /* To be used without the NUL byte. */
40     uint32_t version;                 /* Version in big endian format. */
41 #define XS_STATE_VERSION  0x00000002
42     uint32_t flags;                   /* Endianess. */
43 #if __BYTE_ORDER == __LITTLE_ENDIAN
44 #define XS_STATE_FLAGS    0x00000000  /* Little endian. */
45 #else
46 #define XS_STATE_FLAGS    0x00000001  /* Big endian. */
47 #endif
48 };
49 
50 /*
51  * Each record is starting with xs_state_record_header.
52  * All records have a length of a multiple of 8 bytes.
53  */
54 
55 /* Common record layout: */
56 struct xs_state_record_header {
57     uint32_t type;
58 #define XS_STATE_TYPE_END        0x00000000
59 #define XS_STATE_TYPE_GLOBAL     0x00000001
60 #define XS_STATE_TYPE_CONN       0x00000002
61 #define XS_STATE_TYPE_WATCH      0x00000003
62 #define XS_STATE_TYPE_TA         0x00000004
63 #define XS_STATE_TYPE_NODE       0x00000005
64 #define XS_STATE_TYPE_GLB_QUOTA  0x00000006
65 #define XS_STATE_TYPE_DOMAIN     0x00000007
66 #define XS_STATE_TYPE_WATCH_EXT  0x00000008
67     uint32_t length;         /* Length of record in bytes. */
68 };
69 
70 /* Global state of Xenstore: */
71 struct xs_state_global {
72     int32_t socket_fd;      /* File descriptor for socket connections or -1. */
73     int32_t evtchn_fd;      /* File descriptor for event channel operations. */
74 };
75 
76 /* Connection to Xenstore: */
77 struct xs_state_connection {
78     uint32_t conn_id;       /* Used as reference in watch and TA records. */
79     uint16_t conn_type;
80 #define XS_STATE_CONN_TYPE_RING   0
81 #define XS_STATE_CONN_TYPE_SOCKET 1
82     uint16_t fields;
83 #define XS_STATE_CONN_FIELDS_UNIQ_ID 0x0001
84     union {
85         struct {
86             uint16_t domid;  /* Domain-Id. */
87             uint16_t tdomid; /* Id of target domain or DOMID_INVALID. */
88             uint32_t evtchn; /* Event channel port. */
89         } ring;
90         int32_t socket_fd;   /* File descriptor for socket connections. */
91     } spec;
92     uint16_t data_in_len;    /* Number of unprocessed bytes read from conn. */
93     uint16_t data_resp_len;  /* Size of partial response pending for conn. */
94     uint32_t data_out_len;   /* Number of bytes not yet written to conn. */
95     uint8_t  data[];         /* Pending data (read, written) + 0-7 pad bytes. */
96 };
97 
98 /* Watch: */
99 struct xs_state_watch {
100     uint32_t conn_id;       /* Connection this watch is associated with. */
101     uint16_t path_length;   /* Number of bytes of path watched (incl. 0). */
102     uint16_t token_length;  /* Number of bytes of watch token (incl. 0). */
103     uint8_t data[];         /* Path bytes, token bytes, 0-7 pad bytes. */
104 };
105 
106 struct xs_state_watch_ext {
107     uint32_t conn_id;       /* Connection this watch is associated with. */
108     uint16_t path_length;   /* Number of bytes of path watched (incl. 0). */
109     uint16_t token_length;  /* Number of bytes of watch token (incl. 0). */
110     uint16_t depth;         /* Number of directory levels below watched path */
111                             /* to consider for a match. */
112     uint8_t data[];         /* Path bytes, token bytes, 0-7 pad bytes. */
113 };
114 
115 /* Transaction: */
116 struct xs_state_transaction {
117     uint32_t conn_id;       /* Connection this TA is associated with. */
118     uint32_t ta_id;         /* Transaction Id. */
119 };
120 
121 /* Node (either XS_STATE_TYPE_NODE or XS_STATE_TYPE_TANODE[_MOD]): */
122 struct xs_state_node_perm {
123     uint8_t access;         /* Access rights. */
124 #define XS_STATE_NODE_PERM_NONE   'n'
125 #define XS_STATE_NODE_PERM_READ   'r'
126 #define XS_STATE_NODE_PERM_WRITE  'w'
127 #define XS_STATE_NODE_PERM_BOTH   'b'
128     uint8_t flags;
129 #define XS_STATE_NODE_PERM_IGNORE 0x01 /* Stale permission, ignore for check. */
130     uint16_t domid;         /* Domain-Id. */
131 };
132 struct xs_state_node {
133     uint32_t conn_id;       /* Connection in case of transaction or 0. */
134     uint32_t ta_id;         /* Transaction Id or 0. */
135     uint16_t path_len;      /* Length of path string including NUL byte. */
136     uint16_t data_len;      /* Length of node data. */
137     uint16_t ta_access;
138 #define XS_STATE_NODE_TA_DELETED  0x0000
139 #define XS_STATE_NODE_TA_READ     0x0001
140 #define XS_STATE_NODE_TA_WRITTEN  0x0002
141     uint16_t perm_n;        /* Number of permissions (0 in TA: node deleted). */
142     /* Permissions (first is owner, has full access). */
143     struct xs_state_node_perm perms[];
144     /* Path and data follows, plus 0-7 pad bytes. */
145 };
146 
147 /* Global quota data: */
148 struct xs_state_glb_quota {
149     uint16_t n_dom_quota;   /* Number of quota values applying to domains. */
150     uint16_t n_glob_quota;  /* Number of quota values applying globally only. */
151     uint32_t quota_val[];   /* Array of quota values (domain ones first). */
152 };
153 
154 /* Domain data: */
155 struct xs_state_domain {
156     uint16_t domain_id;     /* Domain-id identifying the domain. */
157     uint16_t n_quota;       /* Number of quota values. */
158     uint32_t features;      /* Server features available to the domain. */
159     uint32_t quota_val[];   /* Array of quota values. */
160 };
161 #endif /* XENSTORE_STATE_H */
162