drbd_protocol.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __DRBD_PROTOCOL_H
  3. #define __DRBD_PROTOCOL_H
  4. enum 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. /* (meta socket) */
  26. P_PING = 0x13,
  27. P_PING_ACK = 0x14,
  28. P_RECV_ACK = 0x15, /* Used in protocol B */
  29. P_WRITE_ACK = 0x16, /* Used in protocol C */
  30. P_RS_WRITE_ACK = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */
  31. P_SUPERSEDED = 0x18, /* Used in proto C, two-primaries conflict detection */
  32. P_NEG_ACK = 0x19, /* Sent if local disk is unusable */
  33. P_NEG_DREPLY = 0x1a, /* Local disk is broken... */
  34. P_NEG_RS_DREPLY = 0x1b, /* Local disk is broken... */
  35. P_BARRIER_ACK = 0x1c,
  36. P_STATE_CHG_REPLY = 0x1d,
  37. /* "new" commands, no longer fitting into the ordering scheme above */
  38. P_OV_REQUEST = 0x1e, /* data socket */
  39. P_OV_REPLY = 0x1f,
  40. P_OV_RESULT = 0x20, /* meta socket */
  41. P_CSUM_RS_REQUEST = 0x21, /* data socket */
  42. P_RS_IS_IN_SYNC = 0x22, /* meta socket */
  43. P_SYNC_PARAM89 = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */
  44. P_COMPRESSED_BITMAP = 0x24, /* compressed or otherwise encoded bitmap transfer */
  45. /* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */
  46. /* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */
  47. P_DELAY_PROBE = 0x27, /* is used on BOTH sockets */
  48. P_OUT_OF_SYNC = 0x28, /* Mark as out of sync (Outrunning), data socket */
  49. P_RS_CANCEL = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */
  50. P_CONN_ST_CHG_REQ = 0x2a, /* data sock: Connection wide state request */
  51. P_CONN_ST_CHG_REPLY = 0x2b, /* meta sock: Connection side state req reply */
  52. P_RETRY_WRITE = 0x2c, /* Protocol C: retry conflicting write request */
  53. P_PROTOCOL_UPDATE = 0x2d, /* data sock: is used in established connections */
  54. /* 0x2e to 0x30 reserved, used in drbd 9 */
  55. /* REQ_OP_DISCARD. We used "discard" in different contexts before,
  56. * which is why I chose TRIM here, to disambiguate. */
  57. P_TRIM = 0x31,
  58. /* Only use these two if both support FF_THIN_RESYNC */
  59. P_RS_THIN_REQ = 0x32, /* Request a block for resync or reply P_RS_DEALLOCATED */
  60. P_RS_DEALLOCATED = 0x33, /* Contains only zeros on sync source node */
  61. /* REQ_WRITE_SAME.
  62. * On a receiving side without REQ_WRITE_SAME,
  63. * we may fall back to an opencoded loop instead. */
  64. P_WSAME = 0x34,
  65. /* 0x35 already claimed in DRBD 9 */
  66. P_ZEROES = 0x36, /* data sock: zero-out, WRITE_ZEROES */
  67. /* 0x40 .. 0x48 already claimed in DRBD 9 */
  68. P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
  69. P_MAX_OPT_CMD = 0x101,
  70. /* special command ids for handshake */
  71. P_INITIAL_META = 0xfff1, /* First Packet on the MetaSock */
  72. P_INITIAL_DATA = 0xfff2, /* First Packet on the Socket */
  73. P_CONNECTION_FEATURES = 0xfffe /* FIXED for the next century! */
  74. };
  75. #ifndef __packed
  76. #define __packed __attribute__((packed))
  77. #endif
  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. */
  88. struct p_header80 {
  89. u32 magic;
  90. u16 command;
  91. u16 length; /* bytes of data after this header */
  92. } __packed;
  93. /* Header for big packets, Used for data packets exceeding 64kB */
  94. struct p_header95 {
  95. u16 magic; /* use DRBD_MAGIC_BIG here */
  96. u16 command;
  97. u32 length;
  98. } __packed;
  99. struct p_header100 {
  100. u32 magic;
  101. u16 volume;
  102. u16 command;
  103. u32 length;
  104. u32 pad;
  105. } __packed;
  106. /* These defines must not be changed without changing the protocol version.
  107. * New defines may only be introduced together with protocol version bump or
  108. * new protocol feature flags.
  109. */
  110. #define DP_HARDBARRIER 1 /* no longer used */
  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_PREFLUSH */
  116. #define DP_DISCARD 64 /* equals REQ_OP_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. #define DP_WSAME 512 /* equiv. REQ_WRITE_SAME */
  120. #define DP_ZEROES 1024 /* equiv. REQ_OP_WRITE_ZEROES */
  121. /* possible combinations:
  122. * REQ_OP_WRITE_ZEROES: DP_DISCARD | DP_ZEROES
  123. * REQ_OP_WRITE_ZEROES + REQ_NOUNMAP: DP_ZEROES
  124. */
  125. struct p_data {
  126. u64 sector; /* 64 bits sector number */
  127. u64 block_id; /* to identify the request in protocol B&C */
  128. u32 seq_num;
  129. u32 dp_flags;
  130. } __packed;
  131. struct p_trim {
  132. struct p_data p_data;
  133. u32 size; /* == bio->bi_size */
  134. } __packed;
  135. struct p_wsame {
  136. struct p_data p_data;
  137. u32 size; /* == bio->bi_size */
  138. } __packed;
  139. /*
  140. * commands which share a struct:
  141. * p_block_ack:
  142. * P_RECV_ACK (proto B), P_WRITE_ACK (proto C),
  143. * P_SUPERSEDED (proto C, two-primaries conflict detection)
  144. * p_block_req:
  145. * P_DATA_REQUEST, P_RS_DATA_REQUEST
  146. */
  147. struct p_block_ack {
  148. u64 sector;
  149. u64 block_id;
  150. u32 blksize;
  151. u32 seq_num;
  152. } __packed;
  153. struct p_block_req {
  154. u64 sector;
  155. u64 block_id;
  156. u32 blksize;
  157. u32 pad; /* to multiple of 8 Byte */
  158. } __packed;
  159. /*
  160. * commands with their own struct for additional fields:
  161. * P_CONNECTION_FEATURES
  162. * P_BARRIER
  163. * P_BARRIER_ACK
  164. * P_SYNC_PARAM
  165. * ReportParams
  166. */
  167. /* supports TRIM/DISCARD on the "wire" protocol */
  168. #define DRBD_FF_TRIM 1
  169. /* Detect all-zeros during resync, and rather TRIM/UNMAP/DISCARD those blocks
  170. * instead of fully allocate a supposedly thin volume on initial resync */
  171. #define DRBD_FF_THIN_RESYNC 2
  172. /* supports REQ_WRITE_SAME on the "wire" protocol.
  173. * Note: this flag is overloaded,
  174. * its presence also
  175. * - indicates support for 128 MiB "batch bios",
  176. * max discard size of 128 MiB
  177. * instead of 4M before that.
  178. * - indicates that we exchange additional settings in p_sizes
  179. * drbd_send_sizes()/receive_sizes()
  180. */
  181. #define DRBD_FF_WSAME 4
  182. /* supports REQ_OP_WRITE_ZEROES on the "wire" protocol.
  183. *
  184. * We used to map that to "discard" on the sending side, and if we cannot
  185. * guarantee that discard zeroes data, the receiving side would map discard
  186. * back to zero-out.
  187. *
  188. * With the introduction of REQ_OP_WRITE_ZEROES,
  189. * we started to use that for both WRITE_ZEROES and DISCARDS,
  190. * hoping that WRITE_ZEROES would "do what we want",
  191. * UNMAP if possible, zero-out the rest.
  192. *
  193. * The example scenario is some LVM "thin" backend.
  194. *
  195. * While an un-allocated block on dm-thin reads as zeroes, on a dm-thin
  196. * with "skip_block_zeroing=true", after a partial block write allocated
  197. * that block, that same block may well map "undefined old garbage" from
  198. * the backends on LBAs that have not yet been written to.
  199. *
  200. * If we cannot distinguish between zero-out and discard on the receiving
  201. * side, to avoid "undefined old garbage" to pop up randomly at later times
  202. * on supposedly zero-initialized blocks, we'd need to map all discards to
  203. * zero-out on the receiving side. But that would potentially do a full
  204. * alloc on thinly provisioned backends, even when the expectation was to
  205. * unmap/trim/discard/de-allocate.
  206. *
  207. * We need to distinguish on the protocol level, whether we need to guarantee
  208. * zeroes (and thus use zero-out, potentially doing the mentioned full-alloc),
  209. * or if we want to put the emphasis on discard, and only do a "best effort
  210. * zeroing" (by "discarding" blocks aligned to discard-granularity, and zeroing
  211. * only potential unaligned head and tail clippings), to at least *try* to
  212. * avoid "false positives" in an online-verify later, hoping that someone
  213. * set skip_block_zeroing=false.
  214. */
  215. #define DRBD_FF_WZEROES 8
  216. struct p_connection_features {
  217. u32 protocol_min;
  218. u32 feature_flags;
  219. u32 protocol_max;
  220. /* should be more than enough for future enhancements
  221. * for now, feature_flags and the reserved array shall be zero.
  222. */
  223. u32 _pad;
  224. u64 reserved[7];
  225. } __packed;
  226. struct p_barrier {
  227. u32 barrier; /* barrier number _handle_ only */
  228. u32 pad; /* to multiple of 8 Byte */
  229. } __packed;
  230. struct p_barrier_ack {
  231. u32 barrier;
  232. u32 set_size;
  233. } __packed;
  234. struct p_rs_param {
  235. u32 resync_rate;
  236. /* Since protocol version 88 and higher. */
  237. char verify_alg[];
  238. } __packed;
  239. struct p_rs_param_89 {
  240. u32 resync_rate;
  241. /* protocol version 89: */
  242. char verify_alg[SHARED_SECRET_MAX];
  243. char csums_alg[SHARED_SECRET_MAX];
  244. } __packed;
  245. struct p_rs_param_95 {
  246. u32 resync_rate;
  247. struct_group(algs,
  248. char verify_alg[SHARED_SECRET_MAX];
  249. char csums_alg[SHARED_SECRET_MAX];
  250. );
  251. u32 c_plan_ahead;
  252. u32 c_delay_target;
  253. u32 c_fill_target;
  254. u32 c_max_rate;
  255. } __packed;
  256. enum drbd_conn_flags {
  257. CF_DISCARD_MY_DATA = 1,
  258. CF_DRY_RUN = 2,
  259. };
  260. struct p_protocol {
  261. u32 protocol;
  262. u32 after_sb_0p;
  263. u32 after_sb_1p;
  264. u32 after_sb_2p;
  265. u32 conn_flags;
  266. u32 two_primaries;
  267. /* Since protocol version 87 and higher. */
  268. char integrity_alg[];
  269. } __packed;
  270. struct p_uuids {
  271. u64 uuid[UI_EXTENDED_SIZE];
  272. } __packed;
  273. struct p_rs_uuid {
  274. u64 uuid;
  275. } __packed;
  276. /* optional queue_limits if (agreed_features & DRBD_FF_WSAME)
  277. * see also struct queue_limits, as of late 2015 */
  278. struct o_qlim {
  279. /* we don't need it yet, but we may as well communicate it now */
  280. u32 physical_block_size;
  281. /* so the original in struct queue_limits is unsigned short,
  282. * but I'd have to put in padding anyways. */
  283. u32 logical_block_size;
  284. /* One incoming bio becomes one DRBD request,
  285. * which may be translated to several bio on the receiving side.
  286. * We don't need to communicate chunk/boundary/segment ... limits.
  287. */
  288. /* various IO hints may be useful with "diskless client" setups */
  289. u32 alignment_offset;
  290. u32 io_min;
  291. u32 io_opt;
  292. /* We may need to communicate integrity stuff at some point,
  293. * but let's not get ahead of ourselves. */
  294. /* Backend discard capabilities.
  295. * Receiving side uses "blkdev_issue_discard()", no need to communicate
  296. * more specifics. If the backend cannot do discards, the DRBD peer
  297. * may fall back to blkdev_issue_zeroout().
  298. */
  299. u8 discard_enabled;
  300. u8 discard_zeroes_data;
  301. u8 write_same_capable;
  302. u8 _pad;
  303. } __packed;
  304. struct p_sizes {
  305. u64 d_size; /* size of disk */
  306. u64 u_size; /* user requested size */
  307. u64 c_size; /* current exported size */
  308. u32 max_bio_size; /* Maximal size of a BIO */
  309. u16 queue_order_type; /* not yet implemented in DRBD*/
  310. u16 dds_flags; /* use enum dds_flags here. */
  311. /* optional queue_limits if (agreed_features & DRBD_FF_WSAME) */
  312. struct o_qlim qlim[];
  313. } __packed;
  314. struct p_state {
  315. u32 state;
  316. } __packed;
  317. struct p_req_state {
  318. u32 mask;
  319. u32 val;
  320. } __packed;
  321. struct p_req_state_reply {
  322. u32 retcode;
  323. } __packed;
  324. struct p_drbd06_param {
  325. u64 size;
  326. u32 state;
  327. u32 blksize;
  328. u32 protocol;
  329. u32 version;
  330. u32 gen_cnt[5];
  331. u32 bit_map_gen[5];
  332. } __packed;
  333. struct p_block_desc {
  334. u64 sector;
  335. u32 blksize;
  336. u32 pad; /* to multiple of 8 Byte */
  337. } __packed;
  338. /* Valid values for the encoding field.
  339. * Bump proto version when changing this. */
  340. enum drbd_bitmap_code {
  341. /* RLE_VLI_Bytes = 0,
  342. * and other bit variants had been defined during
  343. * algorithm evaluation. */
  344. RLE_VLI_Bits = 2,
  345. };
  346. struct p_compressed_bm {
  347. /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
  348. * (encoding & 0x80): polarity (set/unset) of first runlength
  349. * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
  350. * used to pad up to head.length bytes
  351. */
  352. u8 encoding;
  353. u8 code[];
  354. } __packed;
  355. struct p_delay_probe93 {
  356. u32 seq_num; /* sequence number to match the two probe packets */
  357. u32 offset; /* usecs the probe got sent after the reference time point */
  358. } __packed;
  359. /*
  360. * Bitmap packets need to fit within a single page on the sender and receiver,
  361. * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).
  362. */
  363. #define DRBD_SOCKET_BUFFER_SIZE 4096
  364. #endif /* __DRBD_PROTOCOL_H */