hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/nvdimm/btt.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Block Translation Table
34 * Copyright (c) 2014-2015, Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
135 */
146 #include <linux/highmem.h>
157 #include <linux/debugfs.h>
....@@ -1447,10 +1439,10 @@
14471439 return ret;
14481440 }
14491441
1450
-static blk_qc_t btt_make_request(struct request_queue *q, struct bio *bio)
1442
+static blk_qc_t btt_submit_bio(struct bio *bio)
14511443 {
14521444 struct bio_integrity_payload *bip = bio_integrity(bio);
1453
- struct btt *btt = q->queuedata;
1445
+ struct btt *btt = bio->bi_disk->private_data;
14541446 struct bvec_iter iter;
14551447 unsigned long start;
14561448 struct bio_vec bvec;
....@@ -1460,7 +1452,9 @@
14601452 if (!bio_integrity_prep(bio))
14611453 return BLK_QC_T_NONE;
14621454
1463
- do_acct = nd_iostat_start(bio, &start);
1455
+ do_acct = blk_queue_io_stat(bio->bi_disk->queue);
1456
+ if (do_acct)
1457
+ start = bio_start_io_acct(bio);
14641458 bio_for_each_segment(bvec, bio, iter) {
14651459 unsigned int len = bvec.bv_len;
14661460
....@@ -1485,7 +1479,7 @@
14851479 }
14861480 }
14871481 if (do_acct)
1488
- nd_iostat_end(bio, start);
1482
+ bio_end_io_acct(bio, start);
14891483
14901484 bio_endio(bio);
14911485 return BLK_QC_T_NONE;
....@@ -1496,10 +1490,8 @@
14961490 {
14971491 struct btt *btt = bdev->bd_disk->private_data;
14981492 int rc;
1499
- unsigned int len;
15001493
1501
- len = hpage_nr_pages(page) * PAGE_SIZE;
1502
- rc = btt_do_bvec(btt, NULL, page, len, 0, op, sector);
1494
+ rc = btt_do_bvec(btt, NULL, page, thp_size(page), 0, op, sector);
15031495 if (rc == 0)
15041496 page_endio(page, op_is_write(op), 0);
15051497
....@@ -1518,9 +1510,9 @@
15181510
15191511 static const struct block_device_operations btt_fops = {
15201512 .owner = THIS_MODULE,
1513
+ .submit_bio = btt_submit_bio,
15211514 .rw_page = btt_rw_page,
15221515 .getgeo = btt_getgeo,
1523
- .revalidate_disk = nvdimm_revalidate_disk,
15241516 };
15251517
15261518 static int btt_blk_init(struct btt *btt)
....@@ -1529,7 +1521,7 @@
15291521 struct nd_namespace_common *ndns = nd_btt->ndns;
15301522
15311523 /* create a new disk and request queue for btt */
1532
- btt->btt_queue = blk_alloc_queue(GFP_KERNEL);
1524
+ btt->btt_queue = blk_alloc_queue(NUMA_NO_NODE);
15331525 if (!btt->btt_queue)
15341526 return -ENOMEM;
15351527
....@@ -1545,14 +1537,10 @@
15451537 btt->btt_disk->private_data = btt;
15461538 btt->btt_disk->queue = btt->btt_queue;
15471539 btt->btt_disk->flags = GENHD_FL_EXT_DEVT;
1548
- btt->btt_disk->queue->backing_dev_info->capabilities |=
1549
- BDI_CAP_SYNCHRONOUS_IO;
15501540
1551
- blk_queue_make_request(btt->btt_queue, btt_make_request);
15521541 blk_queue_logical_block_size(btt->btt_queue, btt->sector_size);
15531542 blk_queue_max_hw_sectors(btt->btt_queue, UINT_MAX);
15541543 blk_queue_flag_set(QUEUE_FLAG_NONROT, btt->btt_queue);
1555
- btt->btt_queue->queuedata = btt;
15561544
15571545 if (btt_meta_size(btt)) {
15581546 int rc = nd_integrity_init(btt->btt_disk, btt_meta_size(btt));
....@@ -1565,9 +1553,9 @@
15651553 }
15661554 }
15671555 set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9);
1568
- device_add_disk(&btt->nd_btt->dev, btt->btt_disk);
1556
+ device_add_disk(&btt->nd_btt->dev, btt->btt_disk, NULL);
15691557 btt->nd_btt->size = btt->nlba * (u64)btt->sector_size;
1570
- revalidate_disk(btt->btt_disk);
1558
+ nvdimm_check_and_set_ro(btt->btt_disk);
15711559
15721560 return 0;
15731561 }
....@@ -1682,7 +1670,8 @@
16821670 struct nd_region *nd_region;
16831671 struct btt_sb *btt_sb;
16841672 struct btt *btt;
1685
- size_t rawsize;
1673
+ size_t size, rawsize;
1674
+ int rc;
16861675
16871676 if (!nd_btt->uuid || !nd_btt->ndns || !nd_btt->lbasize) {
16881677 dev_dbg(&nd_btt->dev, "incomplete btt configuration\n");
....@@ -1693,6 +1682,11 @@
16931682 if (!btt_sb)
16941683 return -ENOMEM;
16951684
1685
+ size = nvdimm_namespace_capacity(ndns);
1686
+ rc = devm_namespace_enable(&nd_btt->dev, ndns, size);
1687
+ if (rc)
1688
+ return rc;
1689
+
16961690 /*
16971691 * If this returns < 0, that is ok as it just means there wasn't
16981692 * an existing BTT, and we're creating a new one. We still need to
....@@ -1701,7 +1695,7 @@
17011695 */
17021696 nd_btt_version(nd_btt, ndns, btt_sb);
17031697
1704
- rawsize = nvdimm_namespace_capacity(ndns) - nd_btt->initial_offset;
1698
+ rawsize = size - nd_btt->initial_offset;
17051699 if (rawsize < ARENA_MIN_SIZE) {
17061700 dev_dbg(&nd_btt->dev, "%s must be at least %ld bytes\n",
17071701 dev_name(&ndns->dev),