drbd: prepare receiving side for REQ_DISCARD
[linux-2.6-block.git] / drivers / block / drbd / drbd_protocol.h
CommitLineData
a3603a6e
AG
1#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
26 /* asender (meta socket */
27 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 */
a0fb3c47
LE
57 /* 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,
a3603a6e
AG
62
63 P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
64 P_MAX_OPT_CMD = 0x101,
65
66 /* special command ids for handshake */
67
68 P_INITIAL_META = 0xfff1, /* First Packet on the MetaSock */
69 P_INITIAL_DATA = 0xfff2, /* First Packet on the Socket */
70
71 P_CONNECTION_FEATURES = 0xfffe /* FIXED for the next century! */
72};
73
74#ifndef __packed
75#define __packed __attribute__((packed))
76#endif
77
78/* This is the layout for a packet on the wire.
79 * The byteorder is the network byte order.
80 * (except block_id and barrier fields.
81 * these are pointers to local structs
82 * and have no relevance for the partner,
83 * which just echoes them as received.)
84 *
85 * NOTE that the payload starts at a long aligned offset,
86 * regardless of 32 or 64 bit arch!
87 */
88struct p_header80 {
89 u32 magic;
90 u16 command;
91 u16 length; /* bytes of data after this header */
92} __packed;
93
94/* Header for big packets, Used for data packets exceeding 64kB */
95struct p_header95 {
96 u16 magic; /* use DRBD_MAGIC_BIG here */
97 u16 command;
98 u32 length;
99} __packed;
100
101struct p_header100 {
102 u32 magic;
103 u16 volume;
104 u16 command;
105 u32 length;
106 u32 pad;
107} __packed;
108
109/* these defines must not be changed without changing the protocol version */
110#define DP_HARDBARRIER 1 /* depricated */
111#define DP_RW_SYNC 2 /* equals REQ_SYNC */
112#define DP_MAY_SET_IN_SYNC 4
113#define DP_UNPLUG 8 /* not used anymore */
114#define DP_FUA 16 /* equals REQ_FUA */
115#define DP_FLUSH 32 /* equals REQ_FLUSH */
116#define DP_DISCARD 64 /* equals REQ_DISCARD */
117#define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */
118#define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */
119
120struct p_data {
121 u64 sector; /* 64 bits sector number */
122 u64 block_id; /* to identify the request in protocol B&C */
123 u32 seq_num;
124 u32 dp_flags;
125} __packed;
126
a0fb3c47
LE
127struct p_trim {
128 struct p_data p_data;
129 u32 size; /* == bio->bi_size */
130} __packed;
131
a3603a6e
AG
132/*
133 * commands which share a struct:
134 * p_block_ack:
135 * P_RECV_ACK (proto B), P_WRITE_ACK (proto C),
136 * P_SUPERSEDED (proto C, two-primaries conflict detection)
137 * p_block_req:
138 * P_DATA_REQUEST, P_RS_DATA_REQUEST
139 */
140struct p_block_ack {
141 u64 sector;
142 u64 block_id;
143 u32 blksize;
144 u32 seq_num;
145} __packed;
146
147struct p_block_req {
148 u64 sector;
149 u64 block_id;
150 u32 blksize;
151 u32 pad; /* to multiple of 8 Byte */
152} __packed;
153
154/*
155 * commands with their own struct for additional fields:
156 * P_CONNECTION_FEATURES
157 * P_BARRIER
158 * P_BARRIER_ACK
159 * P_SYNC_PARAM
160 * ReportParams
161 */
162
163struct p_connection_features {
164 u32 protocol_min;
165 u32 feature_flags;
166 u32 protocol_max;
167
168 /* should be more than enough for future enhancements
169 * for now, feature_flags and the reserved array shall be zero.
170 */
171
172 u32 _pad;
173 u64 reserved[7];
174} __packed;
175
176struct p_barrier {
177 u32 barrier; /* barrier number _handle_ only */
178 u32 pad; /* to multiple of 8 Byte */
179} __packed;
180
181struct p_barrier_ack {
182 u32 barrier;
183 u32 set_size;
184} __packed;
185
186struct p_rs_param {
187 u32 resync_rate;
188
189 /* Since protocol version 88 and higher. */
190 char verify_alg[0];
191} __packed;
192
193struct p_rs_param_89 {
194 u32 resync_rate;
195 /* protocol version 89: */
196 char verify_alg[SHARED_SECRET_MAX];
197 char csums_alg[SHARED_SECRET_MAX];
198} __packed;
199
200struct p_rs_param_95 {
201 u32 resync_rate;
202 char verify_alg[SHARED_SECRET_MAX];
203 char csums_alg[SHARED_SECRET_MAX];
204 u32 c_plan_ahead;
205 u32 c_delay_target;
206 u32 c_fill_target;
207 u32 c_max_rate;
208} __packed;
209
210enum drbd_conn_flags {
211 CF_DISCARD_MY_DATA = 1,
212 CF_DRY_RUN = 2,
213};
214
215struct p_protocol {
216 u32 protocol;
217 u32 after_sb_0p;
218 u32 after_sb_1p;
219 u32 after_sb_2p;
220 u32 conn_flags;
221 u32 two_primaries;
222
223 /* Since protocol version 87 and higher. */
224 char integrity_alg[0];
225
226} __packed;
227
228struct p_uuids {
229 u64 uuid[UI_EXTENDED_SIZE];
230} __packed;
231
232struct p_rs_uuid {
233 u64 uuid;
234} __packed;
235
236struct p_sizes {
237 u64 d_size; /* size of disk */
238 u64 u_size; /* user requested size */
239 u64 c_size; /* current exported size */
240 u32 max_bio_size; /* Maximal size of a BIO */
241 u16 queue_order_type; /* not yet implemented in DRBD*/
242 u16 dds_flags; /* use enum dds_flags here. */
243} __packed;
244
245struct p_state {
246 u32 state;
247} __packed;
248
249struct p_req_state {
250 u32 mask;
251 u32 val;
252} __packed;
253
254struct p_req_state_reply {
255 u32 retcode;
256} __packed;
257
258struct p_drbd06_param {
259 u64 size;
260 u32 state;
261 u32 blksize;
262 u32 protocol;
263 u32 version;
264 u32 gen_cnt[5];
265 u32 bit_map_gen[5];
266} __packed;
267
268struct p_block_desc {
269 u64 sector;
270 u32 blksize;
271 u32 pad; /* to multiple of 8 Byte */
272} __packed;
273
274/* Valid values for the encoding field.
275 * Bump proto version when changing this. */
276enum drbd_bitmap_code {
277 /* RLE_VLI_Bytes = 0,
278 * and other bit variants had been defined during
279 * algorithm evaluation. */
280 RLE_VLI_Bits = 2,
281};
282
283struct p_compressed_bm {
284 /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
285 * (encoding & 0x80): polarity (set/unset) of first runlength
286 * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
287 * used to pad up to head.length bytes
288 */
289 u8 encoding;
290
291 u8 code[0];
292} __packed;
293
294struct p_delay_probe93 {
295 u32 seq_num; /* sequence number to match the two probe packets */
296 u32 offset; /* usecs the probe got sent after the reference time point */
297} __packed;
298
299/*
300 * Bitmap packets need to fit within a single page on the sender and receiver,
301 * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).
302 */
303#define DRBD_SOCKET_BUFFER_SIZE 4096
304
305#endif /* __DRBD_PROTOCOL_H */