Lines Matching +full:l2 +full:- +full:ws +full:- +full:latency

1 // SPDX-License-Identifier: GPL-2.0-only
7 Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
8 Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
9 Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
68 * page->private being our "next" pointer.
90 if (--n == 0) in page_chain_del()
160 drbd_pp_vacant -= number; in __drbd_alloc_pages()
166 /* GFP_TRY, because we must not cause arbitrary write-out: in a DRBD in __drbd_alloc_pages()
167 * "criss-cross" setup, that might cause write-out on some other DRBD, in __drbd_alloc_pages()
203 list_for_each_entry_safe(peer_req, tmp, &device->net_ee, w.list) { in reclaim_finished_net_peer_reqs()
206 list_move(&peer_req->w.list, to_be_freed); in reclaim_finished_net_peer_reqs()
215 spin_lock_irq(&device->resource->req_lock); in drbd_reclaim_net_peer_reqs()
217 spin_unlock_irq(&device->resource->req_lock); in drbd_reclaim_net_peer_reqs()
228 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { in conn_reclaim_net_peer_reqs()
229 struct drbd_device *device = peer_device->device; in conn_reclaim_net_peer_reqs()
230 if (!atomic_read(&device->pp_in_use_by_net)) in conn_reclaim_net_peer_reqs()
233 kref_get(&device->kref); in conn_reclaim_net_peer_reqs()
236 kref_put(&device->kref, drbd_destroy_device); in conn_reclaim_net_peer_reqs()
243 * drbd_alloc_pages() - Returns @number pages, retries forever (or until signalled)
255 * We do not use max-buffers as hard limit, because it could lead to
256 * congestion and further to a distributed deadlock during online-verify or
257 * (checksum based) resync, if the max-buffers, socket buffer sizes and
258 * resync-rate settings are mis-configured.
260 * Returns a page chain linked via page->private.
265 struct drbd_device *device = peer_device->device; in drbd_alloc_pages()
272 nc = rcu_dereference(peer_device->connection->net_conf); in drbd_alloc_pages()
273 mxb = nc ? nc->max_buffers : 1000000; in drbd_alloc_pages()
276 if (atomic_read(&device->pp_in_use) < mxb) in drbd_alloc_pages()
281 if (page && atomic_read(&device->pp_in_use_by_net) > 512) in drbd_alloc_pages()
289 if (atomic_read(&device->pp_in_use) < mxb) { in drbd_alloc_pages()
309 atomic_add(number, &device->pp_in_use); in drbd_alloc_pages()
314 * Is also used from inside an other spin_lock_irq(&resource->req_lock);
319 atomic_t *a = is_net ? &device->pp_in_use_by_net : &device->pp_in_use; in drbd_free_pages()
363 struct drbd_device *device = peer_device->device; in drbd_alloc_peer_req()
386 INIT_LIST_HEAD(&peer_req->w.list); in drbd_alloc_peer_req()
387 drbd_clear_interval(&peer_req->i); in drbd_alloc_peer_req()
388 peer_req->i.size = request_size; in drbd_alloc_peer_req()
389 peer_req->i.sector = sector; in drbd_alloc_peer_req()
390 peer_req->submit_jif = jiffies; in drbd_alloc_peer_req()
391 peer_req->peer_device = peer_device; in drbd_alloc_peer_req()
392 peer_req->pages = page; in drbd_alloc_peer_req()
397 peer_req->block_id = id; in drbd_alloc_peer_req()
410 if (peer_req->flags & EE_HAS_DIGEST) in __drbd_free_peer_req()
411 kfree(peer_req->digest); in __drbd_free_peer_req()
412 drbd_free_pages(device, peer_req->pages, is_net); in __drbd_free_peer_req()
413 D_ASSERT(device, atomic_read(&peer_req->pending_bios) == 0); in __drbd_free_peer_req()
414 D_ASSERT(device, drbd_interval_empty(&peer_req->i)); in __drbd_free_peer_req()
415 if (!expect(device, !(peer_req->flags & EE_CALL_AL_COMPLETE_IO))) { in __drbd_free_peer_req()
416 peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO; in __drbd_free_peer_req()
417 drbd_al_complete_io(device, &peer_req->i); in __drbd_free_peer_req()
427 int is_net = list == &device->net_ee; in drbd_free_peer_reqs()
429 spin_lock_irq(&device->resource->req_lock); in drbd_free_peer_reqs()
431 spin_unlock_irq(&device->resource->req_lock); in drbd_free_peer_reqs()
450 spin_lock_irq(&device->resource->req_lock); in drbd_finish_peer_reqs()
452 list_splice_init(&device->done_ee, &work_list); in drbd_finish_peer_reqs()
453 spin_unlock_irq(&device->resource->req_lock); in drbd_finish_peer_reqs()
466 err2 = peer_req->w.cb(&peer_req->w, !!err); in drbd_finish_peer_reqs()
471 wake_up(&device->ee_wait); in drbd_finish_peer_reqs()
484 prepare_to_wait(&device->ee_wait, &wait, TASK_UNINTERRUPTIBLE); in _drbd_wait_ee_list_empty()
485 spin_unlock_irq(&device->resource->req_lock); in _drbd_wait_ee_list_empty()
487 finish_wait(&device->ee_wait, &wait); in _drbd_wait_ee_list_empty()
488 spin_lock_irq(&device->resource->req_lock); in _drbd_wait_ee_list_empty()
495 spin_lock_irq(&device->resource->req_lock); in drbd_wait_ee_list_empty()
497 spin_unlock_irq(&device->resource->req_lock); in drbd_wait_ee_list_empty()
517 rv = drbd_recv_short(connection->data.socket, buf, size, 0); in drbd_recv()
520 if (rv == -ECONNRESET) in drbd_recv()
522 else if (rv != -ERESTARTSYS) 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()
553 err = -EIO; in drbd_recv_all()
579 sock->sk->sk_sndbuf = snd; in drbd_setbufsize()
580 sock->sk->sk_userlocks |= SOCK_SNDBUF_LOCK; in drbd_setbufsize()
583 sock->sk->sk_rcvbuf = rcv; in drbd_setbufsize()
584 sock->sk->sk_userlocks |= SOCK_RCVBUF_LOCK; in drbd_setbufsize()
600 nc = rcu_dereference(connection->net_conf); in drbd_try_connect()
605 sndbuf_size = nc->sndbuf_size; in drbd_try_connect()
606 rcvbuf_size = nc->rcvbuf_size; in drbd_try_connect()
607 connect_int = nc->connect_int; 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()
616 ((struct sockaddr_in *)&src_in6)->sin_port = 0; /* AF_INET & AF_SCI */ 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()
622 err = sock_create_kern(&init_net, ((struct sockaddr *)&src_in6)->sa_family, in drbd_try_connect()
629 sock->sk->sk_rcvtimeo = in drbd_try_connect()
630 sock->sk->sk_sndtimeo = connect_int * HZ; in drbd_try_connect()
641 err = sock->ops->bind(sock, (struct sockaddr *) &src_in6, my_addr_len); in drbd_try_connect()
649 err = sock->ops->connect(sock, (struct sockaddr *) &peer_in6, peer_addr_len, 0); in drbd_try_connect()
657 switch (-err) { in drbd_try_connect()
686 struct accept_wait_data *ad = sk->sk_user_data; in drbd_incoming_connection()
689 state_change = ad->original_sk_state_change; in drbd_incoming_connection()
690 if (sk->sk_state == TCP_ESTABLISHED) in drbd_incoming_connection()
691 complete(&ad->door_bell); in drbd_incoming_connection()
704 nc = rcu_dereference(connection->net_conf); in prepare_listen_socket()
707 return -EIO; in prepare_listen_socket()
709 sndbuf_size = nc->sndbuf_size; in prepare_listen_socket()
710 rcvbuf_size = nc->rcvbuf_size; 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()
717 err = sock_create_kern(&init_net, ((struct sockaddr *)&my_addr)->sa_family, in prepare_listen_socket()
724 s_listen->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */ in prepare_listen_socket()
728 err = s_listen->ops->bind(s_listen, (struct sockaddr *)&my_addr, my_addr_len); in prepare_listen_socket()
732 ad->s_listen = s_listen; in prepare_listen_socket()
733 write_lock_bh(&s_listen->sk->sk_callback_lock); in prepare_listen_socket()
734 ad->original_sk_state_change = s_listen->sk->sk_state_change; in prepare_listen_socket()
735 s_listen->sk->sk_state_change = drbd_incoming_connection; in prepare_listen_socket()
736 s_listen->sk->sk_user_data = ad; in prepare_listen_socket()
737 write_unlock_bh(&s_listen->sk->sk_callback_lock); in prepare_listen_socket()
740 err = s_listen->ops->listen(s_listen, 5); in prepare_listen_socket()
749 if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { in prepare_listen_socket()
755 return -EIO; in prepare_listen_socket()
760 write_lock_bh(&sk->sk_callback_lock); in unregister_state_change()
761 sk->sk_state_change = ad->original_sk_state_change; in unregister_state_change()
762 sk->sk_user_data = NULL; in unregister_state_change()
763 write_unlock_bh(&sk->sk_callback_lock); in unregister_state_change()
773 nc = rcu_dereference(connection->net_conf); in drbd_wait_for_connect()
778 connect_int = nc->connect_int; in drbd_wait_for_connect()
783 timeo += get_random_u32_below(2) ? timeo / 7 : -timeo / 7; in drbd_wait_for_connect()
785 err = wait_for_completion_interruptible_timeout(&ad->door_bell, timeo); in drbd_wait_for_connect()
789 err = kernel_accept(ad->s_listen, &s_estab, 0); in drbd_wait_for_connect()
791 if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { in drbd_wait_for_connect()
798 unregister_state_change(s_estab->sk, ad); in drbd_wait_for_connect()
809 return -EIO; in send_first_packet()
821 nc = rcu_dereference(connection->net_conf); in receive_first_packet()
824 return -EIO; in receive_first_packet()
826 sock->sk->sk_rcvtimeo = nc->ping_timeo * 4 * HZ / 10; in receive_first_packet()
829 err = drbd_recv_short(sock, connection->data.rbuf, header_size, 0); in receive_first_packet()
832 err = -EIO; in receive_first_packet()
835 err = decode_header(connection, connection->data.rbuf, &pi); in receive_first_packet()
842 * drbd_socket_okay() - Free the socket if its connection is not okay
855 if (rr > 0 || rr == -EAGAIN) { in drbd_socket_okay()
876 nc = rcu_dereference(connection->net_conf); in connection_established()
877 timeout = (nc->sock_check_timeo ?: nc->ping_timeo) * HZ / 10; in connection_established()
891 struct drbd_device *device = peer_device->device; in drbd_connected()
894 atomic_set(&device->packet_seq, 0); in drbd_connected()
895 device->peer_seq = 0; in drbd_connected()
897 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ? in drbd_connected()
898 &peer_device->connection->cstate_mutex : in drbd_connected()
899 &device->own_state_mutex; in drbd_connected()
908 clear_bit(USE_DEGR_WFC_T, &device->flags); in drbd_connected()
909 clear_bit(RESIZE_PENDING, &device->flags); in drbd_connected()
910 atomic_set(&device->ap_in_flight, 0); in drbd_connected()
911 mod_timer(&device->request_timer, jiffies + HZ); /* just start it here. */ in drbd_connected()
919 * -1 peer talks different language,
921 * -2 We do not have a network config...
936 clear_bit(DISCONNECT_SENT, &connection->flags); in conn_connect()
938 return -2; 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()
964 clear_bit(RESOLVE_CONFLICTS, &connection->flags); in conn_connect()
993 set_bit(RESOLVE_CONFLICTS, &connection->flags); in conn_connect()
1011 if (connection->cstate <= C_DISCONNECTING) in conn_connect()
1016 if (get_t_state(&connection->receiver) == EXITING) in conn_connect()
1026 sock.socket->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */ in conn_connect()
1027 msock.socket->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */ in conn_connect()
1029 sock.socket->sk->sk_allocation = GFP_NOIO; in conn_connect()
1030 msock.socket->sk->sk_allocation = GFP_NOIO; in conn_connect()
1032 sock.socket->sk->sk_use_task_frag = false; in conn_connect()
1033 msock.socket->sk->sk_use_task_frag = false; in conn_connect()
1035 sock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE_BULK; in conn_connect()
1036 msock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE; in conn_connect()
1039 * sock.socket->sk->sk_sndtimeo = connection->net_conf->timeout*HZ/10; in conn_connect()
1040 * sock.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; in conn_connect()
1044 nc = rcu_dereference(connection->net_conf); in conn_connect()
1046 sock.socket->sk->sk_sndtimeo = in conn_connect()
1047 sock.socket->sk->sk_rcvtimeo = nc->ping_timeo*4*HZ/10; in conn_connect()
1049 msock.socket->sk->sk_rcvtimeo = nc->ping_int*HZ; in conn_connect()
1050 timeout = nc->timeout * HZ / 10; in conn_connect()
1051 discard_my_data = nc->discard_my_data; in conn_connect()
1054 msock.socket->sk->sk_sndtimeo = timeout; in conn_connect()
1058 tcp_sock_set_nodelay(sock.socket->sk); in conn_connect()
1059 tcp_sock_set_nodelay(msock.socket->sk); 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()
1069 if (connection->cram_hmac_tfm) { in conn_connect()
1072 case -1: in conn_connect()
1074 return -1; 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()
1085 return -1; in conn_connect()
1087 /* Prevent a race between resync-handshake and in conn_connect()
1094 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) in conn_connect()
1095 mutex_lock(peer_device->device->state_mutex); 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()
1103 mutex_unlock(peer_device->device->state_mutex); in conn_connect()
1106 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { in conn_connect()
1107 struct drbd_device *device = peer_device->device; in conn_connect()
1108 kref_get(&device->kref); in conn_connect()
1112 set_bit(DISCARD_MY_DATA, &device->flags); in conn_connect()
1114 clear_bit(DISCARD_MY_DATA, &device->flags); in conn_connect()
1117 kref_put(&device->kref, drbd_destroy_device); 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()
1138 mutex_lock(&connection->resource->conf_update); in conn_connect()
1139 /* The discard_my_data flag is a single-shot modifier to the next in conn_connect()
1143 connection->net_conf->discard_my_data = 0; in conn_connect()
1144 mutex_unlock(&connection->resource->conf_update); in conn_connect()
1155 return -1; in conn_connect()
1165 if (h->pad != 0) { in decode_header()
1167 return -EINVAL; in decode_header()
1169 pi->vnr = be16_to_cpu(h->volume); in decode_header()
1170 pi->cmd = be16_to_cpu(h->command); in decode_header()
1171 pi->size = be32_to_cpu(h->length); in decode_header()
1175 pi->cmd = be16_to_cpu(h->command); in decode_header()
1176 pi->size = be32_to_cpu(h->length); in decode_header()
1177 pi->vnr = 0; in decode_header()
1181 pi->cmd = be16_to_cpu(h->command); in decode_header()
1182 pi->size = be16_to_cpu(h->length); in decode_header()
1183 pi->vnr = 0; in decode_header()
1187 connection->agreed_pro_version); in decode_header()
1188 return -EINVAL; in decode_header()
1190 pi->data = header + header_size; in decode_header()
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()
1204 void *buffer = connection->data.rbuf; in drbd_recv_header()
1212 connection->last_received = jiffies; in drbd_recv_header()
1219 void *buffer = connection->data.rbuf; 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()
1226 * application latency, try to drain the backend queues as in drbd_recv_header_maybe_unplug()
1229 if (err == -EAGAIN) { in drbd_recv_header_maybe_unplug()
1230 tcp_sock_set_quickack(connection->data.socket->sk, 2); in drbd_recv_header_maybe_unplug()
1235 size -= err; 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()
1263 struct one_flush_context *octx = bio->bi_private; in one_flush_endio()
1264 struct drbd_device *device = octx->device; in one_flush_endio()
1265 struct issue_flush_context *ctx = octx->ctx; in one_flush_endio()
1267 if (bio->bi_status) { in one_flush_endio()
1268 ctx->error = blk_status_to_errno(bio->bi_status); in one_flush_endio()
1269 drbd_info(device, "local disk FLUSH FAILED with status %d\n", bio->bi_status); in one_flush_endio()
1274 clear_bit(FLUSH_PENDING, &device->flags); in one_flush_endio()
1276 kref_put(&device->kref, drbd_destroy_device); in one_flush_endio()
1278 if (atomic_dec_and_test(&ctx->pending)) in one_flush_endio()
1279 complete(&ctx->done); in one_flush_endio()
1284 struct bio *bio = bio_alloc(device->ldev->backing_bdev, 0, in submit_one_flush()
1295 ctx->error = -ENOMEM; in submit_one_flush()
1297 kref_put(&device->kref, drbd_destroy_device); in submit_one_flush()
1301 octx->device = device; in submit_one_flush()
1302 octx->ctx = ctx; in submit_one_flush()
1303 bio->bi_private = octx; in submit_one_flush()
1304 bio->bi_end_io = one_flush_endio; in submit_one_flush()
1306 device->flush_jif = jiffies; in submit_one_flush()
1307 set_bit(FLUSH_PENDING, &device->flags); in submit_one_flush()
1308 atomic_inc(&ctx->pending); in submit_one_flush()
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()
1325 struct drbd_device *device = peer_device->device; in drbd_flush()
1329 kref_get(&device->kref); in drbd_flush()
1339 * if disk-timeout is set? */ in drbd_flush()
1346 * if (rv == -EOPNOTSUPP) */ in drbd_flush()
1348 drbd_bump_write_ordering(connection->resource, NULL, WO_DRAIN_IO); in drbd_flush()
1354 * drbd_may_finish_epoch() - Applies an epoch_event to the epoch's state, eventually finishes it.
1367 spin_lock(&connection->epoch_lock); in drbd_may_finish_epoch()
1371 epoch_size = atomic_read(&epoch->epoch_size); in drbd_may_finish_epoch()
1375 atomic_dec(&epoch->active); in drbd_may_finish_epoch()
1378 set_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags); in drbd_may_finish_epoch()
1386 atomic_read(&epoch->active) == 0 && in drbd_may_finish_epoch()
1387 (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags) || ev & EV_CLEANUP)) { 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()
1396 if (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags)) 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()
1401 next_epoch = list_entry(epoch->list.next, struct drbd_epoch, list); in drbd_may_finish_epoch()
1402 list_del(&epoch->list); in drbd_may_finish_epoch()
1404 connection->epochs--; in drbd_may_finish_epoch()
1410 epoch->flags = 0; in drbd_may_finish_epoch()
1411 atomic_set(&epoch->epoch_size, 0); in drbd_may_finish_epoch()
1412 /* atomic_set(&epoch->active, 0); is already zero */ in drbd_may_finish_epoch()
1424 spin_unlock(&connection->epoch_lock); in drbd_may_finish_epoch()
1434 dc = rcu_dereference(bdev->disk_conf); in max_allowed_wo()
1436 if (wo == WO_BDEV_FLUSH && !dc->disk_flushes) in max_allowed_wo()
1438 if (wo == WO_DRAIN_IO && !dc->disk_drain) in max_allowed_wo()
1445 * drbd_bump_write_ordering() - Fall back to an other write ordering method
1460 pwo = resource->write_ordering; in drbd_bump_write_ordering()
1464 idr_for_each_entry(&resource->devices, device, vnr) { in drbd_bump_write_ordering()
1466 wo = max_allowed_wo(device->ldev, wo); in drbd_bump_write_ordering()
1467 if (device->ldev == bdev) in drbd_bump_write_ordering()
1478 resource->write_ordering = wo; in drbd_bump_write_ordering()
1479 if (pwo != resource->write_ordering || wo == WO_BDEV_FLUSH) in drbd_bump_write_ordering()
1480 …drbd_info(resource, "Method to ensure write ordering: %s\n", write_ordering_str[resource->write_or… in drbd_bump_write_ordering()
1485 * Drivers have to "announce" q->limits.max_write_zeroes_sectors, or it
1489 * And dm-thin does not do this (yet), mostly because in general it has
1491 * https://www.mail-archive.com/dm-devel%40redhat.com/msg07965.html
1492 * https://www.redhat.com/archives/dm-devel/2018-January/msg00271.html
1494 * We *may* ignore the discard-zeroes-data setting, if so configured.
1500 * LVM version: 2.02.115(2)-RHEL7 (2015-01-28)
1501 * Library version: 1.02.93-RHEL7 (2015-01-28)
1506 * we zero-out the initial (and/or) trailing unaligned partial chunks,
1515 struct block_device *bdev = device->ldev->backing_bdev; in drbd_issue_discard_or_zero_out()
1524 /* Zero-sector (unknown) and one-sector granularities are the same. */ in drbd_issue_discard_or_zero_out()
1529 max_discard_sectors -= max_discard_sectors % granularity; in drbd_issue_discard_or_zero_out()
1540 /* start + gran - (start + gran - align) % gran */ in drbd_issue_discard_or_zero_out()
1541 tmp = start + granularity - alignment; in drbd_issue_discard_or_zero_out()
1542 tmp = start + granularity - sector_div(tmp, granularity); in drbd_issue_discard_or_zero_out()
1544 nr = tmp - start; in drbd_issue_discard_or_zero_out()
1548 nr_sectors -= nr; in drbd_issue_discard_or_zero_out()
1554 nr_sectors -= max_discard_sectors; in drbd_issue_discard_or_zero_out()
1563 nr -= (unsigned int)nr % granularity; in drbd_issue_discard_or_zero_out()
1566 nr_sectors -= nr; in drbd_issue_discard_or_zero_out()
1583 if (!bdev_max_discard_sectors(device->ldev->backing_bdev)) in can_do_reliable_discards()
1587 dc = rcu_dereference(device->ldev->disk_conf); in can_do_reliable_discards()
1588 can_do = dc->discard_zeroes_if_aligned; in can_do_reliable_discards()
1596 * read-back zeroes in discarded ranges, we fall back to in drbd_issue_peer_discard_or_zero_out()
1597 * zero-out. Unless configuration specifically requested in drbd_issue_peer_discard_or_zero_out()
1600 peer_req->flags |= EE_ZEROOUT; in drbd_issue_peer_discard_or_zero_out()
1602 if (drbd_issue_discard_or_zero_out(device, peer_req->i.sector, in drbd_issue_peer_discard_or_zero_out()
1603 peer_req->i.size >> 9, peer_req->flags & (EE_ZEROOUT|EE_TRIM))) in drbd_issue_peer_discard_or_zero_out()
1604 peer_req->flags |= EE_WAS_ERROR; in drbd_issue_peer_discard_or_zero_out()
1611 return peer_req->flags & EE_APPLICATION ? in peer_request_fault_type()
1614 return peer_req->flags & EE_APPLICATION ? in peer_request_fault_type()
1627 * -ENOMEM if we could not allocate enough bios,
1628 * -ENOSPC (any better suggestion?) if we have not been able to bio_add_page a
1636 struct drbd_device *device = peer_req->peer_device->device; in drbd_submit_peer_request()
1639 struct page *page = peer_req->pages; in drbd_submit_peer_request()
1640 sector_t sector = peer_req->i.sector; in drbd_submit_peer_request()
1641 unsigned int data_size = peer_req->i.size; in drbd_submit_peer_request()
1651 if (peer_req->flags & (EE_TRIM | EE_ZEROOUT)) { in drbd_submit_peer_request()
1654 conn_wait_active_ee_empty(peer_req->peer_device->connection); in drbd_submit_peer_request()
1657 peer_req->submit_jif = jiffies; in drbd_submit_peer_request()
1658 peer_req->flags |= EE_SUBMITTED; in drbd_submit_peer_request()
1662 if (list_empty(&peer_req->w.list)) { in drbd_submit_peer_request()
1663 spin_lock_irq(&device->resource->req_lock); in drbd_submit_peer_request()
1664 list_add_tail(&peer_req->w.list, &device->active_ee); in drbd_submit_peer_request()
1665 spin_unlock_irq(&device->resource->req_lock); in drbd_submit_peer_request()
1688 drbd_err(device, "Invalid bio op received: 0x%x\n", peer_req->opf); in drbd_submit_peer_request()
1689 return -EINVAL; in drbd_submit_peer_request()
1692 bio = bio_alloc(device->ldev->backing_bdev, nr_pages, peer_req->opf, GFP_NOIO); in drbd_submit_peer_request()
1693 /* > peer_req->i.sector, unless this is the first bio */ in drbd_submit_peer_request()
1694 bio->bi_iter.bi_sector = sector; in drbd_submit_peer_request()
1695 bio->bi_private = peer_req; in drbd_submit_peer_request()
1696 bio->bi_end_io = drbd_peer_request_endio; in drbd_submit_peer_request()
1698 bio->bi_next = bios; in drbd_submit_peer_request()
1706 data_size -= len; in drbd_submit_peer_request()
1708 --nr_pages; in drbd_submit_peer_request()
1713 atomic_set(&peer_req->pending_bios, n_bios); in drbd_submit_peer_request()
1715 peer_req->submit_jif = jiffies; in drbd_submit_peer_request()
1716 peer_req->flags |= EE_SUBMITTED; in drbd_submit_peer_request()
1719 bios = bios->bi_next; in drbd_submit_peer_request()
1720 bio->bi_next = NULL; in drbd_submit_peer_request()
1730 struct drbd_interval *i = &peer_req->i; in drbd_remove_epoch_entry_interval()
1732 drbd_remove_interval(&device->write_requests, i); in drbd_remove_epoch_entry_interval()
1736 if (i->waiting) in drbd_remove_epoch_entry_interval()
1737 wake_up(&device->misc_wait); in drbd_remove_epoch_entry_interval()
1746 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { in conn_wait_active_ee_empty()
1747 struct drbd_device *device = peer_device->device; in conn_wait_active_ee_empty()
1749 kref_get(&device->kref); in conn_wait_active_ee_empty()
1751 drbd_wait_ee_list_empty(device, &device->active_ee); in conn_wait_active_ee_empty()
1752 kref_put(&device->kref, drbd_destroy_device); in conn_wait_active_ee_empty()
1761 struct p_barrier *p = pi->data; in receive_Barrier()
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()
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()
1805 return -EIO; in receive_Barrier()
1808 epoch->flags = 0; in receive_Barrier()
1809 atomic_set(&epoch->epoch_size, 0); in receive_Barrier()
1810 atomic_set(&epoch->active, 0); 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()
1831 unsigned int tmp = r->i.size; in drbd_csum_ee_size()
1832 r->i.size = payload_size; in drbd_csum_ee_size()
1834 r->i.size = tmp; in drbd_csum_ee_size()
1850 struct drbd_device *device = peer_device->device; in read_in_block()
1851 const sector_t capacity = get_capacity(device->vdisk); in read_in_block()
1855 unsigned int data_size = pi->size, ds; in read_in_block()
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()
1859 struct p_trim *trim = (pi->cmd == P_TRIM) ? pi->data : NULL; in read_in_block()
1860 struct p_trim *zeroes = (pi->cmd == P_ZEROES) ? pi->data : NULL; 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()
1872 data_size -= digest_size; in read_in_block()
1880 ds = be32_to_cpu(trim->size); in read_in_block()
1884 ds = be32_to_cpu(zeroes->size); in read_in_block()
1905 /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD in read_in_block()
1906 * "criss-cross" setup, that might cause write-out on some other DRBD, in read_in_block()
1912 peer_req->flags |= EE_WRITE; in read_in_block()
1914 peer_req->flags |= EE_TRIM; in read_in_block()
1918 peer_req->flags |= EE_ZEROOUT; in read_in_block()
1924 page = peer_req->pages; in read_in_block()
1928 err = drbd_recv_all_warn(peer_device->connection, data, len); in read_in_block()
1931 data[0] = data[0] ^ (unsigned long)-1; in read_in_block()
1938 ds -= 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()
1950 device->recv_cnt += data_size >> 9; in read_in_block()
1972 err = drbd_recv_all_warn(peer_device->connection, data, len); in drbd_drain_block()
1975 data_size -= len; in drbd_drain_block()
1978 drbd_free_pages(peer_device->device, page, 0); 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()
1998 data_size -= digest_size; in recv_dless_read()
2003 peer_device->device->recv_cnt += data_size>>9; in recv_dless_read()
2005 bio = req->master_bio; in recv_dless_read()
2006 D_ASSERT(peer_device->device, sector == bio->bi_iter.bi_sector); in recv_dless_read()
2011 err = drbd_recv_all_warn(peer_device->connection, mapped, expect); in recv_dless_read()
2015 data_size -= expect; in recv_dless_read()
2019 drbd_csum_bio(peer_device->connection->peer_integrity_tfm, bio, dig_vv); in recv_dless_read()
2022 return -EINVAL; in recv_dless_read()
2026 D_ASSERT(peer_device->device, data_size == 0); in recv_dless_read()
2038 struct drbd_peer_device *peer_device = peer_req->peer_device; in e_end_resync_block()
2039 struct drbd_device *device = peer_device->device; in e_end_resync_block()
2040 sector_t sector = peer_req->i.sector; in e_end_resync_block()
2043 D_ASSERT(device, drbd_interval_empty(&peer_req->i)); in e_end_resync_block()
2045 if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { in e_end_resync_block()
2046 drbd_set_in_sync(peer_device, sector, peer_req->i.size); in e_end_resync_block()
2050 drbd_rs_failed_io(peer_device, sector, peer_req->i.size); in e_end_resync_block()
2062 struct drbd_device *device = peer_device->device; in recv_resync_read()
2075 peer_req->w.cb = e_end_resync_block; in recv_resync_read()
2076 peer_req->opf = REQ_OP_WRITE; in recv_resync_read()
2077 peer_req->submit_jif = jiffies; in recv_resync_read()
2079 spin_lock_irq(&device->resource->req_lock); in recv_resync_read()
2080 list_add_tail(&peer_req->w.list, &device->sync_ee); in recv_resync_read()
2081 spin_unlock_irq(&device->resource->req_lock); in recv_resync_read()
2083 atomic_add(pi->size >> 9, &device->rs_sect_ev); in recv_resync_read()
2088 drbd_err(device, "submit failed, triggering re-connect\n"); in recv_resync_read()
2089 spin_lock_irq(&device->resource->req_lock); in recv_resync_read()
2090 list_del(&peer_req->w.list); in recv_resync_read()
2091 spin_unlock_irq(&device->resource->req_lock); in recv_resync_read()
2096 return -EIO; in recv_resync_read()
2107 if (drbd_contains_interval(root, sector, &req->i) && req->i.local) in find_request()
2123 struct p_data *p = pi->data; in receive_DataReply()
2125 peer_device = conn_peer_device(connection, pi->vnr); in receive_DataReply()
2127 return -EIO; in receive_DataReply()
2128 device = peer_device->device; in receive_DataReply()
2130 sector = be64_to_cpu(p->sector); in receive_DataReply()
2132 spin_lock_irq(&device->resource->req_lock); in receive_DataReply()
2133 req = find_request(device, &device->read_requests, p->block_id, sector, false, __func__); in receive_DataReply()
2134 spin_unlock_irq(&device->resource->req_lock); in receive_DataReply()
2136 return -EIO; in receive_DataReply()
2138 err = recv_dless_read(peer_device, req, sector, pi->size); in receive_DataReply()
2143 * in case we are "on-disconnect: freeze" */ in receive_DataReply()
2154 struct p_data *p = pi->data; in receive_RSDataReply()
2156 peer_device = conn_peer_device(connection, pi->vnr); in receive_RSDataReply()
2158 return -EIO; in receive_RSDataReply()
2159 device = peer_device->device; in receive_RSDataReply()
2161 sector = be64_to_cpu(p->sector); in receive_RSDataReply()
2162 D_ASSERT(device, p->block_id == ID_SYNCER); in receive_RSDataReply()
2173 err = drbd_drain_block(peer_device, pi->size); in receive_RSDataReply()
2175 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size); in receive_RSDataReply()
2178 atomic_add(pi->size >> 9, &device->rs_sect_in); in receive_RSDataReply()
2189 drbd_for_each_overlap(i, &device->write_requests, sector, size) { in restart_conflicting_writes()
2190 if (!i->local) in restart_conflicting_writes()
2193 if (req->rq_state & RQ_LOCAL_PENDING || in restart_conflicting_writes()
2194 !(req->rq_state & RQ_POSTPONED)) in restart_conflicting_writes()
2209 struct drbd_peer_device *peer_device = peer_req->peer_device; in e_end_block()
2210 struct drbd_device *device = peer_device->device; in e_end_block()
2211 sector_t sector = peer_req->i.sector; in e_end_block()
2214 if (peer_req->flags & EE_SEND_WRITE_ACK) { in e_end_block()
2215 if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { in e_end_block()
2216 pcmd = (device->state.conn >= C_SYNC_SOURCE && in e_end_block()
2217 device->state.conn <= C_PAUSED_SYNC_T && in e_end_block()
2218 peer_req->flags & EE_MAY_SET_IN_SYNC) ? in e_end_block()
2222 drbd_set_in_sync(peer_device, sector, peer_req->i.size); in e_end_block()
2233 if (peer_req->flags & EE_IN_INTERVAL_TREE) { in e_end_block()
2234 spin_lock_irq(&device->resource->req_lock); in e_end_block()
2235 D_ASSERT(device, !drbd_interval_empty(&peer_req->i)); in e_end_block()
2237 if (peer_req->flags & EE_RESTART_REQUESTS) in e_end_block()
2238 restart_conflicting_writes(device, sector, peer_req->i.size); in e_end_block()
2239 spin_unlock_irq(&device->resource->req_lock); in e_end_block()
2241 D_ASSERT(device, drbd_interval_empty(&peer_req->i)); in e_end_block()
2243 …drbd_may_finish_epoch(peer_device->connection, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0)… in e_end_block()
2252 struct drbd_peer_device *peer_device = peer_req->peer_device; in e_send_ack()
2256 dec_unacked(peer_device->device); in e_send_ack()
2270 struct drbd_connection *connection = peer_req->peer_device->connection; in e_send_retry_write()
2272 return e_send_ack(w, connection->agreed_pro_version >= 100 ? in e_send_retry_write()
2279 * We assume 32-bit wrap-around here. in seq_greater()
2280 * For 24-bit wrap-around, we would have to shift: in seq_greater()
2283 return (s32)a - (s32)b > 0; in seq_greater()
2293 struct drbd_device *device = peer_device->device; in update_peer_seq()
2296 if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) { in update_peer_seq()
2297 spin_lock(&device->peer_seq_lock); in update_peer_seq()
2298 newest_peer_seq = seq_max(device->peer_seq, peer_seq); in update_peer_seq()
2299 device->peer_seq = newest_peer_seq; in update_peer_seq()
2300 spin_unlock(&device->peer_seq_lock); in update_peer_seq()
2301 /* wake up only if we actually changed device->peer_seq */ in update_peer_seq()
2303 wake_up(&device->seq_wait); in update_peer_seq()
2307 static inline int overlaps(sector_t s1, int l1, sector_t s2, int l2) in overlaps() argument
2309 return !((s1 + (l1>>9) <= s2) || (s1 >= s2 + (l2>>9))); in overlaps()
2318 spin_lock_irq(&device->resource->req_lock); in overlapping_resync_write()
2319 list_for_each_entry(rs_req, &device->sync_ee, w.list) { in overlapping_resync_write()
2320 if (overlaps(peer_req->i.sector, peer_req->i.size, in overlapping_resync_write()
2321 rs_req->i.sector, rs_req->i.size)) { in overlapping_resync_write()
2326 spin_unlock_irq(&device->resource->req_lock); in overlapping_resync_write()
2340 * In case packet_seq is larger than device->peer_seq number, there are
2342 * In case we are the logically next packet, we update device->peer_seq
2351 * -ERESTARTSYS if we were interrupted (by disconnect signal). */
2354 struct drbd_device *device = peer_device->device; in wait_for_and_update_peer_seq()
2359 if (!test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) in wait_for_and_update_peer_seq()
2362 spin_lock(&device->peer_seq_lock); in wait_for_and_update_peer_seq()
2364 if (!seq_greater(peer_seq - 1, device->peer_seq)) { in wait_for_and_update_peer_seq()
2365 device->peer_seq = seq_max(device->peer_seq, peer_seq); in wait_for_and_update_peer_seq()
2370 ret = -ERESTARTSYS; 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()
2382 prepare_to_wait(&device->seq_wait, &wait, TASK_INTERRUPTIBLE); in wait_for_and_update_peer_seq()
2383 spin_unlock(&device->peer_seq_lock); 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()
2388 spin_lock(&device->peer_seq_lock); in wait_for_and_update_peer_seq()
2390 ret = -ETIMEDOUT; in wait_for_and_update_peer_seq()
2395 spin_unlock(&device->peer_seq_lock); in wait_for_and_update_peer_seq()
2396 finish_wait(&device->seq_wait, &wait); in wait_for_and_update_peer_seq()
2426 drbd_for_each_overlap(i, &device->write_requests, sector, size) { in fail_postponed_requests()
2430 if (!i->local) in fail_postponed_requests()
2433 if (!(req->rq_state & RQ_POSTPONED)) in fail_postponed_requests()
2435 req->rq_state &= ~RQ_POSTPONED; in fail_postponed_requests()
2437 spin_unlock_irq(&device->resource->req_lock); in fail_postponed_requests()
2440 spin_lock_irq(&device->resource->req_lock); in fail_postponed_requests()
2448 struct drbd_connection *connection = peer_req->peer_device->connection; in handle_write_conflicts()
2449 bool resolve_conflicts = test_bit(RESOLVE_CONFLICTS, &connection->flags); in handle_write_conflicts()
2450 sector_t sector = peer_req->i.sector; in handle_write_conflicts()
2451 const unsigned int size = peer_req->i.size; in handle_write_conflicts()
2460 drbd_insert_interval(&device->write_requests, &peer_req->i); in handle_write_conflicts()
2463 drbd_for_each_overlap(i, &device->write_requests, sector, size) { in handle_write_conflicts()
2464 if (i == &peer_req->i) in handle_write_conflicts()
2466 if (i->completed) in handle_write_conflicts()
2469 if (!i->local) { in handle_write_conflicts()
2472 * should not happen in a two-node setup. Wait for the in handle_write_conflicts()
2481 equal = i->sector == sector && i->size == size; in handle_write_conflicts()
2489 bool superseded = i->sector <= sector && i->sector + in handle_write_conflicts()
2490 (i->size >> 9) >= sector + (size >> 9); in handle_write_conflicts()
2496 (unsigned long long)i->sector, i->size, in handle_write_conflicts()
2500 peer_req->w.cb = superseded ? e_send_superseded : in handle_write_conflicts()
2502 list_add_tail(&peer_req->w.list, &device->done_ee); in handle_write_conflicts()
2503 queue_work(connection->ack_sender, &peer_req->peer_device->send_acks_work); in handle_write_conflicts()
2505 err = -ENOENT; in handle_write_conflicts()
2514 (unsigned long long)i->sector, i->size, in handle_write_conflicts()
2517 if (req->rq_state & RQ_LOCAL_PENDING || in handle_write_conflicts()
2518 !(req->rq_state & RQ_POSTPONED)) { in handle_write_conflicts()
2530 err = drbd_wait_misc(device, &req->i); in handle_write_conflicts()
2542 peer_req->flags |= EE_RESTART_REQUESTS; in handle_write_conflicts()
2561 struct p_data *p = pi->data; in receive_Data()
2562 u32 peer_seq = be32_to_cpu(p->seq_num); in receive_Data()
2566 peer_device = conn_peer_device(connection, pi->vnr); in receive_Data()
2568 return -EIO; in receive_Data()
2569 device = peer_device->device; in receive_Data()
2575 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size); in receive_Data()
2576 atomic_inc(&connection->current_epoch->epoch_size); in receive_Data()
2577 err2 = drbd_drain_block(peer_device, pi->size); in receive_Data()
2589 sector = be64_to_cpu(p->sector); in receive_Data()
2590 peer_req = read_in_block(peer_device, p->block_id, sector, pi); in receive_Data()
2593 return -EIO; in receive_Data()
2596 peer_req->w.cb = e_end_block; in receive_Data()
2597 peer_req->submit_jif = jiffies; in receive_Data()
2598 peer_req->flags |= EE_APPLICATION; in receive_Data()
2600 dp_flags = be32_to_cpu(p->dp_flags); in receive_Data()
2601 peer_req->opf = wire_flags_to_bio(connection, dp_flags); in receive_Data()
2602 if (pi->cmd == P_TRIM) { in receive_Data()
2603 D_ASSERT(peer_device, peer_req->i.size > 0); in receive_Data()
2605 D_ASSERT(peer_device, peer_req->pages == NULL); in receive_Data()
2607 * may mean zero-out while sending P_TRIM. */ in receive_Data()
2608 if (0 == (connection->agreed_features & DRBD_FF_WZEROES)) in receive_Data()
2609 peer_req->flags |= EE_ZEROOUT; in receive_Data()
2610 } else if (pi->cmd == P_ZEROES) { in receive_Data()
2611 D_ASSERT(peer_device, peer_req->i.size > 0); in receive_Data()
2613 D_ASSERT(peer_device, peer_req->pages == NULL); in receive_Data()
2616 peer_req->flags |= EE_TRIM; in receive_Data()
2617 } else if (peer_req->pages == NULL) { in receive_Data()
2618 D_ASSERT(device, peer_req->i.size == 0); in receive_Data()
2623 peer_req->flags |= EE_MAY_SET_IN_SYNC; in receive_Data()
2625 spin_lock(&connection->epoch_lock); in receive_Data()
2626 peer_req->epoch = connection->current_epoch; in receive_Data()
2627 atomic_inc(&peer_req->epoch->epoch_size); in receive_Data()
2628 atomic_inc(&peer_req->epoch->active); in receive_Data()
2629 spin_unlock(&connection->epoch_lock); in receive_Data()
2632 nc = rcu_dereference(peer_device->connection->net_conf); in receive_Data()
2633 tp = nc->two_primaries; in receive_Data()
2634 if (peer_device->connection->agreed_pro_version < 100) { in receive_Data()
2635 switch (nc->wire_protocol) { in receive_Data()
2647 peer_req->flags |= EE_SEND_WRITE_ACK; in receive_Data()
2662 peer_req->flags |= EE_IN_INTERVAL_TREE; in receive_Data()
2666 spin_lock_irq(&device->resource->req_lock); in receive_Data()
2669 spin_unlock_irq(&device->resource->req_lock); in receive_Data()
2670 if (err == -ENOENT) { in receive_Data()
2678 spin_lock_irq(&device->resource->req_lock); in receive_Data()
2684 if ((peer_req->flags & (EE_TRIM | EE_ZEROOUT)) == 0) in receive_Data()
2685 list_add_tail(&peer_req->w.list, &device->active_ee); in receive_Data()
2686 spin_unlock_irq(&device->resource->req_lock); in receive_Data()
2688 if (device->state.conn == C_SYNC_TARGET) in receive_Data()
2689 wait_event(device->ee_wait, !overlapping_resync_write(device, peer_req)); in receive_Data()
2691 if (device->state.pdsk < D_INCONSISTENT) { in receive_Data()
2693 drbd_set_out_of_sync(peer_device, peer_req->i.sector, peer_req->i.size); in receive_Data()
2694 peer_req->flags &= ~EE_MAY_SET_IN_SYNC; in receive_Data()
2695 drbd_al_begin_io(device, &peer_req->i); in receive_Data()
2696 peer_req->flags |= EE_CALL_AL_COMPLETE_IO; in receive_Data()
2704 drbd_err(device, "submit failed, triggering re-connect\n"); in receive_Data()
2705 spin_lock_irq(&device->resource->req_lock); in receive_Data()
2706 list_del(&peer_req->w.list); in receive_Data()
2708 spin_unlock_irq(&device->resource->req_lock); in receive_Data()
2709 if (peer_req->flags & EE_CALL_AL_COMPLETE_IO) { in receive_Data()
2710 peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO; in receive_Data()
2711 drbd_al_complete_io(device, &peer_req->i); in receive_Data()
2715 drbd_may_finish_epoch(connection, peer_req->epoch, EV_PUT | EV_CLEANUP); in receive_Data()
2735 struct drbd_device *device = peer_device->device; in drbd_rs_should_slow_down()
2742 spin_lock_irq(&device->al_lock); in drbd_rs_should_slow_down()
2743 tmp = lc_find(device->resync, BM_SECT_TO_EXT(sector)); in drbd_rs_should_slow_down()
2746 if (test_bit(BME_PRIORITY, &bm_ext->flags)) in drbd_rs_should_slow_down()
2751 spin_unlock_irq(&device->al_lock); in drbd_rs_should_slow_down()
2758 struct gendisk *disk = device->ldev->backing_bdev->bd_disk; in drbd_rs_c_min_rate_throttle()
2764 c_min_rate = rcu_dereference(device->ldev->disk_conf)->c_min_rate; in drbd_rs_c_min_rate_throttle()
2771 curr_events = (int)part_stat_read_accum(disk->part0, sectors) - in drbd_rs_c_min_rate_throttle()
2772 atomic_read(&device->rs_sect_ev); in drbd_rs_c_min_rate_throttle()
2774 if (atomic_read(&device->ap_actlog_cnt) in drbd_rs_c_min_rate_throttle()
2775 || curr_events - device->rs_last_events > 64) { in drbd_rs_c_min_rate_throttle()
2779 device->rs_last_events = curr_events; in drbd_rs_c_min_rate_throttle()
2783 i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; in drbd_rs_c_min_rate_throttle()
2785 if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T) in drbd_rs_c_min_rate_throttle()
2786 rs_left = device->ov_left; in drbd_rs_c_min_rate_throttle()
2788 rs_left = drbd_bm_total_weight(device) - device->rs_failed; in drbd_rs_c_min_rate_throttle()
2790 dt = ((long)jiffies - (long)device->rs_mark_time[i]) / HZ; in drbd_rs_c_min_rate_throttle()
2793 db = device->rs_mark_left[i] - rs_left; in drbd_rs_c_min_rate_throttle()
2811 struct p_block_req *p = pi->data; in receive_DataRequest()
2813 peer_device = conn_peer_device(connection, pi->vnr); in receive_DataRequest()
2815 return -EIO; in receive_DataRequest()
2816 device = peer_device->device; in receive_DataRequest()
2817 capacity = get_capacity(device->vdisk); in receive_DataRequest()
2819 sector = be64_to_cpu(p->sector); in receive_DataRequest()
2820 size = be32_to_cpu(p->blksize); in receive_DataRequest()
2825 return -EINVAL; in receive_DataRequest()
2830 return -EINVAL; in receive_DataRequest()
2835 switch (pi->cmd) { in receive_DataRequest()
2858 return drbd_drain_block(peer_device, pi->size); in receive_DataRequest()
2861 /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD in receive_DataRequest()
2862 * "criss-cross" setup, that might cause write-out on some other DRBD, in receive_DataRequest()
2864 peer_req = drbd_alloc_peer_req(peer_device, p->block_id, sector, size, in receive_DataRequest()
2868 return -ENOMEM; in receive_DataRequest()
2870 peer_req->opf = REQ_OP_READ; in receive_DataRequest()
2872 switch (pi->cmd) { in receive_DataRequest()
2874 peer_req->w.cb = w_e_end_data_req; in receive_DataRequest()
2876 peer_req->flags |= EE_APPLICATION; in receive_DataRequest()
2884 peer_req->flags |= EE_RS_THIN_REQ; in receive_DataRequest()
2887 peer_req->w.cb = w_e_end_rsdata_req; in receive_DataRequest()
2889 device->bm_resync_fo = BM_SECT_TO_BIT(sector); in receive_DataRequest()
2894 di = kmalloc(sizeof(*di) + pi->size, GFP_NOIO); in receive_DataRequest()
2898 di->digest_size = pi->size; in receive_DataRequest()
2899 di->digest = (((char *)di)+sizeof(struct digest_info)); in receive_DataRequest()
2901 peer_req->digest = di; in receive_DataRequest()
2902 peer_req->flags |= EE_HAS_DIGEST; in receive_DataRequest()
2904 if (drbd_recv_all(peer_device->connection, di->digest, pi->size)) in receive_DataRequest()
2907 if (pi->cmd == P_CSUM_RS_REQUEST) { in receive_DataRequest()
2908 D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89); in receive_DataRequest()
2909 peer_req->w.cb = w_e_end_csum_rs_req; in receive_DataRequest()
2911 device->bm_resync_fo = BM_SECT_TO_BIT(sector); in receive_DataRequest()
2913 device->use_csums = true; in receive_DataRequest()
2914 } else if (pi->cmd == P_OV_REPLY) { in receive_DataRequest()
2916 atomic_add(size >> 9, &device->rs_sect_in); in receive_DataRequest()
2917 peer_req->w.cb = w_e_end_ov_reply; in receive_DataRequest()
2926 if (device->ov_start_sector == ~(sector_t)0 && in receive_DataRequest()
2927 peer_device->connection->agreed_pro_version >= 90) { in receive_DataRequest()
2930 device->ov_start_sector = sector; in receive_DataRequest()
2931 device->ov_position = sector; in receive_DataRequest()
2932 device->ov_left = drbd_bm_bits(device) - BM_SECT_TO_BIT(sector); in receive_DataRequest()
2933 device->rs_total = device->ov_left; in receive_DataRequest()
2935 device->rs_mark_left[i] = device->ov_left; in receive_DataRequest()
2936 device->rs_mark_time[i] = now; in receive_DataRequest()
2941 peer_req->w.cb = w_e_end_ov_req; in receive_DataRequest()
2975 spin_lock_irq(&device->resource->req_lock); in receive_DataRequest()
2976 list_add_tail(&peer_req->w.list, &device->read_ee); in receive_DataRequest()
2977 spin_unlock_irq(&device->resource->req_lock); in receive_DataRequest()
2980 if (device->state.peer != R_PRIMARY in receive_DataRequest()
2988 atomic_add(size >> 9, &device->rs_sect_ev); in receive_DataRequest()
2997 drbd_err(device, "submit failed, triggering re-connect\n"); in receive_DataRequest()
3000 spin_lock_irq(&device->resource->req_lock); in receive_DataRequest()
3001 list_del(&peer_req->w.list); in receive_DataRequest()
3002 spin_unlock_irq(&device->resource->req_lock); in receive_DataRequest()
3007 return -EIO; in receive_DataRequest()
3011 * drbd_asb_recover_0p - Recover after split-brain with no remaining primaries
3015 struct drbd_device *device = peer_device->device; in drbd_asb_recover_0p()
3016 int self, peer, rv = -100; in drbd_asb_recover_0p()
3020 self = device->ldev->md.uuid[UI_BITMAP] & 1; in drbd_asb_recover_0p()
3021 peer = device->p_uuid[UI_BITMAP] & 1; in drbd_asb_recover_0p()
3023 ch_peer = device->p_uuid[UI_SIZE]; in drbd_asb_recover_0p()
3024 ch_self = device->comm_bm_set; in drbd_asb_recover_0p()
3027 after_sb_0p = rcu_dereference(peer_device->connection->net_conf)->after_sb_0p; in drbd_asb_recover_0p()
3040 rv = -1; in drbd_asb_recover_0p()
3054 rv = -1; in drbd_asb_recover_0p()
3059 "Using discard-least-changes instead\n"); in drbd_asb_recover_0p()
3063 rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) in drbd_asb_recover_0p()
3064 ? -1 : 1; in drbd_asb_recover_0p()
3068 if (ch_self == 0) { rv = -1; break; } in drbd_asb_recover_0p()
3075 rv = -1; in drbd_asb_recover_0p()
3080 rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) in drbd_asb_recover_0p()
3081 ? -1 : 1; in drbd_asb_recover_0p()
3084 rv = -1; in drbd_asb_recover_0p()
3094 * drbd_asb_recover_1p - Recover after split-brain with one remaining primary
3098 struct drbd_device *device = peer_device->device; in drbd_asb_recover_1p()
3099 int hg, rv = -100; in drbd_asb_recover_1p()
3103 after_sb_1p = rcu_dereference(peer_device->connection->net_conf)->after_sb_1p; in drbd_asb_recover_1p()
3118 if (hg == -1 && device->state.role == R_SECONDARY) in drbd_asb_recover_1p()
3120 if (hg == 1 && device->state.role == R_PRIMARY) in drbd_asb_recover_1p()
3127 return device->state.role == R_PRIMARY ? 1 : -1; in drbd_asb_recover_1p()
3130 if (hg == -1 && device->state.role == R_PRIMARY) { in drbd_asb_recover_1p()
3138 drbd_khelper(device, "pri-lost-after-sb"); in drbd_asb_recover_1p()
3151 * drbd_asb_recover_2p - Recover after split-brain with two remaining primaries
3155 struct drbd_device *device = peer_device->device; in drbd_asb_recover_2p()
3156 int hg, rv = -100; in drbd_asb_recover_2p()
3160 after_sb_2p = rcu_dereference(peer_device->connection->net_conf)->after_sb_2p; in drbd_asb_recover_2p()
3180 if (hg == -1) { in drbd_asb_recover_2p()
3188 drbd_khelper(device, "pri-lost-after-sb"); in drbd_asb_recover_2p()
3222 -1 C_SYNC_TARGET use BitMap
3223 -2 C_SYNC_TARGET set BitMap
3224 -100 after split brain, disconnect
3225 -1000 unrelated data
3226 -1091 requires proto 91
3227 -1096 requires proto 96
3233 struct drbd_connection *const connection = peer_device->connection; in drbd_uuid_compare()
3234 struct drbd_device *device = peer_device->device; in drbd_uuid_compare()
3238 self = device->ldev->md.uuid[UI_CURRENT] & ~((u64)1); in drbd_uuid_compare()
3239 peer = device->p_uuid[UI_CURRENT] & ~((u64)1); in drbd_uuid_compare()
3248 return -2; in drbd_uuid_compare()
3258 if (device->p_uuid[UI_BITMAP] == (u64)0 && device->ldev->md.uuid[UI_BITMAP] != (u64)0) { in drbd_uuid_compare()
3260 if (connection->agreed_pro_version < 91) in drbd_uuid_compare()
3261 return -1091; in drbd_uuid_compare()
3263 …if ((device->ldev->md.uuid[UI_BITMAP] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START] & ~((u64)1… in drbd_uuid_compare()
3264 …(device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START + 1] & ~… in drbd_uuid_compare()
3267 device->ldev->md.uuid[UI_HISTORY_START] = device->ldev->md.uuid[UI_BITMAP]; in drbd_uuid_compare()
3268 device->ldev->md.uuid[UI_BITMAP] = 0; in drbd_uuid_compare()
3270 drbd_uuid_dump(device, "self", device->ldev->md.uuid, in drbd_uuid_compare()
3271 device->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(device) : 0, 0); in drbd_uuid_compare()
3281 if (device->ldev->md.uuid[UI_BITMAP] == (u64)0 && device->p_uuid[UI_BITMAP] != (u64)0) { in drbd_uuid_compare()
3283 if (connection->agreed_pro_version < 91) in drbd_uuid_compare()
3284 return -1091; in drbd_uuid_compare()
3286 …if ((device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (device->p_uuid[UI_BITMAP] & ~((u64)1… in drbd_uuid_compare()
3287 …(device->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START] & ~… in drbd_uuid_compare()
3290 device->p_uuid[UI_HISTORY_START + 1] = device->p_uuid[UI_HISTORY_START]; in drbd_uuid_compare()
3291 device->p_uuid[UI_HISTORY_START] = device->p_uuid[UI_BITMAP]; in drbd_uuid_compare()
3292 device->p_uuid[UI_BITMAP] = 0UL; in drbd_uuid_compare()
3294 … drbd_uuid_dump(device, "peer", device->p_uuid, device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); in drbd_uuid_compare()
3301 return -1; in drbd_uuid_compare()
3305 rct = (test_bit(CRASHED_PRIMARY, &device->flags) ? 1 : 0) + in drbd_uuid_compare()
3306 (device->p_uuid[UI_FLAGS] & 2); in drbd_uuid_compare()
3318 * frozen, so no UUID-bump happened. in drbd_uuid_compare()
3320 * for "new-enough" peer DRBD version. */ in drbd_uuid_compare()
3321 if (device->state.role == R_PRIMARY || peer_role == R_PRIMARY) { in drbd_uuid_compare()
3323 if (!(connection->agreed_features & DRBD_FF_WSAME)) { in drbd_uuid_compare()
3325 return -(0x10000 | PRO_VERSION_MAX | (DRBD_FF_WSAME << 8)); in drbd_uuid_compare()
3327 if (device->state.role == R_PRIMARY && peer_role == R_PRIMARY) { in drbd_uuid_compare()
3332 return -100; in drbd_uuid_compare()
3334 if (device->state.role == R_PRIMARY) in drbd_uuid_compare()
3336 return -1; in drbd_uuid_compare()
3345 case 2: /* !self_pri && peer_pri */ return -1; in drbd_uuid_compare()
3347 dc = test_bit(RESOLVE_CONFLICTS, &connection->flags); in drbd_uuid_compare()
3348 return dc ? -1 : 1; in drbd_uuid_compare()
3353 peer = device->p_uuid[UI_BITMAP] & ~((u64)1); in drbd_uuid_compare()
3355 return -1; in drbd_uuid_compare()
3358 peer = device->p_uuid[UI_HISTORY_START] & ~((u64)1); in drbd_uuid_compare()
3360 if (connection->agreed_pro_version < 96 ? in drbd_uuid_compare()
3361 (device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == in drbd_uuid_compare()
3362 (device->p_uuid[UI_HISTORY_START + 1] & ~((u64)1)) : in drbd_uuid_compare()
3363 peer + UUID_NEW_BM_OFFSET == (device->p_uuid[UI_BITMAP] & ~((u64)1))) { in drbd_uuid_compare()
3367 if (connection->agreed_pro_version < 91) in drbd_uuid_compare()
3368 return -1091; in drbd_uuid_compare()
3370 device->p_uuid[UI_BITMAP] = device->p_uuid[UI_HISTORY_START]; in drbd_uuid_compare()
3371 device->p_uuid[UI_HISTORY_START] = device->p_uuid[UI_HISTORY_START + 1]; in drbd_uuid_compare()
3374 … drbd_uuid_dump(device, "peer", device->p_uuid, device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); in drbd_uuid_compare()
3376 return -1; in drbd_uuid_compare()
3381 self = device->ldev->md.uuid[UI_CURRENT] & ~((u64)1); in drbd_uuid_compare()
3383 peer = device->p_uuid[i] & ~((u64)1); in drbd_uuid_compare()
3385 return -2; in drbd_uuid_compare()
3389 self = device->ldev->md.uuid[UI_BITMAP] & ~((u64)1); in drbd_uuid_compare()
3390 peer = device->p_uuid[UI_CURRENT] & ~((u64)1); in drbd_uuid_compare()
3395 self = device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1); in drbd_uuid_compare()
3397 if (connection->agreed_pro_version < 96 ? in drbd_uuid_compare()
3398 (device->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == in drbd_uuid_compare()
3399 (device->p_uuid[UI_HISTORY_START] & ~((u64)1)) : in drbd_uuid_compare()
3400 self + UUID_NEW_BM_OFFSET == (device->ldev->md.uuid[UI_BITMAP] & ~((u64)1))) { in drbd_uuid_compare()
3404 if (connection->agreed_pro_version < 91) in drbd_uuid_compare()
3405 return -1091; in drbd_uuid_compare()
3407 __drbd_uuid_set(device, UI_BITMAP, device->ldev->md.uuid[UI_HISTORY_START]); in drbd_uuid_compare()
3408 __drbd_uuid_set(device, UI_HISTORY_START, device->ldev->md.uuid[UI_HISTORY_START + 1]); in drbd_uuid_compare()
3411 drbd_uuid_dump(device, "self", device->ldev->md.uuid, in drbd_uuid_compare()
3412 device->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(device) : 0, 0); in drbd_uuid_compare()
3420 peer = device->p_uuid[UI_CURRENT] & ~((u64)1); in drbd_uuid_compare()
3422 self = device->ldev->md.uuid[i] & ~((u64)1); in drbd_uuid_compare()
3428 self = device->ldev->md.uuid[UI_BITMAP] & ~((u64)1); in drbd_uuid_compare()
3429 peer = device->p_uuid[UI_BITMAP] & ~((u64)1); in drbd_uuid_compare()
3435 self = device->ldev->md.uuid[i] & ~((u64)1); in drbd_uuid_compare()
3437 peer = device->p_uuid[j] & ~((u64)1); in drbd_uuid_compare()
3439 return -100; in drbd_uuid_compare()
3443 return -1000; in drbd_uuid_compare()
3447 CONN_MASK (-1) on failure.
3453 struct drbd_device *device = peer_device->device; in drbd_sync_handshake()
3459 mydisk = device->state.disk; in drbd_sync_handshake()
3461 mydisk = device->new_state_tmp.disk; in drbd_sync_handshake()
3465 spin_lock_irq(&device->ldev->md.uuid_lock); in drbd_sync_handshake()
3466 drbd_uuid_dump(device, "self", device->ldev->md.uuid, device->comm_bm_set, 0); in drbd_sync_handshake()
3467 drbd_uuid_dump(device, "peer", device->p_uuid, in drbd_sync_handshake()
3468 device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); in drbd_sync_handshake()
3471 spin_unlock_irq(&device->ldev->md.uuid_lock); in drbd_sync_handshake()
3475 if (hg == -1000) { in drbd_sync_handshake()
3479 if (hg < -0x10000) { in drbd_sync_handshake()
3481 hg = -hg; in drbd_sync_handshake()
3488 if (hg < -1000) { in drbd_sync_handshake()
3489 …drbd_alert(device, "To resolve this both sides have to support at least protocol %d\n", -hg - 1000… in drbd_sync_handshake()
3495 int f = (hg == -100) || abs(hg) == 2; in drbd_sync_handshake()
3496 hg = mydisk > D_INCONSISTENT ? 1 : -1; in drbd_sync_handshake()
3504 drbd_khelper(device, "initial-split-brain"); in drbd_sync_handshake()
3507 nc = rcu_dereference(peer_device->connection->net_conf); in drbd_sync_handshake()
3508 always_asbp = nc->always_asbp; in drbd_sync_handshake()
3509 rr_conflict = nc->rr_conflict; in drbd_sync_handshake()
3510 tentative = nc->tentative; in drbd_sync_handshake()
3513 if (hg == 100 || (hg == -100 && always_asbp)) { in drbd_sync_handshake()
3514 int pcount = (device->state.role == R_PRIMARY) in drbd_sync_handshake()
3516 int forced = (hg == -100); in drbd_sync_handshake()
3530 drbd_warn(device, "Split-Brain detected, %d primaries, " in drbd_sync_handshake()
3541 if (hg == -100) { in drbd_sync_handshake()
3542 if (test_bit(DISCARD_MY_DATA, &device->flags) && !(device->p_uuid[UI_FLAGS]&1)) in drbd_sync_handshake()
3543 hg = -1; in drbd_sync_handshake()
3544 if (!test_bit(DISCARD_MY_DATA, &device->flags) && (device->p_uuid[UI_FLAGS]&1)) in drbd_sync_handshake()
3548 drbd_warn(device, "Split-Brain detected, manually solved. " in drbd_sync_handshake()
3553 if (hg == -100) { in drbd_sync_handshake()
3556 * We just refuse to attach -- well, we drop the "connection" in drbd_sync_handshake()
3558 drbd_alert(device, "Split-Brain detected but unresolved, dropping connection!\n"); in drbd_sync_handshake()
3559 drbd_khelper(device, "split-brain"); in drbd_sync_handshake()
3569 device->state.role == R_PRIMARY && device->state.disk >= D_CONSISTENT) { in drbd_sync_handshake()
3572 drbd_khelper(device, "pri-lost"); in drbd_sync_handshake()
3578 drbd_warn(device, "Becoming SyncTarget, violating the stable-data" in drbd_sync_handshake()
3583 if (tentative || test_bit(CONN_DRY_RUN, &peer_device->connection->flags)) { in drbd_sync_handshake()
3585 drbd_info(device, "dry-run connect: No resync, would become Connected immediately.\n"); in drbd_sync_handshake()
3587 drbd_info(device, "dry-run connect: Would become %s, doing a %s resync.", in drbd_sync_handshake()
3589 abs(hg) >= 2 ? "full" : "bit-map based"); in drbd_sync_handshake()
3617 /* ASB_DISCARD_REMOTE - ASB_DISCARD_LOCAL is valid */ in convert_after_sb()
3631 struct p_protocol *p = pi->data; in receive_protocol()
3639 p_proto = be32_to_cpu(p->protocol); in receive_protocol()
3640 p_after_sb_0p = be32_to_cpu(p->after_sb_0p); in receive_protocol()
3641 p_after_sb_1p = be32_to_cpu(p->after_sb_1p); in receive_protocol()
3642 p_after_sb_2p = be32_to_cpu(p->after_sb_2p); in receive_protocol()
3643 p_two_primaries = be32_to_cpu(p->two_primaries); in receive_protocol()
3644 cf = be32_to_cpu(p->conn_flags); in receive_protocol()
3647 if (connection->agreed_pro_version >= 87) { in receive_protocol()
3650 if (pi->size > sizeof(integrity_alg)) in receive_protocol()
3651 return -EIO; in receive_protocol()
3652 err = drbd_recv_all(connection, integrity_alg, pi->size); in receive_protocol()
3655 integrity_alg[SHARED_SECRET_MAX - 1] = 0; in receive_protocol()
3658 if (pi->cmd != P_PROTOCOL_UPDATE) { 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()
3667 if (p_proto != nc->wire_protocol) { in receive_protocol()
3672 if (convert_after_sb(p_after_sb_0p) != nc->after_sb_0p) { in receive_protocol()
3673 drbd_err(connection, "incompatible %s settings\n", "after-sb-0pri"); in receive_protocol()
3677 if (convert_after_sb(p_after_sb_1p) != nc->after_sb_1p) { in receive_protocol()
3678 drbd_err(connection, "incompatible %s settings\n", "after-sb-1pri"); in receive_protocol()
3682 if (convert_after_sb(p_after_sb_2p) != nc->after_sb_2p) { in receive_protocol()
3683 drbd_err(connection, "incompatible %s settings\n", "after-sb-2pri"); in receive_protocol()
3687 if (p_discard_my_data && nc->discard_my_data) { in receive_protocol()
3688 drbd_err(connection, "incompatible %s settings\n", "discard-my-data"); in receive_protocol()
3692 if (p_two_primaries != nc->two_primaries) { in receive_protocol()
3693 drbd_err(connection, "incompatible %s settings\n", "allow-two-primaries"); in receive_protocol()
3697 if (strcmp(integrity_alg, nc->integrity_alg)) { 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()
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()
3743 new_net_conf->wire_protocol = p_proto; in receive_protocol()
3744 new_net_conf->after_sb_0p = convert_after_sb(p_after_sb_0p); in receive_protocol()
3745 new_net_conf->after_sb_1p = convert_after_sb(p_after_sb_1p); in receive_protocol()
3746 new_net_conf->after_sb_2p = convert_after_sb(p_after_sb_2p); in receive_protocol()
3747 new_net_conf->two_primaries = p_two_primaries; 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()
3760 if (strcmp(old_net_conf->integrity_alg, integrity_alg)) in receive_protocol()
3761 drbd_info(connection, "peer data-integrity-alg: %s\n", in receive_protocol()
3774 return -EIO; in receive_protocol()
3802 void *buffer = connection->data.rbuf; in ignore_remaining_packet()
3803 int size = pi->size; in ignore_remaining_packet()
3813 size -= s; in ignore_remaining_packet()
3816 return -EIO; in ignore_remaining_packet()
3821 * config_unknown_volume - device configuration command for unknown volume
3834 cmdname(pi->cmd), pi->vnr); in config_unknown_volume()
3848 const int apv = connection->agreed_pro_version; in receive_SyncParam()
3853 peer_device = conn_peer_device(connection, pi->vnr); in receive_SyncParam()
3856 device = peer_device->device; in receive_SyncParam()
3864 if (pi->size > exp_max_sz) { in receive_SyncParam()
3866 pi->size, exp_max_sz); in receive_SyncParam()
3867 return -EIO; in receive_SyncParam()
3872 data_size = pi->size - header_size; in receive_SyncParam()
3875 data_size = pi->size - header_size; in receive_SyncParam()
3879 data_size = pi->size - header_size; in receive_SyncParam()
3884 p = pi->data; in receive_SyncParam()
3885 BUILD_BUG_ON(sizeof(p->algs) != 2 * SHARED_SECRET_MAX); in receive_SyncParam()
3886 memset(&p->algs, 0, sizeof(p->algs)); 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()
3900 return -ENOMEM; in receive_SyncParam()
3903 old_disk_conf = device->ldev->disk_conf; in receive_SyncParam()
3906 new_disk_conf->resync_rate = be32_to_cpu(p->resync_rate); in receive_SyncParam()
3912 drbd_err(device, "verify-alg of wrong size, " in receive_SyncParam()
3918 err = drbd_recv_all(peer_device->connection, p->verify_alg, data_size); in receive_SyncParam()
3923 D_ASSERT(device, p->verify_alg[data_size-1] == 0); in receive_SyncParam()
3924 p->verify_alg[data_size-1] = 0; in receive_SyncParam()
3929 D_ASSERT(device, p->verify_alg[SHARED_SECRET_MAX-1] == 0); in receive_SyncParam()
3930 D_ASSERT(device, p->csums_alg[SHARED_SECRET_MAX-1] == 0); in receive_SyncParam()
3931 p->verify_alg[SHARED_SECRET_MAX-1] = 0; in receive_SyncParam()
3932 p->csums_alg[SHARED_SECRET_MAX-1] = 0; in receive_SyncParam()
3935 if (strcmp(old_net_conf->verify_alg, p->verify_alg)) { in receive_SyncParam()
3936 if (device->state.conn == C_WF_REPORT_PARAMS) { in receive_SyncParam()
3937 drbd_err(device, "Different verify-alg settings. me=\"%s\" peer=\"%s\"\n", in receive_SyncParam()
3938 old_net_conf->verify_alg, p->verify_alg); in receive_SyncParam()
3942 p->verify_alg, "verify-alg"); in receive_SyncParam()
3949 if (apv >= 89 && strcmp(old_net_conf->csums_alg, p->csums_alg)) { in receive_SyncParam()
3950 if (device->state.conn == C_WF_REPORT_PARAMS) { in receive_SyncParam()
3951 drbd_err(device, "Different csums-alg settings. me=\"%s\" peer=\"%s\"\n", in receive_SyncParam()
3952 old_net_conf->csums_alg, p->csums_alg); in receive_SyncParam()
3956 p->csums_alg, "csums-alg"); in receive_SyncParam()
3964 new_disk_conf->c_plan_ahead = be32_to_cpu(p->c_plan_ahead); in receive_SyncParam()
3965 new_disk_conf->c_delay_target = be32_to_cpu(p->c_delay_target); in receive_SyncParam()
3966 new_disk_conf->c_fill_target = be32_to_cpu(p->c_fill_target); in receive_SyncParam()
3967 new_disk_conf->c_max_rate = be32_to_cpu(p->c_max_rate); in receive_SyncParam()
3969 fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; in receive_SyncParam()
3970 if (fifo_size != device->rs_plan_s->size) { in receive_SyncParam()
3988 strcpy(new_net_conf->verify_alg, p->verify_alg); in receive_SyncParam()
3989 new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1; 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()
3992 drbd_info(device, "using verify-alg: \"%s\"\n", p->verify_alg); in receive_SyncParam()
3995 strcpy(new_net_conf->csums_alg, p->csums_alg); in receive_SyncParam()
3996 new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1; 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()
3999 drbd_info(device, "using csums-alg: \"%s\"\n", p->csums_alg); in receive_SyncParam()
4001 rcu_assign_pointer(connection->net_conf, new_net_conf); in receive_SyncParam()
4006 rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); in receive_SyncParam()
4011 old_plan = device->rs_plan_s; in receive_SyncParam()
4012 rcu_assign_pointer(device->rs_plan_s, new_plan); in receive_SyncParam()
4015 mutex_unlock(&connection->resource->conf_update); in receive_SyncParam()
4029 mutex_unlock(&connection->resource->conf_update); in receive_SyncParam()
4030 return -EIO; 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()
4045 return -EIO; in receive_SyncParam()
4055 d = (a > b) ? (a - b) : (b - a); in warn_if_differ_considerably()
4065 struct p_sizes *p = pi->data; in receive_sizes()
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()
4076 device = peer_device->device; in receive_sizes()
4077 cur_size = get_capacity(device->vdisk); in receive_sizes()
4079 p_size = be64_to_cpu(p->d_size); in receive_sizes()
4080 p_usize = be64_to_cpu(p->u_size); in receive_sizes()
4081 p_csize = be64_to_cpu(p->c_size); in receive_sizes()
4085 device->p_size = p_size; in receive_sizes()
4089 my_usize = rcu_dereference(device->ldev->disk_conf)->disk_size; in receive_sizes()
4093 p_size, drbd_get_max_capacity(device->ldev)); in receive_sizes()
4099 if (device->state.conn == C_WF_REPORT_PARAMS) in receive_sizes()
4105 new_size = drbd_new_dev_size(device, device->ldev, p_usize, 0); in receive_sizes()
4107 device->state.disk >= D_OUTDATED && in receive_sizes()
4108 (device->state.conn < C_CONNECTED || device->state.pdsk == D_DISKLESS)) { in receive_sizes()
4111 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); in receive_sizes()
4113 return -EIO; in receive_sizes()
4122 return -ENOMEM; in receive_sizes()
4125 mutex_lock(&connection->resource->conf_update); in receive_sizes()
4126 old_disk_conf = device->ldev->disk_conf; in receive_sizes()
4128 new_disk_conf->disk_size = p_usize; in receive_sizes()
4130 rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); in receive_sizes()
4131 mutex_unlock(&connection->resource->conf_update); in receive_sizes()
4141 device->peer_max_bio_size = be32_to_cpu(p->max_bio_size); in receive_sizes()
4147 ddsf = be16_to_cpu(p->dds_flags); in receive_sizes()
4149 drbd_reconsider_queue_parameters(device, device->ldev, o); in receive_sizes()
4153 return -EIO; in receive_sizes()
4167 * take his (user-capped or) backing disk size anyways. in receive_sizes()
4181 } else if (new_size < cur_size && device->state.role == R_PRIMARY) { in receive_sizes()
4184 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); in receive_sizes()
4185 return -EIO; in receive_sizes()
4188 * - I don't have a current size myself in receive_sizes()
4189 * - we agree on the size anyways in receive_sizes()
4190 * - I do have a current size, am Secondary, in receive_sizes()
4192 * - I do have a current size, am Primary, in receive_sizes()
4201 if (device->ldev->known_size != drbd_get_capacity(device->ldev->backing_bdev)) { in receive_sizes()
4202 device->ldev->known_size = drbd_get_capacity(device->ldev->backing_bdev); in receive_sizes()
4209 if (device->state.conn > C_WF_REPORT_PARAMS) { in receive_sizes()
4210 if (be64_to_cpu(p->c_size) != get_capacity(device->vdisk) || in receive_sizes()
4216 if (test_and_clear_bit(RESIZE_PENDING, &device->flags) || in receive_sizes()
4217 (dd == DS_GREW && device->state.conn == C_CONNECTED)) { in receive_sizes()
4218 if (device->state.pdsk >= D_INCONSISTENT && in receive_sizes()
4219 device->state.disk >= D_INCONSISTENT) { in receive_sizes()
4221 drbd_info(device, "Resync of new storage suppressed with --assume-clean\n"); in receive_sizes()
4225 set_bit(RESYNC_AFTER_NEG, &device->flags); in receive_sizes()
4236 struct p_uuids *p = pi->data; in receive_uuids()
4240 peer_device = conn_peer_device(connection, pi->vnr); in receive_uuids()
4243 device = peer_device->device; in receive_uuids()
4250 p_uuid[i] = be64_to_cpu(p->uuid[i]); in receive_uuids()
4252 kfree(device->p_uuid); in receive_uuids()
4253 device->p_uuid = p_uuid; in receive_uuids()
4255 if ((device->state.conn < C_CONNECTED || device->state.pdsk == D_DISKLESS) && in receive_uuids()
4256 device->state.disk < D_INCONSISTENT && in receive_uuids()
4257 device->state.role == R_PRIMARY && in receive_uuids()
4258 (device->ed_uuid & ~((u64)1)) != (p_uuid[UI_CURRENT] & ~((u64)1))) { in receive_uuids()
4260 (unsigned long long)device->ed_uuid); in receive_uuids()
4261 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); in receive_uuids()
4262 return -EIO; in receive_uuids()
4267 device->state.conn == C_CONNECTED && in receive_uuids()
4268 peer_device->connection->agreed_pro_version >= 90 && in receive_uuids()
4269 device->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && in receive_uuids()
4284 } else if (device->state.disk < D_INCONSISTENT && in receive_uuids()
4285 device->state.role == R_PRIMARY) { in receive_uuids()
4295 mutex_lock(device->state_mutex); in receive_uuids()
4296 mutex_unlock(device->state_mutex); in receive_uuids()
4297 if (device->state.conn >= C_CONNECTED && device->state.disk < D_INCONSISTENT) in receive_uuids()
4307 * convert_state() - Converts the peer's view of the cluster state to our point of view
4341 struct p_req_state *p = pi->data; in receive_req_state()
4345 peer_device = conn_peer_device(connection, pi->vnr); in receive_req_state()
4347 return -EIO; in receive_req_state()
4348 device = peer_device->device; in receive_req_state()
4350 mask.i = be32_to_cpu(p->mask); in receive_req_state()
4351 val.i = be32_to_cpu(p->val); in receive_req_state()
4353 if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) && in receive_req_state()
4354 mutex_is_locked(device->state_mutex)) { in receive_req_state()
4372 struct p_req_state *p = pi->data; in receive_req_conn_state()
4376 mask.i = be32_to_cpu(p->mask); in receive_req_conn_state()
4377 val.i = be32_to_cpu(p->val); in receive_req_conn_state()
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()
4398 struct p_state *p = pi->data; in receive_state()
4404 peer_device = conn_peer_device(connection, pi->vnr); in receive_state()
4407 device = peer_device->device; in receive_state()
4409 peer_state.i = be32_to_cpu(p->state); in receive_state()
4413 real_peer_disk = device->p_uuid[UI_FLAGS] & 4 ? D_INCONSISTENT : D_CONSISTENT; in receive_state()
4417 spin_lock_irq(&device->resource->req_lock); in receive_state()
4420 spin_unlock_irq(&device->resource->req_lock); in receive_state()
4424 * we must not "re-establish" it here. */ in receive_state()
4426 return -ECONNRESET; in receive_state()
4430 * set) resync started in PausedSyncT, or if the timing of pause-/ in receive_state()
4431 * unpause-sync events has been "just right", the peer disk may in receive_state()
4438 * preparation, ignore its uptodate-ness to avoid flapping, it in receive_state()
4441 * It may have changed syncer-paused flags, however, so we in receive_state()
4452 if (drbd_bm_total_weight(device) <= device->rs_failed) in receive_state()
4500 if (device->p_uuid && peer_state.disk >= D_NEGOTIATING && in receive_state()
4512 * forced to be UpToDate with --force */ in receive_state()
4513 cr |= test_bit(CONSIDER_RESYNC, &device->flags); in receive_state()
4515 * start a sync by "invalidate" or "invalidate-remote" */ in receive_state()
4526 if (device->state.disk == D_NEGOTIATING) { in receive_state()
4533 if (test_and_clear_bit(CONN_DRY_RUN, &peer_device->connection->flags)) in receive_state()
4534 return -EIO; in receive_state()
4536 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); in receive_state()
4537 return -EIO; in receive_state()
4542 spin_lock_irq(&device->resource->req_lock); in receive_state()
4545 clear_bit(CONSIDER_RESYNC, &device->flags); in receive_state()
4550 ns.disk = device->new_state_tmp.disk; in receive_state()
4553 test_bit(NEW_CUR_UUID, &device->flags)) { in receive_state()
4556 spin_unlock_irq(&device->resource->req_lock); in receive_state()
4558 tl_clear(peer_device->connection); in receive_state()
4560 clear_bit(NEW_CUR_UUID, &device->flags); in receive_state()
4561 conn_request_state(peer_device->connection, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD); in receive_state()
4562 return -EIO; in receive_state()
4566 spin_unlock_irq(&device->resource->req_lock); in receive_state()
4569 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); in receive_state()
4570 return -EIO; in receive_state()
4584 clear_bit(DISCARD_MY_DATA, &device->flags); in receive_state()
4595 struct p_rs_uuid *p = pi->data; in receive_sync_uuid()
4597 peer_device = conn_peer_device(connection, pi->vnr); in receive_sync_uuid()
4599 return -EIO; in receive_sync_uuid()
4600 device = peer_device->device; in receive_sync_uuid()
4602 wait_event(device->misc_wait, in receive_sync_uuid()
4603 device->state.conn == C_WF_SYNC_UUID || in receive_sync_uuid()
4604 device->state.conn == C_BEHIND || in receive_sync_uuid()
4605 device->state.conn < C_CONNECTED || in receive_sync_uuid()
4606 device->state.disk < D_NEGOTIATING); in receive_sync_uuid()
4608 /* D_ASSERT(device, device->state.conn == C_WF_SYNC_UUID ); */ in receive_sync_uuid()
4613 _drbd_uuid_set(device, UI_CURRENT, be64_to_cpu(p->uuid)); in receive_sync_uuid()
4636 unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - in receive_bitmap_plain()
4637 drbd_header_size(peer_device->connection); in receive_bitmap_plain()
4639 c->bm_words - c->word_offset); in receive_bitmap_plain()
4645 return -EIO; in receive_bitmap_plain()
4649 err = drbd_recv_all(peer_device->connection, p, want); in receive_bitmap_plain()
4653 drbd_bm_merge_lel(peer_device->device, c->word_offset, num_words, p); in receive_bitmap_plain()
4655 c->word_offset += num_words; in receive_bitmap_plain()
4656 c->bit_offset = c->word_offset * BITS_PER_LONG; in receive_bitmap_plain()
4657 if (c->bit_offset > c->bm_bits) in receive_bitmap_plain()
4658 c->bit_offset = c->bm_bits; in receive_bitmap_plain()
4665 return (enum drbd_bitmap_code)(p->encoding & 0x0f); in dcbp_get_code()
4670 return (p->encoding & 0x80) != 0; in dcbp_get_start()
4675 return (p->encoding >> 4) & 0x7; in dcbp_get_pad_bits()
4694 unsigned long s = c->bit_offset; in recv_bm_rle_bits()
4700 bitstream_init(&bs, p->code, len, dcbp_get_pad_bits(p)); in recv_bm_rle_bits()
4704 return -EIO; in recv_bm_rle_bits()
4709 return -EIO; in recv_bm_rle_bits()
4712 e = s + rl -1; in recv_bm_rle_bits()
4713 if (e >= c->bm_bits) { in recv_bm_rle_bits()
4715 return -EIO; in recv_bm_rle_bits()
4717 _drbd_bm_set_bits(peer_device->device, s, e); in recv_bm_rle_bits()
4723 (unsigned int)(bs.cur.b - p->code), in recv_bm_rle_bits()
4725 return -EIO; in recv_bm_rle_bits()
4732 have -= bits; in recv_bm_rle_bits()
4734 bits = bitstream_get_bits(&bs, &tmp, 64 - have); in recv_bm_rle_bits()
4736 return -EIO; in recv_bm_rle_bits()
4741 c->bit_offset = s; in recv_bm_rle_bits()
4744 return (s != c->bm_bits); in recv_bm_rle_bits()
4760 return recv_bm_rle_bits(peer_device, p, c, len - sizeof(*p)); in decode_bitmap_c()
4766 drbd_err(peer_device, "receive_bitmap_c: unknown encoding %u\n", p->encoding); in decode_bitmap_c()
4767 conn_request_state(peer_device->connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD); in decode_bitmap_c()
4768 return -EIO; in decode_bitmap_c()
4775 unsigned int header_size = drbd_header_size(peer_device->connection); in INFO_bm_xfer_stats()
4776 unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - header_size; in INFO_bm_xfer_stats()
4778 header_size * (DIV_ROUND_UP(c->bm_words, data_size) + 1) + in INFO_bm_xfer_stats()
4779 c->bm_words * sizeof(unsigned long); in INFO_bm_xfer_stats()
4780 unsigned int total = c->bytes[0] + c->bytes[1]; in INFO_bm_xfer_stats()
4798 r = 1000 - r; in INFO_bm_xfer_stats()
4802 c->bytes[1], c->packets[1], in INFO_bm_xfer_stats()
4803 c->bytes[0], c->packets[0], in INFO_bm_xfer_stats()
4822 peer_device = conn_peer_device(connection, pi->vnr); in receive_bitmap()
4824 return -EIO; in receive_bitmap()
4825 device = peer_device->device; in receive_bitmap()
4828 /* you are supposed to send additional out-of-sync information in receive_bitmap()
4837 if (pi->cmd == P_BITMAP) in receive_bitmap()
4838 err = receive_bitmap_plain(peer_device, pi->size, pi->data, &c); in receive_bitmap()
4839 else if (pi->cmd == P_COMPRESSED_BITMAP) { in receive_bitmap()
4842 struct p_compressed_bm *p = pi->data; in receive_bitmap()
4844 if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(connection)) { in receive_bitmap()
4846 err = -EIO; in receive_bitmap()
4849 if (pi->size <= sizeof(*p)) { in receive_bitmap()
4850 drbd_err(device, "ReportCBitmap packet too small (l:%u)\n", pi->size); in receive_bitmap()
4851 err = -EIO; in receive_bitmap()
4854 err = drbd_recv_all(peer_device->connection, p, pi->size); in receive_bitmap()
4857 err = decode_bitmap_c(peer_device, p, &c, pi->size); in receive_bitmap()
4859 …drbd_warn(device, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", pi->cmd); in receive_bitmap()
4860 err = -EIO; in receive_bitmap()
4864 c.packets[pi->cmd == P_BITMAP]++; 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()
4879 if (device->state.conn == C_WF_BITMAP_T) { in receive_bitmap()
4888 } else if (device->state.conn != C_WF_BITMAP_S) { in receive_bitmap()
4892 drbd_conn_str(device->state.conn)); in receive_bitmap()
4898 if (!err && device->state.conn == C_WF_BITMAP_S) in receive_bitmap()
4906 pi->cmd, pi->size); in receive_skip()
4915 tcp_sock_set_quickack(connection->data.socket->sk, 2); in receive_UnplugRemote()
4923 struct p_block_desc *p = pi->data; in receive_out_of_sync()
4925 peer_device = conn_peer_device(connection, pi->vnr); in receive_out_of_sync()
4927 return -EIO; in receive_out_of_sync()
4928 device = peer_device->device; in receive_out_of_sync()
4930 switch (device->state.conn) { in receive_out_of_sync()
4937 drbd_conn_str(device->state.conn)); in receive_out_of_sync()
4940 drbd_set_out_of_sync(peer_device, be64_to_cpu(p->sector), be32_to_cpu(p->blksize)); in receive_out_of_sync()
4948 struct p_block_desc *p = pi->data; in receive_rs_deallocated()
4953 peer_device = conn_peer_device(connection, pi->vnr); in receive_rs_deallocated()
4955 return -EIO; in receive_rs_deallocated()
4956 device = peer_device->device; in receive_rs_deallocated()
4958 sector = be64_to_cpu(p->sector); in receive_rs_deallocated()
4959 size = be32_to_cpu(p->blksize); in receive_rs_deallocated()
4970 return -ENOMEM; in receive_rs_deallocated()
4973 peer_req->w.cb = e_end_resync_block; in receive_rs_deallocated()
4974 peer_req->opf = REQ_OP_DISCARD; in receive_rs_deallocated()
4975 peer_req->submit_jif = jiffies; in receive_rs_deallocated()
4976 peer_req->flags |= EE_TRIM; in receive_rs_deallocated()
4978 spin_lock_irq(&device->resource->req_lock); in receive_rs_deallocated()
4979 list_add_tail(&peer_req->w.list, &device->sync_ee); in receive_rs_deallocated()
4980 spin_unlock_irq(&device->resource->req_lock); in receive_rs_deallocated()
4982 atomic_add(pi->size >> 9, &device->rs_sect_ev); in receive_rs_deallocated()
4986 spin_lock_irq(&device->resource->req_lock); in receive_rs_deallocated()
4987 list_del(&peer_req->w.list); in receive_rs_deallocated()
4988 spin_unlock_irq(&device->resource->req_lock); in receive_rs_deallocated()
5006 atomic_add(size >> 9, &device->rs_sect_in); in receive_rs_deallocated()
5054 while (get_t_state(&connection->receiver) == RUNNING) { in drbdd()
5057 drbd_thread_current_set_cpu(&connection->receiver); in drbdd()
5063 if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) || !cmd->fn)) { in drbdd()
5069 shs = cmd->pkt_size; in drbdd()
5070 if (pi.cmd == P_SIZES && connection->agreed_features & DRBD_FF_WSAME) in drbdd()
5072 if (pi.size > shs && !cmd->expect_payload) { in drbdd()
5088 pi.size -= shs; in drbdd()
5091 update_receiver_timing_details(connection, cmd->fn); in drbdd()
5092 err = cmd->fn(connection, &pi); in drbdd()
5111 if (connection->cstate == C_STANDALONE) 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()
5130 idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { in conn_disconnect()
5131 struct drbd_device *device = peer_device->device; in conn_disconnect()
5132 kref_get(&device->kref); in conn_disconnect()
5135 kref_put(&device->kref, drbd_destroy_device); 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()
5151 spin_lock_irq(&connection->resource->req_lock); in conn_disconnect()
5152 oc = connection->cstate; in conn_disconnect()
5156 spin_unlock_irq(&connection->resource->req_lock); in conn_disconnect()
5164 struct drbd_device *device = peer_device->device; in drbd_disconnected()
5168 spin_lock_irq(&device->resource->req_lock); in drbd_disconnected()
5169 _drbd_wait_ee_list_empty(device, &device->active_ee); in drbd_disconnected()
5170 _drbd_wait_ee_list_empty(device, &device->sync_ee); in drbd_disconnected()
5171 _drbd_wait_ee_list_empty(device, &device->read_ee); in drbd_disconnected()
5172 spin_unlock_irq(&device->resource->req_lock); in drbd_disconnected()
5182 * the disk-IO, while the rs_pending_cnt only tracks the blocks in drbd_disconnected()
5185 device->rs_total = 0; in drbd_disconnected()
5186 device->rs_failed = 0; in drbd_disconnected()
5187 atomic_set(&device->rs_pending_cnt, 0); in drbd_disconnected()
5188 wake_up(&device->misc_wait); in drbd_disconnected()
5190 del_timer_sync(&device->resync_timer); in drbd_disconnected()
5191 resync_timer_fn(&device->resync_timer); in drbd_disconnected()
5196 drbd_flush_workqueue(&peer_device->connection->sender_work); in drbd_disconnected()
5203 drbd_flush_workqueue(&peer_device->connection->sender_work); in drbd_disconnected()
5209 kfree(device->p_uuid); in drbd_disconnected()
5210 device->p_uuid = NULL; in drbd_disconnected()
5213 tl_clear(peer_device->connection); in drbd_disconnected()
5230 i = drbd_free_peer_reqs(device, &device->net_ee); in drbd_disconnected()
5233 i = atomic_read(&device->pp_in_use_by_net); in drbd_disconnected()
5236 i = atomic_read(&device->pp_in_use); in drbd_disconnected()
5240 D_ASSERT(device, list_empty(&device->read_ee)); in drbd_disconnected()
5241 D_ASSERT(device, list_empty(&device->active_ee)); in drbd_disconnected()
5242 D_ASSERT(device, list_empty(&device->sync_ee)); in drbd_disconnected()
5243 D_ASSERT(device, list_empty(&device->done_ee)); in drbd_disconnected()
5262 sock = &connection->data; in drbd_send_features()
5265 return -EIO; in drbd_send_features()
5267 p->protocol_min = cpu_to_be32(PRO_VERSION_MIN); in drbd_send_features()
5268 p->protocol_max = cpu_to_be32(PRO_VERSION_MAX); in drbd_send_features()
5269 p->feature_flags = cpu_to_be32(PRO_FEATURES); in drbd_send_features()
5277 * -1 peer talks different language,
5282 /* ASSERT current == connection->receiver ... */ in drbd_do_features()
5299 return -1; in drbd_do_features()
5305 return -1; in drbd_do_features()
5313 p->protocol_min = be32_to_cpu(p->protocol_min); in drbd_do_features()
5314 p->protocol_max = be32_to_cpu(p->protocol_max); in drbd_do_features()
5315 if (p->protocol_max == 0) in drbd_do_features()
5316 p->protocol_max = p->protocol_min; in drbd_do_features()
5318 if (PRO_VERSION_MAX < p->protocol_min || in drbd_do_features()
5319 PRO_VERSION_MIN > p->protocol_max) 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()
5326 "Agreed network protocol version %d\n", connection->agreed_pro_version); 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()
5340 "I support %d-%d, peer supports %d-%d\n", in drbd_do_features()
5342 p->protocol_min, p->protocol_max); in drbd_do_features()
5343 return -1; in drbd_do_features()
5350 drbd_err(connection, "You need to disable 'cram-hmac-alg' in drbd.conf.\n"); in drbd_do_auth()
5351 return -1; in drbd_do_auth()
5357 1 - auth succeeded,
5358 0 - failed, try again (network error),
5359 -1 - auth failed, don't try again.
5380 nc = rcu_dereference(connection->net_conf); in drbd_do_auth()
5381 key_len = strlen(nc->shared_secret); in drbd_do_auth()
5382 memcpy(secret, nc->shared_secret, key_len); in drbd_do_auth()
5386 crypto_shash_descsize(connection->cram_hmac_tfm), in drbd_do_auth()
5389 rv = -1; 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()
5397 rv = -1; in drbd_do_auth()
5403 sock = &connection->data; in drbd_do_auth()
5422 rv = -1; in drbd_do_auth()
5428 rv = -1; in drbd_do_auth()
5434 rv = -1; in drbd_do_auth()
5440 rv = -1; in drbd_do_auth()
5452 rv = -1; in drbd_do_auth()
5456 resp_size = crypto_shash_digestsize(connection->cram_hmac_tfm); in drbd_do_auth()
5459 rv = -1; in drbd_do_auth()
5466 rv = -1; in drbd_do_auth()
5506 rv = -1; in drbd_do_auth()
5514 rv = -1; in drbd_do_auth()
5524 rv = -1; in drbd_do_auth()
5541 struct drbd_connection *connection = thi->connection; in drbd_receiver()
5552 if (h == -1) { in drbd_receiver()
5559 blk_start_plug(&connection->receiver_plug); in drbd_receiver()
5561 blk_finish_plug(&connection->receiver_plug); in drbd_receiver()
5574 struct p_req_state_reply *p = pi->data; in got_conn_RqSReply()
5575 int retcode = be32_to_cpu(p->retcode); in got_conn_RqSReply()
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()
5584 wake_up(&connection->ping_wait); in got_conn_RqSReply()
5593 struct p_req_state_reply *p = pi->data; in got_RqSReply()
5594 int retcode = be32_to_cpu(p->retcode); in got_RqSReply()
5596 peer_device = conn_peer_device(connection, pi->vnr); in got_RqSReply()
5598 return -EIO; in got_RqSReply()
5599 device = peer_device->device; 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()
5607 set_bit(CL_ST_CHG_SUCCESS, &device->flags); in got_RqSReply()
5609 set_bit(CL_ST_CHG_FAIL, &device->flags); in got_RqSReply()
5613 wake_up(&device->state_wait); in got_RqSReply()
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()
5638 struct p_block_ack *p = pi->data; in got_IsInSync()
5639 sector_t sector = be64_to_cpu(p->sector); in got_IsInSync()
5640 int blksize = be32_to_cpu(p->blksize); in got_IsInSync()
5642 peer_device = conn_peer_device(connection, pi->vnr); in got_IsInSync()
5644 return -EIO; in got_IsInSync()
5645 device = peer_device->device; in got_IsInSync()
5647 D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89); in got_IsInSync()
5649 update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); in got_IsInSync()
5655 device->rs_same_csum += (blksize >> BM_BLOCK_SHIFT); in got_IsInSync()
5659 atomic_add(blksize >> 9, &device->rs_sect_in); in got_IsInSync()
5669 struct drbd_device *device = peer_device->device; in validate_req_change_req_state()
5673 spin_lock_irq(&device->resource->req_lock); in validate_req_change_req_state()
5676 spin_unlock_irq(&device->resource->req_lock); in validate_req_change_req_state()
5677 return -EIO; in validate_req_change_req_state()
5680 spin_unlock_irq(&device->resource->req_lock); in validate_req_change_req_state()
5691 struct p_block_ack *p = pi->data; in got_BlockAck()
5692 sector_t sector = be64_to_cpu(p->sector); in got_BlockAck()
5693 int blksize = be32_to_cpu(p->blksize); in got_BlockAck()
5696 peer_device = conn_peer_device(connection, pi->vnr); in got_BlockAck()
5698 return -EIO; in got_BlockAck()
5699 device = peer_device->device; in got_BlockAck()
5701 update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); in got_BlockAck()
5703 if (p->block_id == ID_SYNCER) { in got_BlockAck()
5708 switch (pi->cmd) { in got_BlockAck()
5728 return validate_req_change_req_state(peer_device, p->block_id, sector, in got_BlockAck()
5729 &device->write_requests, __func__, in got_BlockAck()
5737 struct p_block_ack *p = pi->data; in got_NegAck()
5738 sector_t sector = be64_to_cpu(p->sector); in got_NegAck()
5739 int size = be32_to_cpu(p->blksize); in got_NegAck()
5742 peer_device = conn_peer_device(connection, pi->vnr); in got_NegAck()
5744 return -EIO; in got_NegAck()
5745 device = peer_device->device; in got_NegAck()
5747 update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); in got_NegAck()
5749 if (p->block_id == ID_SYNCER) { in got_NegAck()
5755 err = validate_req_change_req_state(peer_device, p->block_id, sector, in got_NegAck()
5756 &device->write_requests, __func__, in got_NegAck()
5773 struct p_block_ack *p = pi->data; in got_NegDReply()
5774 sector_t sector = be64_to_cpu(p->sector); in got_NegDReply()
5776 peer_device = conn_peer_device(connection, pi->vnr); in got_NegDReply()
5778 return -EIO; in got_NegDReply()
5779 device = peer_device->device; in got_NegDReply()
5781 update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); in got_NegDReply()
5784 (unsigned long long)sector, be32_to_cpu(p->blksize)); in got_NegDReply()
5786 return validate_req_change_req_state(peer_device, p->block_id, sector, in got_NegDReply()
5787 &device->read_requests, __func__, in got_NegDReply()
5797 struct p_block_ack *p = pi->data; in got_NegRSDReply()
5799 peer_device = conn_peer_device(connection, pi->vnr); in got_NegRSDReply()
5801 return -EIO; in got_NegRSDReply()
5802 device = peer_device->device; in got_NegRSDReply()
5804 sector = be64_to_cpu(p->sector); in got_NegRSDReply()
5805 size = be32_to_cpu(p->blksize); in got_NegRSDReply()
5807 update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); in got_NegRSDReply()
5813 switch (pi->cmd) { in got_NegRSDReply()
5830 struct p_barrier_ack *p = pi->data; in got_BarrierAck()
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()
5838 struct drbd_device *device = peer_device->device; in got_BarrierAck()
5840 if (device->state.conn == C_AHEAD && in got_BarrierAck()
5841 atomic_read(&device->ap_in_flight) == 0 && in got_BarrierAck()
5842 !test_and_set_bit(AHEAD_TO_SYNC_SOURCE, &device->flags)) { in got_BarrierAck()
5843 device->start_resync_timer.expires = jiffies + HZ; in got_BarrierAck()
5844 add_timer(&device->start_resync_timer); in got_BarrierAck()
5856 struct p_block_ack *p = pi->data; in got_OVResult()
5861 peer_device = conn_peer_device(connection, pi->vnr); in got_OVResult()
5863 return -EIO; in got_OVResult()
5864 device = peer_device->device; in got_OVResult()
5866 sector = be64_to_cpu(p->sector); in got_OVResult()
5867 size = be32_to_cpu(p->blksize); in got_OVResult()
5869 update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); in got_OVResult()
5871 if (be64_to_cpu(p->block_id) == ID_OUT_OF_SYNC) in got_OVResult()
5882 --device->ov_left; in got_OVResult()
5885 if ((device->ov_left & 0x200) == 0x200) in got_OVResult()
5886 drbd_advance_rs_marks(peer_device, device->ov_left); in got_OVResult()
5888 if (device->ov_left == 0) { in got_OVResult()
5891 dw->w.cb = w_ov_finished; in got_OVResult()
5892 dw->device = device; in got_OVResult()
5893 drbd_queue_work(&peer_device->connection->sender_work, &dw->w); in got_OVResult()
5920 nc = rcu_dereference(connection->net_conf); in set_rcvtimeo()
5921 t = ping_timeout ? nc->ping_timeo : nc->ping_int; in set_rcvtimeo()
5928 connection->meta.socket->sk->sk_rcvtimeo = t; in set_rcvtimeo()
5963 struct drbd_connection *connection = thi->connection; in drbd_ack_receiver()
5968 void *buf = connection->meta.rbuf; in drbd_ack_receiver()
5981 if (test_and_clear_bit(SEND_PING, &connection->flags)) { in drbd_ack_receiver()
5991 rv = drbd_recv_short(connection->meta.socket, buf, expect-received, 0); in drbd_ack_receiver()
5994 * -EINTR (on meta) we got a signal in drbd_ack_receiver()
5995 * -EAGAIN (on meta) rcvtimeo expired in drbd_ack_receiver()
5996 * -ECONNRESET other side closed the connection in drbd_ack_receiver()
5997 * -ERESTARTSYS (on data) we got a signal 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()
6021 } else if (rv == -EAGAIN) { in drbd_ack_receiver()
6024 if (time_after(connection->last_received, pre_recv_jif)) in drbd_ack_receiver()
6030 set_bit(SEND_PING, &connection->flags); in drbd_ack_receiver()
6032 } else if (rv == -EINTR) { in drbd_ack_receiver()
6044 if (decode_header(connection, connection->meta.rbuf, &pi)) in drbd_ack_receiver()
6047 if (pi.cmd >= ARRAY_SIZE(ack_receiver_tbl) || !cmd->fn) { in drbd_ack_receiver()
6052 expect = header_size + cmd->pkt_size; in drbd_ack_receiver()
6053 if (pi.size != expect - header_size) { 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()
6075 buf = connection->meta.rbuf; in drbd_ack_receiver()
6097 void drbd_send_acks_wf(struct work_struct *ws) in drbd_send_acks_wf() argument
6100 container_of(ws, struct drbd_peer_device, send_acks_work); in drbd_send_acks_wf()
6101 struct drbd_connection *connection = peer_device->connection; in drbd_send_acks_wf()
6102 struct drbd_device *device = peer_device->device; in drbd_send_acks_wf()
6107 nc = rcu_dereference(connection->net_conf); in drbd_send_acks_wf()
6108 tcp_cork = nc->tcp_cork; in drbd_send_acks_wf()
6112 tcp_sock_set_cork(connection->meta.socket->sk, true); in drbd_send_acks_wf()
6115 kref_put(&device->kref, drbd_destroy_device); in drbd_send_acks_wf()
6125 tcp_sock_set_cork(connection->meta.socket->sk, false); in drbd_send_acks_wf()