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