drbd_protocol.h 8.3 KB

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