Commit 907599e0 authored by Philipp Reisner's avatar Philipp Reisner

drbd: Converted drbd_connect() from mdev to tconn

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 062e879c
...@@ -746,6 +746,24 @@ static int drbd_socket_okay(struct socket **sock) ...@@ -746,6 +746,24 @@ static int drbd_socket_okay(struct socket **sock)
} }
} }
static int drbd_connected(int vnr, void *p, void *data)
{
struct drbd_conf *mdev = (struct drbd_conf *)p;
int ok = 1;
atomic_set(&mdev->packet_seq, 0);
mdev->peer_seq = 0;
ok &= drbd_send_sync_param(mdev, &mdev->sync_conf);
ok &= drbd_send_sizes(mdev, 0, 0);
ok &= drbd_send_uuids(mdev);
ok &= drbd_send_state(mdev);
clear_bit(USE_DEGR_WFC_T, &mdev->flags);
clear_bit(RESIZE_PENDING, &mdev->flags);
return !ok;
}
/* /*
* return values: * return values:
* 1 yes, we have a valid connection * 1 yes, we have a valid connection
...@@ -754,18 +772,16 @@ static int drbd_socket_okay(struct socket **sock) ...@@ -754,18 +772,16 @@ static int drbd_socket_okay(struct socket **sock)
* no point in trying again, please go standalone. * no point in trying again, please go standalone.
* -2 We do not have a network config... * -2 We do not have a network config...
*/ */
static int drbd_connect(struct drbd_conf *mdev) static int drbd_connect(struct drbd_tconn *tconn)
{ {
struct socket *s, *sock, *msock; struct socket *s, *sock, *msock;
int try, h, ok; int try, h, ok;
D_ASSERT(!mdev->tconn->data.socket); if (drbd_request_state(tconn->volume0, NS(conn, C_WF_CONNECTION)) < SS_SUCCESS)
if (drbd_request_state(mdev, NS(conn, C_WF_CONNECTION)) < SS_SUCCESS)
return -2; return -2;
clear_bit(DISCARD_CONCURRENT, &mdev->tconn->flags); clear_bit(DISCARD_CONCURRENT, &tconn->flags);
mdev->tconn->agreed_pro_version = 99; tconn->agreed_pro_version = 99;
/* agreed_pro_version must be smaller than 100 so we send the old /* agreed_pro_version must be smaller than 100 so we send the old
header (h80) in the first packet and in the handshake packet. */ header (h80) in the first packet and in the handshake packet. */
...@@ -775,7 +791,7 @@ static int drbd_connect(struct drbd_conf *mdev) ...@@ -775,7 +791,7 @@ static int drbd_connect(struct drbd_conf *mdev)
do { do {
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(mdev->tconn); s = drbd_try_connect(tconn);
if (s || ++try >= 3) if (s || ++try >= 3)
break; break;
/* give the other side time to call bind() & listen() */ /* give the other side time to call bind() & listen() */
...@@ -784,21 +800,21 @@ static int drbd_connect(struct drbd_conf *mdev) ...@@ -784,21 +800,21 @@ static int drbd_connect(struct drbd_conf *mdev)
if (s) { if (s) {
if (!sock) { if (!sock) {
drbd_send_fp(mdev->tconn, s, P_HAND_SHAKE_S); drbd_send_fp(tconn, s, P_HAND_SHAKE_S);
sock = s; sock = s;
s = NULL; s = NULL;
} else if (!msock) { } else if (!msock) {
drbd_send_fp(mdev->tconn, s, P_HAND_SHAKE_M); drbd_send_fp(tconn, s, P_HAND_SHAKE_M);
msock = s; msock = s;
s = NULL; s = NULL;
} else { } else {
dev_err(DEV, "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 (sock && msock) {
schedule_timeout_interruptible(mdev->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(&sock);
ok = drbd_socket_okay(&msock) && ok; ok = drbd_socket_okay(&msock) && ok;
if (ok) if (ok)
...@@ -806,41 +822,41 @@ static int drbd_connect(struct drbd_conf *mdev) ...@@ -806,41 +822,41 @@ static int drbd_connect(struct drbd_conf *mdev)
} }
retry: retry:
s = drbd_wait_for_connect(mdev->tconn); s = drbd_wait_for_connect(tconn);
if (s) { if (s) {
try = drbd_recv_fp(mdev->tconn, s); try = drbd_recv_fp(tconn, s);
drbd_socket_okay(&sock); drbd_socket_okay(&sock);
drbd_socket_okay(&msock); drbd_socket_okay(&msock);
switch (try) { switch (try) {
case P_HAND_SHAKE_S: case P_HAND_SHAKE_S:
if (sock) { if (sock) {
dev_warn(DEV, "initial packet S crossed\n"); conn_warn(tconn, "initial packet S crossed\n");
sock_release(sock); sock_release(sock);
} }
sock = s; sock = s;
break; break;
case P_HAND_SHAKE_M: case P_HAND_SHAKE_M:
if (msock) { if (msock) {
dev_warn(DEV, "initial packet M crossed\n"); conn_warn(tconn, "initial packet M crossed\n");
sock_release(msock); sock_release(msock);
} }
msock = s; msock = s;
set_bit(DISCARD_CONCURRENT, &mdev->tconn->flags); set_bit(DISCARD_CONCURRENT, &tconn->flags);
break; break;
default: default:
dev_warn(DEV, "Error receiving initial packet\n"); conn_warn(tconn, "Error receiving initial packet\n");
sock_release(s); sock_release(s);
if (random32() & 1) if (random32() & 1)
goto retry; goto retry;
} }
} }
if (mdev->state.conn <= C_DISCONNECTING) if (tconn->volume0->state.conn <= C_DISCONNECTING)
goto out_release_sockets; goto out_release_sockets;
if (signal_pending(current)) { if (signal_pending(current)) {
flush_signals(current); flush_signals(current);
smp_rmb(); smp_rmb();
if (get_t_state(&mdev->tconn->receiver) == EXITING) if (get_t_state(&tconn->receiver) == EXITING)
goto out_release_sockets; goto out_release_sockets;
} }
...@@ -862,65 +878,53 @@ static int drbd_connect(struct drbd_conf *mdev) ...@@ -862,65 +878,53 @@ static int drbd_connect(struct drbd_conf *mdev)
msock->sk->sk_priority = TC_PRIO_INTERACTIVE; msock->sk->sk_priority = TC_PRIO_INTERACTIVE;
/* NOT YET ... /* NOT YET ...
* sock->sk->sk_sndtimeo = mdev->tconn->net_conf->timeout*HZ/10; * sock->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10;
* sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; * sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
* first set it to the P_HAND_SHAKE timeout, * first set it to the P_HAND_SHAKE timeout,
* which we set to 4x the configured ping_timeout. */ * which we set to 4x the configured ping_timeout. */
sock->sk->sk_sndtimeo = sock->sk->sk_sndtimeo =
sock->sk->sk_rcvtimeo = mdev->tconn->net_conf->ping_timeo*4*HZ/10; sock->sk->sk_rcvtimeo = tconn->net_conf->ping_timeo*4*HZ/10;
msock->sk->sk_sndtimeo = mdev->tconn->net_conf->timeout*HZ/10; msock->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10;
msock->sk->sk_rcvtimeo = mdev->tconn->net_conf->ping_int*HZ; msock->sk->sk_rcvtimeo = tconn->net_conf->ping_int*HZ;
/* we don't want delays. /* we don't want delays.
* we use TCP_CORK where appropriate, though */ * we use TCP_CORK where appropriate, though */
drbd_tcp_nodelay(sock); drbd_tcp_nodelay(sock);
drbd_tcp_nodelay(msock); drbd_tcp_nodelay(msock);
mdev->tconn->data.socket = sock; tconn->data.socket = sock;
mdev->tconn->meta.socket = msock; tconn->meta.socket = msock;
mdev->tconn->last_received = jiffies; tconn->last_received = jiffies;
D_ASSERT(mdev->tconn->asender.task == NULL);
h = drbd_do_handshake(mdev->tconn); h = drbd_do_handshake(tconn);
if (h <= 0) if (h <= 0)
return h; return h;
if (mdev->tconn->cram_hmac_tfm) { if (tconn->cram_hmac_tfm) {
/* drbd_request_state(mdev, NS(conn, WFAuth)); */ /* drbd_request_state(mdev, NS(conn, WFAuth)); */
switch (drbd_do_auth(mdev->tconn)) { switch (drbd_do_auth(tconn)) {
case -1: case -1:
dev_err(DEV, "Authentication of peer failed\n"); conn_err(tconn, "Authentication of peer failed\n");
return -1; return -1;
case 0: case 0:
dev_err(DEV, "Authentication of peer failed, trying again.\n"); conn_err(tconn, "Authentication of peer failed, trying again.\n");
return 0; return 0;
} }
} }
if (drbd_request_state(mdev, NS(conn, C_WF_REPORT_PARAMS)) < SS_SUCCESS) if (drbd_request_state(tconn->volume0, NS(conn, C_WF_REPORT_PARAMS)) < SS_SUCCESS)
return 0; return 0;
sock->sk->sk_sndtimeo = mdev->tconn->net_conf->timeout*HZ/10; sock->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10;
sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
atomic_set(&mdev->packet_seq, 0); drbd_thread_start(&tconn->asender);
mdev->peer_seq = 0;
drbd_thread_start(&mdev->tconn->asender);
if (drbd_send_protocol(mdev->tconn) == -1) if (drbd_send_protocol(tconn) == -1)
return -1; return -1;
drbd_send_sync_param(mdev, &mdev->sync_conf);
drbd_send_sizes(mdev, 0, 0);
drbd_send_uuids(mdev);
drbd_send_state(mdev);
clear_bit(USE_DEGR_WFC_T, &mdev->flags);
clear_bit(RESIZE_PENDING, &mdev->flags);
mod_timer(&mdev->request_timer, jiffies + HZ); /* just start it here. */
return 1; return !idr_for_each(&tconn->volumes, drbd_connected, tconn);
out_release_sockets: out_release_sockets:
if (sock) if (sock)
...@@ -4222,7 +4226,7 @@ int drbdd_init(struct drbd_thread *thi) ...@@ -4222,7 +4226,7 @@ int drbdd_init(struct drbd_thread *thi)
dev_info(DEV, "receiver (re)started\n"); dev_info(DEV, "receiver (re)started\n");
do { do {
h = drbd_connect(mdev); h = drbd_connect(mdev->tconn);
if (h == 0) { if (h == 0) {
drbd_disconnect(mdev); drbd_disconnect(mdev);
schedule_timeout_interruptible(HZ); schedule_timeout_interruptible(HZ);
......
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