hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/block/drbd/drbd_worker.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 drbd_worker.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
....@@ -34,6 +22,7 @@
3422 #include <linux/random.h>
3523 #include <linux/string.h>
3624 #include <linux/scatterlist.h>
25
+#include <linux/part_stat.h>
3726
3827 #include "drbd_int.h"
3928 #include "drbd_protocol.h"
....@@ -152,8 +141,8 @@
152141
153142 do_wake = list_empty(block_id == ID_SYNCER ? &device->sync_ee : &device->active_ee);
154143
155
- /* FIXME do we want to detach for failed REQ_DISCARD?
156
- * ((peer_req->flags & (EE_WAS_ERROR|EE_IS_TRIM)) == EE_WAS_ERROR) */
144
+ /* FIXME do we want to detach for failed REQ_OP_DISCARD?
145
+ * ((peer_req->flags & (EE_WAS_ERROR|EE_TRIM)) == EE_WAS_ERROR) */
157146 if (peer_req->flags & EE_WAS_ERROR)
158147 __drbd_chk_io_error(device, DRBD_WRITE_ERROR);
159148
....@@ -295,60 +284,59 @@
295284 complete_master_bio(device, &m);
296285 }
297286
298
-void drbd_csum_ee(struct crypto_ahash *tfm, struct drbd_peer_request *peer_req, void *digest)
287
+void drbd_csum_ee(struct crypto_shash *tfm, struct drbd_peer_request *peer_req, void *digest)
299288 {
300
- AHASH_REQUEST_ON_STACK(req, tfm);
301
- struct scatterlist sg;
289
+ SHASH_DESC_ON_STACK(desc, tfm);
302290 struct page *page = peer_req->pages;
303291 struct page *tmp;
304292 unsigned len;
293
+ void *src;
305294
306
- ahash_request_set_tfm(req, tfm);
307
- ahash_request_set_callback(req, 0, NULL, NULL);
295
+ desc->tfm = tfm;
308296
309
- sg_init_table(&sg, 1);
310
- crypto_ahash_init(req);
297
+ crypto_shash_init(desc);
311298
299
+ src = kmap_atomic(page);
312300 while ((tmp = page_chain_next(page))) {
313301 /* all but the last page will be fully used */
314
- sg_set_page(&sg, page, PAGE_SIZE, 0);
315
- ahash_request_set_crypt(req, &sg, NULL, sg.length);
316
- crypto_ahash_update(req);
302
+ crypto_shash_update(desc, src, PAGE_SIZE);
303
+ kunmap_atomic(src);
317304 page = tmp;
305
+ src = kmap_atomic(page);
318306 }
319307 /* and now the last, possibly only partially used page */
320308 len = peer_req->i.size & (PAGE_SIZE - 1);
321
- sg_set_page(&sg, page, len ?: PAGE_SIZE, 0);
322
- ahash_request_set_crypt(req, &sg, digest, sg.length);
323
- crypto_ahash_finup(req);
324
- ahash_request_zero(req);
309
+ crypto_shash_update(desc, src, len ?: PAGE_SIZE);
310
+ kunmap_atomic(src);
311
+
312
+ crypto_shash_final(desc, digest);
313
+ shash_desc_zero(desc);
325314 }
326315
327
-void drbd_csum_bio(struct crypto_ahash *tfm, struct bio *bio, void *digest)
316
+void drbd_csum_bio(struct crypto_shash *tfm, struct bio *bio, void *digest)
328317 {
329
- AHASH_REQUEST_ON_STACK(req, tfm);
330
- struct scatterlist sg;
318
+ SHASH_DESC_ON_STACK(desc, tfm);
331319 struct bio_vec bvec;
332320 struct bvec_iter iter;
333321
334
- ahash_request_set_tfm(req, tfm);
335
- ahash_request_set_callback(req, 0, NULL, NULL);
322
+ desc->tfm = tfm;
336323
337
- sg_init_table(&sg, 1);
338
- crypto_ahash_init(req);
324
+ crypto_shash_init(desc);
339325
340326 bio_for_each_segment(bvec, bio, iter) {
341
- sg_set_page(&sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset);
342
- ahash_request_set_crypt(req, &sg, NULL, sg.length);
343
- crypto_ahash_update(req);
327
+ u8 *src;
328
+
329
+ src = kmap_atomic(bvec.bv_page);
330
+ crypto_shash_update(desc, src + bvec.bv_offset, bvec.bv_len);
331
+ kunmap_atomic(src);
332
+
344333 /* REQ_OP_WRITE_SAME has only one segment,
345334 * checksum the payload only once. */
346335 if (bio_op(bio) == REQ_OP_WRITE_SAME)
347336 break;
348337 }
349
- ahash_request_set_crypt(req, NULL, digest, 0);
350
- crypto_ahash_final(req);
351
- ahash_request_zero(req);
338
+ crypto_shash_final(desc, digest);
339
+ shash_desc_zero(desc);
352340 }
353341
354342 /* MAYBE merge common code with w_e_end_ov_req */
....@@ -367,7 +355,7 @@
367355 if (unlikely((peer_req->flags & EE_WAS_ERROR) != 0))
368356 goto out;
369357
370
- digest_size = crypto_ahash_digestsize(peer_device->connection->csums_tfm);
358
+ digest_size = crypto_shash_digestsize(peer_device->connection->csums_tfm);
371359 digest = kmalloc(digest_size, GFP_NOIO);
372360 if (digest) {
373361 sector_t sector = peer_req->i.sector;
....@@ -495,11 +483,11 @@
495483 fb->values[i] += value;
496484 }
497485
498
-struct fifo_buffer *fifo_alloc(int fifo_size)
486
+struct fifo_buffer *fifo_alloc(unsigned int fifo_size)
499487 {
500488 struct fifo_buffer *fb;
501489
502
- fb = kzalloc(sizeof(struct fifo_buffer) + sizeof(int) * fifo_size, GFP_NOIO);
490
+ fb = kzalloc(struct_size(fb, values, fifo_size), GFP_NOIO);
503491 if (!fb)
504492 return NULL;
505493
....@@ -603,7 +591,7 @@
603591 struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL;
604592 unsigned long bit;
605593 sector_t sector;
606
- const sector_t capacity = drbd_get_capacity(device->this_bdev);
594
+ const sector_t capacity = get_capacity(device->vdisk);
607595 int max_bio_size;
608596 int number, rollback_i, size;
609597 int align, requeue = 0;
....@@ -781,7 +769,7 @@
781769 {
782770 int number, i, size;
783771 sector_t sector;
784
- const sector_t capacity = drbd_get_capacity(device->this_bdev);
772
+ const sector_t capacity = get_capacity(device->vdisk);
785773 bool stop_sector_reached = false;
786774
787775 if (unlikely(cancel))
....@@ -1205,7 +1193,7 @@
12051193 * a real fix would be much more involved,
12061194 * introducing more locking mechanisms */
12071195 if (peer_device->connection->csums_tfm) {
1208
- digest_size = crypto_ahash_digestsize(peer_device->connection->csums_tfm);
1196
+ digest_size = crypto_shash_digestsize(peer_device->connection->csums_tfm);
12091197 D_ASSERT(device, digest_size == di->digest_size);
12101198 digest = kmalloc(digest_size, GFP_NOIO);
12111199 }
....@@ -1255,7 +1243,7 @@
12551243 if (unlikely(cancel))
12561244 goto out;
12571245
1258
- digest_size = crypto_ahash_digestsize(peer_device->connection->verify_tfm);
1246
+ digest_size = crypto_shash_digestsize(peer_device->connection->verify_tfm);
12591247 digest = kmalloc(digest_size, GFP_NOIO);
12601248 if (!digest) {
12611249 err = 1; /* terminate the connection in case the allocation failed */
....@@ -1327,7 +1315,7 @@
13271315 di = peer_req->digest;
13281316
13291317 if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) {
1330
- digest_size = crypto_ahash_digestsize(peer_device->connection->verify_tfm);
1318
+ digest_size = crypto_shash_digestsize(peer_device->connection->verify_tfm);
13311319 digest = kmalloc(digest_size, GFP_NOIO);
13321320 if (digest) {
13331321 drbd_csum_ee(peer_device->connection->verify_tfm, peer_req, digest);
....@@ -1537,7 +1525,7 @@
15371525
15381526 drbd_req_make_private_bio(req, req->master_bio);
15391527 bio_set_dev(req->private_bio, device->ldev->backing_bdev);
1540
- generic_make_request(req->private_bio);
1528
+ submit_bio_noacct(req->private_bio);
15411529
15421530 return 0;
15431531 }
....@@ -1684,7 +1672,7 @@
16841672
16851673 void drbd_rs_controller_reset(struct drbd_device *device)
16861674 {
1687
- struct gendisk *disk = device->ldev->backing_bdev->bd_contains->bd_disk;
1675
+ struct gendisk *disk = device->ldev->backing_bdev->bd_disk;
16881676 struct fifo_buffer *plan;
16891677
16901678 atomic_set(&device->rs_sect_in, 0);
....@@ -2110,7 +2098,7 @@
21102098 if (uncork) {
21112099 mutex_lock(&connection->data.mutex);
21122100 if (connection->data.socket)
2113
- drbd_tcp_uncork(connection->data.socket);
2101
+ tcp_sock_set_cork(connection->data.socket->sk, false);
21142102 mutex_unlock(&connection->data.mutex);
21152103 }
21162104
....@@ -2165,9 +2153,9 @@
21652153 mutex_lock(&connection->data.mutex);
21662154 if (connection->data.socket) {
21672155 if (cork)
2168
- drbd_tcp_cork(connection->data.socket);
2156
+ tcp_sock_set_cork(connection->data.socket->sk, true);
21692157 else if (!uncork)
2170
- drbd_tcp_uncork(connection->data.socket);
2158
+ tcp_sock_set_cork(connection->data.socket->sk, false);
21712159 }
21722160 mutex_unlock(&connection->data.mutex);
21732161 }