drbd_protocol.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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_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. P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
  66. P_MAX_OPT_CMD = 0x101,
  67. /* special command ids for handshake */
  68. P_INITIAL_META = 0xfff1, /* First Packet on the MetaSock */
  69. P_INITIAL_DATA = 0xfff2, /* First Packet on the Socket */
  70. P_CONNECTION_FEATURES = 0xfffe /* FIXED for the next century! */
  71. };
  72. #ifndef __packed
  73. #define __packed __attribute__((packed))
  74. #endif
  75. /* This is the layout for a packet on the wire.
  76. * The byteorder is the network byte order.
  77. * (except block_id and barrier fields.
  78. * these are pointers to local structs
  79. * and have no relevance for the partner,
  80. * which just echoes them as received.)
  81. *
  82. * NOTE that the payload starts at a long aligned offset,
  83. * regardless of 32 or 64 bit arch!
  84. */
  85. struct p_header80 {
  86. u32 magic;
  87. u16 command;
  88. u16 length; /* bytes of data after this header */
  89. } __packed;
  90. /* Header for big packets, Used for data packets exceeding 64kB */
  91. struct p_header95 {
  92. u16 magic; /* use DRBD_MAGIC_BIG here */
  93. u16 command;
  94. u32 length;
  95. } __packed;
  96. struct p_header100 {
  97. u32 magic;
  98. u16 volume;
  99. u16 command;
  100. u32 length;
  101. u32 pad;
  102. } __packed;
  103. /* These defines must not be changed without changing the protocol version.
  104. * New defines may only be introduced together with protocol version bump or
  105. * new protocol feature flags.
  106. */
  107. #define DP_HARDBARRIER 1 /* no longer used */
  108. #define DP_RW_SYNC 2 /* equals REQ_SYNC */
  109. #define DP_MAY_SET_IN_SYNC 4
  110. #define DP_UNPLUG 8 /* not used anymore */
  111. #define DP_FUA 16 /* equals REQ_FUA */
  112. #define DP_FLUSH 32 /* equals REQ_PREFLUSH */
  113. #define DP_DISCARD 64 /* equals REQ_DISCARD */
  114. #define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */
  115. #define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */
  116. #define DP_WSAME 512 /* equiv. REQ_WRITE_SAME */
  117. struct p_data {
  118. u64 sector; /* 64 bits sector number */
  119. u64 block_id; /* to identify the request in protocol B&C */
  120. u32 seq_num;
  121. u32 dp_flags;
  122. } __packed;
  123. struct p_trim {
  124. struct p_data p_data;
  125. u32 size; /* == bio->bi_size */
  126. } __packed;
  127. struct p_wsame {
  128. struct p_data p_data;
  129. u32 size; /* == bio->bi_size */
  130. } __packed;
  131. /*
  132. * commands which share a struct:
  133. * p_block_ack:
  134. * P_RECV_ACK (proto B), P_WRITE_ACK (proto C),
  135. * P_SUPERSEDED (proto C, two-primaries conflict detection)
  136. * p_block_req:
  137. * P_DATA_REQUEST, P_RS_DATA_REQUEST
  138. */
  139. struct p_block_ack {
  140. u64 sector;
  141. u64 block_id;
  142. u32 blksize;
  143. u32 seq_num;
  144. } __packed;
  145. struct p_block_req {
  146. u64 sector;
  147. u64 block_id;
  148. u32 blksize;
  149. u32 pad; /* to multiple of 8 Byte */
  150. } __packed;
  151. /*
  152. * commands with their own struct for additional fields:
  153. * P_CONNECTION_FEATURES
  154. * P_BARRIER
  155. * P_BARRIER_ACK
  156. * P_SYNC_PARAM
  157. * ReportParams
  158. */
  159. /* supports TRIM/DISCARD on the "wire" protocol */
  160. #define DRBD_FF_TRIM 1
  161. /* Detect all-zeros during resync, and rather TRIM/UNMAP/DISCARD those blocks
  162. * instead of fully allocate a supposedly thin volume on initial resync */
  163. #define DRBD_FF_THIN_RESYNC 2
  164. /* supports REQ_WRITE_SAME on the "wire" protocol.
  165. * Note: this flag is overloaded,
  166. * its presence also
  167. * - indicates support for 128 MiB "batch bios",
  168. * max discard size of 128 MiB
  169. * instead of 4M before that.
  170. * - indicates that we exchange additional settings in p_sizes
  171. * drbd_send_sizes()/receive_sizes()
  172. */
  173. #define DRBD_FF_WSAME 4
  174. struct p_connection_features {
  175. u32 protocol_min;
  176. u32 feature_flags;
  177. u32 protocol_max;
  178. /* should be more than enough for future enhancements
  179. * for now, feature_flags and the reserved array shall be zero.
  180. */
  181. u32 _pad;
  182. u64 reserved[7];
  183. } __packed;
  184. struct p_barrier {
  185. u32 barrier; /* barrier number _handle_ only */
  186. u32 pad; /* to multiple of 8 Byte */
  187. } __packed;
  188. struct p_barrier_ack {
  189. u32 barrier;
  190. u32 set_size;
  191. } __packed;
  192. struct p_rs_param {
  193. u32 resync_rate;
  194. /* Since protocol version 88 and higher. */
  195. char verify_alg[0];
  196. } __packed;
  197. struct p_rs_param_89 {
  198. u32 resync_rate;
  199. /* protocol version 89: */
  200. char verify_alg[SHARED_SECRET_MAX];
  201. char csums_alg[SHARED_SECRET_MAX];
  202. } __packed;
  203. struct p_rs_param_95 {
  204. u32 resync_rate;
  205. char verify_alg[SHARED_SECRET_MAX];
  206. char csums_alg[SHARED_SECRET_MAX];
  207. u32 c_plan_ahead;
  208. u32 c_delay_target;
  209. u32 c_fill_target;
  210. u32 c_max_rate;
  211. } __packed;
  212. enum drbd_conn_flags {
  213. CF_DISCARD_MY_DATA = 1,
  214. CF_DRY_RUN = 2,
  215. };
  216. struct p_protocol {
  217. u32 protocol;
  218. u32 after_sb_0p;
  219. u32 after_sb_1p;
  220. u32 after_sb_2p;
  221. u32 conn_flags;
  222. u32 two_primaries;
  223. /* Since protocol version 87 and higher. */
  224. char integrity_alg[0];
  225. } __packed;
  226. struct p_uuids {
  227. u64 uuid[UI_EXTENDED_SIZE];
  228. } __packed;
  229. struct p_rs_uuid {
  230. u64 uuid;
  231. } __packed;
  232. /* optional queue_limits if (agreed_features & DRBD_FF_WSAME)
  233. * see also struct queue_limits, as of late 2015 */
  234. struct o_qlim {
  235. /* we don't need it yet, but we may as well communicate it now */
  236. u32 physical_block_size;
  237. /* so the original in struct queue_limits is unsigned short,
  238. * but I'd have to put in padding anyways. */
  239. u32 logical_block_size;
  240. /* One incoming bio becomes one DRBD request,
  241. * which may be translated to several bio on the receiving side.
  242. * We don't need to communicate chunk/boundary/segment ... limits.
  243. */
  244. /* various IO hints may be useful with "diskless client" setups */
  245. u32 alignment_offset;
  246. u32 io_min;
  247. u32 io_opt;
  248. /* We may need to communicate integrity stuff at some point,
  249. * but let's not get ahead of ourselves. */
  250. /* Backend discard capabilities.
  251. * Receiving side uses "blkdev_issue_discard()", no need to communicate
  252. * more specifics. If the backend cannot do discards, the DRBD peer
  253. * may fall back to blkdev_issue_zeroout().
  254. */
  255. u8 discard_enabled;
  256. u8 discard_zeroes_data;
  257. u8 write_same_capable;
  258. u8 _pad;
  259. } __packed;
  260. struct p_sizes {
  261. u64 d_size; /* size of disk */
  262. u64 u_size; /* user requested size */
  263. u64 c_size; /* current exported size */
  264. u32 max_bio_size; /* Maximal size of a BIO */
  265. u16 queue_order_type; /* not yet implemented in DRBD*/
  266. u16 dds_flags; /* use enum dds_flags here. */
  267. /* optional queue_limits if (agreed_features & DRBD_FF_WSAME) */
  268. struct o_qlim qlim[0];
  269. } __packed;
  270. struct p_state {
  271. u32 state;
  272. } __packed;
  273. struct p_req_state {
  274. u32 mask;
  275. u32 val;
  276. } __packed;
  277. struct p_req_state_reply {
  278. u32 retcode;
  279. } __packed;
  280. struct p_drbd06_param {
  281. u64 size;
  282. u32 state;
  283. u32 blksize;
  284. u32 protocol;
  285. u32 version;
  286. u32 gen_cnt[5];
  287. u32 bit_map_gen[5];
  288. } __packed;
  289. struct p_block_desc {
  290. u64 sector;
  291. u32 blksize;
  292. u32 pad; /* to multiple of 8 Byte */
  293. } __packed;
  294. /* Valid values for the encoding field.
  295. * Bump proto version when changing this. */
  296. enum drbd_bitmap_code {
  297. /* RLE_VLI_Bytes = 0,
  298. * and other bit variants had been defined during
  299. * algorithm evaluation. */
  300. RLE_VLI_Bits = 2,
  301. };
  302. struct p_compressed_bm {
  303. /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
  304. * (encoding & 0x80): polarity (set/unset) of first runlength
  305. * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
  306. * used to pad up to head.length bytes
  307. */
  308. u8 encoding;
  309. u8 code[0];
  310. } __packed;
  311. struct p_delay_probe93 {
  312. u32 seq_num; /* sequence number to match the two probe packets */
  313. u32 offset; /* usecs the probe got sent after the reference time point */
  314. } __packed;
  315. /*
  316. * Bitmap packets need to fit within a single page on the sender and receiver,
  317. * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).
  318. */
  319. #define DRBD_SOCKET_BUFFER_SIZE 4096
  320. #endif /* __DRBD_PROTOCOL_H */