提交 2bf89621 编写于 作者: A Andreas Gruenbacher 提交者: Philipp Reisner

drbd: drbd_connect(): Initialize struct drbd_socket before sending anything

Signed-off-by: NPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: NLars Ellenberg <lars.ellenberg@linbit.com>
上级 1952e916
...@@ -807,7 +807,7 @@ int drbd_connected(int vnr, void *p, void *data) ...@@ -807,7 +807,7 @@ int drbd_connected(int vnr, void *p, void *data)
*/ */
static int drbd_connect(struct drbd_tconn *tconn) static int drbd_connect(struct drbd_tconn *tconn)
{ {
struct socket *s, *sock, *msock; struct socket *sock, *msock;
int try, h, ok; int try, h, ok;
if (conn_request_state(tconn, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS) 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) ...@@ -818,10 +818,9 @@ static int drbd_connect(struct drbd_tconn *tconn)
/* Assume that the peer only understands protocol 80 until we know better. */ /* Assume that the peer only understands protocol 80 until we know better. */
tconn->agreed_pro_version = 80; tconn->agreed_pro_version = 80;
sock = NULL;
msock = NULL;
do { do {
struct socket *s;
for (try = 0;;) { for (try = 0;;) {
/* 3 tries, this should take less than a second! */ /* 3 tries, this should take less than a second! */
s = drbd_try_connect(tconn); s = drbd_try_connect(tconn);
...@@ -832,24 +831,22 @@ static int drbd_connect(struct drbd_tconn *tconn) ...@@ -832,24 +831,22 @@ static int drbd_connect(struct drbd_tconn *tconn)
} }
if (s) { if (s) {
if (!sock) { if (!tconn->data.socket) {
drbd_send_fp(tconn, s, P_HAND_SHAKE_S); tconn->data.socket = s;
sock = s; drbd_send_fp(tconn, tconn->data.socket, P_HAND_SHAKE_S);
s = NULL; } else if (!tconn->meta.socket) {
} else if (!msock) { tconn->meta.socket = s;
drbd_send_fp(tconn, s, P_HAND_SHAKE_M); drbd_send_fp(tconn, tconn->meta.socket, P_HAND_SHAKE_M);
msock = s;
s = NULL;
} else { } else {
conn_err(tconn, "Logic error in drbd_connect()\n"); conn_err(tconn, "Logic error in drbd_connect()\n");
goto out_release_sockets; goto out_release_sockets;
} }
} }
if (sock && msock) { if (tconn->data.socket && tconn->meta.socket) {
schedule_timeout_interruptible(tconn->net_conf->ping_timeo*HZ/10); schedule_timeout_interruptible(tconn->net_conf->ping_timeo*HZ/10);
ok = drbd_socket_okay(&sock); ok = drbd_socket_okay(&tconn->data.socket);
ok = drbd_socket_okay(&msock) && ok; ok = drbd_socket_okay(&tconn->meta.socket) && ok;
if (ok) if (ok)
break; break;
} }
...@@ -858,22 +855,22 @@ static int drbd_connect(struct drbd_tconn *tconn) ...@@ -858,22 +855,22 @@ static int drbd_connect(struct drbd_tconn *tconn)
s = drbd_wait_for_connect(tconn); s = drbd_wait_for_connect(tconn);
if (s) { if (s) {
try = drbd_recv_fp(tconn, s); try = drbd_recv_fp(tconn, s);
drbd_socket_okay(&sock); drbd_socket_okay(&tconn->data.socket);
drbd_socket_okay(&msock); drbd_socket_okay(&tconn->meta.socket);
switch (try) { switch (try) {
case P_HAND_SHAKE_S: case P_HAND_SHAKE_S:
if (sock) { if (tconn->data.socket) {
conn_warn(tconn, "initial packet S crossed\n"); conn_warn(tconn, "initial packet S crossed\n");
sock_release(sock); sock_release(tconn->data.socket);
} }
sock = s; tconn->data.socket = s;
break; break;
case P_HAND_SHAKE_M: case P_HAND_SHAKE_M:
if (msock) { if (tconn->meta.socket) {
conn_warn(tconn, "initial packet M crossed\n"); 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); set_bit(DISCARD_CONCURRENT, &tconn->flags);
break; break;
default: default:
...@@ -893,14 +890,17 @@ static int drbd_connect(struct drbd_tconn *tconn) ...@@ -893,14 +890,17 @@ static int drbd_connect(struct drbd_tconn *tconn)
goto out_release_sockets; goto out_release_sockets;
} }
if (sock && msock) { if (tconn->data.socket && &tconn->meta.socket) {
ok = drbd_socket_okay(&sock); ok = drbd_socket_okay(&tconn->data.socket);
ok = drbd_socket_okay(&msock) && ok; ok = drbd_socket_okay(&tconn->meta.socket) && ok;
if (ok) if (ok)
break; break;
} }
} while (1); } while (1);
sock = tconn->data.socket;
msock = tconn->meta.socket;
msock->sk->sk_reuse = 1; /* SO_REUSEADDR */ msock->sk->sk_reuse = 1; /* SO_REUSEADDR */
sock->sk->sk_reuse = 1; /* SO_REUSEADDR */ sock->sk->sk_reuse = 1; /* SO_REUSEADDR */
...@@ -926,8 +926,6 @@ static int drbd_connect(struct drbd_tconn *tconn) ...@@ -926,8 +926,6 @@ static int drbd_connect(struct drbd_tconn *tconn)
drbd_tcp_nodelay(sock); drbd_tcp_nodelay(sock);
drbd_tcp_nodelay(msock); drbd_tcp_nodelay(msock);
tconn->data.socket = sock;
tconn->meta.socket = msock;
tconn->last_received = jiffies; tconn->last_received = jiffies;
h = drbd_do_handshake(tconn); h = drbd_do_handshake(tconn);
...@@ -960,10 +958,14 @@ static int drbd_connect(struct drbd_tconn *tconn) ...@@ -960,10 +958,14 @@ static int drbd_connect(struct drbd_tconn *tconn)
return !idr_for_each(&tconn->volumes, drbd_connected, tconn); return !idr_for_each(&tconn->volumes, drbd_connected, tconn);
out_release_sockets: out_release_sockets:
if (sock) if (tconn->data.socket) {
sock_release(sock); sock_release(tconn->data.socket);
if (msock) tconn->data.socket = NULL;
sock_release(msock); }
if (tconn->meta.socket) {
sock_release(tconn->meta.socket);
tconn->meta.socket = NULL;
}
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册