blob: ce0e72ca47ecd1180c94f4129407dc0b6c594f5a [file] [log] [blame]
Andreas Gruenbachera3603a62011-05-30 11:47:37 +02001#ifndef __DRBD_PROTOCOL_H
2#define __DRBD_PROTOCOL_H
3
4enum drbd_packet {
5 /* receiver (data socket) */
6 P_DATA = 0x00,
7 P_DATA_REPLY = 0x01, /* Response to P_DATA_REQUEST */
8 P_RS_DATA_REPLY = 0x02, /* Response to P_RS_DATA_REQUEST */
9 P_BARRIER = 0x03,
10 P_BITMAP = 0x04,
11 P_BECOME_SYNC_TARGET = 0x05,
12 P_BECOME_SYNC_SOURCE = 0x06,
13 P_UNPLUG_REMOTE = 0x07, /* Used at various times to hint the peer */
14 P_DATA_REQUEST = 0x08, /* Used to ask for a data block */
15 P_RS_DATA_REQUEST = 0x09, /* Used to ask for a data block for resync */
16 P_SYNC_PARAM = 0x0a,
17 P_PROTOCOL = 0x0b,
18 P_UUIDS = 0x0c,
19 P_SIZES = 0x0d,
20 P_STATE = 0x0e,
21 P_SYNC_UUID = 0x0f,
22 P_AUTH_CHALLENGE = 0x10,
23 P_AUTH_RESPONSE = 0x11,
24 P_STATE_CHG_REQ = 0x12,
25
Philipp Reisner668700b2015-03-16 16:08:29 +010026 /* (meta socket) */
Andreas Gruenbachera3603a62011-05-30 11:47:37 +020027 P_PING = 0x13,
28 P_PING_ACK = 0x14,
29 P_RECV_ACK = 0x15, /* Used in protocol B */
30 P_WRITE_ACK = 0x16, /* Used in protocol C */
31 P_RS_WRITE_ACK = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */
32 P_SUPERSEDED = 0x18, /* Used in proto C, two-primaries conflict detection */
33 P_NEG_ACK = 0x19, /* Sent if local disk is unusable */
34 P_NEG_DREPLY = 0x1a, /* Local disk is broken... */
35 P_NEG_RS_DREPLY = 0x1b, /* Local disk is broken... */
36 P_BARRIER_ACK = 0x1c,
37 P_STATE_CHG_REPLY = 0x1d,
38
39 /* "new" commands, no longer fitting into the ordering scheme above */
40
41 P_OV_REQUEST = 0x1e, /* data socket */
42 P_OV_REPLY = 0x1f,
43 P_OV_RESULT = 0x20, /* meta socket */
44 P_CSUM_RS_REQUEST = 0x21, /* data socket */
45 P_RS_IS_IN_SYNC = 0x22, /* meta socket */
46 P_SYNC_PARAM89 = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */
47 P_COMPRESSED_BITMAP = 0x24, /* compressed or otherwise encoded bitmap transfer */
48 /* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */
49 /* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */
50 P_DELAY_PROBE = 0x27, /* is used on BOTH sockets */
51 P_OUT_OF_SYNC = 0x28, /* Mark as out of sync (Outrunning), data socket */
52 P_RS_CANCEL = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */
53 P_CONN_ST_CHG_REQ = 0x2a, /* data sock: Connection wide state request */
54 P_CONN_ST_CHG_REPLY = 0x2b, /* meta sock: Connection side state req reply */
55 P_RETRY_WRITE = 0x2c, /* Protocol C: retry conflicting write request */
56 P_PROTOCOL_UPDATE = 0x2d, /* data sock: is used in established connections */
Lars Ellenberga0fb3c42014-04-28 18:43:23 +020057 /* 0x2e to 0x30 reserved, used in drbd 9 */
58
59 /* REQ_DISCARD. We used "discard" in different contexts before,
60 * which is why I chose TRIM here, to disambiguate. */
61 P_TRIM = 0x31,
Andreas Gruenbachera3603a62011-05-30 11:47:37 +020062
Philipp Reisner700ca8c2016-06-14 00:26:13 +020063 /* Only use these two if both support FF_THIN_RESYNC */
64 P_RS_THIN_REQ = 0x32, /* Request a block for resync or reply P_RS_DEALLOCATED */
65 P_RS_DEALLOCATED = 0x33, /* Contains only zeros on sync source node */
66
Andreas Gruenbachera3603a62011-05-30 11:47:37 +020067 P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
68 P_MAX_OPT_CMD = 0x101,
69
70 /* special command ids for handshake */
71
72 P_INITIAL_META = 0xfff1, /* First Packet on the MetaSock */
73 P_INITIAL_DATA = 0xfff2, /* First Packet on the Socket */
74
75 P_CONNECTION_FEATURES = 0xfffe /* FIXED for the next century! */
76};
77
78#ifndef __packed
79#define __packed __attribute__((packed))
80#endif
81
82/* This is the layout for a packet on the wire.
83 * The byteorder is the network byte order.
84 * (except block_id and barrier fields.
85 * these are pointers to local structs
86 * and have no relevance for the partner,
87 * which just echoes them as received.)
88 *
89 * NOTE that the payload starts at a long aligned offset,
90 * regardless of 32 or 64 bit arch!
91 */
92struct p_header80 {
93 u32 magic;
94 u16 command;
95 u16 length; /* bytes of data after this header */
96} __packed;
97
98/* Header for big packets, Used for data packets exceeding 64kB */
99struct p_header95 {
100 u16 magic; /* use DRBD_MAGIC_BIG here */
101 u16 command;
102 u32 length;
103} __packed;
104
105struct p_header100 {
106 u32 magic;
107 u16 volume;
108 u16 command;
109 u32 length;
110 u32 pad;
111} __packed;
112
113/* these defines must not be changed without changing the protocol version */
114#define DP_HARDBARRIER 1 /* depricated */
115#define DP_RW_SYNC 2 /* equals REQ_SYNC */
116#define DP_MAY_SET_IN_SYNC 4
117#define DP_UNPLUG 8 /* not used anymore */
118#define DP_FUA 16 /* equals REQ_FUA */
Mike Christie28a8f0d2016-06-05 14:32:25 -0500119#define DP_FLUSH 32 /* equals REQ_PREFLUSH */
Andreas Gruenbachera3603a62011-05-30 11:47:37 +0200120#define DP_DISCARD 64 /* equals REQ_DISCARD */
121#define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */
122#define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */
123
124struct p_data {
125 u64 sector; /* 64 bits sector number */
126 u64 block_id; /* to identify the request in protocol B&C */
127 u32 seq_num;
128 u32 dp_flags;
129} __packed;
130
Lars Ellenberga0fb3c42014-04-28 18:43:23 +0200131struct p_trim {
132 struct p_data p_data;
133 u32 size; /* == bio->bi_size */
134} __packed;
135
Andreas Gruenbachera3603a62011-05-30 11:47:37 +0200136/*
137 * commands which share a struct:
138 * p_block_ack:
139 * P_RECV_ACK (proto B), P_WRITE_ACK (proto C),
140 * P_SUPERSEDED (proto C, two-primaries conflict detection)
141 * p_block_req:
142 * P_DATA_REQUEST, P_RS_DATA_REQUEST
143 */
144struct p_block_ack {
145 u64 sector;
146 u64 block_id;
147 u32 blksize;
148 u32 seq_num;
149} __packed;
150
151struct p_block_req {
152 u64 sector;
153 u64 block_id;
154 u32 blksize;
155 u32 pad; /* to multiple of 8 Byte */
156} __packed;
157
158/*
159 * commands with their own struct for additional fields:
160 * P_CONNECTION_FEATURES
161 * P_BARRIER
162 * P_BARRIER_ACK
163 * P_SYNC_PARAM
164 * ReportParams
165 */
166
Lars Ellenberg20c68fd2014-04-28 18:43:25 +0200167#define FF_TRIM 1
168
Andreas Gruenbachera3603a62011-05-30 11:47:37 +0200169struct p_connection_features {
170 u32 protocol_min;
171 u32 feature_flags;
172 u32 protocol_max;
173
174 /* should be more than enough for future enhancements
175 * for now, feature_flags and the reserved array shall be zero.
176 */
177
178 u32 _pad;
179 u64 reserved[7];
180} __packed;
181
182struct p_barrier {
183 u32 barrier; /* barrier number _handle_ only */
184 u32 pad; /* to multiple of 8 Byte */
185} __packed;
186
187struct p_barrier_ack {
188 u32 barrier;
189 u32 set_size;
190} __packed;
191
192struct p_rs_param {
193 u32 resync_rate;
194
195 /* Since protocol version 88 and higher. */
196 char verify_alg[0];
197} __packed;
198
199struct p_rs_param_89 {
200 u32 resync_rate;
201 /* protocol version 89: */
202 char verify_alg[SHARED_SECRET_MAX];
203 char csums_alg[SHARED_SECRET_MAX];
204} __packed;
205
206struct p_rs_param_95 {
207 u32 resync_rate;
208 char verify_alg[SHARED_SECRET_MAX];
209 char csums_alg[SHARED_SECRET_MAX];
210 u32 c_plan_ahead;
211 u32 c_delay_target;
212 u32 c_fill_target;
213 u32 c_max_rate;
214} __packed;
215
216enum drbd_conn_flags {
217 CF_DISCARD_MY_DATA = 1,
218 CF_DRY_RUN = 2,
219};
220
221struct p_protocol {
222 u32 protocol;
223 u32 after_sb_0p;
224 u32 after_sb_1p;
225 u32 after_sb_2p;
226 u32 conn_flags;
227 u32 two_primaries;
228
229 /* Since protocol version 87 and higher. */
230 char integrity_alg[0];
231
232} __packed;
233
234struct p_uuids {
235 u64 uuid[UI_EXTENDED_SIZE];
236} __packed;
237
238struct p_rs_uuid {
239 u64 uuid;
240} __packed;
241
242struct p_sizes {
243 u64 d_size; /* size of disk */
244 u64 u_size; /* user requested size */
245 u64 c_size; /* current exported size */
246 u32 max_bio_size; /* Maximal size of a BIO */
247 u16 queue_order_type; /* not yet implemented in DRBD*/
248 u16 dds_flags; /* use enum dds_flags here. */
249} __packed;
250
251struct p_state {
252 u32 state;
253} __packed;
254
255struct p_req_state {
256 u32 mask;
257 u32 val;
258} __packed;
259
260struct p_req_state_reply {
261 u32 retcode;
262} __packed;
263
264struct p_drbd06_param {
265 u64 size;
266 u32 state;
267 u32 blksize;
268 u32 protocol;
269 u32 version;
270 u32 gen_cnt[5];
271 u32 bit_map_gen[5];
272} __packed;
273
274struct p_block_desc {
275 u64 sector;
276 u32 blksize;
277 u32 pad; /* to multiple of 8 Byte */
278} __packed;
279
280/* Valid values for the encoding field.
281 * Bump proto version when changing this. */
282enum drbd_bitmap_code {
283 /* RLE_VLI_Bytes = 0,
284 * and other bit variants had been defined during
285 * algorithm evaluation. */
286 RLE_VLI_Bits = 2,
287};
288
289struct p_compressed_bm {
290 /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
291 * (encoding & 0x80): polarity (set/unset) of first runlength
292 * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
293 * used to pad up to head.length bytes
294 */
295 u8 encoding;
296
297 u8 code[0];
298} __packed;
299
300struct p_delay_probe93 {
301 u32 seq_num; /* sequence number to match the two probe packets */
302 u32 offset; /* usecs the probe got sent after the reference time point */
303} __packed;
304
305/*
306 * Bitmap packets need to fit within a single page on the sender and receiver,
307 * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).
308 */
309#define DRBD_SOCKET_BUFFER_SIZE 4096
310
311#endif /* __DRBD_PROTOCOL_H */