Commit e658983a authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Philipp Reisner

drbd: Remove headers from on-the-wire data structures (struct p_*)

Prepare the introduction of the protocol 100 headers. The actual protocol
header is removed for the packet declarations. I.e. allow us to use the
packets with different headers.
Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 50d0b1ad
...@@ -307,32 +307,8 @@ struct p_header95 { ...@@ -307,32 +307,8 @@ struct p_header95 {
u32 length; /* Use only 24 bits of that. Ignore the highest 8 bit. */ u32 length; /* Use only 24 bits of that. Ignore the highest 8 bit. */
} __packed; } __packed;
struct p_header {
union {
struct p_header80 h80;
struct p_header95 h95;
};
u8 payload[0];
};
extern unsigned int drbd_header_size(struct drbd_tconn *tconn); extern unsigned int drbd_header_size(struct drbd_tconn *tconn);
/*
* short commands, packets without payload, plain p_header:
* P_PING
* P_PING_ACK
* P_BECOME_SYNC_TARGET
* P_BECOME_SYNC_SOURCE
* P_UNPLUG_REMOTE
*/
/*
* commands with out-of-struct payload:
* P_BITMAP (no additional fields)
* P_DATA, P_DATA_REPLY (see p_data)
* P_COMPRESSED_BITMAP (see receive_compressed_bitmap)
*/
/* these defines must not be changed without changing the protocol version */ /* these defines must not be changed without changing the protocol version */
#define DP_HARDBARRIER 1 /* depricated */ #define DP_HARDBARRIER 1 /* depricated */
#define DP_RW_SYNC 2 /* equals REQ_SYNC */ #define DP_RW_SYNC 2 /* equals REQ_SYNC */
...@@ -343,7 +319,6 @@ extern unsigned int drbd_header_size(struct drbd_tconn *tconn); ...@@ -343,7 +319,6 @@ extern unsigned int drbd_header_size(struct drbd_tconn *tconn);
#define DP_DISCARD 64 /* equals REQ_DISCARD */ #define DP_DISCARD 64 /* equals REQ_DISCARD */
struct p_data { struct p_data {
struct p_header head;
u64 sector; /* 64 bits sector number */ u64 sector; /* 64 bits sector number */
u64 block_id; /* to identify the request in protocol B&C */ u64 block_id; /* to identify the request in protocol B&C */
u32 seq_num; u32 seq_num;
...@@ -359,7 +334,6 @@ struct p_data { ...@@ -359,7 +334,6 @@ struct p_data {
* P_DATA_REQUEST, P_RS_DATA_REQUEST * P_DATA_REQUEST, P_RS_DATA_REQUEST
*/ */
struct p_block_ack { struct p_block_ack {
struct p_header head;
u64 sector; u64 sector;
u64 block_id; u64 block_id;
u32 blksize; u32 blksize;
...@@ -367,7 +341,6 @@ struct p_block_ack { ...@@ -367,7 +341,6 @@ struct p_block_ack {
} __packed; } __packed;
struct p_block_req { struct p_block_req {
struct p_header head;
u64 sector; u64 sector;
u64 block_id; u64 block_id;
u32 blksize; u32 blksize;
...@@ -384,7 +357,6 @@ struct p_block_req { ...@@ -384,7 +357,6 @@ struct p_block_req {
*/ */
struct p_connection_features { struct p_connection_features {
struct p_header head; /* Note: vnr will be ignored */
u32 protocol_min; u32 protocol_min;
u32 feature_flags; u32 feature_flags;
u32 protocol_max; u32 protocol_max;
...@@ -396,22 +368,18 @@ struct p_connection_features { ...@@ -396,22 +368,18 @@ struct p_connection_features {
u32 _pad; u32 _pad;
u64 reserverd[7]; u64 reserverd[7];
} __packed; } __packed;
/* 80 bytes, FIXED for the next century */
struct p_barrier { struct p_barrier {
struct p_header head;
u32 barrier; /* barrier number _handle_ only */ u32 barrier; /* barrier number _handle_ only */
u32 pad; /* to multiple of 8 Byte */ u32 pad; /* to multiple of 8 Byte */
} __packed; } __packed;
struct p_barrier_ack { struct p_barrier_ack {
struct p_header head;
u32 barrier; u32 barrier;
u32 set_size; u32 set_size;
} __packed; } __packed;
struct p_rs_param { struct p_rs_param {
struct p_header head;
u32 rate; u32 rate;
/* Since protocol version 88 and higher. */ /* Since protocol version 88 and higher. */
...@@ -419,7 +387,6 @@ struct p_rs_param { ...@@ -419,7 +387,6 @@ struct p_rs_param {
} __packed; } __packed;
struct p_rs_param_89 { struct p_rs_param_89 {
struct p_header head;
u32 rate; u32 rate;
/* protocol version 89: */ /* protocol version 89: */
char verify_alg[SHARED_SECRET_MAX]; char verify_alg[SHARED_SECRET_MAX];
...@@ -427,7 +394,6 @@ struct p_rs_param_89 { ...@@ -427,7 +394,6 @@ struct p_rs_param_89 {
} __packed; } __packed;
struct p_rs_param_95 { struct p_rs_param_95 {
struct p_header head;
u32 rate; u32 rate;
char verify_alg[SHARED_SECRET_MAX]; char verify_alg[SHARED_SECRET_MAX];
char csums_alg[SHARED_SECRET_MAX]; char csums_alg[SHARED_SECRET_MAX];
...@@ -443,7 +409,6 @@ enum drbd_conn_flags { ...@@ -443,7 +409,6 @@ enum drbd_conn_flags {
}; };
struct p_protocol { struct p_protocol {
struct p_header head;
u32 protocol; u32 protocol;
u32 after_sb_0p; u32 after_sb_0p;
u32 after_sb_1p; u32 after_sb_1p;
...@@ -457,17 +422,14 @@ struct p_protocol { ...@@ -457,17 +422,14 @@ struct p_protocol {
} __packed; } __packed;
struct p_uuids { struct p_uuids {
struct p_header head;
u64 uuid[UI_EXTENDED_SIZE]; u64 uuid[UI_EXTENDED_SIZE];
} __packed; } __packed;
struct p_rs_uuid { struct p_rs_uuid {
struct p_header head;
u64 uuid; u64 uuid;
} __packed; } __packed;
struct p_sizes { struct p_sizes {
struct p_header head;
u64 d_size; /* size of disk */ u64 d_size; /* size of disk */
u64 u_size; /* user requested size */ u64 u_size; /* user requested size */
u64 c_size; /* current exported size */ u64 c_size; /* current exported size */
...@@ -477,18 +439,15 @@ struct p_sizes { ...@@ -477,18 +439,15 @@ struct p_sizes {
} __packed; } __packed;
struct p_state { struct p_state {
struct p_header head;
u32 state; u32 state;
} __packed; } __packed;
struct p_req_state { struct p_req_state {
struct p_header head;
u32 mask; u32 mask;
u32 val; u32 val;
} __packed; } __packed;
struct p_req_state_reply { struct p_req_state_reply {
struct p_header head;
u32 retcode; u32 retcode;
} __packed; } __packed;
...@@ -503,14 +462,12 @@ struct p_drbd06_param { ...@@ -503,14 +462,12 @@ struct p_drbd06_param {
} __packed; } __packed;
struct p_discard { struct p_discard {
struct p_header head;
u64 block_id; u64 block_id;
u32 seq_num; u32 seq_num;
u32 pad; u32 pad;
} __packed; } __packed;
struct p_block_desc { struct p_block_desc {
struct p_header head;
u64 sector; u64 sector;
u32 blksize; u32 blksize;
u32 pad; /* to multiple of 8 Byte */ u32 pad; /* to multiple of 8 Byte */
...@@ -526,7 +483,6 @@ enum drbd_bitmap_code { ...@@ -526,7 +483,6 @@ enum drbd_bitmap_code {
}; };
struct p_compressed_bm { struct p_compressed_bm {
struct p_header head;
/* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code
* (encoding & 0x80): polarity (set/unset) of first runlength * (encoding & 0x80): polarity (set/unset) of first runlength
* ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits
...@@ -538,7 +494,6 @@ struct p_compressed_bm { ...@@ -538,7 +494,6 @@ struct p_compressed_bm {
} __packed; } __packed;
struct p_delay_probe93 { struct p_delay_probe93 {
struct p_header head;
u32 seq_num; /* sequence number to match the two probe packets */ u32 seq_num; /* sequence number to match the two probe packets */
u32 offset; /* usecs the probe got sent after the reference time point */ u32 offset; /* usecs the probe got sent after the reference time point */
} __packed; } __packed;
......
...@@ -703,27 +703,29 @@ unsigned int drbd_header_size(struct drbd_tconn *tconn) ...@@ -703,27 +703,29 @@ unsigned int drbd_header_size(struct drbd_tconn *tconn)
return sizeof(struct p_header80); return sizeof(struct p_header80);
} }
static void prepare_header80(struct p_header80 *h, enum drbd_packet cmd, int size) static unsigned int prepare_header80(struct p_header80 *h, enum drbd_packet cmd, int size)
{ {
h->magic = cpu_to_be32(DRBD_MAGIC); h->magic = cpu_to_be32(DRBD_MAGIC);
h->command = cpu_to_be16(cmd); h->command = cpu_to_be16(cmd);
h->length = cpu_to_be16(size); h->length = cpu_to_be16(size);
return sizeof(struct p_header80);
} }
static void prepare_header95(struct p_header95 *h, enum drbd_packet cmd, int size) static unsigned int prepare_header95(struct p_header95 *h, enum drbd_packet cmd, int size)
{ {
h->magic = cpu_to_be16(DRBD_MAGIC_BIG); h->magic = cpu_to_be16(DRBD_MAGIC_BIG);
h->command = cpu_to_be16(cmd); h->command = cpu_to_be16(cmd);
h->length = cpu_to_be32(size); h->length = cpu_to_be32(size);
return sizeof(struct p_header95);
} }
static void prepare_header(struct drbd_tconn *tconn, int vnr, struct p_header *h, static unsigned int prepare_header(struct drbd_tconn *tconn, int vnr, void *buffer,
enum drbd_packet cmd, int size) enum drbd_packet cmd, int size)
{ {
if (tconn->agreed_pro_version >= 95) if (tconn->agreed_pro_version >= 95)
prepare_header95(&h->h95, cmd, size); return prepare_header95(buffer, cmd, size);
else else
prepare_header80(&h->h80, cmd, size); return prepare_header80(buffer, cmd, size);
} }
void *conn_prepare_command(struct drbd_tconn *tconn, struct drbd_socket *sock) void *conn_prepare_command(struct drbd_tconn *tconn, struct drbd_socket *sock)
...@@ -733,7 +735,7 @@ void *conn_prepare_command(struct drbd_tconn *tconn, struct drbd_socket *sock) ...@@ -733,7 +735,7 @@ void *conn_prepare_command(struct drbd_tconn *tconn, struct drbd_socket *sock)
mutex_unlock(&sock->mutex); mutex_unlock(&sock->mutex);
return NULL; return NULL;
} }
return sock->sbuf; return sock->sbuf + drbd_header_size(tconn);
} }
void *drbd_prepare_command(struct drbd_conf *mdev, struct drbd_socket *sock) void *drbd_prepare_command(struct drbd_conf *mdev, struct drbd_socket *sock)
...@@ -758,8 +760,8 @@ static int __send_command(struct drbd_tconn *tconn, int vnr, ...@@ -758,8 +760,8 @@ static int __send_command(struct drbd_tconn *tconn, int vnr,
*/ */
msg_flags = data ? MSG_MORE : 0; msg_flags = data ? MSG_MORE : 0;
prepare_header(tconn, vnr, sock->sbuf, cmd, header_size += prepare_header(tconn, vnr, sock->sbuf, cmd,
header_size - sizeof(struct p_header) + size); header_size + size);
err = drbd_send_all(tconn, sock->socket, sock->sbuf, header_size, err = drbd_send_all(tconn, sock->socket, sock->sbuf, header_size,
msg_flags); msg_flags);
if (data && !err) if (data && !err)
...@@ -797,7 +799,7 @@ int drbd_send_ping(struct drbd_tconn *tconn) ...@@ -797,7 +799,7 @@ int drbd_send_ping(struct drbd_tconn *tconn)
sock = &tconn->meta; sock = &tconn->meta;
if (!conn_prepare_command(tconn, sock)) if (!conn_prepare_command(tconn, sock))
return -EIO; return -EIO;
return conn_send_command(tconn, sock, P_PING, sizeof(struct p_header), NULL, 0); return conn_send_command(tconn, sock, P_PING, 0, NULL, 0);
} }
int drbd_send_ping_ack(struct drbd_tconn *tconn) int drbd_send_ping_ack(struct drbd_tconn *tconn)
...@@ -807,7 +809,7 @@ int drbd_send_ping_ack(struct drbd_tconn *tconn) ...@@ -807,7 +809,7 @@ int drbd_send_ping_ack(struct drbd_tconn *tconn)
sock = &tconn->meta; sock = &tconn->meta;
if (!conn_prepare_command(tconn, sock)) if (!conn_prepare_command(tconn, sock))
return -EIO; return -EIO;
return conn_send_command(tconn, sock, P_PING_ACK, sizeof(struct p_header), NULL, 0); return conn_send_command(tconn, sock, P_PING_ACK, 0, NULL, 0);
} }
int drbd_send_sync_param(struct drbd_conf *mdev) int drbd_send_sync_param(struct drbd_conf *mdev)
...@@ -1205,10 +1207,11 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c) ...@@ -1205,10 +1207,11 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c)
{ {
struct drbd_socket *sock = &mdev->tconn->data; struct drbd_socket *sock = &mdev->tconn->data;
unsigned int header_size = drbd_header_size(mdev->tconn); unsigned int header_size = drbd_header_size(mdev->tconn);
struct p_compressed_bm *p = sock->sbuf; struct p_compressed_bm *p = sock->sbuf + header_size;
int len, err; int len, err;
len = fill_bitmap_rle_bits(mdev, p, DRBD_SOCKET_BUFFER_SIZE - sizeof(*p) /* FIXME */, c); len = fill_bitmap_rle_bits(mdev, p,
DRBD_SOCKET_BUFFER_SIZE - header_size - sizeof(*p), c);
if (len < 0) if (len < 0)
return -EIO; return -EIO;
...@@ -1218,7 +1221,7 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c) ...@@ -1218,7 +1221,7 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c)
P_COMPRESSED_BITMAP, sizeof(*p) + len, P_COMPRESSED_BITMAP, sizeof(*p) + len,
NULL, 0); NULL, 0);
c->packets[0]++; c->packets[0]++;
c->bytes[0] += sizeof(*p) + len; c->bytes[0] += header_size + sizeof(*p) + len;
if (c->bit_offset >= c->bm_bits) if (c->bit_offset >= c->bm_bits)
len = 0; /* DONE */ len = 0; /* DONE */
...@@ -1227,17 +1230,15 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c) ...@@ -1227,17 +1230,15 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c)
* send a buffer full of plain text bits instead. */ * send a buffer full of plain text bits instead. */
unsigned int data_size; unsigned int data_size;
unsigned long num_words; unsigned long num_words;
struct p_header *h = sock->sbuf; unsigned long *p = sock->sbuf + header_size;
data_size = DRBD_SOCKET_BUFFER_SIZE - header_size; data_size = DRBD_SOCKET_BUFFER_SIZE - header_size;
num_words = min_t(size_t, data_size / sizeof(unsigned long), num_words = min_t(size_t, data_size / sizeof(*p),
c->bm_words - c->word_offset); c->bm_words - c->word_offset);
len = num_words * sizeof(unsigned long); len = num_words * sizeof(*p);
if (len) if (len)
drbd_bm_get_lel(mdev, c->word_offset, num_words, drbd_bm_get_lel(mdev, c->word_offset, num_words, p);
(unsigned long *)h->payload); err = __send_command(mdev->tconn, mdev->vnr, sock, P_BITMAP, len, NULL, 0);
err = __send_command(mdev->tconn, mdev->vnr, sock, P_BITMAP,
sizeof(*h) + len, NULL, 0);
c->word_offset += num_words; c->word_offset += num_words;
c->bit_offset = c->word_offset * BITS_PER_LONG; c->bit_offset = c->word_offset * BITS_PER_LONG;
...@@ -2556,8 +2557,6 @@ int __init drbd_init(void) ...@@ -2556,8 +2557,6 @@ int __init drbd_init(void)
{ {
int err; int err;
BUILD_BUG_ON(sizeof(struct p_connection_features) != 80);
if (minor_count < DRBD_MINOR_COUNT_MIN || minor_count > DRBD_MINOR_COUNT_MAX) { if (minor_count < DRBD_MINOR_COUNT_MIN || minor_count > DRBD_MINOR_COUNT_MAX) {
printk(KERN_ERR printk(KERN_ERR
"drbd: invalid minor_count (%d)\n", minor_count); "drbd: invalid minor_count (%d)\n", minor_count);
......
This diff is collapsed.
...@@ -1229,7 +1229,7 @@ int w_send_write_hint(struct drbd_work *w, int cancel) ...@@ -1229,7 +1229,7 @@ int w_send_write_hint(struct drbd_work *w, int cancel)
sock = &mdev->tconn->data; sock = &mdev->tconn->data;
if (!drbd_prepare_command(mdev, sock)) if (!drbd_prepare_command(mdev, sock))
return -EIO; return -EIO;
return drbd_send_command(mdev, sock, P_UNPLUG_REMOTE, sizeof(struct p_header), NULL, 0); return drbd_send_command(mdev, sock, P_UNPLUG_REMOTE, 0, NULL, 0);
} }
int w_send_out_of_sync(struct drbd_work *w, int cancel) int w_send_out_of_sync(struct drbd_work *w, int cancel)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment