Commit 52b061a4 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Philipp Reisner

drbd: Introduce drbd_header_size()

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent dba58587
...@@ -315,6 +315,8 @@ struct p_header { ...@@ -315,6 +315,8 @@ struct p_header {
u8 payload[0]; u8 payload[0];
}; };
extern unsigned int drbd_header_size(struct drbd_tconn *tconn);
/* /*
* short commands, packets without payload, plain p_header: * short commands, packets without payload, plain p_header:
* P_PING * P_PING
......
...@@ -689,6 +689,20 @@ void drbd_thread_current_set_cpu(struct drbd_thread *thi) ...@@ -689,6 +689,20 @@ void drbd_thread_current_set_cpu(struct drbd_thread *thi)
} }
#endif #endif
/**
* drbd_header_size - size of a packet header
*
* The header size is a multiple of 8, so any payload following the header is
* word aligned on 64-bit architectures. (The bitmap send and receive code
* relies on this.)
*/
unsigned int drbd_header_size(struct drbd_tconn *tconn)
{
BUILD_BUG_ON(sizeof(struct p_header80) != sizeof(struct p_header95));
BUILD_BUG_ON(!IS_ALIGNED(sizeof(struct p_header80), 8));
return sizeof(struct p_header80);
}
static void prepare_header80(struct p_header80 *h, enum drbd_packet cmd, int size) static void 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);
......
...@@ -995,7 +995,7 @@ static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi) ...@@ -995,7 +995,7 @@ static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi)
struct p_header *h = tconn->data.rbuf; struct p_header *h = tconn->data.rbuf;
int err; int err;
err = drbd_recv_all_warn(tconn, h, sizeof(*h)); err = drbd_recv_all_warn(tconn, h, drbd_header_size(tconn));
if (err) if (err)
return err; return err;
...@@ -4842,7 +4842,8 @@ int drbd_asender(struct drbd_thread *thi) ...@@ -4842,7 +4842,8 @@ int drbd_asender(struct drbd_thread *thi)
int rv; int rv;
void *buf = h; void *buf = h;
int received = 0; int received = 0;
int expect = sizeof(struct p_header); unsigned int header_size = drbd_header_size(tconn);
int expect = header_size;
int ping_timeout_active = 0; int ping_timeout_active = 0;
current->policy = SCHED_RR; /* Make this a realtime task! */ current->policy = SCHED_RR; /* Make this a realtime task! */
...@@ -4926,7 +4927,7 @@ int drbd_asender(struct drbd_thread *thi) ...@@ -4926,7 +4927,7 @@ int drbd_asender(struct drbd_thread *thi)
goto disconnect; goto disconnect;
} }
expect = cmd->pkt_size; expect = cmd->pkt_size;
if (pi.size != expect - sizeof(struct p_header)) { if (pi.size != expect - header_size) {
conn_err(tconn, "Wrong packet size on meta (c: %d, l: %d)\n", conn_err(tconn, "Wrong packet size on meta (c: %d, l: %d)\n",
pi.cmd, pi.size); pi.cmd, pi.size);
goto reconnect; goto reconnect;
...@@ -4950,7 +4951,7 @@ int drbd_asender(struct drbd_thread *thi) ...@@ -4950,7 +4951,7 @@ int drbd_asender(struct drbd_thread *thi)
buf = h; buf = h;
received = 0; received = 0;
expect = sizeof(struct p_header); expect = header_size;
cmd = NULL; cmd = NULL;
} }
} }
......
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