hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/block/drbd/drbd_receiver.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 drbd_receiver.c
34
....@@ -7,19 +8,6 @@
78 Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
89 Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
910
10
- drbd is free software; you can redistribute it and/or modify
11
- it under the terms of the GNU General Public License as published by
12
- the Free Software Foundation; either version 2, or (at your option)
13
- any later version.
14
-
15
- drbd is distributed in the hope that it will be useful,
16
- but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- GNU General Public License for more details.
19
-
20
- You should have received a copy of the GNU General Public License
21
- along with drbd; see the file COPYING. If not, write to
22
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
2311 */
2412
2513
....@@ -45,12 +33,13 @@
4533 #include <linux/random.h>
4634 #include <linux/string.h>
4735 #include <linux/scatterlist.h>
36
+#include <linux/part_stat.h>
4837 #include "drbd_int.h"
4938 #include "drbd_protocol.h"
5039 #include "drbd_req.h"
5140 #include "drbd_vli.h"
5241
53
-#define PRO_FEATURES (DRBD_FF_TRIM|DRBD_FF_THIN_RESYNC|DRBD_FF_WSAME)
42
+#define PRO_FEATURES (DRBD_FF_TRIM|DRBD_FF_THIN_RESYNC|DRBD_FF_WSAME|DRBD_FF_WZEROES)
5443
5544 struct packet_info {
5645 enum drbd_packet cmd;
....@@ -516,7 +505,7 @@
516505 struct msghdr msg = {
517506 .msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL)
518507 };
519
- iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &iov, 1, size);
508
+ iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, size);
520509 return sock_recvmsg(sock, &msg, msg.msg_flags);
521510 }
522511
....@@ -1062,8 +1051,8 @@
10621051
10631052 /* we don't want delays.
10641053 * we use TCP_CORK where appropriate, though */
1065
- drbd_tcp_nodelay(sock.socket);
1066
- drbd_tcp_nodelay(msock.socket);
1054
+ tcp_sock_set_nodelay(sock.socket->sk);
1055
+ tcp_sock_set_nodelay(msock.socket->sk);
10671056
10681057 connection->data.socket = sock.socket;
10691058 connection->meta.socket = msock.socket;
....@@ -1234,7 +1223,7 @@
12341223 * quickly as possible, and let remote TCP know what we have
12351224 * received so far. */
12361225 if (err == -EAGAIN) {
1237
- drbd_tcp_quickack(connection->data.socket);
1226
+ tcp_sock_set_quickack(connection->data.socket->sk, 2);
12381227 drbd_unplug_all_devices(connection);
12391228 }
12401229 if (err > 0) {
....@@ -1310,7 +1299,7 @@
13101299 bio_set_dev(bio, device->ldev->backing_bdev);
13111300 bio->bi_private = octx;
13121301 bio->bi_end_io = one_flush_endio;
1313
- bio->bi_opf = REQ_OP_FLUSH | REQ_PREFLUSH;
1302
+ bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
13141303
13151304 device->flush_jif = jiffies;
13161305 set_bit(FLUSH_PENDING, &device->flags);
....@@ -1490,14 +1479,129 @@
14901479 drbd_info(resource, "Method to ensure write ordering: %s\n", write_ordering_str[resource->write_ordering]);
14911480 }
14921481
1493
-static void drbd_issue_peer_discard(struct drbd_device *device, struct drbd_peer_request *peer_req)
1482
+/*
1483
+ * Mapping "discard" to ZEROOUT with UNMAP does not work for us:
1484
+ * Drivers have to "announce" q->limits.max_write_zeroes_sectors, or it
1485
+ * will directly go to fallback mode, submitting normal writes, and
1486
+ * never even try to UNMAP.
1487
+ *
1488
+ * And dm-thin does not do this (yet), mostly because in general it has
1489
+ * to assume that "skip_block_zeroing" is set. See also:
1490
+ * https://www.mail-archive.com/dm-devel%40redhat.com/msg07965.html
1491
+ * https://www.redhat.com/archives/dm-devel/2018-January/msg00271.html
1492
+ *
1493
+ * We *may* ignore the discard-zeroes-data setting, if so configured.
1494
+ *
1495
+ * Assumption is that this "discard_zeroes_data=0" is only because the backend
1496
+ * may ignore partial unaligned discards.
1497
+ *
1498
+ * LVM/DM thin as of at least
1499
+ * LVM version: 2.02.115(2)-RHEL7 (2015-01-28)
1500
+ * Library version: 1.02.93-RHEL7 (2015-01-28)
1501
+ * Driver version: 4.29.0
1502
+ * still behaves this way.
1503
+ *
1504
+ * For unaligned (wrt. alignment and granularity) or too small discards,
1505
+ * we zero-out the initial (and/or) trailing unaligned partial chunks,
1506
+ * but discard all the aligned full chunks.
1507
+ *
1508
+ * At least for LVM/DM thin, with skip_block_zeroing=false,
1509
+ * the result is effectively "discard_zeroes_data=1".
1510
+ */
1511
+/* flags: EE_TRIM|EE_ZEROOUT */
1512
+int drbd_issue_discard_or_zero_out(struct drbd_device *device, sector_t start, unsigned int nr_sectors, int flags)
14941513 {
14951514 struct block_device *bdev = device->ldev->backing_bdev;
1515
+ struct request_queue *q = bdev_get_queue(bdev);
1516
+ sector_t tmp, nr;
1517
+ unsigned int max_discard_sectors, granularity;
1518
+ int alignment;
1519
+ int err = 0;
14961520
1497
- if (blkdev_issue_zeroout(bdev, peer_req->i.sector, peer_req->i.size >> 9,
1498
- GFP_NOIO, 0))
1521
+ if ((flags & EE_ZEROOUT) || !(flags & EE_TRIM))
1522
+ goto zero_out;
1523
+
1524
+ /* Zero-sector (unknown) and one-sector granularities are the same. */
1525
+ granularity = max(q->limits.discard_granularity >> 9, 1U);
1526
+ alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
1527
+
1528
+ max_discard_sectors = min(q->limits.max_discard_sectors, (1U << 22));
1529
+ max_discard_sectors -= max_discard_sectors % granularity;
1530
+ if (unlikely(!max_discard_sectors))
1531
+ goto zero_out;
1532
+
1533
+ if (nr_sectors < granularity)
1534
+ goto zero_out;
1535
+
1536
+ tmp = start;
1537
+ if (sector_div(tmp, granularity) != alignment) {
1538
+ if (nr_sectors < 2*granularity)
1539
+ goto zero_out;
1540
+ /* start + gran - (start + gran - align) % gran */
1541
+ tmp = start + granularity - alignment;
1542
+ tmp = start + granularity - sector_div(tmp, granularity);
1543
+
1544
+ nr = tmp - start;
1545
+ /* don't flag BLKDEV_ZERO_NOUNMAP, we don't know how many
1546
+ * layers are below us, some may have smaller granularity */
1547
+ err |= blkdev_issue_zeroout(bdev, start, nr, GFP_NOIO, 0);
1548
+ nr_sectors -= nr;
1549
+ start = tmp;
1550
+ }
1551
+ while (nr_sectors >= max_discard_sectors) {
1552
+ err |= blkdev_issue_discard(bdev, start, max_discard_sectors, GFP_NOIO, 0);
1553
+ nr_sectors -= max_discard_sectors;
1554
+ start += max_discard_sectors;
1555
+ }
1556
+ if (nr_sectors) {
1557
+ /* max_discard_sectors is unsigned int (and a multiple of
1558
+ * granularity, we made sure of that above already);
1559
+ * nr is < max_discard_sectors;
1560
+ * I don't need sector_div here, even though nr is sector_t */
1561
+ nr = nr_sectors;
1562
+ nr -= (unsigned int)nr % granularity;
1563
+ if (nr) {
1564
+ err |= blkdev_issue_discard(bdev, start, nr, GFP_NOIO, 0);
1565
+ nr_sectors -= nr;
1566
+ start += nr;
1567
+ }
1568
+ }
1569
+ zero_out:
1570
+ if (nr_sectors) {
1571
+ err |= blkdev_issue_zeroout(bdev, start, nr_sectors, GFP_NOIO,
1572
+ (flags & EE_TRIM) ? 0 : BLKDEV_ZERO_NOUNMAP);
1573
+ }
1574
+ return err != 0;
1575
+}
1576
+
1577
+static bool can_do_reliable_discards(struct drbd_device *device)
1578
+{
1579
+ struct request_queue *q = bdev_get_queue(device->ldev->backing_bdev);
1580
+ struct disk_conf *dc;
1581
+ bool can_do;
1582
+
1583
+ if (!blk_queue_discard(q))
1584
+ return false;
1585
+
1586
+ rcu_read_lock();
1587
+ dc = rcu_dereference(device->ldev->disk_conf);
1588
+ can_do = dc->discard_zeroes_if_aligned;
1589
+ rcu_read_unlock();
1590
+ return can_do;
1591
+}
1592
+
1593
+static void drbd_issue_peer_discard_or_zero_out(struct drbd_device *device, struct drbd_peer_request *peer_req)
1594
+{
1595
+ /* If the backend cannot discard, or does not guarantee
1596
+ * read-back zeroes in discarded ranges, we fall back to
1597
+ * zero-out. Unless configuration specifically requested
1598
+ * otherwise. */
1599
+ if (!can_do_reliable_discards(device))
1600
+ peer_req->flags |= EE_ZEROOUT;
1601
+
1602
+ if (drbd_issue_discard_or_zero_out(device, peer_req->i.sector,
1603
+ peer_req->i.size >> 9, peer_req->flags & (EE_ZEROOUT|EE_TRIM)))
14991604 peer_req->flags |= EE_WAS_ERROR;
1500
-
15011605 drbd_endio_write_sec_final(peer_req);
15021606 }
15031607
....@@ -1550,7 +1654,7 @@
15501654 * Correctness first, performance later. Next step is to code an
15511655 * asynchronous variant of the same.
15521656 */
1553
- if (peer_req->flags & (EE_IS_TRIM|EE_WRITE_SAME)) {
1657
+ if (peer_req->flags & (EE_TRIM|EE_WRITE_SAME|EE_ZEROOUT)) {
15541658 /* wait for all pending IO completions, before we start
15551659 * zeroing things out. */
15561660 conn_wait_active_ee_empty(peer_req->peer_device->connection);
....@@ -1567,8 +1671,8 @@
15671671 spin_unlock_irq(&device->resource->req_lock);
15681672 }
15691673
1570
- if (peer_req->flags & EE_IS_TRIM)
1571
- drbd_issue_peer_discard(device, peer_req);
1674
+ if (peer_req->flags & (EE_TRIM|EE_ZEROOUT))
1675
+ drbd_issue_peer_discard_or_zero_out(device, peer_req);
15721676 else /* EE_WRITE_SAME */
15731677 drbd_issue_peer_wsame(device, peer_req);
15741678 return 0;
....@@ -1619,7 +1723,7 @@
16191723 bios = bios->bi_next;
16201724 bio->bi_next = NULL;
16211725
1622
- drbd_generic_make_request(device, fault_type, bio);
1726
+ drbd_submit_bio_noacct(device, fault_type, bio);
16231727 } while (bios);
16241728 return 0;
16251729
....@@ -1693,7 +1797,7 @@
16931797 break;
16941798 else
16951799 drbd_warn(connection, "Allocation of an epoch failed, slowing down\n");
1696
- /* Fall through */
1800
+ fallthrough;
16971801
16981802 case WO_BDEV_FLUSH:
16991803 case WO_DRAIN_IO:
....@@ -1732,7 +1836,7 @@
17321836 }
17331837
17341838 /* quick wrapper in case payload size != request_size (write same) */
1735
-static void drbd_csum_ee_size(struct crypto_ahash *h,
1839
+static void drbd_csum_ee_size(struct crypto_shash *h,
17361840 struct drbd_peer_request *r, void *d,
17371841 unsigned int payload_size)
17381842 {
....@@ -1756,7 +1860,7 @@
17561860 struct packet_info *pi) __must_hold(local)
17571861 {
17581862 struct drbd_device *device = peer_device->device;
1759
- const sector_t capacity = drbd_get_capacity(device->this_bdev);
1863
+ const sector_t capacity = get_capacity(device->vdisk);
17601864 struct drbd_peer_request *peer_req;
17611865 struct page *page;
17621866 int digest_size, err;
....@@ -1765,11 +1869,12 @@
17651869 void *dig_vv = peer_device->connection->int_dig_vv;
17661870 unsigned long *data;
17671871 struct p_trim *trim = (pi->cmd == P_TRIM) ? pi->data : NULL;
1872
+ struct p_trim *zeroes = (pi->cmd == P_ZEROES) ? pi->data : NULL;
17681873 struct p_trim *wsame = (pi->cmd == P_WSAME) ? pi->data : NULL;
17691874
17701875 digest_size = 0;
17711876 if (!trim && peer_device->connection->peer_integrity_tfm) {
1772
- digest_size = crypto_ahash_digestsize(peer_device->connection->peer_integrity_tfm);
1877
+ digest_size = crypto_shash_digestsize(peer_device->connection->peer_integrity_tfm);
17731878 /*
17741879 * FIXME: Receive the incoming digest into the receive buffer
17751880 * here, together with its struct p_data?
....@@ -1786,6 +1891,10 @@
17861891 if (!expect(data_size == 0))
17871892 return NULL;
17881893 ds = be32_to_cpu(trim->size);
1894
+ } else if (zeroes) {
1895
+ if (!expect(data_size == 0))
1896
+ return NULL;
1897
+ ds = be32_to_cpu(zeroes->size);
17891898 } else if (wsame) {
17901899 if (data_size != queue_logical_block_size(device->rq_queue)) {
17911900 drbd_err(peer_device, "data size (%u) != drbd logical block size (%u)\n",
....@@ -1802,7 +1911,7 @@
18021911
18031912 if (!expect(IS_ALIGNED(ds, 512)))
18041913 return NULL;
1805
- if (trim || wsame) {
1914
+ if (trim || wsame || zeroes) {
18061915 if (!expect(ds <= (DRBD_MAX_BBIO_SECTORS << 9)))
18071916 return NULL;
18081917 } else if (!expect(ds <= DRBD_MAX_BIO_SIZE))
....@@ -1827,7 +1936,11 @@
18271936
18281937 peer_req->flags |= EE_WRITE;
18291938 if (trim) {
1830
- peer_req->flags |= EE_IS_TRIM;
1939
+ peer_req->flags |= EE_TRIM;
1940
+ return peer_req;
1941
+ }
1942
+ if (zeroes) {
1943
+ peer_req->flags |= EE_ZEROOUT;
18311944 return peer_req;
18321945 }
18331946 if (wsame)
....@@ -1905,7 +2018,7 @@
19052018
19062019 digest_size = 0;
19072020 if (peer_device->connection->peer_integrity_tfm) {
1908
- digest_size = crypto_ahash_digestsize(peer_device->connection->peer_integrity_tfm);
2021
+ digest_size = crypto_shash_digestsize(peer_device->connection->peer_integrity_tfm);
19092022 err = drbd_recv_all_warn(peer_device->connection, dig_in, digest_size);
19102023 if (err)
19112024 return err;
....@@ -2326,8 +2439,12 @@
23262439
23272440 static unsigned long wire_flags_to_bio_op(u32 dpf)
23282441 {
2329
- if (dpf & DP_DISCARD)
2442
+ if (dpf & DP_ZEROES)
23302443 return REQ_OP_WRITE_ZEROES;
2444
+ if (dpf & DP_DISCARD)
2445
+ return REQ_OP_DISCARD;
2446
+ if (dpf & DP_WSAME)
2447
+ return REQ_OP_WRITE_SAME;
23312448 else
23322449 return REQ_OP_WRITE;
23332450 }
....@@ -2518,8 +2635,19 @@
25182635 op_flags = wire_flags_to_bio_flags(dp_flags);
25192636 if (pi->cmd == P_TRIM) {
25202637 D_ASSERT(peer_device, peer_req->i.size > 0);
2638
+ D_ASSERT(peer_device, op == REQ_OP_DISCARD);
2639
+ D_ASSERT(peer_device, peer_req->pages == NULL);
2640
+ /* need to play safe: an older DRBD sender
2641
+ * may mean zero-out while sending P_TRIM. */
2642
+ if (0 == (connection->agreed_features & DRBD_FF_WZEROES))
2643
+ peer_req->flags |= EE_ZEROOUT;
2644
+ } else if (pi->cmd == P_ZEROES) {
2645
+ D_ASSERT(peer_device, peer_req->i.size > 0);
25212646 D_ASSERT(peer_device, op == REQ_OP_WRITE_ZEROES);
25222647 D_ASSERT(peer_device, peer_req->pages == NULL);
2648
+ /* Do (not) pass down BLKDEV_ZERO_NOUNMAP? */
2649
+ if (dp_flags & DP_DISCARD)
2650
+ peer_req->flags |= EE_TRIM;
25232651 } else if (peer_req->pages == NULL) {
25242652 D_ASSERT(device, peer_req->i.size == 0);
25252653 D_ASSERT(device, dp_flags & DP_FLUSH);
....@@ -2587,7 +2715,7 @@
25872715 * we wait for all pending requests, respectively wait for
25882716 * active_ee to become empty in drbd_submit_peer_request();
25892717 * better not add ourselves here. */
2590
- if ((peer_req->flags & (EE_IS_TRIM|EE_WRITE_SAME)) == 0)
2718
+ if ((peer_req->flags & (EE_TRIM|EE_WRITE_SAME|EE_ZEROOUT)) == 0)
25912719 list_add_tail(&peer_req->w.list, &device->active_ee);
25922720 spin_unlock_irq(&device->resource->req_lock);
25932721
....@@ -2661,7 +2789,7 @@
26612789
26622790 bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
26632791 {
2664
- struct gendisk *disk = device->ldev->backing_bdev->bd_contains->bd_disk;
2792
+ struct gendisk *disk = device->ldev->backing_bdev->bd_disk;
26652793 unsigned long db, dt, dbdt;
26662794 unsigned int c_min_rate;
26672795 int curr_events;
....@@ -2721,7 +2849,7 @@
27212849 if (!peer_device)
27222850 return -EIO;
27232851 device = peer_device->device;
2724
- capacity = drbd_get_capacity(device->this_bdev);
2852
+ capacity = get_capacity(device->vdisk);
27252853
27262854 sector = be64_to_cpu(p->sector);
27272855 size = be32_to_cpu(p->blksize);
....@@ -2789,7 +2917,7 @@
27892917 then we would do something smarter here than reading
27902918 the block... */
27912919 peer_req->flags |= EE_RS_THIN_REQ;
2792
- /* fall through */
2920
+ fallthrough;
27932921 case P_RS_DATA_REQUEST:
27942922 peer_req->w.cb = w_e_end_rsdata_req;
27952923 fault_type = DRBD_FAULT_RS_RD;
....@@ -2955,7 +3083,7 @@
29553083 rv = 1;
29563084 break;
29573085 }
2958
- /* Else fall through to one of the other strategies... */
3086
+ fallthrough; /* to one of the other strategies */
29593087 case ASB_DISCARD_OLDER_PRI:
29603088 if (self == 0 && peer == 1) {
29613089 rv = 1;
....@@ -2968,7 +3096,7 @@
29683096 /* Else fall through to one of the other strategies... */
29693097 drbd_warn(device, "Discard younger/older primary did not find a decision\n"
29703098 "Using discard-least-changes instead\n");
2971
- /* fall through */
3099
+ fallthrough;
29723100 case ASB_DISCARD_ZERO_CHG:
29733101 if (ch_peer == 0 && ch_self == 0) {
29743102 rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)
....@@ -2980,7 +3108,7 @@
29803108 }
29813109 if (after_sb_0p == ASB_DISCARD_ZERO_CHG)
29823110 break;
2983
- /* else: fall through */
3111
+ fallthrough;
29843112 case ASB_DISCARD_LEAST_CHG:
29853113 if (ch_self < ch_peer)
29863114 rv = -1;
....@@ -3480,7 +3608,7 @@
34803608 switch (rr_conflict) {
34813609 case ASB_CALL_HELPER:
34823610 drbd_khelper(device, "pri-lost");
3483
- /* fall through */
3611
+ fallthrough;
34843612 case ASB_DISCONNECT:
34853613 drbd_err(device, "I shall become SyncTarget, but I am primary!\n");
34863614 return C_MASK;
....@@ -3543,7 +3671,7 @@
35433671 int p_proto, p_discard_my_data, p_two_primaries, cf;
35443672 struct net_conf *nc, *old_net_conf, *new_net_conf = NULL;
35453673 char integrity_alg[SHARED_SECRET_MAX] = "";
3546
- struct crypto_ahash *peer_integrity_tfm = NULL;
3674
+ struct crypto_shash *peer_integrity_tfm = NULL;
35473675 void *int_dig_in = NULL, *int_dig_vv = NULL;
35483676
35493677 p_proto = be32_to_cpu(p->protocol);
....@@ -3624,7 +3752,7 @@
36243752 * change.
36253753 */
36263754
3627
- peer_integrity_tfm = crypto_alloc_ahash(integrity_alg, 0, CRYPTO_ALG_ASYNC);
3755
+ peer_integrity_tfm = crypto_alloc_shash(integrity_alg, 0, 0);
36283756 if (IS_ERR(peer_integrity_tfm)) {
36293757 peer_integrity_tfm = NULL;
36303758 drbd_err(connection, "peer data-integrity-alg %s not supported\n",
....@@ -3632,7 +3760,7 @@
36323760 goto disconnect;
36333761 }
36343762
3635
- hash_size = crypto_ahash_digestsize(peer_integrity_tfm);
3763
+ hash_size = crypto_shash_digestsize(peer_integrity_tfm);
36363764 int_dig_in = kmalloc(hash_size, GFP_KERNEL);
36373765 int_dig_vv = kmalloc(hash_size, GFP_KERNEL);
36383766 if (!(int_dig_in && int_dig_vv)) {
....@@ -3662,7 +3790,7 @@
36623790 mutex_unlock(&connection->resource->conf_update);
36633791 mutex_unlock(&connection->data.mutex);
36643792
3665
- crypto_free_ahash(connection->peer_integrity_tfm);
3793
+ crypto_free_shash(connection->peer_integrity_tfm);
36663794 kfree(connection->int_dig_in);
36673795 kfree(connection->int_dig_vv);
36683796 connection->peer_integrity_tfm = peer_integrity_tfm;
....@@ -3680,7 +3808,7 @@
36803808 disconnect_rcu_unlock:
36813809 rcu_read_unlock();
36823810 disconnect:
3683
- crypto_free_ahash(peer_integrity_tfm);
3811
+ crypto_free_shash(peer_integrity_tfm);
36843812 kfree(int_dig_in);
36853813 kfree(int_dig_vv);
36863814 conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD);
....@@ -3692,15 +3820,16 @@
36923820 * return: NULL (alg name was "")
36933821 * ERR_PTR(error) if something goes wrong
36943822 * or the crypto hash ptr, if it worked out ok. */
3695
-static struct crypto_ahash *drbd_crypto_alloc_digest_safe(const struct drbd_device *device,
3823
+static struct crypto_shash *drbd_crypto_alloc_digest_safe(
3824
+ const struct drbd_device *device,
36963825 const char *alg, const char *name)
36973826 {
3698
- struct crypto_ahash *tfm;
3827
+ struct crypto_shash *tfm;
36993828
37003829 if (!alg[0])
37013830 return NULL;
37023831
3703
- tfm = crypto_alloc_ahash(alg, 0, CRYPTO_ALG_ASYNC);
3832
+ tfm = crypto_alloc_shash(alg, 0, 0);
37043833 if (IS_ERR(tfm)) {
37053834 drbd_err(device, "Can not allocate \"%s\" as %s (reason: %ld)\n",
37063835 alg, name, PTR_ERR(tfm));
....@@ -3753,13 +3882,13 @@
37533882 struct drbd_device *device;
37543883 struct p_rs_param_95 *p;
37553884 unsigned int header_size, data_size, exp_max_sz;
3756
- struct crypto_ahash *verify_tfm = NULL;
3757
- struct crypto_ahash *csums_tfm = NULL;
3885
+ struct crypto_shash *verify_tfm = NULL;
3886
+ struct crypto_shash *csums_tfm = NULL;
37583887 struct net_conf *old_net_conf, *new_net_conf = NULL;
37593888 struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL;
37603889 const int apv = connection->agreed_pro_version;
37613890 struct fifo_buffer *old_plan = NULL, *new_plan = NULL;
3762
- int fifo_size = 0;
3891
+ unsigned int fifo_size = 0;
37633892 int err;
37643893
37653894 peer_device = conn_peer_device(connection, pi->vnr);
....@@ -3901,14 +4030,14 @@
39014030 if (verify_tfm) {
39024031 strcpy(new_net_conf->verify_alg, p->verify_alg);
39034032 new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1;
3904
- crypto_free_ahash(peer_device->connection->verify_tfm);
4033
+ crypto_free_shash(peer_device->connection->verify_tfm);
39054034 peer_device->connection->verify_tfm = verify_tfm;
39064035 drbd_info(device, "using verify-alg: \"%s\"\n", p->verify_alg);
39074036 }
39084037 if (csums_tfm) {
39094038 strcpy(new_net_conf->csums_alg, p->csums_alg);
39104039 new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1;
3911
- crypto_free_ahash(peer_device->connection->csums_tfm);
4040
+ crypto_free_shash(peer_device->connection->csums_tfm);
39124041 peer_device->connection->csums_tfm = csums_tfm;
39134042 drbd_info(device, "using csums-alg: \"%s\"\n", p->csums_alg);
39144043 }
....@@ -3952,9 +4081,9 @@
39524081 mutex_unlock(&connection->resource->conf_update);
39534082 /* just for completeness: actually not needed,
39544083 * as this is not reached if csums_tfm was ok. */
3955
- crypto_free_ahash(csums_tfm);
4084
+ crypto_free_shash(csums_tfm);
39564085 /* but free the verify_tfm again, if csums_tfm did not work out */
3957
- crypto_free_ahash(verify_tfm);
4086
+ crypto_free_shash(verify_tfm);
39584087 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
39594088 return -EIO;
39604089 }
....@@ -3988,7 +4117,7 @@
39884117 if (!peer_device)
39894118 return config_unknown_volume(connection, pi);
39904119 device = peer_device->device;
3991
- cur_size = drbd_get_capacity(device->this_bdev);
4120
+ cur_size = get_capacity(device->vdisk);
39924121
39934122 p_size = be64_to_cpu(p->d_size);
39944123 p_usize = be64_to_cpu(p->u_size);
....@@ -4013,12 +4142,13 @@
40134142 if (device->state.conn == C_WF_REPORT_PARAMS)
40144143 p_usize = min_not_zero(my_usize, p_usize);
40154144
4016
- /* Never shrink a device with usable data during connect.
4017
- But allow online shrinking if we are connected. */
4145
+ /* Never shrink a device with usable data during connect,
4146
+ * or "attach" on the peer.
4147
+ * But allow online shrinking if we are connected. */
40184148 new_size = drbd_new_dev_size(device, device->ldev, p_usize, 0);
40194149 if (new_size < cur_size &&
40204150 device->state.disk >= D_OUTDATED &&
4021
- device->state.conn < C_CONNECTED) {
4151
+ (device->state.conn < C_CONNECTED || device->state.pdsk == D_DISKLESS)) {
40224152 drbd_err(device, "The peer's disk size is too small! (%llu < %llu sectors)\n",
40234153 (unsigned long long)new_size, (unsigned long long)cur_size);
40244154 conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD);
....@@ -4046,8 +4176,8 @@
40464176 synchronize_rcu();
40474177 kfree(old_disk_conf);
40484178
4049
- drbd_info(device, "Peer sets u_size to %lu sectors\n",
4050
- (unsigned long)my_usize);
4179
+ drbd_info(device, "Peer sets u_size to %lu sectors (old: %lu)\n",
4180
+ (unsigned long)p_usize, (unsigned long)my_usize);
40514181 }
40524182
40534183 put_ldev(device);
....@@ -4122,8 +4252,8 @@
41224252 }
41234253
41244254 if (device->state.conn > C_WF_REPORT_PARAMS) {
4125
- if (be64_to_cpu(p->c_size) !=
4126
- drbd_get_capacity(device->this_bdev) || ldsc) {
4255
+ if (be64_to_cpu(p->c_size) != get_capacity(device->vdisk) ||
4256
+ ldsc) {
41274257 /* we have different sizes, probably peer
41284258 * needs to know my new size... */
41294259 drbd_send_sizes(peer_device, 0, ddsf);
....@@ -4426,7 +4556,7 @@
44264556 (peer_state.disk == D_NEGOTIATING ||
44274557 os.disk == D_NEGOTIATING));
44284558 /* if we have both been inconsistent, and the peer has been
4429
- * forced to be UpToDate with --overwrite-data */
4559
+ * forced to be UpToDate with --force */
44304560 cr |= test_bit(CONSIDER_RESYNC, &device->flags);
44314561 /* if we had been plain connected, and the admin requested to
44324562 * start a sync by "invalidate" or "invalidate-remote" */
....@@ -4829,8 +4959,7 @@
48294959 {
48304960 /* Make sure we've acked all the TCP data associated
48314961 * with the data requests being unplugged */
4832
- drbd_tcp_quickack(connection->data.socket);
4833
-
4962
+ tcp_sock_set_quickack(connection->data.socket->sk, 2);
48344963 return 0;
48354964 }
48364965
....@@ -4891,7 +5020,7 @@
48915020
48925021 peer_req->w.cb = e_end_resync_block;
48935022 peer_req->submit_jif = jiffies;
4894
- peer_req->flags |= EE_IS_TRIM;
5023
+ peer_req->flags |= EE_TRIM;
48955024
48965025 spin_lock_irq(&device->resource->req_lock);
48975026 list_add_tail(&peer_req->w.list, &device->sync_ee);
....@@ -4959,6 +5088,7 @@
49595088 [P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_conn_state },
49605089 [P_PROTOCOL_UPDATE] = { 1, sizeof(struct p_protocol), receive_protocol },
49615090 [P_TRIM] = { 0, sizeof(struct p_trim), receive_Data },
5091
+ [P_ZEROES] = { 0, sizeof(struct p_trim), receive_Data },
49625092 [P_RS_DEALLOCATED] = { 0, sizeof(struct p_block_desc), receive_rs_deallocated },
49635093 [P_WSAME] = { 1, sizeof(struct p_wsame), receive_Data },
49645094 };
....@@ -5243,11 +5373,12 @@
52435373 drbd_info(connection, "Handshake successful: "
52445374 "Agreed network protocol version %d\n", connection->agreed_pro_version);
52455375
5246
- drbd_info(connection, "Feature flags enabled on protocol level: 0x%x%s%s%s.\n",
5376
+ drbd_info(connection, "Feature flags enabled on protocol level: 0x%x%s%s%s%s.\n",
52475377 connection->agreed_features,
52485378 connection->agreed_features & DRBD_FF_TRIM ? " TRIM" : "",
52495379 connection->agreed_features & DRBD_FF_THIN_RESYNC ? " THIN_RESYNC" : "",
5250
- connection->agreed_features & DRBD_FF_WSAME ? " WRITE_SAME" :
5380
+ connection->agreed_features & DRBD_FF_WSAME ? " WRITE_SAME" : "",
5381
+ connection->agreed_features & DRBD_FF_WZEROES ? " WRITE_ZEROES" :
52515382 connection->agreed_features ? "" : " none");
52525383
52535384 return 1;
....@@ -5307,7 +5438,6 @@
53075438 goto fail;
53085439 }
53095440 desc->tfm = connection->cram_hmac_tfm;
5310
- desc->flags = 0;
53115441
53125442 rv = crypto_shash_setkey(connection->cram_hmac_tfm, (u8 *)secret, key_len);
53135443 if (rv) {
....@@ -5337,7 +5467,7 @@
53375467 if (pi.cmd != P_AUTH_CHALLENGE) {
53385468 drbd_err(connection, "expected AuthChallenge packet, received: %s (0x%04x)\n",
53395469 cmdname(pi.cmd), pi.cmd);
5340
- rv = 0;
5470
+ rv = -1;
53415471 goto fail;
53425472 }
53435473
....@@ -5889,11 +6019,8 @@
58896019 unsigned int header_size = drbd_header_size(connection);
58906020 int expect = header_size;
58916021 bool ping_timeout_active = false;
5892
- struct sched_param param = { .sched_priority = 2 };
58936022
5894
- rv = sched_setscheduler(current, SCHED_RR, &param);
5895
- if (rv < 0)
5896
- drbd_err(connection, "drbd_ack_receiver: ERROR set priority, ret=%d\n", rv);
6023
+ sched_set_fifo_low(current);
58976024
58986025 while (get_t_state(thi) == RUNNING) {
58996026 drbd_thread_current_set_cpu(thi);
....@@ -5983,7 +6110,7 @@
59836110
59846111 err = cmd->fn(connection, &pi);
59856112 if (err) {
5986
- drbd_err(connection, "%pf failed\n", cmd->fn);
6113
+ drbd_err(connection, "%ps failed\n", cmd->fn);
59876114 goto reconnect;
59886115 }
59896116
....@@ -6031,7 +6158,7 @@
60316158 rcu_read_unlock();
60326159
60336160 if (tcp_cork)
6034
- drbd_tcp_cork(connection->meta.socket);
6161
+ tcp_sock_set_cork(connection->meta.socket->sk, true);
60356162
60366163 err = drbd_finish_peer_reqs(device);
60376164 kref_put(&device->kref, drbd_destroy_device);
....@@ -6044,7 +6171,7 @@
60446171 }
60456172
60466173 if (tcp_cork)
6047
- drbd_tcp_uncork(connection->meta.socket);
6174
+ tcp_sock_set_cork(connection->meta.socket->sk, false);
60486175
60496176 return;
60506177 }