aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm-cache-target.c13
-rw-r--r--drivers/md/dm-io.c23
-rw-r--r--drivers/md/dm-mpath.c7
-rw-r--r--drivers/md/dm-raid1.c3
-rw-r--r--drivers/md/dm-thin-metadata.c21
-rw-r--r--drivers/md/dm-thin-metadata.h10
-rw-r--r--drivers/md/dm-thin.c39
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.c2
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.h11
9 files changed, 89 insertions, 40 deletions
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index ffd472e015ca..1af70145fab9 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -289,6 +289,7 @@ struct per_bio_data {
289 bool tick:1; 289 bool tick:1;
290 unsigned req_nr:2; 290 unsigned req_nr:2;
291 struct dm_deferred_entry *all_io_entry; 291 struct dm_deferred_entry *all_io_entry;
292 struct dm_hook_info hook_info;
292 293
293 /* 294 /*
294 * writethrough fields. These MUST remain at the end of this 295 * writethrough fields. These MUST remain at the end of this
@@ -297,7 +298,6 @@ struct per_bio_data {
297 */ 298 */
298 struct cache *cache; 299 struct cache *cache;
299 dm_cblock_t cblock; 300 dm_cblock_t cblock;
300 struct dm_hook_info hook_info;
301 struct dm_bio_details bio_details; 301 struct dm_bio_details bio_details;
302}; 302};
303 303
@@ -671,15 +671,16 @@ static void remap_to_cache(struct cache *cache, struct bio *bio,
671 dm_cblock_t cblock) 671 dm_cblock_t cblock)
672{ 672{
673 sector_t bi_sector = bio->bi_iter.bi_sector; 673 sector_t bi_sector = bio->bi_iter.bi_sector;
674 sector_t block = from_cblock(cblock);
674 675
675 bio->bi_bdev = cache->cache_dev->bdev; 676 bio->bi_bdev = cache->cache_dev->bdev;
676 if (!block_size_is_power_of_two(cache)) 677 if (!block_size_is_power_of_two(cache))
677 bio->bi_iter.bi_sector = 678 bio->bi_iter.bi_sector =
678 (from_cblock(cblock) * cache->sectors_per_block) + 679 (block * cache->sectors_per_block) +
679 sector_div(bi_sector, cache->sectors_per_block); 680 sector_div(bi_sector, cache->sectors_per_block);
680 else 681 else
681 bio->bi_iter.bi_sector = 682 bio->bi_iter.bi_sector =
682 (from_cblock(cblock) << cache->sectors_per_block_shift) | 683 (block << cache->sectors_per_block_shift) |
683 (bi_sector & (cache->sectors_per_block - 1)); 684 (bi_sector & (cache->sectors_per_block - 1));
684} 685}
685 686
@@ -1010,13 +1011,15 @@ static void overwrite_endio(struct bio *bio, int err)
1010 struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size); 1011 struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size);
1011 unsigned long flags; 1012 unsigned long flags;
1012 1013
1014 dm_unhook_bio(&pb->hook_info, bio);
1015
1013 if (err) 1016 if (err)
1014 mg->err = true; 1017 mg->err = true;
1015 1018
1019 mg->requeue_holder = false;
1020
1016 spin_lock_irqsave(&cache->lock, flags); 1021 spin_lock_irqsave(&cache->lock, flags);
1017 list_add_tail(&mg->list, &cache->completed_migrations); 1022 list_add_tail(&mg->list, &cache->completed_migrations);
1018 dm_unhook_bio(&pb->hook_info, bio);
1019 mg->requeue_holder = false;
1020 spin_unlock_irqrestore(&cache->lock, flags); 1023 spin_unlock_irqrestore(&cache->lock, flags);
1021 1024
1022 wake_worker(cache); 1025 wake_worker(cache);
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index b2b8a10e8427..3842ac738f98 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -201,29 +201,28 @@ static void list_dp_init(struct dpages *dp, struct page_list *pl, unsigned offse
201/* 201/*
202 * Functions for getting the pages from a bvec. 202 * Functions for getting the pages from a bvec.
203 */ 203 */
204static void bio_get_page(struct dpages *dp, 204static void bio_get_page(struct dpages *dp, struct page **p,
205 struct page **p, unsigned long *len, unsigned *offset) 205 unsigned long *len, unsigned *offset)
206{ 206{
207 struct bio *bio = dp->context_ptr; 207 struct bio_vec *bvec = dp->context_ptr;
208 struct bio_vec bvec = bio_iovec(bio); 208 *p = bvec->bv_page;
209 *p = bvec.bv_page; 209 *len = bvec->bv_len - dp->context_u;
210 *len = bvec.bv_len; 210 *offset = bvec->bv_offset + dp->context_u;
211 *offset = bvec.bv_offset;
212} 211}
213 212
214static void bio_next_page(struct dpages *dp) 213static void bio_next_page(struct dpages *dp)
215{ 214{
216 struct bio *bio = dp->context_ptr; 215 struct bio_vec *bvec = dp->context_ptr;
217 struct bio_vec bvec = bio_iovec(bio); 216 dp->context_ptr = bvec + 1;
218 217 dp->context_u = 0;
219 bio_advance(bio, bvec.bv_len);
220} 218}
221 219
222static void bio_dp_init(struct dpages *dp, struct bio *bio) 220static void bio_dp_init(struct dpages *dp, struct bio *bio)
223{ 221{
224 dp->get_page = bio_get_page; 222 dp->get_page = bio_get_page;
225 dp->next_page = bio_next_page; 223 dp->next_page = bio_next_page;
226 dp->context_ptr = bio; 224 dp->context_ptr = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
225 dp->context_u = bio->bi_iter.bi_bvec_done;
227} 226}
228 227
229/* 228/*
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 6eb9dc9ef8f3..422a9fdeb53e 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1626,8 +1626,11 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
1626 /* 1626 /*
1627 * Only pass ioctls through if the device sizes match exactly. 1627 * Only pass ioctls through if the device sizes match exactly.
1628 */ 1628 */
1629 if (!r && ti->len != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) 1629 if (!bdev || ti->len != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) {
1630 r = scsi_verify_blk_ioctl(NULL, cmd); 1630 int err = scsi_verify_blk_ioctl(NULL, cmd);
1631 if (err)
1632 r = err;
1633 }
1631 1634
1632 if (r == -ENOTCONN && !fatal_signal_pending(current)) 1635 if (r == -ENOTCONN && !fatal_signal_pending(current))
1633 queue_work(kmultipathd, &m->process_queued_ios); 1636 queue_work(kmultipathd, &m->process_queued_ios);
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index f284e0bfb25f..7dfdb5c746d6 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -1244,6 +1244,9 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1244 1244
1245 dm_bio_restore(bd, bio); 1245 dm_bio_restore(bd, bio);
1246 bio_record->details.bi_bdev = NULL; 1246 bio_record->details.bi_bdev = NULL;
1247
1248 atomic_inc(&bio->bi_remaining);
1249
1247 queue_bio(ms, bio, rw); 1250 queue_bio(ms, bio, rw);
1248 return DM_ENDIO_INCOMPLETE; 1251 return DM_ENDIO_INCOMPLETE;
1249 } 1252 }
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index 7da347665552..baa87ff12816 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -483,7 +483,7 @@ static int __write_initial_superblock(struct dm_pool_metadata *pmd)
483 483
484 disk_super->data_mapping_root = cpu_to_le64(pmd->root); 484 disk_super->data_mapping_root = cpu_to_le64(pmd->root);
485 disk_super->device_details_root = cpu_to_le64(pmd->details_root); 485 disk_super->device_details_root = cpu_to_le64(pmd->details_root);
486 disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 486 disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE);
487 disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT); 487 disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT);
488 disk_super->data_block_size = cpu_to_le32(pmd->data_block_size); 488 disk_super->data_block_size = cpu_to_le32(pmd->data_block_size);
489 489
@@ -651,7 +651,7 @@ static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, bool f
651{ 651{
652 int r; 652 int r;
653 653
654 pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE, 654 pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE << SECTOR_SHIFT,
655 THIN_METADATA_CACHE_SIZE, 655 THIN_METADATA_CACHE_SIZE,
656 THIN_MAX_CONCURRENT_LOCKS); 656 THIN_MAX_CONCURRENT_LOCKS);
657 if (IS_ERR(pmd->bm)) { 657 if (IS_ERR(pmd->bm)) {
@@ -1489,6 +1489,23 @@ bool dm_thin_changed_this_transaction(struct dm_thin_device *td)
1489 return r; 1489 return r;
1490} 1490}
1491 1491
1492bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd)
1493{
1494 bool r = false;
1495 struct dm_thin_device *td, *tmp;
1496
1497 down_read(&pmd->root_lock);
1498 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) {
1499 if (td->changed) {
1500 r = td->changed;
1501 break;
1502 }
1503 }
1504 up_read(&pmd->root_lock);
1505
1506 return r;
1507}
1508
1492bool dm_thin_aborted_changes(struct dm_thin_device *td) 1509bool dm_thin_aborted_changes(struct dm_thin_device *td)
1493{ 1510{
1494 bool r; 1511 bool r;
diff --git a/drivers/md/dm-thin-metadata.h b/drivers/md/dm-thin-metadata.h
index 9a368567632f..82ea384d36ff 100644
--- a/drivers/md/dm-thin-metadata.h
+++ b/drivers/md/dm-thin-metadata.h
@@ -9,16 +9,14 @@
9 9
10#include "persistent-data/dm-block-manager.h" 10#include "persistent-data/dm-block-manager.h"
11#include "persistent-data/dm-space-map.h" 11#include "persistent-data/dm-space-map.h"
12#include "persistent-data/dm-space-map-metadata.h"
12 13
13#define THIN_METADATA_BLOCK_SIZE 4096 14#define THIN_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
14 15
15/* 16/*
16 * The metadata device is currently limited in size. 17 * The metadata device is currently limited in size.
17 *
18 * We have one block of index, which can hold 255 index entries. Each
19 * index entry contains allocation info about 16k metadata blocks.
20 */ 18 */
21#define THIN_METADATA_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT))) 19#define THIN_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
22 20
23/* 21/*
24 * A metadata device larger than 16GB triggers a warning. 22 * A metadata device larger than 16GB triggers a warning.
@@ -161,6 +159,8 @@ int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
161 */ 159 */
162bool dm_thin_changed_this_transaction(struct dm_thin_device *td); 160bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
163 161
162bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd);
163
164bool dm_thin_aborted_changes(struct dm_thin_device *td); 164bool dm_thin_aborted_changes(struct dm_thin_device *td);
165 165
166int dm_thin_get_highest_mapped_block(struct dm_thin_device *td, 166int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index faaf944597ab..7e84baccf0ad 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -1357,7 +1357,8 @@ static void process_deferred_bios(struct pool *pool)
1357 bio_list_init(&pool->deferred_flush_bios); 1357 bio_list_init(&pool->deferred_flush_bios);
1358 spin_unlock_irqrestore(&pool->lock, flags); 1358 spin_unlock_irqrestore(&pool->lock, flags);
1359 1359
1360 if (bio_list_empty(&bios) && !need_commit_due_to_time(pool)) 1360 if (bio_list_empty(&bios) &&
1361 !(dm_pool_changed_this_transaction(pool->pmd) && need_commit_due_to_time(pool)))
1361 return; 1362 return;
1362 1363
1363 if (commit(pool)) { 1364 if (commit(pool)) {
@@ -1999,16 +2000,27 @@ static void metadata_low_callback(void *context)
1999 dm_table_event(pool->ti->table); 2000 dm_table_event(pool->ti->table);
2000} 2001}
2001 2002
2002static sector_t get_metadata_dev_size(struct block_device *bdev) 2003static sector_t get_dev_size(struct block_device *bdev)
2004{
2005 return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
2006}
2007
2008static void warn_if_metadata_device_too_big(struct block_device *bdev)
2003{ 2009{
2004 sector_t metadata_dev_size = i_size_read(bdev->bd_inode) >> SECTOR_SHIFT; 2010 sector_t metadata_dev_size = get_dev_size(bdev);
2005 char buffer[BDEVNAME_SIZE]; 2011 char buffer[BDEVNAME_SIZE];
2006 2012
2007 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS_WARNING) { 2013 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS_WARNING)
2008 DMWARN("Metadata device %s is larger than %u sectors: excess space will not be used.", 2014 DMWARN("Metadata device %s is larger than %u sectors: excess space will not be used.",
2009 bdevname(bdev, buffer), THIN_METADATA_MAX_SECTORS); 2015 bdevname(bdev, buffer), THIN_METADATA_MAX_SECTORS);
2010 metadata_dev_size = THIN_METADATA_MAX_SECTORS_WARNING; 2016}
2011 } 2017
2018static sector_t get_metadata_dev_size(struct block_device *bdev)
2019{
2020 sector_t metadata_dev_size = get_dev_size(bdev);
2021
2022 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS)
2023 metadata_dev_size = THIN_METADATA_MAX_SECTORS;
2012 2024
2013 return metadata_dev_size; 2025 return metadata_dev_size;
2014} 2026}
@@ -2017,7 +2029,7 @@ static dm_block_t get_metadata_dev_size_in_blocks(struct block_device *bdev)
2017{ 2029{
2018 sector_t metadata_dev_size = get_metadata_dev_size(bdev); 2030 sector_t metadata_dev_size = get_metadata_dev_size(bdev);
2019 2031
2020 sector_div(metadata_dev_size, THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 2032 sector_div(metadata_dev_size, THIN_METADATA_BLOCK_SIZE);
2021 2033
2022 return metadata_dev_size; 2034 return metadata_dev_size;
2023} 2035}
@@ -2095,12 +2107,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
2095 ti->error = "Error opening metadata block device"; 2107 ti->error = "Error opening metadata block device";
2096 goto out_unlock; 2108 goto out_unlock;
2097 } 2109 }
2098 2110 warn_if_metadata_device_too_big(metadata_dev->bdev);
2099 /*
2100 * Run for the side-effect of possibly issuing a warning if the
2101 * device is too big.
2102 */
2103 (void) get_metadata_dev_size(metadata_dev->bdev);
2104 2111
2105 r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev); 2112 r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev);
2106 if (r) { 2113 if (r) {
@@ -2287,6 +2294,7 @@ static int maybe_resize_metadata_dev(struct dm_target *ti, bool *need_commit)
2287 return -EINVAL; 2294 return -EINVAL;
2288 2295
2289 } else if (metadata_dev_size > sb_metadata_dev_size) { 2296 } else if (metadata_dev_size > sb_metadata_dev_size) {
2297 warn_if_metadata_device_too_big(pool->md_dev);
2290 DMINFO("%s: growing the metadata device from %llu to %llu blocks", 2298 DMINFO("%s: growing the metadata device from %llu to %llu blocks",
2291 dm_device_name(pool->pool_md), 2299 dm_device_name(pool->pool_md),
2292 sb_metadata_dev_size, metadata_dev_size); 2300 sb_metadata_dev_size, metadata_dev_size);
@@ -2894,6 +2902,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2894 2902
2895 if (get_pool_mode(tc->pool) == PM_FAIL) { 2903 if (get_pool_mode(tc->pool) == PM_FAIL) {
2896 ti->error = "Couldn't open thin device, Pool is in fail mode"; 2904 ti->error = "Couldn't open thin device, Pool is in fail mode";
2905 r = -EINVAL;
2897 goto bad_thin_open; 2906 goto bad_thin_open;
2898 } 2907 }
2899 2908
@@ -2905,7 +2914,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2905 2914
2906 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block); 2915 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block);
2907 if (r) 2916 if (r)
2908 goto bad_thin_open; 2917 goto bad_target_max_io_len;
2909 2918
2910 ti->num_flush_bios = 1; 2919 ti->num_flush_bios = 1;
2911 ti->flush_supported = true; 2920 ti->flush_supported = true;
@@ -2926,6 +2935,8 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2926 2935
2927 return 0; 2936 return 0;
2928 2937
2938bad_target_max_io_len:
2939 dm_pool_close_thin_device(tc->td);
2929bad_thin_open: 2940bad_thin_open:
2930 __pool_dec(tc->pool); 2941 __pool_dec(tc->pool);
2931bad_pool_lookup: 2942bad_pool_lookup:
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
index 536782e3bcb7..e9bdd462f4f5 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -680,6 +680,8 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
680 if (r) 680 if (r)
681 return r; 681 return r;
682 682
683 if (nr_blocks > DM_SM_METADATA_MAX_BLOCKS)
684 nr_blocks = DM_SM_METADATA_MAX_BLOCKS;
683 r = sm_ll_extend(&smm->ll, nr_blocks); 685 r = sm_ll_extend(&smm->ll, nr_blocks);
684 if (r) 686 if (r)
685 return r; 687 return r;
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.h b/drivers/md/persistent-data/dm-space-map-metadata.h
index 39bba0801cf2..64df923974d8 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.h
+++ b/drivers/md/persistent-data/dm-space-map-metadata.h
@@ -9,6 +9,17 @@
9 9
10#include "dm-transaction-manager.h" 10#include "dm-transaction-manager.h"
11 11
12#define DM_SM_METADATA_BLOCK_SIZE (4096 >> SECTOR_SHIFT)
13
14/*
15 * The metadata device is currently limited in size.
16 *
17 * We have one block of index, which can hold 255 index entries. Each
18 * index entry contains allocation info about ~16k metadata blocks.
19 */
20#define DM_SM_METADATA_MAX_BLOCKS (255 * ((1 << 14) - 64))
21#define DM_SM_METADATA_MAX_SECTORS (DM_SM_METADATA_MAX_BLOCKS * DM_SM_METADATA_BLOCK_SIZE)
22
12/* 23/*
13 * Unfortunately we have to use two-phase construction due to the cycle 24 * Unfortunately we have to use two-phase construction due to the cycle
14 * between the tm and sm. 25 * between the tm and sm.