/* SPDX-License-Identifier: GPL-2.0-only */1#ifndef __DRBD_PROTOCOL_H2#define __DRBD_PROTOCOL_H34enum drbd_packet {5/* receiver (data socket) */6P_DATA = 0x00,7P_DATA_REPLY = 0x01, /* Response to P_DATA_REQUEST */8P_RS_DATA_REPLY = 0x02, /* Response to P_RS_DATA_REQUEST */9P_BARRIER = 0x03,10P_BITMAP = 0x04,11P_BECOME_SYNC_TARGET = 0x05,12P_BECOME_SYNC_SOURCE = 0x06,13P_UNPLUG_REMOTE = 0x07, /* Used at various times to hint the peer */14P_DATA_REQUEST = 0x08, /* Used to ask for a data block */15P_RS_DATA_REQUEST = 0x09, /* Used to ask for a data block for resync */16P_SYNC_PARAM = 0x0a,17P_PROTOCOL = 0x0b,18P_UUIDS = 0x0c,19P_SIZES = 0x0d,20P_STATE = 0x0e,21P_SYNC_UUID = 0x0f,22P_AUTH_CHALLENGE = 0x10,23P_AUTH_RESPONSE = 0x11,24P_STATE_CHG_REQ = 0x12,2526/* (meta socket) */27P_PING = 0x13,28P_PING_ACK = 0x14,29P_RECV_ACK = 0x15, /* Used in protocol B */30P_WRITE_ACK = 0x16, /* Used in protocol C */31P_RS_WRITE_ACK = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */32P_SUPERSEDED = 0x18, /* Used in proto C, two-primaries conflict detection */33P_NEG_ACK = 0x19, /* Sent if local disk is unusable */34P_NEG_DREPLY = 0x1a, /* Local disk is broken... */35P_NEG_RS_DREPLY = 0x1b, /* Local disk is broken... */36P_BARRIER_ACK = 0x1c,37P_STATE_CHG_REPLY = 0x1d,3839/* "new" commands, no longer fitting into the ordering scheme above */4041P_OV_REQUEST = 0x1e, /* data socket */42P_OV_REPLY = 0x1f,43P_OV_RESULT = 0x20, /* meta socket */44P_CSUM_RS_REQUEST = 0x21, /* data socket */45P_RS_IS_IN_SYNC = 0x22, /* meta socket */46P_SYNC_PARAM89 = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */47P_COMPRESSED_BITMAP = 0x24, /* compressed or otherwise encoded bitmap transfer */48/* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */49/* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */50P_DELAY_PROBE = 0x27, /* is used on BOTH sockets */51P_OUT_OF_SYNC = 0x28, /* Mark as out of sync (Outrunning), data socket */52P_RS_CANCEL = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */53P_CONN_ST_CHG_REQ = 0x2a, /* data sock: Connection wide state request */54P_CONN_ST_CHG_REPLY = 0x2b, /* meta sock: Connection side state req reply */55P_RETRY_WRITE = 0x2c, /* Protocol C: retry conflicting write request */56P_PROTOCOL_UPDATE = 0x2d, /* data sock: is used in established connections */57/* 0x2e to 0x30 reserved, used in drbd 9 */5859/* REQ_OP_DISCARD. We used "discard" in different contexts before,60* which is why I chose TRIM here, to disambiguate. */61P_TRIM = 0x31,6263/* Only use these two if both support FF_THIN_RESYNC */64P_RS_THIN_REQ = 0x32, /* Request a block for resync or reply P_RS_DEALLOCATED */65P_RS_DEALLOCATED = 0x33, /* Contains only zeros on sync source node */6667/* REQ_WRITE_SAME.68* On a receiving side without REQ_WRITE_SAME,69* we may fall back to an opencoded loop instead. */70P_WSAME = 0x34,7172/* 0x35 already claimed in DRBD 9 */73P_ZEROES = 0x36, /* data sock: zero-out, WRITE_ZEROES */7475/* 0x40 .. 0x48 already claimed in DRBD 9 */7677P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */78P_MAX_OPT_CMD = 0x101,7980/* special command ids for handshake */8182P_INITIAL_META = 0xfff1, /* First Packet on the MetaSock */83P_INITIAL_DATA = 0xfff2, /* First Packet on the Socket */8485P_CONNECTION_FEATURES = 0xfffe /* FIXED for the next century! */86};8788#ifndef __packed89#define __packed __attribute__((packed))90#endif9192/* This is the layout for a packet on the wire.93* The byteorder is the network byte order.94* (except block_id and barrier fields.95* these are pointers to local structs96* and have no relevance for the partner,97* which just echoes them as received.)98*99* NOTE that the payload starts at a long aligned offset,100* regardless of 32 or 64 bit arch!101*/102struct p_header80 {103u32 magic;104u16 command;105u16 length; /* bytes of data after this header */106} __packed;107108/* Header for big packets, Used for data packets exceeding 64kB */109struct p_header95 {110u16 magic; /* use DRBD_MAGIC_BIG here */111u16 command;112u32 length;113} __packed;114115struct p_header100 {116u32 magic;117u16 volume;118u16 command;119u32 length;120u32 pad;121} __packed;122123/* These defines must not be changed without changing the protocol version.124* New defines may only be introduced together with protocol version bump or125* new protocol feature flags.126*/127#define DP_HARDBARRIER 1 /* no longer used */128#define DP_RW_SYNC 2 /* equals REQ_SYNC */129#define DP_MAY_SET_IN_SYNC 4130#define DP_UNPLUG 8 /* not used anymore */131#define DP_FUA 16 /* equals REQ_FUA */132#define DP_FLUSH 32 /* equals REQ_PREFLUSH */133#define DP_DISCARD 64 /* equals REQ_OP_DISCARD */134#define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */135#define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */136#define DP_WSAME 512 /* equiv. REQ_WRITE_SAME */137#define DP_ZEROES 1024 /* equiv. REQ_OP_WRITE_ZEROES */138139/* possible combinations:140* REQ_OP_WRITE_ZEROES: DP_DISCARD | DP_ZEROES141* REQ_OP_WRITE_ZEROES + REQ_NOUNMAP: DP_ZEROES142*/143144struct p_data {145u64 sector; /* 64 bits sector number */146u64 block_id; /* to identify the request in protocol B&C */147u32 seq_num;148u32 dp_flags;149} __packed;150151struct p_trim {152struct p_data p_data;153u32 size; /* == bio->bi_size */154} __packed;155156struct p_wsame {157struct p_data p_data;158u32 size; /* == bio->bi_size */159} __packed;160161/*162* commands which share a struct:163* p_block_ack:164* P_RECV_ACK (proto B), P_WRITE_ACK (proto C),165* P_SUPERSEDED (proto C, two-primaries conflict detection)166* p_block_req:167* P_DATA_REQUEST, P_RS_DATA_REQUEST168*/169struct p_block_ack {170u64 sector;171u64 block_id;172u32 blksize;173u32 seq_num;174} __packed;175176struct p_block_req {177u64 sector;178u64 block_id;179u32 blksize;180u32 pad; /* to multiple of 8 Byte */181} __packed;182183/*184* commands with their own struct for additional fields:185* P_CONNECTION_FEATURES186* P_BARRIER187* P_BARRIER_ACK188* P_SYNC_PARAM189* ReportParams190*/191192/* supports TRIM/DISCARD on the "wire" protocol */193#define DRBD_FF_TRIM 1194195/* Detect all-zeros during resync, and rather TRIM/UNMAP/DISCARD those blocks196* instead of fully allocate a supposedly thin volume on initial resync */197#define DRBD_FF_THIN_RESYNC 2198199/* supports REQ_WRITE_SAME on the "wire" protocol.200* Note: this flag is overloaded,201* its presence also202* - indicates support for 128 MiB "batch bios",203* max discard size of 128 MiB204* instead of 4M before that.205* - indicates that we exchange additional settings in p_sizes206* drbd_send_sizes()/receive_sizes()207*/208#define DRBD_FF_WSAME 4209210/* supports REQ_OP_WRITE_ZEROES on the "wire" protocol.211*212* We used to map that to "discard" on the sending side, and if we cannot213* guarantee that discard zeroes data, the receiving side would map discard214* back to zero-out.215*216* With the introduction of REQ_OP_WRITE_ZEROES,217* we started to use that for both WRITE_ZEROES and DISCARDS,218* hoping that WRITE_ZEROES would "do what we want",219* UNMAP if possible, zero-out the rest.220*221* The example scenario is some LVM "thin" backend.222*223* While an un-allocated block on dm-thin reads as zeroes, on a dm-thin224* with "skip_block_zeroing=true", after a partial block write allocated225* that block, that same block may well map "undefined old garbage" from226* the backends on LBAs that have not yet been written to.227*228* If we cannot distinguish between zero-out and discard on the receiving229* side, to avoid "undefined old garbage" to pop up randomly at later times230* on supposedly zero-initialized blocks, we'd need to map all discards to231* zero-out on the receiving side. But that would potentially do a full232* alloc on thinly provisioned backends, even when the expectation was to233* unmap/trim/discard/de-allocate.234*235* We need to distinguish on the protocol level, whether we need to guarantee236* zeroes (and thus use zero-out, potentially doing the mentioned full-alloc),237* or if we want to put the emphasis on discard, and only do a "best effort238* zeroing" (by "discarding" blocks aligned to discard-granularity, and zeroing239* only potential unaligned head and tail clippings), to at least *try* to240* avoid "false positives" in an online-verify later, hoping that someone241* set skip_block_zeroing=false.242*/243#define DRBD_FF_WZEROES 8244245246struct p_connection_features {247u32 protocol_min;248u32 feature_flags;249u32 protocol_max;250251/* should be more than enough for future enhancements252* for now, feature_flags and the reserved array shall be zero.253*/254255u32 _pad;256u64 reserved[7];257} __packed;258259struct p_barrier {260u32 barrier; /* barrier number _handle_ only */261u32 pad; /* to multiple of 8 Byte */262} __packed;263264struct p_barrier_ack {265u32 barrier;266u32 set_size;267} __packed;268269struct p_rs_param {270u32 resync_rate;271272/* Since protocol version 88 and higher. */273char verify_alg[];274} __packed;275276struct p_rs_param_89 {277u32 resync_rate;278/* protocol version 89: */279char verify_alg[SHARED_SECRET_MAX];280char csums_alg[SHARED_SECRET_MAX];281} __packed;282283struct p_rs_param_95 {284u32 resync_rate;285struct_group(algs,286char verify_alg[SHARED_SECRET_MAX];287char csums_alg[SHARED_SECRET_MAX];288);289u32 c_plan_ahead;290u32 c_delay_target;291u32 c_fill_target;292u32 c_max_rate;293} __packed;294295enum drbd_conn_flags {296CF_DISCARD_MY_DATA = 1,297CF_DRY_RUN = 2,298};299300struct p_protocol {301u32 protocol;302u32 after_sb_0p;303u32 after_sb_1p;304u32 after_sb_2p;305u32 conn_flags;306u32 two_primaries;307308/* Since protocol version 87 and higher. */309char integrity_alg[];310311} __packed;312313struct p_uuids {314u64 uuid[UI_EXTENDED_SIZE];315} __packed;316317struct p_rs_uuid {318u64 uuid;319} __packed;320321/* optional queue_limits if (agreed_features & DRBD_FF_WSAME)322* see also struct queue_limits, as of late 2015 */323struct o_qlim {324/* we don't need it yet, but we may as well communicate it now */325u32 physical_block_size;326327/* so the original in struct queue_limits is unsigned short,328* but I'd have to put in padding anyways. */329u32 logical_block_size;330331/* One incoming bio becomes one DRBD request,332* which may be translated to several bio on the receiving side.333* We don't need to communicate chunk/boundary/segment ... limits.334*/335336/* various IO hints may be useful with "diskless client" setups */337u32 alignment_offset;338u32 io_min;339u32 io_opt;340341/* We may need to communicate integrity stuff at some point,342* but let's not get ahead of ourselves. */343344/* Backend discard capabilities.345* Receiving side uses "blkdev_issue_discard()", no need to communicate346* more specifics. If the backend cannot do discards, the DRBD peer347* may fall back to blkdev_issue_zeroout().348*/349u8 discard_enabled;350u8 discard_zeroes_data;351u8 write_same_capable;352u8 _pad;353} __packed;354355struct p_sizes {356u64 d_size; /* size of disk */357u64 u_size; /* user requested size */358u64 c_size; /* current exported size */359u32 max_bio_size; /* Maximal size of a BIO */360u16 queue_order_type; /* not yet implemented in DRBD*/361u16 dds_flags; /* use enum dds_flags here. */362363/* optional queue_limits if (agreed_features & DRBD_FF_WSAME) */364struct o_qlim qlim[];365} __packed;366367struct p_state {368u32 state;369} __packed;370371struct p_req_state {372u32 mask;373u32 val;374} __packed;375376struct p_req_state_reply {377u32 retcode;378} __packed;379380struct p_drbd06_param {381u64 size;382u32 state;383u32 blksize;384u32 protocol;385u32 version;386u32 gen_cnt[5];387u32 bit_map_gen[5];388} __packed;389390struct p_block_desc {391u64 sector;392u32 blksize;393u32 pad; /* to multiple of 8 Byte */394} __packed;395396/* Valid values for the encoding field.397* Bump proto version when changing this. */398enum drbd_bitmap_code {399/* RLE_VLI_Bytes = 0,400* and other bit variants had been defined during401* algorithm evaluation. */402RLE_VLI_Bits = 2,403};404405struct p_compressed_bm {406/* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code407* (encoding & 0x80): polarity (set/unset) of first runlength408* ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits409* used to pad up to head.length bytes410*/411u8 encoding;412413u8 code[];414} __packed;415416struct p_delay_probe93 {417u32 seq_num; /* sequence number to match the two probe packets */418u32 offset; /* usecs the probe got sent after the reference time point */419} __packed;420421/*422* Bitmap packets need to fit within a single page on the sender and receiver,423* so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger).424*/425#define DRBD_SOCKET_BUFFER_SIZE 4096426427#endif /* __DRBD_PROTOCOL_H */428429430