1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __DRBD_PROTOCOL_H
3 #define __DRBD_PROTOCOL_H
6 /* receiver (data socket) */
8 P_DATA_REPLY
= 0x01, /* Response to P_DATA_REQUEST */
9 P_RS_DATA_REPLY
= 0x02, /* Response to P_RS_DATA_REQUEST */
12 P_BECOME_SYNC_TARGET
= 0x05,
13 P_BECOME_SYNC_SOURCE
= 0x06,
14 P_UNPLUG_REMOTE
= 0x07, /* Used at various times to hint the peer */
15 P_DATA_REQUEST
= 0x08, /* Used to ask for a data block */
16 P_RS_DATA_REQUEST
= 0x09, /* Used to ask for a data block for resync */
23 P_AUTH_CHALLENGE
= 0x10,
24 P_AUTH_RESPONSE
= 0x11,
25 P_STATE_CHG_REQ
= 0x12,
30 P_RECV_ACK
= 0x15, /* Used in protocol B */
31 P_WRITE_ACK
= 0x16, /* Used in protocol C */
32 P_RS_WRITE_ACK
= 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */
33 P_SUPERSEDED
= 0x18, /* Used in proto C, two-primaries conflict detection */
34 P_NEG_ACK
= 0x19, /* Sent if local disk is unusable */
35 P_NEG_DREPLY
= 0x1a, /* Local disk is broken... */
36 P_NEG_RS_DREPLY
= 0x1b, /* Local disk is broken... */
38 P_STATE_CHG_REPLY
= 0x1d,
40 /* "new" commands, no longer fitting into the ordering scheme above */
42 P_OV_REQUEST
= 0x1e, /* data socket */
44 P_OV_RESULT
= 0x20, /* meta socket */
45 P_CSUM_RS_REQUEST
= 0x21, /* data socket */
46 P_RS_IS_IN_SYNC
= 0x22, /* meta socket */
47 P_SYNC_PARAM89
= 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */
48 P_COMPRESSED_BITMAP
= 0x24, /* compressed or otherwise encoded bitmap transfer */
49 /* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */
50 /* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */
51 P_DELAY_PROBE
= 0x27, /* is used on BOTH sockets */
52 P_OUT_OF_SYNC
= 0x28, /* Mark as out of sync (Outrunning), data socket */
53 P_RS_CANCEL
= 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */
54 P_CONN_ST_CHG_REQ
= 0x2a, /* data sock: Connection wide state request */
55 P_CONN_ST_CHG_REPLY
= 0x2b, /* meta sock: Connection side state req reply */
56 P_RETRY_WRITE
= 0x2c, /* Protocol C: retry conflicting write request */
57 P_PROTOCOL_UPDATE
= 0x2d, /* data sock: is used in established connections */
58 /* 0x2e to 0x30 reserved, used in drbd 9 */
60 /* REQ_OP_DISCARD. We used "discard" in different contexts before,
61 * which is why I chose TRIM here, to disambiguate. */
64 /* Only use these two if both support FF_THIN_RESYNC */
65 P_RS_THIN_REQ
= 0x32, /* Request a block for resync or reply P_RS_DEALLOCATED */
66 P_RS_DEALLOCATED
= 0x33, /* Contains only zeros on sync source node */
69 * On a receiving side without REQ_WRITE_SAME,
70 * we may fall back to an opencoded loop instead. */
73 /* 0x35 already claimed in DRBD 9 */
74 P_ZEROES
= 0x36, /* data sock: zero-out, WRITE_ZEROES */
76 /* 0x40 .. 0x48 already claimed in DRBD 9 */
78 P_MAY_IGNORE
= 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
79 P_MAX_OPT_CMD
= 0x101,
81 /* special command ids for handshake */
83 P_INITIAL_META
= 0xfff1, /* First Packet on the MetaSock */
84 P_INITIAL_DATA
= 0xfff2, /* First Packet on the Socket */
86 P_CONNECTION_FEATURES
= 0xfffe /* FIXED for the next century! */
90 #define __packed __attribute__((packed))
93 /* This is the layout for a packet on the wire.
94 * The byteorder is the network byte order.
95 * (except block_id and barrier fields.
96 * these are pointers to local structs
97 * and have no relevance for the partner,
98 * which just echoes them as received.)
100 * NOTE that the payload starts at a long aligned offset,
101 * regardless of 32 or 64 bit arch!
106 u16 length
; /* bytes of data after this header */
109 /* Header for big packets, Used for data packets exceeding 64kB */
111 u16 magic
; /* use DRBD_MAGIC_BIG here */
124 /* These defines must not be changed without changing the protocol version.
125 * New defines may only be introduced together with protocol version bump or
126 * new protocol feature flags.
128 #define DP_HARDBARRIER 1 /* no longer used */
129 #define DP_RW_SYNC 2 /* equals REQ_SYNC */
130 #define DP_MAY_SET_IN_SYNC 4
131 #define DP_UNPLUG 8 /* not used anymore */
132 #define DP_FUA 16 /* equals REQ_FUA */
133 #define DP_FLUSH 32 /* equals REQ_PREFLUSH */
134 #define DP_DISCARD 64 /* equals REQ_OP_DISCARD */
135 #define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */
136 #define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */
137 #define DP_WSAME 512 /* equiv. REQ_WRITE_SAME */
138 #define DP_ZEROES 1024 /* equiv. REQ_OP_WRITE_ZEROES */
140 /* possible combinations:
141 * REQ_OP_WRITE_ZEROES: DP_DISCARD | DP_ZEROES
142 * REQ_OP_WRITE_ZEROES + REQ_NOUNMAP: DP_ZEROES
146 u64 sector
; /* 64 bits sector number */
147 u64 block_id
; /* to identify the request in protocol B&C */
153 struct p_data p_data
;
154 u32 size
; /* == bio->bi_size */
158 struct p_data p_data
;
159 u32 size
; /* == bio->bi_size */
163 * commands which share a struct:
165 * P_RECV_ACK (proto B), P_WRITE_ACK (proto C),
166 * P_SUPERSEDED (proto C, two-primaries conflict detection)
168 * P_DATA_REQUEST, P_RS_DATA_REQUEST
181 u32 pad
; /* to multiple of 8 Byte */
185 * commands with their own struct for additional fields:
186 * P_CONNECTION_FEATURES
193 /* supports TRIM/DISCARD on the "wire" protocol */
194 #define DRBD_FF_TRIM 1
196 /* Detect all-zeros during resync, and rather TRIM/UNMAP/DISCARD those blocks
197 * instead of fully allocate a supposedly thin volume on initial resync */
198 #define DRBD_FF_THIN_RESYNC 2
200 /* supports REQ_WRITE_SAME on the "wire" protocol.
201 * Note: this flag is overloaded,
203 * - indicates support for 128 MiB "batch bios",
204 * max discard size of 128 MiB
205 * instead of 4M before that.
206 * - indicates that we exchange additional settings in p_sizes
207 * drbd_send_sizes()/receive_sizes()
209 #define DRBD_FF_WSAME 4
211 /* supports REQ_OP_WRITE_ZEROES on the "wire" protocol.
213 * We used to map that to "discard" on the sending side, and if we cannot
214 * guarantee that discard zeroes data, the receiving side would map discard
217 * With the introduction of REQ_OP_WRITE_ZEROES,
218 * we started to use that for both WRITE_ZEROES and DISCARDS,
219 * hoping that WRITE_ZEROES would "do what we want",
220 * UNMAP if possible, zero-out the rest.
222 * The example scenario is some LVM "thin" backend.
224 * While an un-allocated block on dm-thin reads as zeroes, on a dm-thin
225 * with "skip_block_zeroing=true", after a partial block write allocated
226 * that block, that same block may well map "undefined old garbage" from
227 * the backends on LBAs that have not yet been written to.
229 * If we cannot distinguish between zero-out and discard on the receiving
230 * side, to avoid "undefined old garbage" to pop up randomly at later times
231 * on supposedly zero-initialized blocks, we'd need to map all discards to
232 * zero-out on the receiving side. But that would potentially do a full
233 * alloc on thinly provisioned backends, even when the expectation was to
234 * unmap/trim/discard/de-allocate.
236 * We need to distinguish on the protocol level, whether we need to guarantee
237 * zeroes (and thus use zero-out, potentially doing the mentioned full-alloc),
238 * or if we want to put the emphasis on discard, and only do a "best effort
239 * zeroing" (by "discarding" blocks aligned to discard-granularity, and zeroing
240 * only potential unaligned head and tail clippings), to at least *try* to
241 * avoid "false positives" in an online-verify later, hoping that someone
242 * set skip_block_zeroing=false.
244 #define DRBD_FF_WZEROES 8
247 struct p_connection_features
{
252 /* should be more than enough for future enhancements
253 * for now, feature_flags and the reserved array shall be zero.
261 u32 barrier
; /* barrier number _handle_ only */
262 u32 pad
; /* to multiple of 8 Byte */
265 struct p_barrier_ack
{
273 /* Since protocol version 88 and higher. */
277 struct p_rs_param_89
{
279 /* protocol version 89: */
280 char verify_alg
[SHARED_SECRET_MAX
];
281 char csums_alg
[SHARED_SECRET_MAX
];
284 struct p_rs_param_95
{
286 char verify_alg
[SHARED_SECRET_MAX
];
287 char csums_alg
[SHARED_SECRET_MAX
];
294 enum drbd_conn_flags
{
295 CF_DISCARD_MY_DATA
= 1,
307 /* Since protocol version 87 and higher. */
308 char integrity_alg
[0];
313 u64 uuid
[UI_EXTENDED_SIZE
];
320 /* optional queue_limits if (agreed_features & DRBD_FF_WSAME)
321 * see also struct queue_limits, as of late 2015 */
323 /* we don't need it yet, but we may as well communicate it now */
324 u32 physical_block_size
;
326 /* so the original in struct queue_limits is unsigned short,
327 * but I'd have to put in padding anyways. */
328 u32 logical_block_size
;
330 /* One incoming bio becomes one DRBD request,
331 * which may be translated to several bio on the receiving side.
332 * We don't need to communicate chunk/boundary/segment ... limits.
335 /* various IO hints may be useful with "diskless client" setups */
336 u32 alignment_offset
;
340 /* We may need to communicate integrity stuff at some point,
341 * but let's not get ahead of ourselves. */
343 /* Backend discard capabilities.
344 * Receiving side uses "blkdev_issue_discard()", no need to communicate
345 * more specifics. If the backend cannot do discards, the DRBD peer
346 * may fall back to blkdev_issue_zeroout().
349 u8 discard_zeroes_data
;
350 u8 write_same_capable
;
355 u64 d_size
; /* size of disk */
356 u64 u_size
; /* user requested size */
357 u64 c_size
; /* current exported size */
358 u32 max_bio_size
; /* Maximal size of a BIO */
359 u16 queue_order_type
; /* not yet implemented in DRBD*/
360 u16 dds_flags
; /* use enum dds_flags here. */
362 /* optional queue_limits if (agreed_features & DRBD_FF_WSAME) */
363 struct o_qlim qlim
[0];
375 struct p_req_state_reply
{
379 struct p_drbd06_param
{
389 struct p_block_desc
{
392 u32 pad
; /* to multiple of 8 Byte */
395 /* Valid values for the encoding field.
396 * Bump proto version when changing this. */
397 enum drbd_bitmap_code
{
398 /* RLE_VLI_Bytes = 0,
399 * and other bit variants had been defined during
400 * algorithm evaluation. */
404 struct p_compressed_bm
{
405 /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
406 * (encoding & 0x80): polarity (set/unset) of first runlength
407 * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
408 * used to pad up to head.length bytes
415 struct p_delay_probe93
{
416 u32 seq_num
; /* sequence number to match the two probe packets */
417 u32 offset
; /* usecs the probe got sent after the reference time point */
421 * Bitmap packets need to fit within a single page on the sender and receiver,
422 * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).
424 #define DRBD_SOCKET_BUFFER_SIZE 4096
426 #endif /* __DRBD_PROTOCOL_H */