mirror of https://lore.kernel.org/lkml/
 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 08/16] drbd: drbd_connect(): Initialize struct drbd_socket before sending anything
Date: Thu,  8 Sep 2011 14:45:29 +0200	[thread overview]
Message-ID: <1315485937-18989-9-git-send-email-philipp.reisner@linbit.com> (raw)
In-Reply-To: <1315485937-18989-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_receiver.c |   66 ++++++++++++++++++-----------------
 1 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index cc236d7..830b107 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -807,7 +807,7 @@ int drbd_connected(int vnr, void *p, void *data)
  */
 static int drbd_connect(struct drbd_tconn *tconn)
 {
-	struct socket *s, *sock, *msock;
+	struct socket *sock, *msock;
 	int try, h, ok;
 
 	if (conn_request_state(tconn, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS)
@@ -818,10 +818,9 @@ static int drbd_connect(struct drbd_tconn *tconn)
 	/* Assume that the peer only understands protocol 80 until we know better.  */
 	tconn->agreed_pro_version = 80;
 
-	sock  = NULL;
-	msock = NULL;
-
 	do {
+		struct socket *s;
+
 		for (try = 0;;) {
 			/* 3 tries, this should take less than a second! */
 			s = drbd_try_connect(tconn);
@@ -832,24 +831,22 @@ static int drbd_connect(struct drbd_tconn *tconn)
 		}
 
 		if (s) {
-			if (!sock) {
-				drbd_send_fp(tconn, s, P_HAND_SHAKE_S);
-				sock = s;
-				s = NULL;
-			} else if (!msock) {
-				drbd_send_fp(tconn, s, P_HAND_SHAKE_M);
-				msock = s;
-				s = NULL;
+			if (!tconn->data.socket) {
+				tconn->data.socket = s;
+				drbd_send_fp(tconn, tconn->data.socket, P_HAND_SHAKE_S);
+			} else if (!tconn->meta.socket) {
+				tconn->meta.socket = s;
+				drbd_send_fp(tconn, tconn->meta.socket, P_HAND_SHAKE_M);
 			} else {
 				conn_err(tconn, "Logic error in drbd_connect()\n");
 				goto out_release_sockets;
 			}
 		}
 
-		if (sock && msock) {
+		if (tconn->data.socket && tconn->meta.socket) {
 			schedule_timeout_interruptible(tconn->net_conf->ping_timeo*HZ/10);
-			ok = drbd_socket_okay(&sock);
-			ok = drbd_socket_okay(&msock) && ok;
+			ok = drbd_socket_okay(&tconn->data.socket);
+			ok = drbd_socket_okay(&tconn->meta.socket) && ok;
 			if (ok)
 				break;
 		}
@@ -858,22 +855,22 @@ retry:
 		s = drbd_wait_for_connect(tconn);
 		if (s) {
 			try = drbd_recv_fp(tconn, s);
-			drbd_socket_okay(&sock);
-			drbd_socket_okay(&msock);
+			drbd_socket_okay(&tconn->data.socket);
+			drbd_socket_okay(&tconn->meta.socket);
 			switch (try) {
 			case P_HAND_SHAKE_S:
-				if (sock) {
+				if (tconn->data.socket) {
 					conn_warn(tconn, "initial packet S crossed\n");
-					sock_release(sock);
+					sock_release(tconn->data.socket);
 				}
-				sock = s;
+				tconn->data.socket = s;
 				break;
 			case P_HAND_SHAKE_M:
-				if (msock) {
+				if (tconn->meta.socket) {
 					conn_warn(tconn, "initial packet M crossed\n");
-					sock_release(msock);
+					sock_release(tconn->meta.socket);
 				}
-				msock = s;
+				tconn->meta.socket = s;
 				set_bit(DISCARD_CONCURRENT, &tconn->flags);
 				break;
 			default:
@@ -893,14 +890,17 @@ retry:
 				goto out_release_sockets;
 		}
 
-		if (sock && msock) {
-			ok = drbd_socket_okay(&sock);
-			ok = drbd_socket_okay(&msock) && ok;
+		if (tconn->data.socket && &tconn->meta.socket) {
+			ok = drbd_socket_okay(&tconn->data.socket);
+			ok = drbd_socket_okay(&tconn->meta.socket) && ok;
 			if (ok)
 				break;
 		}
 	} while (1);
 
+	sock  = tconn->data.socket;
+	msock = tconn->meta.socket;
+
 	msock->sk->sk_reuse = 1; /* SO_REUSEADDR */
 	sock->sk->sk_reuse = 1; /* SO_REUSEADDR */
 
@@ -926,8 +926,6 @@ retry:
 	drbd_tcp_nodelay(sock);
 	drbd_tcp_nodelay(msock);
 
-	tconn->data.socket = sock;
-	tconn->meta.socket = msock;
 	tconn->last_received = jiffies;
 
 	h = drbd_do_handshake(tconn);
@@ -960,10 +958,14 @@ retry:
 	return !idr_for_each(&tconn->volumes, drbd_connected, tconn);
 
 out_release_sockets:
-	if (sock)
-		sock_release(sock);
-	if (msock)
-		sock_release(msock);
+	if (tconn->data.socket) {
+		sock_release(tconn->data.socket);
+		tconn->data.socket = NULL;
+	}
+	if (tconn->meta.socket) {
+		sock_release(tconn->meta.socket);
+		tconn->meta.socket = NULL;
+	}
 	return -1;
 }
 
-- 
1.7.4.1


  parent reply	other threads:[~2011-09-08 12:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-08 12:45 [RFC 00/16] drbd: part 8 of adding multiple volume support to drbd Philipp Reisner
2011-09-08 12:45 ` [PATCH 01/16] drbd: Use the idr_for_each_entry() iterator instead of idr_for_each() Philipp Reisner
2011-09-08 12:45 ` [PATCH 02/16] drbd: Fixed logging of old connection state Philipp Reisner
2011-09-08 12:45 ` [PATCH 03/16] drbd: Print common state changes of all volumes as connection state changes Philipp Reisner
2011-09-08 12:45 ` [PATCH 04/16] drbd: Allow to disconnect if one volume is diskless Philipp Reisner
2011-09-08 12:45 ` [PATCH 05/16] drbd: Do not segfault if a sync dependency reaches a diskless device Philipp Reisner
2011-09-08 12:45 ` [PATCH 06/16] drbd: Pass struct packet_info down to the asender receive functions Philipp Reisner
2011-09-08 12:45 ` [PATCH 07/16] drbd: Map from (connection, volume number) to device in the asender handlers Philipp Reisner
2011-09-08 12:45 ` Philipp Reisner [this message]
2011-09-08 12:45 ` [PATCH 09/16] drbd: _conn_send_cmd(), _drbd_send_cmd(): Pass a struct drbd_socket instead of a plain socket Philipp Reisner
2011-09-08 12:45 ` [PATCH 10/16] drbd: Change how the initial packets are called Philipp Reisner
2011-09-08 12:45 ` [PATCH 11/16] drbd: Change how the "handshake" " Philipp Reisner
2011-09-08 12:45 ` [PATCH 12/16] drbd: introduce the "initialized" activity log transaction type Philipp Reisner
2011-09-08 12:45 ` [PATCH 13/16] drbd: preparation commit, pass drbd_interval to drbd_al_begin/complete_io Philipp Reisner
2011-09-08 12:45 ` [PATCH 14/16] drbd: prepare to activate two activity log extents at once Philipp Reisner
2011-09-08 12:45 ` [PATCH 15/16] drbd: get rid of bio_split, allow bios of "arbitrary" size Philipp Reisner
2011-09-08 12:45 ` [PATCH 16/16] drbd: improvements to activate/deactivate multiple activity log extents Philipp Reisner

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=1315485937-18989-9-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®