hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/block/drbd/drbd_req.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 drbd_req.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
....@@ -33,24 +21,6 @@
3321
3422 static bool drbd_may_do_local_read(struct drbd_device *device, sector_t sector, int size);
3523
36
-/* Update disk stats at start of I/O request */
37
-static void _drbd_start_io_acct(struct drbd_device *device, struct drbd_request *req)
38
-{
39
- struct request_queue *q = device->rq_queue;
40
-
41
- generic_start_io_acct(q, bio_op(req->master_bio),
42
- req->i.size >> 9, &device->vdisk->part0);
43
-}
44
-
45
-/* Update disk stats when completing request upwards */
46
-static void _drbd_end_io_acct(struct drbd_device *device, struct drbd_request *req)
47
-{
48
- struct request_queue *q = device->rq_queue;
49
-
50
- generic_end_io_acct(q, bio_op(req->master_bio),
51
- &device->vdisk->part0, req->start_jif);
52
-}
53
-
5424 static struct drbd_request *drbd_req_new(struct drbd_device *device, struct bio *bio_src)
5525 {
5626 struct drbd_request *req;
....@@ -63,7 +33,7 @@
6333 drbd_req_make_private_bio(req, bio_src);
6434 req->rq_state = (bio_data_dir(bio_src) == WRITE ? RQ_WRITE : 0)
6535 | (bio_op(bio_src) == REQ_OP_WRITE_SAME ? RQ_WSAME : 0)
66
- | (bio_op(bio_src) == REQ_OP_WRITE_ZEROES ? RQ_UNMAP : 0)
36
+ | (bio_op(bio_src) == REQ_OP_WRITE_ZEROES ? RQ_ZEROES : 0)
6737 | (bio_op(bio_src) == REQ_OP_DISCARD ? RQ_UNMAP : 0);
6838 req->device = device;
6939 req->master_bio = bio_src;
....@@ -207,7 +177,8 @@
207177 void complete_master_bio(struct drbd_device *device,
208178 struct bio_and_error *m)
209179 {
210
- m->bio->bi_status = errno_to_blk_status(m->error);
180
+ if (unlikely(m->error))
181
+ m->bio->bi_status = errno_to_blk_status(m->error);
211182 bio_endio(m->bio);
212183 dec_ap_bio(device);
213184 }
....@@ -275,7 +246,7 @@
275246 start_new_tl_epoch(first_peer_device(device)->connection);
276247
277248 /* Update disk stats */
278
- _drbd_end_io_acct(device, req);
249
+ bio_end_io_acct(req->master_bio, req->start_jif);
279250
280251 /* If READ failed,
281252 * have it be pushed back to the retry work queue,
....@@ -641,7 +612,7 @@
641612 drbd_set_out_of_sync(device, req->i.sector, req->i.size);
642613 drbd_report_io_error(device, req);
643614 __drbd_chk_io_error(device, DRBD_READ_ERROR);
644
- /* fall through. */
615
+ fallthrough;
645616 case READ_AHEAD_COMPLETED_WITH_ERROR:
646617 /* it is legal to fail read-ahead, no __drbd_chk_io_error in that case. */
647618 mod_rq_state(req, m, RQ_LOCAL_PENDING, RQ_LOCAL_COMPLETED);
....@@ -650,7 +621,7 @@
650621 case DISCARD_COMPLETED_NOTSUPP:
651622 case DISCARD_COMPLETED_WITH_ERROR:
652623 /* I'd rather not detach from local disk just because it
653
- * failed a REQ_DISCARD. */
624
+ * failed a REQ_OP_DISCARD. */
654625 mod_rq_state(req, m, RQ_LOCAL_PENDING, RQ_LOCAL_COMPLETED);
655626 break;
656627
....@@ -866,7 +837,7 @@
866837 } /* else: FIXME can this happen? */
867838 break;
868839 }
869
- /* else, fall through to BARRIER_ACKED */
840
+ fallthrough; /* to BARRIER_ACKED */
870841
871842 case BARRIER_ACKED:
872843 /* barrier ack for READ requests does not make sense */
....@@ -896,7 +867,7 @@
896867 start_new_tl_epoch(connection);
897868 mod_rq_state(req, m, 0, RQ_NET_OK|RQ_NET_DONE);
898869 break;
899
- };
870
+ }
900871
901872 return rv;
902873 }
....@@ -918,7 +889,7 @@
918889 if (device->state.disk != D_INCONSISTENT)
919890 return false;
920891 esector = sector + (size >> 9) - 1;
921
- nr_sectors = drbd_get_capacity(device->this_bdev);
892
+ nr_sectors = get_capacity(device->vdisk);
922893 D_ASSERT(device, sector < nr_sectors);
923894 D_ASSERT(device, esector < nr_sectors);
924895
....@@ -1155,12 +1126,11 @@
11551126 return remote;
11561127 }
11571128
1158
-static void drbd_process_discard_req(struct drbd_request *req)
1129
+static void drbd_process_discard_or_zeroes_req(struct drbd_request *req, int flags)
11591130 {
1160
- struct block_device *bdev = req->device->ldev->backing_bdev;
1161
-
1162
- if (blkdev_issue_zeroout(bdev, req->i.sector, req->i.size >> 9,
1163
- GFP_NOIO, 0))
1131
+ int err = drbd_issue_discard_or_zero_out(req->device,
1132
+ req->i.sector, req->i.size >> 9, flags);
1133
+ if (err)
11641134 req->private_bio->bi_status = BLK_STS_IOERR;
11651135 bio_endio(req->private_bio);
11661136 }
....@@ -1189,11 +1159,13 @@
11891159 if (get_ldev(device)) {
11901160 if (drbd_insert_fault(device, type))
11911161 bio_io_error(bio);
1192
- else if (bio_op(bio) == REQ_OP_WRITE_ZEROES ||
1193
- bio_op(bio) == REQ_OP_DISCARD)
1194
- drbd_process_discard_req(req);
1162
+ else if (bio_op(bio) == REQ_OP_WRITE_ZEROES)
1163
+ drbd_process_discard_or_zeroes_req(req, EE_ZEROOUT |
1164
+ ((bio->bi_opf & REQ_NOUNMAP) ? 0 : EE_TRIM));
1165
+ else if (bio_op(bio) == REQ_OP_DISCARD)
1166
+ drbd_process_discard_or_zeroes_req(req, EE_TRIM);
11951167 else
1196
- generic_make_request(bio);
1168
+ submit_bio_noacct(bio);
11971169 put_ldev(device);
11981170 } else
11991171 bio_io_error(bio);
....@@ -1233,15 +1205,14 @@
12331205 bio_endio(bio);
12341206 return ERR_PTR(-ENOMEM);
12351207 }
1236
- req->start_jif = start_jif;
1208
+
1209
+ /* Update disk stats */
1210
+ req->start_jif = bio_start_io_acct(req->master_bio);
12371211
12381212 if (!get_ldev(device)) {
12391213 bio_put(req->private_bio);
12401214 req->private_bio = NULL;
12411215 }
1242
-
1243
- /* Update disk stats */
1244
- _drbd_start_io_acct(device, req);
12451216
12461217 /* process discards always from our submitter thread */
12471218 if (bio_op(bio) == REQ_OP_WRITE_ZEROES ||
....@@ -1623,12 +1594,12 @@
16231594 }
16241595 }
16251596
1626
-blk_qc_t drbd_make_request(struct request_queue *q, struct bio *bio)
1597
+blk_qc_t drbd_submit_bio(struct bio *bio)
16271598 {
1628
- struct drbd_device *device = (struct drbd_device *) q->queuedata;
1599
+ struct drbd_device *device = bio->bi_disk->private_data;
16291600 unsigned long start_jif;
16301601
1631
- blk_queue_split(q, &bio);
1602
+ blk_queue_split(&bio);
16321603
16331604 start_jif = jiffies;
16341605