Lines Matching defs:connection

56 static int drbd_do_features(struct drbd_connection *connection);
57 static int drbd_do_auth(struct drbd_connection *connection);
59 static void conn_wait_active_ee_empty(struct drbd_connection *connection);
222 static void conn_reclaim_net_peer_reqs(struct drbd_connection *connection)
228 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
272 nc = rcu_dereference(peer_device->connection->net_conf);
513 static int drbd_recv(struct drbd_connection *connection, void *buf, size_t size)
517 rv = drbd_recv_short(connection->data.socket, buf, size, 0);
521 drbd_info(connection, "sock was reset by peer\n");
523 drbd_err(connection, "sock_recvmsg returned %d\n", rv);
525 if (test_bit(DISCONNECT_SENT, &connection->flags)) {
528 t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10;
531 t = wait_event_timeout(connection->ping_wait, connection->cstate < C_WF_REPORT_PARAMS, t);
536 drbd_info(connection, "sock was shut down by peer\n");
540 conn_request_state(connection, NS(conn, C_BROKEN_PIPE), CS_HARD);
546 static int drbd_recv_all(struct drbd_connection *connection, void *buf, size_t size)
550 err = drbd_recv(connection, buf, size);
559 static int drbd_recv_all_warn(struct drbd_connection *connection, void *buf, size_t size)
563 err = drbd_recv_all(connection, buf, size);
565 drbd_warn(connection, "short read (expected size %d)\n", (int)size);
588 static struct socket *drbd_try_connect(struct drbd_connection *connection)
600 nc = rcu_dereference(connection->net_conf);
610 my_addr_len = min_t(int, connection->my_addr_len, sizeof(src_in6));
611 memcpy(&src_in6, &connection->my_addr, my_addr_len);
613 if (((struct sockaddr *)&connection->my_addr)->sa_family == AF_INET6)
618 peer_addr_len = min_t(int, connection->peer_addr_len, sizeof(src_in6));
619 memcpy(&peer_in6, &connection->peer_addr, peer_addr_len);
667 drbd_err(connection, "%s failed, err = %d\n", what, err);
670 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
677 struct drbd_connection *connection;
695 static int prepare_listen_socket(struct drbd_connection *connection, struct accept_wait_data *ad)
704 nc = rcu_dereference(connection->net_conf);
713 my_addr_len = min_t(int, connection->my_addr_len, sizeof(struct sockaddr_in6));
714 memcpy(&my_addr, &connection->my_addr, my_addr_len);
750 drbd_err(connection, "%s failed, err = %d\n", what, err);
751 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
766 static struct socket *drbd_wait_for_connect(struct drbd_connection *connection, struct accept_wait_data *ad)
773 nc = rcu_dereference(connection->net_conf);
792 drbd_err(connection, "accept failed, err = %d\n", err);
793 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
805 static int send_first_packet(struct drbd_connection *connection, struct drbd_socket *sock,
808 if (!conn_prepare_command(connection, sock))
810 return conn_send_command(connection, sock, cmd, 0, NULL, 0);
813 static int receive_first_packet(struct drbd_connection *connection, struct socket *sock)
815 unsigned int header_size = drbd_header_size(connection);
821 nc = rcu_dereference(connection->net_conf);
829 err = drbd_recv_short(sock, connection->data.rbuf, header_size, 0);
835 err = decode_header(connection, connection->data.rbuf, &pi);
842 * drbd_socket_okay() - Free the socket if its connection is not okay
864 static bool connection_established(struct drbd_connection *connection,
876 nc = rcu_dereference(connection->net_conf);
887 /* Gets called if a connection is established, or if a new minor gets created
888 in a connection */
897 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
898 &peer_device->connection->cstate_mutex :
917 * 1 yes, we have a valid connection
923 static int conn_connect(struct drbd_connection *connection)
932 .connection = connection,
936 clear_bit(DISCONNECT_SENT, &connection->flags);
937 if (conn_request_state(connection, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS)
941 sock.sbuf = connection->data.sbuf;
942 sock.rbuf = connection->data.rbuf;
945 msock.sbuf = connection->meta.sbuf;
946 msock.rbuf = connection->meta.rbuf;
950 connection->agreed_pro_version = 80;
952 if (prepare_listen_socket(connection, &ad))
958 s = drbd_try_connect(connection);
962 send_first_packet(connection, &sock, P_INITIAL_DATA);
964 clear_bit(RESOLVE_CONFLICTS, &connection->flags);
966 send_first_packet(connection, &msock, P_INITIAL_META);
968 drbd_err(connection, "Logic error in conn_connect()\n");
973 if (connection_established(connection, &sock.socket, &msock.socket))
977 s = drbd_wait_for_connect(connection, &ad);
979 int fp = receive_first_packet(connection, s);
985 drbd_warn(connection, "initial packet S crossed\n");
993 set_bit(RESOLVE_CONFLICTS, &connection->flags);
995 drbd_warn(connection, "initial packet M crossed\n");
1003 drbd_warn(connection, "Error receiving initial packet\n");
1011 if (connection->cstate <= C_DISCONNECTING)
1016 if (get_t_state(&connection->receiver) == EXITING)
1020 ok = connection_established(connection, &sock.socket, &msock.socket);
1039 * sock.socket->sk->sk_sndtimeo = connection->net_conf->timeout*HZ/10;
1044 nc = rcu_dereference(connection->net_conf);
1061 connection->data.socket = sock.socket;
1062 connection->meta.socket = msock.socket;
1063 connection->last_received = jiffies;
1065 h = drbd_do_features(connection);
1069 if (connection->cram_hmac_tfm) {
1071 switch (drbd_do_auth(connection)) {
1073 drbd_err(connection, "Authentication of peer failed\n");
1076 drbd_err(connection, "Authentication of peer failed, trying again.\n");
1081 connection->data.socket->sk->sk_sndtimeo = timeout;
1082 connection->data.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
1084 if (drbd_send_protocol(connection) == -EOPNOTSUPP)
1094 idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
1098 spin_lock_irq(&connection->resource->req_lock);
1099 set_bit(STATE_SENT, &connection->flags);
1100 spin_unlock_irq(&connection->resource->req_lock);
1102 idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
1106 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1122 rv = conn_request_state(connection, NS(conn, C_WF_REPORT_PARAMS), CS_VERBOSE);
1123 if (rv < SS_SUCCESS || connection->cstate != C_WF_REPORT_PARAMS) {
1124 clear_bit(STATE_SENT, &connection->flags);
1128 drbd_thread_start(&connection->ack_receiver);
1131 connection->ack_sender =
1132 alloc_ordered_workqueue("drbd_as_%s", WQ_MEM_RECLAIM, connection->resource->name);
1133 if (!connection->ack_sender) {
1134 drbd_err(connection, "Failed to create workqueue ack_sender\n");
1138 mutex_lock(&connection->resource->conf_update);
1140 * connection attempt, the handshake of which is now well underway.
1143 connection->net_conf->discard_my_data = 0;
1144 mutex_unlock(&connection->resource->conf_update);
1158 static int decode_header(struct drbd_connection *connection, void *header, struct packet_info *pi)
1160 unsigned int header_size = drbd_header_size(connection);
1166 drbd_err(connection, "Header padding is not zero\n");
1185 drbd_err(connection, "Wrong magic value 0x%08x in protocol version %d\n",
1187 connection->agreed_pro_version);
1194 static void drbd_unplug_all_devices(struct drbd_connection *connection)
1196 if (current->plug == &connection->receiver_plug) {
1197 blk_finish_plug(&connection->receiver_plug);
1198 blk_start_plug(&connection->receiver_plug);
1202 static int drbd_recv_header(struct drbd_connection *connection, struct packet_info *pi)
1204 void *buffer = connection->data.rbuf;
1207 err = drbd_recv_all_warn(connection, buffer, drbd_header_size(connection));
1211 err = decode_header(connection, buffer, pi);
1212 connection->last_received = jiffies;
1217 static int drbd_recv_header_maybe_unplug(struct drbd_connection *connection, struct packet_info *pi)
1219 void *buffer = connection->data.rbuf;
1220 unsigned int size = drbd_header_size(connection);
1223 err = drbd_recv_short(connection->data.socket, buffer, size, MSG_NOSIGNAL|MSG_DONTWAIT);
1230 tcp_sock_set_quickack(connection->data.socket->sk, 2);
1231 drbd_unplug_all_devices(connection);
1237 err = drbd_recv_all_warn(connection, buffer, size);
1242 err = decode_header(connection, connection->data.rbuf, pi);
1243 connection->last_received = jiffies;
1312 static void drbd_flush(struct drbd_connection *connection)
1314 if (connection->resource->write_ordering >= WO_BDEV_FLUSH) {
1324 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1348 drbd_bump_write_ordering(connection->resource, NULL, WO_DRAIN_IO);
1355 * @connection: DRBD connection.
1359 static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connection,
1367 spin_lock(&connection->epoch_lock);
1389 spin_unlock(&connection->epoch_lock);
1390 drbd_send_b_ack(epoch->connection, epoch->barrier_nr, epoch_size);
1391 spin_lock(&connection->epoch_lock);
1394 /* FIXME: dec unacked on connection, once we have
1395 * something to count pending connection packets in. */
1397 dec_unacked(epoch->connection);
1400 if (connection->current_epoch != epoch) {
1404 connection->epochs--;
1424 spin_unlock(&connection->epoch_lock);
1654 conn_wait_active_ee_empty(peer_req->peer_device->connection);
1740 static void conn_wait_active_ee_empty(struct drbd_connection *connection)
1746 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1758 static int receive_Barrier(struct drbd_connection *connection, struct packet_info *pi)
1764 /* FIXME these are unacked on connection,
1767 connection->current_epoch->barrier_nr = p->barrier;
1768 connection->current_epoch->connection = connection;
1769 rv = drbd_may_finish_epoch(connection, connection->current_epoch, EV_GOT_BARRIER_NR);
1776 switch (connection->resource->write_ordering) {
1787 drbd_warn(connection, "Allocation of an epoch failed, slowing down\n");
1792 conn_wait_active_ee_empty(connection);
1793 drbd_flush(connection);
1795 if (atomic_read(&connection->current_epoch->epoch_size)) {
1803 drbd_err(connection, "Strangeness in connection->write_ordering %d\n",
1804 connection->resource->write_ordering);
1812 spin_lock(&connection->epoch_lock);
1813 if (atomic_read(&connection->current_epoch->epoch_size)) {
1814 list_add(&epoch->list, &connection->current_epoch->list);
1815 connection->current_epoch = epoch;
1816 connection->epochs++;
1821 spin_unlock(&connection->epoch_lock);
1856 void *dig_in = peer_device->connection->int_dig_in;
1857 void *dig_vv = peer_device->connection->int_dig_vv;
1863 if (!trim && peer_device->connection->peer_integrity_tfm) {
1864 digest_size = crypto_shash_digestsize(peer_device->connection->peer_integrity_tfm);
1869 err = drbd_recv_all_warn(peer_device->connection, dig_in, digest_size);
1928 err = drbd_recv_all_warn(peer_device->connection, data, len);
1942 drbd_csum_ee_size(peer_device->connection->peer_integrity_tfm, peer_req, dig_vv, data_size);
1972 err = drbd_recv_all_warn(peer_device->connection, data, len);
1989 void *dig_in = peer_device->connection->int_dig_in;
1990 void *dig_vv = peer_device->connection->int_dig_vv;
1993 if (peer_device->connection->peer_integrity_tfm) {
1994 digest_size = crypto_shash_digestsize(peer_device->connection->peer_integrity_tfm);
1995 err = drbd_recv_all_warn(peer_device->connection, dig_in, digest_size);
2011 err = drbd_recv_all_warn(peer_device->connection, mapped, expect);
2019 drbd_csum_bio(peer_device->connection->peer_integrity_tfm, bio, dig_vv);
2116 static int receive_DataReply(struct drbd_connection *connection, struct packet_info *pi)
2125 peer_device = conn_peer_device(connection, pi->vnr);
2148 static int receive_RSDataReply(struct drbd_connection *connection, struct packet_info *pi)
2156 peer_device = conn_peer_device(connection, pi->vnr);
2243 drbd_may_finish_epoch(peer_device->connection, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0));
2270 struct drbd_connection *connection = peer_req->peer_device->connection;
2272 return e_send_ack(w, connection->agreed_pro_version >= 100 ?
2296 if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) {
2345 * Assume we have a 10 GBit connection, that is about 1<<30 byte per second,
2359 if (!test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags))
2375 tp = rcu_dereference(peer_device->connection->net_conf)->two_primaries;
2385 timeout = rcu_dereference(peer_device->connection->net_conf)->ping_timeo*HZ/10;
2411 static blk_opf_t wire_flags_to_bio(struct drbd_connection *connection, u32 dpf)
2448 struct drbd_connection *connection = peer_req->peer_device->connection;
2449 bool resolve_conflicts = test_bit(RESOLVE_CONFLICTS, &connection->flags);
2503 queue_work(connection->ack_sender, &peer_req->peer_device->send_acks_work);
2532 _conn_request_state(connection, NS(conn, C_TIMEOUT), CS_HARD);
2554 static int receive_Data(struct drbd_connection *connection, struct packet_info *pi)
2566 peer_device = conn_peer_device(connection, pi->vnr);
2576 atomic_inc(&connection->current_epoch->epoch_size);
2601 peer_req->opf = wire_flags_to_bio(connection, dp_flags);
2608 if (0 == (connection->agreed_features & DRBD_FF_WZEROES))
2625 spin_lock(&connection->epoch_lock);
2626 peer_req->epoch = connection->current_epoch;
2629 spin_unlock(&connection->epoch_lock);
2632 nc = rcu_dereference(peer_device->connection->net_conf);
2634 if (peer_device->connection->agreed_pro_version < 100) {
2715 drbd_may_finish_epoch(connection, peer_req->epoch, EV_PUT | EV_CLEANUP);
2802 static int receive_DataRequest(struct drbd_connection *connection, struct packet_info *pi)
2813 peer_device = conn_peer_device(connection, pi->vnr);
2904 if (drbd_recv_all(peer_device->connection, di->digest, pi->size))
2908 D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89);
2927 peer_device->connection->agreed_pro_version >= 90) {
2979 update_receiver_timing_details(connection, drbd_rs_should_slow_down);
2983 update_receiver_timing_details(connection, drbd_rs_begin_io);
2991 update_receiver_timing_details(connection, drbd_submit_peer_request);
3003 /* no drbd_rs_complete_io(), we are dropping the connection anyways */
3027 after_sb_0p = rcu_dereference(peer_device->connection->net_conf)->after_sb_0p;
3063 rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)
3080 rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)
3103 after_sb_1p = rcu_dereference(peer_device->connection->net_conf)->after_sb_1p;
3160 after_sb_2p = rcu_dereference(peer_device->connection->net_conf)->after_sb_2p;
3233 struct drbd_connection *const connection = peer_device->connection;
3260 if (connection->agreed_pro_version < 91)
3283 if (connection->agreed_pro_version < 91)
3323 if (!(connection->agreed_features & DRBD_FF_WSAME)) {
3347 dc = test_bit(RESOLVE_CONFLICTS, &connection->flags);
3360 if (connection->agreed_pro_version < 96 ?
3367 if (connection->agreed_pro_version < 91)
3397 if (connection->agreed_pro_version < 96 ?
3404 if (connection->agreed_pro_version < 91)
3507 nc = rcu_dereference(peer_device->connection->net_conf);
3556 * We just refuse to attach -- well, we drop the "connection"
3558 drbd_alert(device, "Split-Brain detected but unresolved, dropping connection!\n");
3583 if (tentative || test_bit(CONN_DRY_RUN, &peer_device->connection->flags)) {
3629 static int receive_protocol(struct drbd_connection *connection, struct packet_info *pi)
3647 if (connection->agreed_pro_version >= 87) {
3652 err = drbd_recv_all(connection, integrity_alg, pi->size);
3659 clear_bit(CONN_DRY_RUN, &connection->flags);
3662 set_bit(CONN_DRY_RUN, &connection->flags);
3665 nc = rcu_dereference(connection->net_conf);
3668 drbd_err(connection, "incompatible %s settings\n", "protocol");
3673 drbd_err(connection, "incompatible %s settings\n", "after-sb-0pri");
3678 drbd_err(connection, "incompatible %s settings\n", "after-sb-1pri");
3683 drbd_err(connection, "incompatible %s settings\n", "after-sb-2pri");
3688 drbd_err(connection, "incompatible %s settings\n", "discard-my-data");
3693 drbd_err(connection, "incompatible %s settings\n", "allow-two-primaries");
3698 drbd_err(connection, "incompatible %s settings\n", "data-integrity-alg");
3720 drbd_err(connection, "peer data-integrity-alg %s not supported\n",
3729 drbd_err(connection, "Allocation of buffers for data integrity checking failed\n");
3738 mutex_lock(&connection->data.mutex);
3739 mutex_lock(&connection->resource->conf_update);
3740 old_net_conf = connection->net_conf;
3749 rcu_assign_pointer(connection->net_conf, new_net_conf);
3750 mutex_unlock(&connection->resource->conf_update);
3751 mutex_unlock(&connection->data.mutex);
3753 crypto_free_shash(connection->peer_integrity_tfm);
3754 kfree(connection->int_dig_in);
3755 kfree(connection->int_dig_vv);
3756 connection->peer_integrity_tfm = peer_integrity_tfm;
3757 connection->int_dig_in = int_dig_in;
3758 connection->int_dig_vv = int_dig_vv;
3761 drbd_info(connection, "peer data-integrity-alg: %s\n",
3773 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
3800 static int ignore_remaining_packet(struct drbd_connection *connection, struct packet_info *pi)
3802 void *buffer = connection->data.rbuf;
3807 s = drbd_recv(connection, buffer, s);
3823 * When a device is added to an existing connection, the node on which the
3831 static int config_unknown_volume(struct drbd_connection *connection, struct packet_info *pi)
3833 drbd_warn(connection, "%s packet received for volume %u, which is not configured locally\n",
3835 return ignore_remaining_packet(connection, pi);
3838 static int receive_SyncParam(struct drbd_connection *connection, struct packet_info *pi)
3848 const int apv = connection->agreed_pro_version;
3853 peer_device = conn_peer_device(connection, pi->vnr);
3855 return config_unknown_volume(connection, pi);
3888 err = drbd_recv_all(peer_device->connection, p, header_size);
3892 mutex_lock(&connection->resource->conf_update);
3893 old_net_conf = peer_device->connection->net_conf;
3898 mutex_unlock(&connection->resource->conf_update);
3918 err = drbd_recv_all(peer_device->connection, p->verify_alg, data_size);
3990 crypto_free_shash(peer_device->connection->verify_tfm);
3991 peer_device->connection->verify_tfm = verify_tfm;
3997 crypto_free_shash(peer_device->connection->csums_tfm);
3998 peer_device->connection->csums_tfm = csums_tfm;
4001 rcu_assign_pointer(connection->net_conf, new_net_conf);
4015 mutex_unlock(&connection->resource->conf_update);
4029 mutex_unlock(&connection->resource->conf_update);
4038 mutex_unlock(&connection->resource->conf_update);
4044 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4061 static int receive_sizes(struct drbd_connection *connection, struct packet_info *pi)
4066 struct o_qlim *o = (connection->agreed_features & DRBD_FF_WSAME) ? p->qlim : NULL;
4073 peer_device = conn_peer_device(connection, pi->vnr);
4075 return config_unknown_volume(connection, pi);
4111 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4125 mutex_lock(&connection->resource->conf_update);
4131 mutex_unlock(&connection->resource->conf_update);
4184 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4232 static int receive_uuids(struct drbd_connection *connection, struct packet_info *pi)
4240 peer_device = conn_peer_device(connection, pi->vnr);
4242 return config_unknown_volume(connection, pi);
4261 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4268 peer_device->connection->agreed_pro_version >= 90 &&
4337 static int receive_req_state(struct drbd_connection *connection, struct packet_info *pi)
4345 peer_device = conn_peer_device(connection, pi->vnr);
4353 if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) &&
4370 static int receive_req_conn_state(struct drbd_connection *connection, struct packet_info *pi)
4379 if (test_bit(RESOLVE_CONFLICTS, &connection->flags) &&
4380 mutex_is_locked(&connection->cstate_mutex)) {
4381 conn_send_sr_reply(connection, SS_CONCURRENT_ST_CHG);
4388 rv = conn_request_state(connection, mask, val, CS_VERBOSE | CS_LOCAL_ONLY | CS_IGN_OUTD_FAIL);
4389 conn_send_sr_reply(connection, rv);
4394 static int receive_state(struct drbd_connection *connection, struct packet_info *pi)
4404 peer_device = conn_peer_device(connection, pi->vnr);
4406 return config_unknown_volume(connection, pi);
4423 * already decided to close the connection again,
4491 * In this scenario, we already dropped the connection hard
4494 * Should we want to change this, that is: not drop the connection in
4504 /* if we established a new connection */
4506 /* if we had an established connection
4533 if (test_and_clear_bit(CONN_DRY_RUN, &peer_device->connection->flags))
4536 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4558 tl_clear(peer_device->connection);
4561 conn_request_state(peer_device->connection, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD);
4569 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4591 static int receive_sync_uuid(struct drbd_connection *connection, struct packet_info *pi)
4597 peer_device = conn_peer_device(connection, pi->vnr);
4637 drbd_header_size(peer_device->connection);
4649 err = drbd_recv_all(peer_device->connection, p, want);
4767 conn_request_state(peer_device->connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD);
4775 unsigned int header_size = drbd_header_size(peer_device->connection);
4815 static int receive_bitmap(struct drbd_connection *connection, struct packet_info *pi)
4822 peer_device = conn_peer_device(connection, pi->vnr);
4844 if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(connection)) {
4854 err = drbd_recv_all(peer_device->connection, p, pi->size);
4865 c.bytes[pi->cmd == P_BITMAP] += drbd_header_size(connection) + pi->size;
4872 err = drbd_recv_header(peer_device->connection, pi);
4903 static int receive_skip(struct drbd_connection *connection, struct packet_info *pi)
4905 drbd_warn(connection, "skipping unknown optional packet type %d, l: %d!\n",
4908 return ignore_remaining_packet(connection, pi);
4911 static int receive_UnplugRemote(struct drbd_connection *connection, struct packet_info *pi)
4915 tcp_sock_set_quickack(connection->data.socket->sk, 2);
4919 static int receive_out_of_sync(struct drbd_connection *connection, struct packet_info *pi)
4925 peer_device = conn_peer_device(connection, pi->vnr);
4945 static int receive_rs_deallocated(struct drbd_connection *connection, struct packet_info *pi)
4953 peer_device = conn_peer_device(connection, pi->vnr);
5048 static void drbdd(struct drbd_connection *connection)
5054 while (get_t_state(&connection->receiver) == RUNNING) {
5057 drbd_thread_current_set_cpu(&connection->receiver);
5058 update_receiver_timing_details(connection, drbd_recv_header_maybe_unplug);
5059 if (drbd_recv_header_maybe_unplug(connection, &pi))
5064 drbd_err(connection, "Unexpected data packet %s (0x%04x)",
5070 if (pi.cmd == P_SIZES && connection->agreed_features & DRBD_FF_WSAME)
5073 drbd_err(connection, "No payload expected %s l:%d\n",
5078 drbd_err(connection, "%s: unexpected packet size, expected:%d received:%d\n",
5084 update_receiver_timing_details(connection, drbd_recv_all_warn);
5085 err = drbd_recv_all_warn(connection, pi.data, shs);
5091 update_receiver_timing_details(connection, cmd->fn);
5092 err = cmd->fn(connection, &pi);
5094 drbd_err(connection, "error receiving %s, e: %d l: %d!\n",
5102 conn_request_state(connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD);
5105 static void conn_disconnect(struct drbd_connection *connection)
5111 if (connection->cstate == C_STANDALONE)
5114 /* We are about to start the cleanup after connection loss.
5119 conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD);
5122 drbd_thread_stop(&connection->ack_receiver);
5123 if (connection->ack_sender) {
5124 destroy_workqueue(connection->ack_sender);
5125 connection->ack_sender = NULL;
5127 drbd_free_sock(connection);
5130 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
5140 if (!list_empty(&connection->current_epoch->list))
5141 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
5143 atomic_set(&connection->current_epoch->epoch_size, 0);
5144 connection->send.seen_any_write_yet = false;
5146 drbd_info(connection, "Connection closed\n");
5148 if (conn_highest_role(connection) == R_PRIMARY && conn_highest_pdsk(connection) >= D_UNKNOWN)
5149 conn_try_outdate_peer_async(connection);
5151 spin_lock_irq(&connection->resource->req_lock);
5152 oc = connection->cstate;
5154 _conn_request_state(connection, NS(conn, C_UNCONNECTED), CS_VERBOSE);
5156 spin_unlock_irq(&connection->resource->req_lock);
5159 conn_request_state(connection, NS(conn, C_STANDALONE), CS_VERBOSE | CS_HARD);
5196 drbd_flush_workqueue(&peer_device->connection->sender_work);
5203 drbd_flush_workqueue(&peer_device->connection->sender_work);
5213 tl_clear(peer_device->connection);
5257 static int drbd_send_features(struct drbd_connection *connection)
5262 sock = &connection->data;
5263 p = conn_prepare_command(connection, sock);
5270 return conn_send_command(connection, sock, P_CONNECTION_FEATURES, sizeof(*p), NULL, 0);
5275 * 1 yes, we have a valid connection
5280 static int drbd_do_features(struct drbd_connection *connection)
5282 /* ASSERT current == connection->receiver ... */
5288 err = drbd_send_features(connection);
5292 err = drbd_recv_header(connection, &pi);
5297 drbd_err(connection, "expected ConnectionFeatures packet, received: %s (0x%04x)\n",
5303 drbd_err(connection, "expected ConnectionFeatures length: %u, received: %u\n",
5309 err = drbd_recv_all_warn(connection, p, expect);
5322 connection->agreed_pro_version = min_t(int, PRO_VERSION_MAX, p->protocol_max);
5323 connection->agreed_features = PRO_FEATURES & be32_to_cpu(p->feature_flags);
5325 drbd_info(connection, "Handshake successful: "
5326 "Agreed network protocol version %d\n", connection->agreed_pro_version);
5328 drbd_info(connection, "Feature flags enabled on protocol level: 0x%x%s%s%s%s.\n",
5329 connection->agreed_features,
5330 connection->agreed_features & DRBD_FF_TRIM ? " TRIM" : "",
5331 connection->agreed_features & DRBD_FF_THIN_RESYNC ? " THIN_RESYNC" : "",
5332 connection->agreed_features & DRBD_FF_WSAME ? " WRITE_SAME" : "",
5333 connection->agreed_features & DRBD_FF_WZEROES ? " WRITE_ZEROES" :
5334 connection->agreed_features ? "" : " none");
5339 drbd_err(connection, "incompatible DRBD dialects: "
5347 static int drbd_do_auth(struct drbd_connection *connection)
5349 drbd_err(connection, "This kernel was build without CONFIG_CRYPTO_HMAC.\n");
5350 drbd_err(connection, "You need to disable 'cram-hmac-alg' in drbd.conf.\n");
5362 static int drbd_do_auth(struct drbd_connection *connection)
5380 nc = rcu_dereference(connection->net_conf);
5386 crypto_shash_descsize(connection->cram_hmac_tfm),
5392 desc->tfm = connection->cram_hmac_tfm;
5394 rv = crypto_shash_setkey(connection->cram_hmac_tfm, (u8 *)secret, key_len);
5396 drbd_err(connection, "crypto_shash_setkey() failed with %d\n", rv);
5403 sock = &connection->data;
5404 if (!conn_prepare_command(connection, sock)) {
5408 rv = !conn_send_command(connection, sock, P_AUTH_CHALLENGE, 0,
5413 err = drbd_recv_header(connection, &pi);
5420 drbd_err(connection, "expected AuthChallenge packet, received: %s (0x%04x)\n",
5427 drbd_err(connection, "expected AuthChallenge payload too big.\n");
5433 drbd_err(connection, "AuthChallenge payload too small.\n");
5444 err = drbd_recv_all_warn(connection, peers_ch, pi.size);
5451 drbd_err(connection, "Peer presented the same challenge!\n");
5456 resp_size = crypto_shash_digestsize(connection->cram_hmac_tfm);
5465 drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv);
5470 if (!conn_prepare_command(connection, sock)) {
5474 rv = !conn_send_command(connection, sock, P_AUTH_RESPONSE, 0,
5479 err = drbd_recv_header(connection, &pi);
5486 drbd_err(connection, "expected AuthResponse packet, received: %s (0x%04x)\n",
5493 drbd_err(connection, "expected AuthResponse payload of wrong size\n");
5498 err = drbd_recv_all_warn(connection, response , resp_size);
5513 drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv);
5521 drbd_info(connection, "Peer authenticated using %d bytes HMAC\n",
5541 struct drbd_connection *connection = thi->connection;
5544 drbd_info(connection, "receiver (re)started\n");
5547 h = conn_connect(connection);
5549 conn_disconnect(connection);
5553 drbd_warn(connection, "Discarding network configuration.\n");
5554 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
5559 blk_start_plug(&connection->receiver_plug);
5560 drbdd(connection);
5561 blk_finish_plug(&connection->receiver_plug);
5564 conn_disconnect(connection);
5566 drbd_info(connection, "receiver terminated\n");
5572 static int got_conn_RqSReply(struct drbd_connection *connection, struct packet_info *pi)
5578 set_bit(CONN_WD_ST_CHG_OKAY, &connection->flags);
5580 set_bit(CONN_WD_ST_CHG_FAIL, &connection->flags);
5581 drbd_err(connection, "Requested state change failed by peer: %s (%d)\n",
5584 wake_up(&connection->ping_wait);
5589 static int got_RqSReply(struct drbd_connection *connection, struct packet_info *pi)
5596 peer_device = conn_peer_device(connection, pi->vnr);
5601 if (test_bit(CONN_WD_ST_CHG_REQ, &connection->flags)) {
5602 D_ASSERT(device, connection->agreed_pro_version < 100);
5603 return got_conn_RqSReply(connection, pi);
5618 static int got_Ping(struct drbd_connection *connection, struct packet_info *pi)
5620 return drbd_send_ping_ack(connection);
5624 static int got_PingAck(struct drbd_connection *connection, struct packet_info *pi)
5627 connection->meta.socket->sk->sk_rcvtimeo = connection->net_conf->ping_int*HZ;
5628 if (!test_and_set_bit(GOT_PING_ACK, &connection->flags))
5629 wake_up(&connection->ping_wait);
5634 static int got_IsInSync(struct drbd_connection *connection, struct packet_info *pi)
5642 peer_device = conn_peer_device(connection, pi->vnr);
5647 D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89);
5687 static int got_BlockAck(struct drbd_connection *connection, struct packet_info *pi)
5696 peer_device = conn_peer_device(connection, pi->vnr);
5733 static int got_NegAck(struct drbd_connection *connection, struct packet_info *pi)
5742 peer_device = conn_peer_device(connection, pi->vnr);
5769 static int got_NegDReply(struct drbd_connection *connection, struct packet_info *pi)
5776 peer_device = conn_peer_device(connection, pi->vnr);
5791 static int got_NegRSDReply(struct drbd_connection *connection, struct packet_info *pi)
5799 peer_device = conn_peer_device(connection, pi->vnr);
5828 static int got_BarrierAck(struct drbd_connection *connection, struct packet_info *pi)
5834 tl_release(connection, p->barrier, be32_to_cpu(p->set_size));
5837 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
5852 static int got_OVResult(struct drbd_connection *connection, struct packet_info *pi)
5861 peer_device = conn_peer_device(connection, pi->vnr);
5893 drbd_queue_work(&peer_device->connection->sender_work, &dw->w);
5904 static int got_skip(struct drbd_connection *connection, struct packet_info *pi)
5911 int (*fn)(struct drbd_connection *connection, struct packet_info *);
5914 static void set_rcvtimeo(struct drbd_connection *connection, bool ping_timeout)
5920 nc = rcu_dereference(connection->net_conf);
5928 connection->meta.socket->sk->sk_rcvtimeo = t;
5931 static void set_ping_timeout(struct drbd_connection *connection)
5933 set_rcvtimeo(connection, 1);
5936 static void set_idle_timeout(struct drbd_connection *connection)
5938 set_rcvtimeo(connection, 0);
5963 struct drbd_connection *connection = thi->connection;
5968 void *buf = connection->meta.rbuf;
5970 unsigned int header_size = drbd_header_size(connection);
5979 conn_reclaim_net_peer_reqs(connection);
5981 if (test_and_clear_bit(SEND_PING, &connection->flags)) {
5982 if (drbd_send_ping(connection)) {
5983 drbd_err(connection, "drbd_send_ping has failed\n");
5986 set_ping_timeout(connection);
5991 rv = drbd_recv_short(connection->meta.socket, buf, expect-received, 0);
5996 * -ECONNRESET other side closed the connection
6001 * rv == 0 : "connection shut down by peer"
6007 if (test_bit(DISCONNECT_SENT, &connection->flags)) {
6010 t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10;
6013 t = wait_event_timeout(connection->ping_wait,
6014 connection->cstate < C_WF_REPORT_PARAMS,
6019 drbd_err(connection, "meta connection shut down by peer.\n");
6024 if (time_after(connection->last_received, pre_recv_jif))
6027 drbd_err(connection, "PingAck did not arrive in time.\n");
6030 set_bit(SEND_PING, &connection->flags);
6039 drbd_err(connection, "sock_recvmsg returned %d\n", rv);
6044 if (decode_header(connection, connection->meta.rbuf, &pi))
6048 drbd_err(connection, "Unexpected meta packet %s (0x%04x)\n",
6054 drbd_err(connection, "Wrong packet size on meta (c: %d, l: %d)\n",
6062 err = cmd->fn(connection, &pi);
6064 drbd_err(connection, "%ps failed\n", cmd->fn);
6068 connection->last_received = jiffies;
6071 set_idle_timeout(connection);
6075 buf = connection->meta.rbuf;
6084 conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD);
6085 conn_md_sync(connection);
6089 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
6092 drbd_info(connection, "ack_receiver terminated\n");
6101 struct drbd_connection *connection = peer_device->connection;
6107 nc = rcu_dereference(connection->net_conf);
6112 tcp_sock_set_cork(connection->meta.socket->sk, true);
6120 conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD);
6125 tcp_sock_set_cork(connection->meta.socket->sk, false);