Lines Matching refs:connection
57 static int drbd_do_features(struct drbd_connection *connection);
58 static int drbd_do_auth(struct drbd_connection *connection);
60 static void conn_wait_active_ee_empty(struct drbd_connection *connection);
221 static void conn_reclaim_net_peer_reqs(struct drbd_connection *connection)
227 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
271 nc = rcu_dereference(peer_device->connection->net_conf);
512 static int drbd_recv(struct drbd_connection *connection, void *buf, size_t size)
516 rv = drbd_recv_short(connection->data.socket, buf, size, 0);
520 drbd_info(connection, "sock was reset by peer\n");
522 drbd_err(connection, "sock_recvmsg returned %d\n", rv);
524 if (test_bit(DISCONNECT_SENT, &connection->flags)) {
527 t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10;
530 t = wait_event_timeout(connection->ping_wait, connection->cstate < C_WF_REPORT_PARAMS, t);
535 drbd_info(connection, "sock was shut down by peer\n");
539 conn_request_state(connection, NS(conn, C_BROKEN_PIPE), CS_HARD);
545 static int drbd_recv_all(struct drbd_connection *connection, void *buf, size_t size)
549 err = drbd_recv(connection, buf, size);
558 static int drbd_recv_all_warn(struct drbd_connection *connection, void *buf, size_t size)
562 err = drbd_recv_all(connection, buf, size);
564 drbd_warn(connection, "short read (expected size %d)\n", (int)size);
587 static struct socket *drbd_try_connect(struct drbd_connection *connection)
599 nc = rcu_dereference(connection->net_conf);
609 my_addr_len = min_t(int, connection->my_addr_len, sizeof(src_in6));
610 memcpy(&src_in6, &connection->my_addr, my_addr_len);
612 if (((struct sockaddr *)&connection->my_addr)->sa_family == AF_INET6)
617 peer_addr_len = min_t(int, connection->peer_addr_len, sizeof(src_in6));
618 memcpy(&peer_in6, &connection->peer_addr, peer_addr_len);
666 drbd_err(connection, "%s failed, err = %d\n", what, err);
669 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
676 struct drbd_connection *connection;
694 static int prepare_listen_socket(struct drbd_connection *connection, struct accept_wait_data *ad)
703 nc = rcu_dereference(connection->net_conf);
712 my_addr_len = min_t(int, connection->my_addr_len, sizeof(struct sockaddr_in6));
713 memcpy(&my_addr, &connection->my_addr, my_addr_len);
749 drbd_err(connection, "%s failed, err = %d\n", what, err);
750 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
765 static struct socket *drbd_wait_for_connect(struct drbd_connection *connection, struct accept_wait_data *ad)
772 nc = rcu_dereference(connection->net_conf);
791 drbd_err(connection, "accept failed, err = %d\n", err);
792 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
804 static int send_first_packet(struct drbd_connection *connection, struct drbd_socket *sock,
807 if (!conn_prepare_command(connection, sock))
809 return conn_send_command(connection, sock, cmd, 0, NULL, 0);
812 static int receive_first_packet(struct drbd_connection *connection, struct socket *sock)
814 unsigned int header_size = drbd_header_size(connection);
820 nc = rcu_dereference(connection->net_conf);
828 err = drbd_recv_short(sock, connection->data.rbuf, header_size, 0);
834 err = decode_header(connection, connection->data.rbuf, &pi);
841 * drbd_socket_okay() - Free the socket if its connection is not okay
863 static bool connection_established(struct drbd_connection *connection,
875 nc = rcu_dereference(connection->net_conf);
886 /* Gets called if a connection is established, or if a new minor gets created
887 in a connection */
896 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
897 &peer_device->connection->cstate_mutex :
916 * 1 yes, we have a valid connection
922 static int conn_connect(struct drbd_connection *connection)
931 .connection = connection,
935 clear_bit(DISCONNECT_SENT, &connection->flags);
936 if (conn_request_state(connection, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS)
940 sock.sbuf = connection->data.sbuf;
941 sock.rbuf = connection->data.rbuf;
944 msock.sbuf = connection->meta.sbuf;
945 msock.rbuf = connection->meta.rbuf;
949 connection->agreed_pro_version = 80;
951 if (prepare_listen_socket(connection, &ad))
957 s = drbd_try_connect(connection);
961 send_first_packet(connection, &sock, P_INITIAL_DATA);
963 clear_bit(RESOLVE_CONFLICTS, &connection->flags);
965 send_first_packet(connection, &msock, P_INITIAL_META);
967 drbd_err(connection, "Logic error in conn_connect()\n");
972 if (connection_established(connection, &sock.socket, &msock.socket))
976 s = drbd_wait_for_connect(connection, &ad);
978 int fp = receive_first_packet(connection, s);
984 drbd_warn(connection, "initial packet S crossed\n");
992 set_bit(RESOLVE_CONFLICTS, &connection->flags);
994 drbd_warn(connection, "initial packet M crossed\n");
1002 drbd_warn(connection, "Error receiving initial packet\n");
1010 if (connection->cstate <= C_DISCONNECTING)
1015 if (get_t_state(&connection->receiver) == EXITING)
1019 ok = connection_established(connection, &sock.socket, &msock.socket);
1035 * sock.socket->sk->sk_sndtimeo = connection->net_conf->timeout*HZ/10;
1040 nc = rcu_dereference(connection->net_conf);
1057 connection->data.socket = sock.socket;
1058 connection->meta.socket = msock.socket;
1059 connection->last_received = jiffies;
1061 h = drbd_do_features(connection);
1065 if (connection->cram_hmac_tfm) {
1067 switch (drbd_do_auth(connection)) {
1069 drbd_err(connection, "Authentication of peer failed\n");
1072 drbd_err(connection, "Authentication of peer failed, trying again.\n");
1077 connection->data.socket->sk->sk_sndtimeo = timeout;
1078 connection->data.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
1080 if (drbd_send_protocol(connection) == -EOPNOTSUPP)
1090 idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
1094 spin_lock_irq(&connection->resource->req_lock);
1095 set_bit(STATE_SENT, &connection->flags);
1096 spin_unlock_irq(&connection->resource->req_lock);
1098 idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
1102 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1118 rv = conn_request_state(connection, NS(conn, C_WF_REPORT_PARAMS), CS_VERBOSE);
1119 if (rv < SS_SUCCESS || connection->cstate != C_WF_REPORT_PARAMS) {
1120 clear_bit(STATE_SENT, &connection->flags);
1124 drbd_thread_start(&connection->ack_receiver);
1127 connection->ack_sender =
1128 alloc_ordered_workqueue("drbd_as_%s", WQ_MEM_RECLAIM, connection->resource->name);
1129 if (!connection->ack_sender) {
1130 drbd_err(connection, "Failed to create workqueue ack_sender\n");
1134 mutex_lock(&connection->resource->conf_update);
1136 * connection attempt, the handshake of which is now well underway.
1139 connection->net_conf->discard_my_data = 0;
1140 mutex_unlock(&connection->resource->conf_update);
1154 static int decode_header(struct drbd_connection *connection, void *header, struct packet_info *pi)
1156 unsigned int header_size = drbd_header_size(connection);
1162 drbd_err(connection, "Header padding is not zero\n");
1181 drbd_err(connection, "Wrong magic value 0x%08x in protocol version %d\n",
1183 connection->agreed_pro_version);
1190 static void drbd_unplug_all_devices(struct drbd_connection *connection)
1192 if (current->plug == &connection->receiver_plug) {
1193 blk_finish_plug(&connection->receiver_plug);
1194 blk_start_plug(&connection->receiver_plug);
1198 static int drbd_recv_header(struct drbd_connection *connection, struct packet_info *pi)
1200 void *buffer = connection->data.rbuf;
1203 err = drbd_recv_all_warn(connection, buffer, drbd_header_size(connection));
1207 err = decode_header(connection, buffer, pi);
1208 connection->last_received = jiffies;
1213 static int drbd_recv_header_maybe_unplug(struct drbd_connection *connection, struct packet_info *pi)
1215 void *buffer = connection->data.rbuf;
1216 unsigned int size = drbd_header_size(connection);
1219 err = drbd_recv_short(connection->data.socket, buffer, size, MSG_NOSIGNAL|MSG_DONTWAIT);
1226 tcp_sock_set_quickack(connection->data.socket->sk, 2);
1227 drbd_unplug_all_devices(connection);
1233 err = drbd_recv_all_warn(connection, buffer, size);
1238 err = decode_header(connection, connection->data.rbuf, pi);
1239 connection->last_received = jiffies;
1310 static void drbd_flush(struct drbd_connection *connection)
1312 if (connection->resource->write_ordering >= WO_BDEV_FLUSH) {
1322 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1346 drbd_bump_write_ordering(connection->resource, NULL, WO_DRAIN_IO);
1357 static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connection,
1365 spin_lock(&connection->epoch_lock);
1387 spin_unlock(&connection->epoch_lock);
1388 drbd_send_b_ack(epoch->connection, epoch->barrier_nr, epoch_size);
1389 spin_lock(&connection->epoch_lock);
1392 /* FIXME: dec unacked on connection, once we have
1393 * something to count pending connection packets in. */
1395 dec_unacked(epoch->connection);
1398 if (connection->current_epoch != epoch) {
1402 connection->epochs--;
1422 spin_unlock(&connection->epoch_lock);
1444 * @connection: DRBD connection.
1660 conn_wait_active_ee_empty(peer_req->peer_device->connection);
1752 static void conn_wait_active_ee_empty(struct drbd_connection *connection)
1758 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
1770 static int receive_Barrier(struct drbd_connection *connection, struct packet_info *pi)
1776 /* FIXME these are unacked on connection,
1779 connection->current_epoch->barrier_nr = p->barrier;
1780 connection->current_epoch->connection = connection;
1781 rv = drbd_may_finish_epoch(connection, connection->current_epoch, EV_GOT_BARRIER_NR);
1788 switch (connection->resource->write_ordering) {
1799 drbd_warn(connection, "Allocation of an epoch failed, slowing down\n");
1804 conn_wait_active_ee_empty(connection);
1805 drbd_flush(connection);
1807 if (atomic_read(&connection->current_epoch->epoch_size)) {
1815 drbd_err(connection, "Strangeness in connection->write_ordering %d\n",
1816 connection->resource->write_ordering);
1824 spin_lock(&connection->epoch_lock);
1825 if (atomic_read(&connection->current_epoch->epoch_size)) {
1826 list_add(&epoch->list, &connection->current_epoch->list);
1827 connection->current_epoch = epoch;
1828 connection->epochs++;
1833 spin_unlock(&connection->epoch_lock);
1868 void *dig_in = peer_device->connection->int_dig_in;
1869 void *dig_vv = peer_device->connection->int_dig_vv;
1876 if (!trim && peer_device->connection->peer_integrity_tfm) {
1877 digest_size = crypto_shash_digestsize(peer_device->connection->peer_integrity_tfm);
1882 err = drbd_recv_all_warn(peer_device->connection, dig_in, digest_size);
1955 err = drbd_recv_all_warn(peer_device->connection, data, len);
1969 drbd_csum_ee_size(peer_device->connection->peer_integrity_tfm, peer_req, dig_vv, data_size);
1999 err = drbd_recv_all_warn(peer_device->connection, data, len);
2016 void *dig_in = peer_device->connection->int_dig_in;
2017 void *dig_vv = peer_device->connection->int_dig_vv;
2020 if (peer_device->connection->peer_integrity_tfm) {
2021 digest_size = crypto_shash_digestsize(peer_device->connection->peer_integrity_tfm);
2022 err = drbd_recv_all_warn(peer_device->connection, dig_in, digest_size);
2038 err = drbd_recv_all_warn(peer_device->connection, mapped, expect);
2046 drbd_csum_bio(peer_device->connection->peer_integrity_tfm, bio, dig_vv);
2143 static int receive_DataReply(struct drbd_connection *connection, struct packet_info *pi)
2152 peer_device = conn_peer_device(connection, pi->vnr);
2178 static int receive_RSDataReply(struct drbd_connection *connection, struct packet_info *pi)
2186 peer_device = conn_peer_device(connection, pi->vnr);
2273 drbd_may_finish_epoch(peer_device->connection, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0));
2300 struct drbd_connection *connection = peer_req->peer_device->connection;
2302 return e_send_ack(w, connection->agreed_pro_version >= 100 ?
2326 if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) {
2375 * Assume we have a 10 GBit connection, that is about 1<<30 byte per second,
2389 if (!test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags))
2405 tp = rcu_dereference(peer_device->connection->net_conf)->two_primaries;
2415 timeout = rcu_dereference(peer_device->connection->net_conf)->ping_timeo*HZ/10;
2480 struct drbd_connection *connection = peer_req->peer_device->connection;
2481 bool resolve_conflicts = test_bit(RESOLVE_CONFLICTS, &connection->flags);
2535 queue_work(connection->ack_sender, &peer_req->peer_device->send_acks_work);
2564 _conn_request_state(connection, NS(conn, C_TIMEOUT), CS_HARD);
2586 static int receive_Data(struct drbd_connection *connection, struct packet_info *pi)
2599 peer_device = conn_peer_device(connection, pi->vnr);
2609 atomic_inc(&connection->current_epoch->epoch_size);
2642 if (0 == (connection->agreed_features & DRBD_FF_WZEROES))
2659 spin_lock(&connection->epoch_lock);
2660 peer_req->epoch = connection->current_epoch;
2663 spin_unlock(&connection->epoch_lock);
2666 nc = rcu_dereference(peer_device->connection->net_conf);
2668 if (peer_device->connection->agreed_pro_version < 100) {
2750 drbd_may_finish_epoch(connection, peer_req->epoch, EV_PUT | EV_CLEANUP);
2836 static int receive_DataRequest(struct drbd_connection *connection, struct packet_info *pi)
2848 peer_device = conn_peer_device(connection, pi->vnr);
2941 if (drbd_recv_all(peer_device->connection, di->digest, pi->size))
2945 D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89);
2964 peer_device->connection->agreed_pro_version >= 90) {
3017 update_receiver_timing_details(connection, drbd_rs_should_slow_down);
3021 update_receiver_timing_details(connection, drbd_rs_begin_io);
3029 update_receiver_timing_details(connection, drbd_submit_peer_request);
3042 /* no drbd_rs_complete_io(), we are dropping the connection anyways */
3066 after_sb_0p = rcu_dereference(peer_device->connection->net_conf)->after_sb_0p;
3102 rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)
3119 rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)
3142 after_sb_1p = rcu_dereference(peer_device->connection->net_conf)->after_sb_1p;
3199 after_sb_2p = rcu_dereference(peer_device->connection->net_conf)->after_sb_2p;
3272 struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL;
3298 if (connection->agreed_pro_version < 91)
3321 if (connection->agreed_pro_version < 91)
3361 if (!(connection->agreed_features & DRBD_FF_WSAME)) {
3385 dc = test_bit(RESOLVE_CONFLICTS, &connection->flags);
3398 if (connection->agreed_pro_version < 96 ?
3405 if (connection->agreed_pro_version < 91)
3435 if (connection->agreed_pro_version < 96 ?
3442 if (connection->agreed_pro_version < 91)
3545 nc = rcu_dereference(peer_device->connection->net_conf);
3594 * We just refuse to attach -- well, we drop the "connection"
3596 drbd_alert(device, "Split-Brain detected but unresolved, dropping connection!\n");
3621 if (tentative || test_bit(CONN_DRY_RUN, &peer_device->connection->flags)) {
3667 static int receive_protocol(struct drbd_connection *connection, struct packet_info *pi)
3685 if (connection->agreed_pro_version >= 87) {
3690 err = drbd_recv_all(connection, integrity_alg, pi->size);
3697 clear_bit(CONN_DRY_RUN, &connection->flags);
3700 set_bit(CONN_DRY_RUN, &connection->flags);
3703 nc = rcu_dereference(connection->net_conf);
3706 drbd_err(connection, "incompatible %s settings\n", "protocol");
3711 drbd_err(connection, "incompatible %s settings\n", "after-sb-0pri");
3716 drbd_err(connection, "incompatible %s settings\n", "after-sb-1pri");
3721 drbd_err(connection, "incompatible %s settings\n", "after-sb-2pri");
3726 drbd_err(connection, "incompatible %s settings\n", "discard-my-data");
3731 drbd_err(connection, "incompatible %s settings\n", "allow-two-primaries");
3736 drbd_err(connection, "incompatible %s settings\n", "data-integrity-alg");
3758 drbd_err(connection, "peer data-integrity-alg %s not supported\n",
3767 drbd_err(connection, "Allocation of buffers for data integrity checking failed\n");
3774 drbd_err(connection, "Allocation of new net_conf failed\n");
3778 mutex_lock(&connection->data.mutex);
3779 mutex_lock(&connection->resource->conf_update);
3780 old_net_conf = connection->net_conf;
3789 rcu_assign_pointer(connection->net_conf, new_net_conf);
3790 mutex_unlock(&connection->resource->conf_update);
3791 mutex_unlock(&connection->data.mutex);
3793 crypto_free_shash(connection->peer_integrity_tfm);
3794 kfree(connection->int_dig_in);
3795 kfree(connection->int_dig_vv);
3796 connection->peer_integrity_tfm = peer_integrity_tfm;
3797 connection->int_dig_in = int_dig_in;
3798 connection->int_dig_vv = int_dig_vv;
3801 drbd_info(connection, "peer data-integrity-alg: %s\n",
3814 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
3841 static int ignore_remaining_packet(struct drbd_connection *connection, struct packet_info *pi)
3843 void *buffer = connection->data.rbuf;
3848 s = drbd_recv(connection, buffer, s);
3864 * When a device is added to an existing connection, the node on which the
3872 static int config_unknown_volume(struct drbd_connection *connection, struct packet_info *pi)
3874 drbd_warn(connection, "%s packet received for volume %u, which is not configured locally\n",
3876 return ignore_remaining_packet(connection, pi);
3879 static int receive_SyncParam(struct drbd_connection *connection, struct packet_info *pi)
3889 const int apv = connection->agreed_pro_version;
3894 peer_device = conn_peer_device(connection, pi->vnr);
3896 return config_unknown_volume(connection, pi);
3928 err = drbd_recv_all(peer_device->connection, p, header_size);
3932 mutex_lock(&connection->resource->conf_update);
3933 old_net_conf = peer_device->connection->net_conf;
3938 mutex_unlock(&connection->resource->conf_update);
3959 err = drbd_recv_all(peer_device->connection, p->verify_alg, data_size);
4033 crypto_free_shash(peer_device->connection->verify_tfm);
4034 peer_device->connection->verify_tfm = verify_tfm;
4040 crypto_free_shash(peer_device->connection->csums_tfm);
4041 peer_device->connection->csums_tfm = csums_tfm;
4044 rcu_assign_pointer(connection->net_conf, new_net_conf);
4058 mutex_unlock(&connection->resource->conf_update);
4072 mutex_unlock(&connection->resource->conf_update);
4081 mutex_unlock(&connection->resource->conf_update);
4087 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4104 static int receive_sizes(struct drbd_connection *connection, struct packet_info *pi)
4109 struct o_qlim *o = (connection->agreed_features & DRBD_FF_WSAME) ? p->qlim : NULL;
4116 peer_device = conn_peer_device(connection, pi->vnr);
4118 return config_unknown_volume(connection, pi);
4154 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4169 mutex_lock(&connection->resource->conf_update);
4175 mutex_unlock(&connection->resource->conf_update);
4229 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4277 static int receive_uuids(struct drbd_connection *connection, struct packet_info *pi)
4285 peer_device = conn_peer_device(connection, pi->vnr);
4287 return config_unknown_volume(connection, pi);
4308 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4315 peer_device->connection->agreed_pro_version >= 90 &&
4384 static int receive_req_state(struct drbd_connection *connection, struct packet_info *pi)
4392 peer_device = conn_peer_device(connection, pi->vnr);
4400 if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) &&
4417 static int receive_req_conn_state(struct drbd_connection *connection, struct packet_info *pi)
4426 if (test_bit(RESOLVE_CONFLICTS, &connection->flags) &&
4427 mutex_is_locked(&connection->cstate_mutex)) {
4428 conn_send_sr_reply(connection, SS_CONCURRENT_ST_CHG);
4435 rv = conn_request_state(connection, mask, val, CS_VERBOSE | CS_LOCAL_ONLY | CS_IGN_OUTD_FAIL);
4436 conn_send_sr_reply(connection, rv);
4441 static int receive_state(struct drbd_connection *connection, struct packet_info *pi)
4451 peer_device = conn_peer_device(connection, pi->vnr);
4453 return config_unknown_volume(connection, pi);
4470 * already decided to close the connection again,
4538 * In this scenario, we already dropped the connection hard
4541 * Should we want to change this, that is: not drop the connection in
4551 /* if we established a new connection */
4553 /* if we had an established connection
4580 if (test_and_clear_bit(CONN_DRY_RUN, &peer_device->connection->flags))
4583 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4605 tl_clear(peer_device->connection);
4608 conn_request_state(peer_device->connection, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD);
4616 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
4638 static int receive_sync_uuid(struct drbd_connection *connection, struct packet_info *pi)
4644 peer_device = conn_peer_device(connection, pi->vnr);
4684 drbd_header_size(peer_device->connection);
4696 err = drbd_recv_all(peer_device->connection, p, want);
4814 conn_request_state(peer_device->connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD);
4822 unsigned int header_size = drbd_header_size(first_peer_device(device)->connection);
4862 static int receive_bitmap(struct drbd_connection *connection, struct packet_info *pi)
4869 peer_device = conn_peer_device(connection, pi->vnr);
4891 if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(connection)) {
4901 err = drbd_recv_all(peer_device->connection, p, pi->size);
4912 c.bytes[pi->cmd == P_BITMAP] += drbd_header_size(connection) + pi->size;
4919 err = drbd_recv_header(peer_device->connection, pi);
4950 static int receive_skip(struct drbd_connection *connection, struct packet_info *pi)
4952 drbd_warn(connection, "skipping unknown optional packet type %d, l: %d!\n",
4955 return ignore_remaining_packet(connection, pi);
4958 static int receive_UnplugRemote(struct drbd_connection *connection, struct packet_info *pi)
4962 tcp_sock_set_quickack(connection->data.socket->sk, 2);
4966 static int receive_out_of_sync(struct drbd_connection *connection, struct packet_info *pi)
4972 peer_device = conn_peer_device(connection, pi->vnr);
4992 static int receive_rs_deallocated(struct drbd_connection *connection, struct packet_info *pi)
5000 peer_device = conn_peer_device(connection, pi->vnr);
5096 static void drbdd(struct drbd_connection *connection)
5102 while (get_t_state(&connection->receiver) == RUNNING) {
5105 drbd_thread_current_set_cpu(&connection->receiver);
5106 update_receiver_timing_details(connection, drbd_recv_header_maybe_unplug);
5107 if (drbd_recv_header_maybe_unplug(connection, &pi))
5112 drbd_err(connection, "Unexpected data packet %s (0x%04x)",
5118 if (pi.cmd == P_SIZES && connection->agreed_features & DRBD_FF_WSAME)
5121 drbd_err(connection, "No payload expected %s l:%d\n",
5126 drbd_err(connection, "%s: unexpected packet size, expected:%d received:%d\n",
5132 update_receiver_timing_details(connection, drbd_recv_all_warn);
5133 err = drbd_recv_all_warn(connection, pi.data, shs);
5139 update_receiver_timing_details(connection, cmd->fn);
5140 err = cmd->fn(connection, &pi);
5142 drbd_err(connection, "error receiving %s, e: %d l: %d!\n",
5150 conn_request_state(connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD);
5153 static void conn_disconnect(struct drbd_connection *connection)
5159 if (connection->cstate == C_STANDALONE)
5162 /* We are about to start the cleanup after connection loss.
5167 conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD);
5170 drbd_thread_stop(&connection->ack_receiver);
5171 if (connection->ack_sender) {
5172 destroy_workqueue(connection->ack_sender);
5173 connection->ack_sender = NULL;
5175 drbd_free_sock(connection);
5178 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
5188 if (!list_empty(&connection->current_epoch->list))
5189 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
5191 atomic_set(&connection->current_epoch->epoch_size, 0);
5192 connection->send.seen_any_write_yet = false;
5194 drbd_info(connection, "Connection closed\n");
5196 if (conn_highest_role(connection) == R_PRIMARY && conn_highest_pdsk(connection) >= D_UNKNOWN)
5197 conn_try_outdate_peer_async(connection);
5199 spin_lock_irq(&connection->resource->req_lock);
5200 oc = connection->cstate;
5202 _conn_request_state(connection, NS(conn, C_UNCONNECTED), CS_VERBOSE);
5204 spin_unlock_irq(&connection->resource->req_lock);
5207 conn_request_state(connection, NS(conn, C_STANDALONE), CS_VERBOSE | CS_HARD);
5244 drbd_flush_workqueue(&peer_device->connection->sender_work);
5251 drbd_flush_workqueue(&peer_device->connection->sender_work);
5261 tl_clear(peer_device->connection);
5305 static int drbd_send_features(struct drbd_connection *connection)
5310 sock = &connection->data;
5311 p = conn_prepare_command(connection, sock);
5318 return conn_send_command(connection, sock, P_CONNECTION_FEATURES, sizeof(*p), NULL, 0);
5323 * 1 yes, we have a valid connection
5328 static int drbd_do_features(struct drbd_connection *connection)
5330 /* ASSERT current == connection->receiver ... */
5336 err = drbd_send_features(connection);
5340 err = drbd_recv_header(connection, &pi);
5345 drbd_err(connection, "expected ConnectionFeatures packet, received: %s (0x%04x)\n",
5351 drbd_err(connection, "expected ConnectionFeatures length: %u, received: %u\n",
5357 err = drbd_recv_all_warn(connection, p, expect);
5370 connection->agreed_pro_version = min_t(int, PRO_VERSION_MAX, p->protocol_max);
5371 connection->agreed_features = PRO_FEATURES & be32_to_cpu(p->feature_flags);
5373 drbd_info(connection, "Handshake successful: "
5374 "Agreed network protocol version %d\n", connection->agreed_pro_version);
5376 drbd_info(connection, "Feature flags enabled on protocol level: 0x%x%s%s%s%s.\n",
5377 connection->agreed_features,
5378 connection->agreed_features & DRBD_FF_TRIM ? " TRIM" : "",
5379 connection->agreed_features & DRBD_FF_THIN_RESYNC ? " THIN_RESYNC" : "",
5380 connection->agreed_features & DRBD_FF_WSAME ? " WRITE_SAME" : "",
5381 connection->agreed_features & DRBD_FF_WZEROES ? " WRITE_ZEROES" :
5382 connection->agreed_features ? "" : " none");
5387 drbd_err(connection, "incompatible DRBD dialects: "
5395 static int drbd_do_auth(struct drbd_connection *connection)
5397 drbd_err(connection, "This kernel was build without CONFIG_CRYPTO_HMAC.\n");
5398 drbd_err(connection, "You need to disable 'cram-hmac-alg' in drbd.conf.\n");
5410 static int drbd_do_auth(struct drbd_connection *connection)
5428 nc = rcu_dereference(connection->net_conf);
5434 crypto_shash_descsize(connection->cram_hmac_tfm),
5440 desc->tfm = connection->cram_hmac_tfm;
5442 rv = crypto_shash_setkey(connection->cram_hmac_tfm, (u8 *)secret, key_len);
5444 drbd_err(connection, "crypto_shash_setkey() failed with %d\n", rv);
5451 sock = &connection->data;
5452 if (!conn_prepare_command(connection, sock)) {
5456 rv = !conn_send_command(connection, sock, P_AUTH_CHALLENGE, 0,
5461 err = drbd_recv_header(connection, &pi);
5468 drbd_err(connection, "expected AuthChallenge packet, received: %s (0x%04x)\n",
5475 drbd_err(connection, "expected AuthChallenge payload too big.\n");
5481 drbd_err(connection, "AuthChallenge payload too small.\n");
5488 drbd_err(connection, "kmalloc of peers_ch failed\n");
5493 err = drbd_recv_all_warn(connection, peers_ch, pi.size);
5500 drbd_err(connection, "Peer presented the same challenge!\n");
5505 resp_size = crypto_shash_digestsize(connection->cram_hmac_tfm);
5508 drbd_err(connection, "kmalloc of response failed\n");
5515 drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv);
5520 if (!conn_prepare_command(connection, sock)) {
5524 rv = !conn_send_command(connection, sock, P_AUTH_RESPONSE, 0,
5529 err = drbd_recv_header(connection, &pi);
5536 drbd_err(connection, "expected AuthResponse packet, received: %s (0x%04x)\n",
5543 drbd_err(connection, "expected AuthResponse payload of wrong size\n");
5548 err = drbd_recv_all_warn(connection, response , resp_size);
5556 drbd_err(connection, "kmalloc of right_response failed\n");
5564 drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv);
5572 drbd_info(connection, "Peer authenticated using %d bytes HMAC\n",
5592 struct drbd_connection *connection = thi->connection;
5595 drbd_info(connection, "receiver (re)started\n");
5598 h = conn_connect(connection);
5600 conn_disconnect(connection);
5604 drbd_warn(connection, "Discarding network configuration.\n");
5605 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
5610 blk_start_plug(&connection->receiver_plug);
5611 drbdd(connection);
5612 blk_finish_plug(&connection->receiver_plug);
5615 conn_disconnect(connection);
5617 drbd_info(connection, "receiver terminated\n");
5623 static int got_conn_RqSReply(struct drbd_connection *connection, struct packet_info *pi)
5629 set_bit(CONN_WD_ST_CHG_OKAY, &connection->flags);
5631 set_bit(CONN_WD_ST_CHG_FAIL, &connection->flags);
5632 drbd_err(connection, "Requested state change failed by peer: %s (%d)\n",
5635 wake_up(&connection->ping_wait);
5640 static int got_RqSReply(struct drbd_connection *connection, struct packet_info *pi)
5647 peer_device = conn_peer_device(connection, pi->vnr);
5652 if (test_bit(CONN_WD_ST_CHG_REQ, &connection->flags)) {
5653 D_ASSERT(device, connection->agreed_pro_version < 100);
5654 return got_conn_RqSReply(connection, pi);
5669 static int got_Ping(struct drbd_connection *connection, struct packet_info *pi)
5671 return drbd_send_ping_ack(connection);
5675 static int got_PingAck(struct drbd_connection *connection, struct packet_info *pi)
5678 connection->meta.socket->sk->sk_rcvtimeo = connection->net_conf->ping_int*HZ;
5679 if (!test_and_set_bit(GOT_PING_ACK, &connection->flags))
5680 wake_up(&connection->ping_wait);
5685 static int got_IsInSync(struct drbd_connection *connection, struct packet_info *pi)
5693 peer_device = conn_peer_device(connection, pi->vnr);
5698 D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89);
5737 static int got_BlockAck(struct drbd_connection *connection, struct packet_info *pi)
5746 peer_device = conn_peer_device(connection, pi->vnr);
5783 static int got_NegAck(struct drbd_connection *connection, struct packet_info *pi)
5792 peer_device = conn_peer_device(connection, pi->vnr);
5819 static int got_NegDReply(struct drbd_connection *connection, struct packet_info *pi)
5826 peer_device = conn_peer_device(connection, pi->vnr);
5841 static int got_NegRSDReply(struct drbd_connection *connection, struct packet_info *pi)
5849 peer_device = conn_peer_device(connection, pi->vnr);
5877 static int got_BarrierAck(struct drbd_connection *connection, struct packet_info *pi)
5883 tl_release(connection, p->barrier, be32_to_cpu(p->set_size));
5886 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
5901 static int got_OVResult(struct drbd_connection *connection, struct packet_info *pi)
5910 peer_device = conn_peer_device(connection, pi->vnr);
5942 drbd_queue_work(&peer_device->connection->sender_work, &dw->w);
5953 static int got_skip(struct drbd_connection *connection, struct packet_info *pi)
5960 int (*fn)(struct drbd_connection *connection, struct packet_info *);
5963 static void set_rcvtimeo(struct drbd_connection *connection, bool ping_timeout)
5969 nc = rcu_dereference(connection->net_conf);
5977 connection->meta.socket->sk->sk_rcvtimeo = t;
5980 static void set_ping_timeout(struct drbd_connection *connection)
5982 set_rcvtimeo(connection, 1);
5985 static void set_idle_timeout(struct drbd_connection *connection)
5987 set_rcvtimeo(connection, 0);
6012 struct drbd_connection *connection = thi->connection;
6017 void *buf = connection->meta.rbuf;
6019 unsigned int header_size = drbd_header_size(connection);
6028 conn_reclaim_net_peer_reqs(connection);
6030 if (test_and_clear_bit(SEND_PING, &connection->flags)) {
6031 if (drbd_send_ping(connection)) {
6032 drbd_err(connection, "drbd_send_ping has failed\n");
6035 set_ping_timeout(connection);
6040 rv = drbd_recv_short(connection->meta.socket, buf, expect-received, 0);
6045 * -ECONNRESET other side closed the connection
6050 * rv == 0 : "connection shut down by peer"
6056 if (test_bit(DISCONNECT_SENT, &connection->flags)) {
6059 t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10;
6062 t = wait_event_timeout(connection->ping_wait,
6063 connection->cstate < C_WF_REPORT_PARAMS,
6068 drbd_err(connection, "meta connection shut down by peer.\n");
6073 if (time_after(connection->last_received, pre_recv_jif))
6076 drbd_err(connection, "PingAck did not arrive in time.\n");
6079 set_bit(SEND_PING, &connection->flags);
6088 drbd_err(connection, "sock_recvmsg returned %d\n", rv);
6093 if (decode_header(connection, connection->meta.rbuf, &pi))
6097 drbd_err(connection, "Unexpected meta packet %s (0x%04x)\n",
6103 drbd_err(connection, "Wrong packet size on meta (c: %d, l: %d)\n",
6111 err = cmd->fn(connection, &pi);
6113 drbd_err(connection, "%ps failed\n", cmd->fn);
6117 connection->last_received = jiffies;
6120 set_idle_timeout(connection);
6124 buf = connection->meta.rbuf;
6133 conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD);
6134 conn_md_sync(connection);
6138 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
6141 drbd_info(connection, "ack_receiver terminated\n");
6150 struct drbd_connection *connection = peer_device->connection;
6156 nc = rcu_dereference(connection->net_conf);
6161 tcp_sock_set_cork(connection->meta.socket->sk, true);
6169 conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD);
6174 tcp_sock_set_cork(connection->meta.socket->sk, false);