| 1 |
The xenstore ring is a datastructure stored within a single 4KiB page |
| 2 |
shared between the xenstore server and the guest. The ring contains |
| 3 |
two queues of bytes -- one in each direction -- and some signalling |
| 4 |
information. The [xenstore protocol](xenstore.txt) is layered on top of |
| 5 |
the byte streams. |
| 6 |
|
| 7 |
The xenstore ring datastructure |
| 8 |
=============================== |
| 9 |
|
| 10 |
The following table describes the ring structure where |
| 11 |
- offsets and lengths are in bytes; |
| 12 |
- "Input" is used to describe the data sent to the server; and |
| 13 |
- "Output" is used to describe the data sent to the domain. |
| 14 |
|
| 15 |
Offset Length Description |
| 16 |
----------------------------------------------------------------- |
| 17 |
0 1024 Input data |
| 18 |
1024 1024 Output data |
| 19 |
2048 4 Input consumer offset |
| 20 |
2052 4 Input producer offset |
| 21 |
2056 4 Output consumer offset |
| 22 |
2060 4 Output producer offset |
| 23 |
2064 4 Server feature bitmap |
| 24 |
2068 4 Connection state |
| 25 |
2072 4 Connection error indicator |
| 26 |
|
| 27 |
The Input data and Output data are circular buffers. Each buffer is |
| 28 |
associated with a pair of free-running offsets labelled "consumer" and |
| 29 |
"producer". |
| 30 |
|
| 31 |
A "producer" offset is the offset in the byte stream of the next byte |
| 32 |
to be written modulo 2^32. A "consumer" offset is the offset in the byte |
| 33 |
stream of the next byte to be read modulo 2^32. Implementations must |
| 34 |
take care to handle wraparound properly when performing arithmetic with |
| 35 |
these values. |
| 36 |
|
| 37 |
The byte at offset 'x' in the byte stream will be stored at offset |
| 38 |
'x modulo 1024' in the circular buffer. |
| 39 |
|
| 40 |
Implementations may only overwrite previously-written data if it has |
| 41 |
been marked as 'consumed' by the relevant consumer pointer. |
| 42 |
|
| 43 |
When the guest domain is created, there is no outstanding Input or Output |
| 44 |
data. However |
| 45 |
|
| 46 |
- guests must not assume that producer or consumer pointers start |
| 47 |
at zero; and |
| 48 |
- guests must not assume that unused bytes in either the Input or |
| 49 |
Output data buffers has any particular value. |
| 50 |
|
| 51 |
A xenstore ring is always associated with an event channel. Whenever the |
| 52 |
ring structure is updated the event channel must be signalled. The |
| 53 |
guest and server are free to inspect the contents of the ring at any |
| 54 |
time, not only in response to an event channel event. This implies that |
| 55 |
updates must be ordered carefully to ensure consistency. |
| 56 |
|
| 57 |
The xenstore server may decide to advertise some features via the |
| 58 |
"Server feature bitmap". The server can start advertising features |
| 59 |
at any time by setting bits but it will never stop advertising features |
| 60 |
i.e. bits will never be cleared. The guest is not permitted to write to |
| 61 |
the server feature bitmap. The server features are offered to the guest; |
| 62 |
it is up to the guest whether to use them or not. The guest should ignore |
| 63 |
any unknown feature bits. |
| 64 |
|
| 65 |
The following features are defined (bit number 0 is equivalent to a mask |
| 66 |
value of 1): |
| 67 |
|
| 68 |
Bit Description |
| 69 |
----------------------------------------------------------------- |
| 70 |
0 Ring reconnection (see the ring reconnection feature below) |
| 71 |
1 Connection error indicator (see connection error feature below) |
| 72 |
2 WATCH can take a third parameter limiting its scope |
| 73 |
|
| 74 |
The "Connection state" field is used to request a ring close and reconnect. |
| 75 |
The "Connection state" field only contains valid data if the server has |
| 76 |
advertised the ring reconnection feature. If the feature has been advertised |
| 77 |
then the "Connection state" may take the following values: |
| 78 |
|
| 79 |
Value Description |
| 80 |
----------------------------------------------------------------- |
| 81 |
0 Ring is connected |
| 82 |
1 Ring close and reconnect is in progress (see the "ring |
| 83 |
reconnection feature" described below) |
| 84 |
|
| 85 |
The "Connection error indicator" is used to let the server indicate it has |
| 86 |
detected some error that led to deactivation of the connection by the server. |
| 87 |
If the feature has been advertised then the "Connection error indicator" may |
| 88 |
take the following values (new values might be added in future without them |
| 89 |
being advertised as a new feature): |
| 90 |
|
| 91 |
Value Description |
| 92 |
----------------------------------------------------------------- |
| 93 |
0 No error, connection is valid |
| 94 |
1 Communication problems (event channel not functional) |
| 95 |
2 Inconsistent producer or consumer offset |
| 96 |
3 Protocol violation (client data package too long) |
| 97 |
|
| 98 |
The ring reconnection feature |
| 99 |
============================= |
| 100 |
|
| 101 |
The ring reconnection feature allows the guest to ask the server to |
| 102 |
reset the ring to a valid initial state i.e. one in which the Input |
| 103 |
and Output queues contain no data and there are no outstanding requests, |
| 104 |
watches or transactions. |
| 105 |
|
| 106 |
The ring reconnection feature is only available if the 'Ring reconnection' |
| 107 |
feature bit has been set by the server in the "Server feature bitmap". |
| 108 |
If a server supports ring reconnection, it will guarantee to advertise |
| 109 |
the feature before producing or consuming any data from the Input or Output |
| 110 |
queues. |
| 111 |
|
| 112 |
Assuming the server has advertised the feature, the guest can initiate |
| 113 |
a reconnection by setting the the Connection state to 1 ("Ring close |
| 114 |
and reconnect is in progress") and signalling the event channel. |
| 115 |
The guest must now ignore all fields except the Connection state and |
| 116 |
wait for it to be set to 0 ("Ring is connected"). |
| 117 |
|
| 118 |
In certain circumstances (e.g. dom0less guests with PV drivers support) |
| 119 |
it is possible for the guest to find the Connection state already set to |
| 120 |
1 by someone else during xenstore initialization. In that case, like in |
| 121 |
the previous case, the guest must ignore all fields except the |
| 122 |
Connection state and wait for it to be set to 0 before proceeding. |
| 123 |
|
| 124 |
The server will guarantee to |
| 125 |
|
| 126 |
- drop any partially read or written higher-level |
| 127 |
[xenstore protocol](xenstore.txt) packets it may have; |
| 128 |
- empty the Input and Output queues in the xenstore ring; |
| 129 |
- discard any in-flight requests |
| 130 |
- discard any watches associated with the connection |
| 131 |
- discard any transactions associated with the connection |
| 132 |
- set the Connection state to 0 ("Ring is connected"); and |
| 133 |
- signal the event channel. |
| 134 |
|
| 135 |
From the point of view of the guest, the connection has been reset on a |
| 136 |
packet boundary. |
| 137 |
|
| 138 |
Note that only the guest may set the Connection state to 1 and only the |
| 139 |
server may set it back to 0. |
| 140 |
|
| 141 |
The connection error feature |
| 142 |
============================ |
| 143 |
|
| 144 |
The connection error feature allows the server to signal error conditions |
| 145 |
leading to a stop of the communication with the client. In case such an error |
| 146 |
condition has occurred, the server will set the appropriate error condition in |
| 147 |
the Connection error indicator and will stop communication with the client. |
| 148 |
|
| 149 |
Any value different from 0 is indicating an error. The value used is meant |
| 150 |
just for diagnostic purposes. A client reading the error value should be |
| 151 |
prepared to see values not described here, as new error cases might be added |
| 152 |
in future. |
| 153 |
|
| 154 |
The server will discard any already read or written packets, in-flight |
| 155 |
requests, watches and transactions associated with the connection. |
| 156 |
|
| 157 |
Depending on the error cause it might be possible that a reconnect via the |
| 158 |
ring reconnection feature (if present) can be performed. There is no guarantee |
| 159 |
this will succeed. |