drbd_protocol.h 11 KB

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