Lines Matching refs:connection
175 * @connection: DRBD connection.
181 * termination of the connection.
183 void tl_release(struct drbd_connection *connection, unsigned int barrier_nr,
191 spin_lock_irq(&connection->resource->req_lock);
195 list_for_each_entry(r, &connection->transfer_log, tl_requests) {
220 drbd_err(connection, "BAD! BarrierAck #%u received, but no epoch in tl!?\n",
225 drbd_err(connection, "BAD! BarrierAck #%u received, expected #%u!\n",
231 drbd_err(connection, "BAD! BarrierAck #%u received with n_writes=%u, expected n_writes=%u!\n",
240 list_for_each_entry(req, &connection->transfer_log, tl_requests)
245 req = list_prepare_entry(tmp, &connection->transfer_log, tl_requests);
246 list_for_each_entry_safe_from(req, r, &connection->transfer_log, tl_requests) {
251 spin_unlock_irq(&connection->resource->req_lock);
256 spin_unlock_irq(&connection->resource->req_lock);
257 conn_request_state(connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD);
263 * @connection: DRBD connection to operate on.
270 void _tl_restart(struct drbd_connection *connection, enum drbd_req_event what)
274 list_for_each_entry_safe(req, r, &connection->transfer_log, tl_requests)
278 void tl_restart(struct drbd_connection *connection, enum drbd_req_event what)
280 spin_lock_irq(&connection->resource->req_lock);
281 _tl_restart(connection, what);
282 spin_unlock_irq(&connection->resource->req_lock);
289 * This is called after the connection to the peer was lost. The storage covered
293 void tl_clear(struct drbd_connection *connection)
295 tl_restart(connection, CONNECTION_LOST_WHILE_PENDING);
304 struct drbd_connection *connection = first_peer_device(device)->connection;
307 spin_lock_irq(&connection->resource->req_lock);
308 list_for_each_entry_safe(req, r, &connection->transfer_log, tl_requests) {
315 spin_unlock_irq(&connection->resource->req_lock);
363 if (thi->connection)
364 kref_put(&thi->connection->kref, drbd_destroy_connection);
378 thi->connection = NULL;
405 if (thi->connection)
406 kref_get(&thi->connection->kref);
420 if (thi->connection)
421 kref_put(&thi->connection->kref, drbd_destroy_connection);
483 int conn_lowest_minor(struct drbd_connection *connection)
489 peer_device = idr_get_next(&connection->peer_devices, &vnr);
564 unsigned int drbd_header_size(struct drbd_connection *connection)
566 if (connection->agreed_pro_version >= 100) {
604 static unsigned int prepare_header(struct drbd_connection *connection, int vnr,
607 if (connection->agreed_pro_version >= 100)
609 else if (connection->agreed_pro_version >= 95 &&
616 static void *__conn_prepare_command(struct drbd_connection *connection,
621 return sock->sbuf + drbd_header_size(connection);
624 void *conn_prepare_command(struct drbd_connection *connection, struct drbd_socket *sock)
629 p = __conn_prepare_command(connection, sock);
638 return conn_prepare_command(peer_device->connection, sock);
641 static int __send_command(struct drbd_connection *connection, int vnr,
658 header_size += prepare_header(connection, vnr, sock->sbuf, cmd,
660 err = drbd_send_all(connection, sock->socket, sock->sbuf, header_size,
663 err = drbd_send_all(connection, sock->socket, data, size, 0);
672 static int __conn_send_command(struct drbd_connection *connection, struct drbd_socket *sock,
676 return __send_command(connection, 0, sock, cmd, header_size, data, size);
679 int conn_send_command(struct drbd_connection *connection, struct drbd_socket *sock,
685 err = __conn_send_command(connection, sock, cmd, header_size, data, size);
696 err = __send_command(peer_device->connection, peer_device->device->vnr,
702 int drbd_send_ping(struct drbd_connection *connection)
706 sock = &connection->meta;
707 if (!conn_prepare_command(connection, sock))
709 return conn_send_command(connection, sock, P_PING, 0, NULL, 0);
712 int drbd_send_ping_ack(struct drbd_connection *connection)
716 sock = &connection->meta;
717 if (!conn_prepare_command(connection, sock))
719 return conn_send_command(connection, sock, P_PING_ACK, 0, NULL, 0);
727 const int apv = peer_device->connection->agreed_pro_version;
732 sock = &peer_device->connection->data;
738 nc = rcu_dereference(peer_device->connection->net_conf);
776 int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cmd)
783 sock = &connection->data;
784 p = __conn_prepare_command(connection, sock);
789 nc = rcu_dereference(connection->net_conf);
791 if (nc->tentative && connection->agreed_pro_version < 92) {
793 drbd_err(connection, "--dry-run is not supported by peer");
798 if (connection->agreed_pro_version >= 87)
813 if (connection->agreed_pro_version >= 87)
817 return __conn_send_command(connection, sock, cmd, size, NULL, 0);
820 int drbd_send_protocol(struct drbd_connection *connection)
824 mutex_lock(&connection->data.mutex);
825 err = __drbd_send_protocol(connection, P_PROTOCOL);
826 mutex_unlock(&connection->data.mutex);
841 sock = &peer_device->connection->data;
855 uuid_flags |= rcu_dereference(peer_device->connection->net_conf)->discard_my_data ? 1 : 0;
911 sock = &peer_device->connection->data;
954 sock = &peer_device->connection->data;
960 if (peer_device->connection->agreed_features & DRBD_FF_WSAME)
983 if (peer_device->connection->agreed_pro_version <= 94)
985 else if (peer_device->connection->agreed_pro_version < 100)
1010 sock = &peer_device->connection->data;
1033 sock = &peer_device->connection->data;
1046 sock = &peer_device->connection->data;
1055 int conn_send_state_req(struct drbd_connection *connection, union drbd_state mask, union drbd_state val)
1061 cmd = connection->agreed_pro_version < 100 ? P_STATE_CHG_REQ : P_CONN_ST_CHG_REQ;
1062 sock = &connection->data;
1063 p = conn_prepare_command(connection, sock);
1068 return conn_send_command(connection, sock, cmd, sizeof(*p), NULL, 0);
1076 sock = &peer_device->connection->meta;
1084 void conn_send_sr_reply(struct drbd_connection *connection, enum drbd_state_rv retcode)
1088 enum drbd_packet cmd = connection->agreed_pro_version < 100 ? P_STATE_CHG_REPLY : P_CONN_ST_CHG_REPLY;
1090 sock = &connection->meta;
1091 p = conn_prepare_command(connection, sock);
1094 conn_send_command(connection, sock, cmd, sizeof(*p), NULL, 0);
1130 use_rle = rcu_dereference(first_peer_device(device)->connection->net_conf)->use_rle;
1132 if (!use_rle || first_peer_device(device)->connection->agreed_pro_version < 90)
1221 struct drbd_socket *sock = &first_peer_device(device)->connection->data;
1222 unsigned int header_size = drbd_header_size(first_peer_device(device)->connection);
1233 err = __send_command(first_peer_device(device)->connection, device->vnr, sock,
1254 err = __send_command(first_peer_device(device)->connection, device->vnr, sock, P_BITMAP, len, NULL, 0);
1314 struct drbd_socket *sock = &first_peer_device(device)->connection->data;
1324 void drbd_send_b_ack(struct drbd_connection *connection, u32 barrier_nr, u32 set_size)
1329 if (connection->cstate < C_WF_REPORT_PARAMS)
1332 sock = &connection->meta;
1333 p = conn_prepare_command(connection, sock);
1338 conn_send_command(connection, sock, P_BARRIER_ACK, sizeof(*p), NULL, 0);
1358 sock = &peer_device->connection->meta;
1375 if (peer_device->connection->peer_integrity_tfm)
1376 data_size -= crypto_shash_digestsize(peer_device->connection->peer_integrity_tfm);
1419 sock = &peer_device->connection->data;
1435 sock = &peer_device->connection->data;
1453 sock = &peer_device->connection->data;
1468 sock = &peer_device->connection->data;
1480 * true if we think connection is dead
1482 static int we_should_drop_the_connection(struct drbd_connection *connection, struct socket *sock)
1487 drop_it = connection->meta.socket == sock
1488 || !connection->ack_receiver.task
1489 || get_t_state(&connection->ack_receiver) != RUNNING
1490 || connection->cstate < C_WF_REPORT_PARAMS;
1495 drop_it = !--connection->ko_count;
1497 drbd_err(connection, "[%s/%d] sock_sendmsg time expired, ko = %u\n",
1498 current->comm, current->pid, connection->ko_count);
1499 request_ping(connection);
1505 static void drbd_update_congested(struct drbd_connection *connection)
1507 struct sock *sk = connection->data.socket->sk;
1509 set_bit(NET_CONGESTED, &connection->flags);
1540 socket = peer_device->connection->data.socket;
1542 err = drbd_send_all(peer_device->connection, socket, addr, size, msg_flags);
1552 struct socket *socket = peer_device->connection->data.socket;
1566 drbd_update_congested(peer_device->connection);
1573 if (we_should_drop_the_connection(peer_device->connection, socket))
1586 clear_bit(NET_CONGESTED, &peer_device->connection->flags);
1658 static u32 bio_flags_to_wire(struct drbd_connection *connection,
1661 if (connection->agreed_pro_version >= 95)
1668 ((connection->agreed_features & DRBD_FF_WZEROES) ?
1690 sock = &peer_device->connection->data;
1692 digest_size = peer_device->connection->integrity_tfm ?
1693 crypto_shash_digestsize(peer_device->connection->integrity_tfm) : 0;
1700 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio);
1704 if (peer_device->connection->agreed_pro_version >= 100) {
1719 err = __send_command(peer_device->connection, device->vnr, sock, cmd, sizeof(*t), NULL, 0);
1735 drbd_csum_bio(peer_device->connection->integrity_tfm, req->master_bio, digest_out);
1738 __send_command(peer_device->connection, device->vnr, sock, P_WSAME,
1743 __send_command(peer_device->connection, device->vnr, sock, P_DATA,
1767 drbd_csum_bio(peer_device->connection->integrity_tfm, req->master_bio, digest);
1796 sock = &peer_device->connection->data;
1799 digest_size = peer_device->connection->integrity_tfm ?
1800 crypto_shash_digestsize(peer_device->connection->integrity_tfm) : 0;
1809 drbd_csum_ee(peer_device->connection->integrity_tfm, peer_req, p + 1);
1810 err = __send_command(peer_device->connection, device->vnr, sock, cmd, sizeof(*p) + digest_size, NULL, peer_req->i.size);
1823 sock = &peer_device->connection->data;
1848 int drbd_send(struct drbd_connection *connection, struct socket *sock,
1862 if (sock == connection->data.socket) {
1864 connection->ko_count = rcu_dereference(connection->net_conf)->ko_count;
1866 drbd_update_congested(connection);
1871 if (we_should_drop_the_connection(connection, sock))
1885 if (sock == connection->data.socket)
1886 clear_bit(NET_CONGESTED, &connection->flags);
1890 drbd_err(connection, "%s_sendmsg returned %d\n",
1891 sock == connection->meta.socket ? "msock" : "sock",
1893 conn_request_state(connection, NS(conn, C_BROKEN_PIPE), CS_HARD);
1895 conn_request_state(connection, NS(conn, C_TIMEOUT), CS_HARD);
1906 int drbd_send_all(struct drbd_connection *connection, struct socket *sock, void *buffer,
1911 err = drbd_send(connection, sock, buffer, size, msg_flags);
1960 &first_peer_device(device)->connection->sender_work,
2052 if (first_peer_device(device)->connection->receiver.t_state != NONE)
2054 first_peer_device(device)->connection->receiver.t_state);
2072 D_ASSERT(device, first_peer_device(device)->connection->net_conf == NULL);
2093 D_ASSERT(device, list_empty(&first_peer_device(device)->connection->sender_work.q));
2260 /* not for_each_connection(connection, resource):
2264 kref_put(&peer_device->connection->kref, drbd_destroy_connection);
2366 struct drbd_connection *connection, *tmp;
2368 for_each_connection_safe(connection, tmp, resource) {
2369 list_del(&connection->connections);
2370 drbd_debugfs_connection_cleanup(connection);
2371 kref_put(&connection->kref, drbd_destroy_connection);
2473 struct drbd_connection *connection;
2477 for_each_connection_rcu(connection, resource) {
2478 if (connection->my_addr_len == my_addr_len &&
2479 connection->peer_addr_len == peer_addr_len &&
2480 !memcmp(&connection->my_addr, my_addr, my_addr_len) &&
2481 !memcmp(&connection->peer_addr, peer_addr, peer_addr_len)) {
2482 kref_get(&connection->kref);
2487 connection = NULL;
2490 return connection;
2510 void conn_free_crypto(struct drbd_connection *connection)
2512 drbd_free_sock(connection);
2514 crypto_free_shash(connection->csums_tfm);
2515 crypto_free_shash(connection->verify_tfm);
2516 crypto_free_shash(connection->cram_hmac_tfm);
2517 crypto_free_shash(connection->integrity_tfm);
2518 crypto_free_shash(connection->peer_integrity_tfm);
2519 kfree(connection->int_dig_in);
2520 kfree(connection->int_dig_vv);
2522 connection->csums_tfm = NULL;
2523 connection->verify_tfm = NULL;
2524 connection->cram_hmac_tfm = NULL;
2525 connection->integrity_tfm = NULL;
2526 connection->peer_integrity_tfm = NULL;
2527 connection->int_dig_in = NULL;
2528 connection->int_dig_vv = NULL;
2533 struct drbd_connection *connection;
2569 for_each_connection_rcu(connection, resource) {
2570 connection->receiver.reset_cpu_mask = 1;
2571 connection->ack_receiver.reset_cpu_mask = 1;
2572 connection->worker.reset_cpu_mask = 1;
2618 struct drbd_connection *connection;
2620 connection = kzalloc(sizeof(struct drbd_connection), GFP_KERNEL);
2621 if (!connection)
2624 if (drbd_alloc_socket(&connection->data))
2626 if (drbd_alloc_socket(&connection->meta))
2629 connection->current_epoch = kzalloc(sizeof(struct drbd_epoch), GFP_KERNEL);
2630 if (!connection->current_epoch)
2633 INIT_LIST_HEAD(&connection->transfer_log);
2635 INIT_LIST_HEAD(&connection->current_epoch->list);
2636 connection->epochs = 1;
2637 spin_lock_init(&connection->epoch_lock);
2639 connection->send.seen_any_write_yet = false;
2640 connection->send.current_epoch_nr = 0;
2641 connection->send.current_epoch_writes = 0;
2647 connection->cstate = C_STANDALONE;
2648 mutex_init(&connection->cstate_mutex);
2649 init_waitqueue_head(&connection->ping_wait);
2650 idr_init(&connection->peer_devices);
2652 drbd_init_workqueue(&connection->sender_work);
2653 mutex_init(&connection->data.mutex);
2654 mutex_init(&connection->meta.mutex);
2656 drbd_thread_init(resource, &connection->receiver, drbd_receiver, "receiver");
2657 connection->receiver.connection = connection;
2658 drbd_thread_init(resource, &connection->worker, drbd_worker, "worker");
2659 connection->worker.connection = connection;
2660 drbd_thread_init(resource, &connection->ack_receiver, drbd_ack_receiver, "ack_recv");
2661 connection->ack_receiver.connection = connection;
2663 kref_init(&connection->kref);
2665 connection->resource = resource;
2671 list_add_tail_rcu(&connection->connections, &resource->connections);
2672 drbd_debugfs_connection_add(connection);
2673 return connection;
2679 kfree(connection->current_epoch);
2680 drbd_free_socket(&connection->meta);
2681 drbd_free_socket(&connection->data);
2682 kfree(connection);
2688 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
2689 struct drbd_resource *resource = connection->resource;
2691 if (atomic_read(&connection->current_epoch->epoch_size) != 0)
2692 drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
2693 kfree(connection->current_epoch);
2695 idr_destroy(&connection->peer_devices);
2697 drbd_free_socket(&connection->meta);
2698 drbd_free_socket(&connection->data);
2699 kfree(connection->int_dig_in);
2700 kfree(connection->int_dig_vv);
2701 memset(connection, 0xfc, sizeof(*connection));
2702 kfree(connection);
2723 struct drbd_connection *connection, *n;
2800 for_each_connection(connection, resource) {
2804 peer_device->connection = connection;
2810 id = idr_alloc(&connection->peer_devices, peer_device, vnr, vnr + 1, GFP_KERNEL);
2816 kref_get(&connection->kref);
2827 /* inherit the connection state */
2840 for_each_connection_safe(connection, n, resource) {
2841 peer_device = idr_remove(&connection->peer_devices, vnr);
2843 kref_put(&connection->kref, drbd_destroy_connection);
2870 struct drbd_connection *connection;
2877 for_each_connection(connection, resource) {
2878 idr_remove(&connection->peer_devices, device->vnr);
2980 void drbd_free_sock(struct drbd_connection *connection)
2982 if (connection->data.socket)
2983 drbd_free_one_sock(&connection->data);
2984 if (connection->meta.socket)
2985 drbd_free_one_sock(&connection->meta);
2990 void conn_md_sync(struct drbd_connection *connection)
2996 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
3543 D_ASSERT(device, current == first_peer_device(device)->connection->worker.task);
3563 drbd_queue_work(&first_peer_device(device)->connection->sender_work,
3585 D_ASSERT(device, current != first_peer_device(device)->connection->worker.task);
3714 nc = rcu_dereference(first_peer_device(device)->connection->net_conf);