All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philipp Reisner <philipp.reisner@linbit.com>
To: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: drbd-dev@lists.linbit.com
Subject: [PATCH 03/10] drbd: Introduce drbd_header_size()
Date: Fri, 23 Sep 2011 16:31:18 +0200	[thread overview]
Message-ID: <1316788285-17433-4-git-send-email-philipp.reisner@linbit.com> (raw)
In-Reply-To: <1316788285-17433-1-git-send-email-philipp.reisner@linbit.com>

From: Andreas Gruenbacher <agruen@linbit.com>

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
---
 drivers/block/drbd/drbd_int.h      |    2 ++
 drivers/block/drbd/drbd_main.c     |   14 ++++++++++++++
 drivers/block/drbd/drbd_receiver.c |    9 +++++----
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index d61819f..29db016 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -315,6 +315,8 @@ struct p_header {
 	u8	  payload[0];
 };
 
+extern unsigned int drbd_header_size(struct drbd_tconn *tconn);
+
 /*
  * short commands, packets without payload, plain p_header:
  *   P_PING
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index c8384cd..b291d73 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -689,6 +689,20 @@ void drbd_thread_current_set_cpu(struct drbd_thread *thi)
 }
 #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)
 {
 	h->magic   = cpu_to_be32(DRBD_MAGIC);
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 6879082..ceca24f 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -998,7 +998,7 @@ static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi)
 	struct p_header *h = tconn->data.rbuf;
 	int err;
 
-	err = drbd_recv_all_warn(tconn, h, sizeof(*h));
+	err = drbd_recv_all_warn(tconn, h, drbd_header_size(tconn));
 	if (err)
 		return err;
 
@@ -4845,7 +4845,8 @@ int drbd_asender(struct drbd_thread *thi)
 	int rv;
 	void *buf    = h;
 	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;
 
 	current->policy = SCHED_RR;  /* Make this a realtime task! */
@@ -4929,7 +4930,7 @@ int drbd_asender(struct drbd_thread *thi)
 				goto disconnect;
 			}
 			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",
 					pi.cmd, pi.size);
 				goto reconnect;
@@ -4953,7 +4954,7 @@ int drbd_asender(struct drbd_thread *thi)
 
 			buf	 = h;
 			received = 0;
-			expect	 = sizeof(struct p_header);
+			expect	 = header_size;
 			cmd	 = NULL;
 		}
 	}
-- 
1.7.4.1


  parent reply	other threads:[~2011-09-23 14:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-23 14:31 [RFC 00/10] drbd: part 10 of adding multiple volume support to drbd Philipp Reisner
2011-09-23 14:31 ` [PATCH 01/10] drbd: drbd_send_ping(), drbd_send_ping(): Return 0 upon success and an error code otherwise Philipp Reisner
2011-09-23 14:31 ` [PATCH 02/10] drbd: Introduce new primitives for sending commands Philipp Reisner
2011-09-23 14:31 ` Philipp Reisner [this message]
2011-09-23 14:31 ` [PATCH 04/10] drbd: Replace and remove old primitives Philipp Reisner
2011-09-23 17:33   ` Kyle Moffett
2011-09-27  9:34     ` Philipp Reisner
2011-09-23 14:31 ` [PATCH 05/10] drbd: Remove now-unused int_dig_out buffer Philipp Reisner
2011-09-23 14:31 ` [PATCH 06/10] drbd: Remove some fixed header size assumptions Philipp Reisner
2011-09-23 14:31 ` [PATCH 07/10] drbd: Remove headers from on-the-wire data structures (struct p_*) Philipp Reisner
2011-09-23 17:38   ` Kyle Moffett
2011-09-27  9:34     ` Philipp Reisner
2011-09-23 14:31 ` [PATCH 08/10] drbd: Introduce protocol version 100 headers Philipp Reisner
2011-09-23 17:42   ` Kyle Moffett
2011-09-27  9:34     ` Philipp Reisner
2011-09-23 14:31 ` [PATCH 09/10] drbd: Remove volume numbers from struct p_header95 Philipp Reisner
2011-09-23 17:28   ` Kyle Moffett
2011-09-27  9:34     ` Philipp Reisner
2011-09-28  4:26       ` Kyle Moffett
2011-09-28  9:20         ` Philipp Reisner
2011-09-28  9:21           ` [PATCH 9/9] drbd: Removed outdated comments and code that envisioned VNRs in header 95 Philipp Reisner
2011-09-23 14:31 ` [PATCH 10/10] drbd: For protocol versions before 100, use mixed header versions Philipp Reisner
2011-09-23 17:24   ` Kyle Moffett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316788285-17433-4-git-send-email-philipp.reisner@linbit.com \
    --to=philipp.reisner@linbit.com \
    --cc=axboe@kernel.dk \
    --cc=drbd-dev@lists.linbit.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.