aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-01-20 02:11:43 -0500
committerChris Mason <clm@fb.com>2015-01-21 21:06:49 -0500
commit10f11900167a83e0c229c4c27e73e720ebd55b5c (patch)
treeab1a3b7bd34f51ea09ef505ed518423332f53a99
parentbe50a8ddaae1d07135fd7e1c7017c1611075a560 (diff)
Btrfs: Include map_type in raid_bio
Corrent code use many kinds of "clever" way to determine operation target's raid type, as: raid_map != NULL or raid_map[MAX_NR] == RAID[56]_Q_STRIPE To make code easy to maintenance, this patch put raid type into bbio, and we can always get raid type from bbio with a "stupid" way. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r--fs/btrfs/raid56.c10
-rw-r--r--fs/btrfs/scrub.c28
-rw-r--r--fs/btrfs/volumes.c1
-rw-r--r--fs/btrfs/volumes.h1
4 files changed, 22 insertions, 18 deletions
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index cbc416204452..5264858ed768 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -994,10 +994,12 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_root *root,
994 rbio->bio_pages = p + sizeof(struct page *) * num_pages; 994 rbio->bio_pages = p + sizeof(struct page *) * num_pages;
995 rbio->dbitmap = p + sizeof(struct page *) * num_pages * 2; 995 rbio->dbitmap = p + sizeof(struct page *) * num_pages * 2;
996 996
997 if (bbio->raid_map[real_stripes - 1] == RAID6_Q_STRIPE) 997 if (bbio->map_type & BTRFS_BLOCK_GROUP_RAID5)
998 nr_data = real_stripes - 1;
999 else if (bbio->map_type & BTRFS_BLOCK_GROUP_RAID6)
998 nr_data = real_stripes - 2; 1000 nr_data = real_stripes - 2;
999 else 1001 else
1000 nr_data = real_stripes - 1; 1002 BUG();
1001 1003
1002 rbio->nr_data = nr_data; 1004 rbio->nr_data = nr_data;
1003 return rbio; 1005 return rbio;
@@ -1850,9 +1852,7 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
1850 } 1852 }
1851 1853
1852 /* all raid6 handling here */ 1854 /* all raid6 handling here */
1853 if (rbio->bbio->raid_map[rbio->real_stripes - 1] == 1855 if (rbio->bbio->map_type & BTRFS_BLOCK_GROUP_RAID6) {
1854 RAID6_Q_STRIPE) {
1855
1856 /* 1856 /*
1857 * single failure, rebuild from parity raid5 1857 * single failure, rebuild from parity raid5
1858 * style 1858 * style
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index c3a98931980f..19781e924443 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1256,19 +1256,16 @@ out:
1256 1256
1257static inline int scrub_nr_raid_mirrors(struct btrfs_bio *bbio) 1257static inline int scrub_nr_raid_mirrors(struct btrfs_bio *bbio)
1258{ 1258{
1259 if (bbio->raid_map) { 1259 if (bbio->map_type & BTRFS_BLOCK_GROUP_RAID5)
1260 int real_stripes = bbio->num_stripes - bbio->num_tgtdevs; 1260 return 2;
1261 1261 else if (bbio->map_type & BTRFS_BLOCK_GROUP_RAID6)
1262 if (bbio->raid_map[real_stripes - 1] == RAID6_Q_STRIPE) 1262 return 3;
1263 return 3; 1263 else
1264 else
1265 return 2;
1266 } else {
1267 return (int)bbio->num_stripes; 1264 return (int)bbio->num_stripes;
1268 }
1269} 1265}
1270 1266
1271static inline void scrub_stripe_index_and_offset(u64 logical, u64 *raid_map, 1267static inline void scrub_stripe_index_and_offset(u64 logical, u64 map_type,
1268 u64 *raid_map,
1272 u64 mapped_length, 1269 u64 mapped_length,
1273 int nstripes, int mirror, 1270 int nstripes, int mirror,
1274 int *stripe_index, 1271 int *stripe_index,
@@ -1276,7 +1273,7 @@ static inline void scrub_stripe_index_and_offset(u64 logical, u64 *raid_map,
1276{ 1273{
1277 int i; 1274 int i;
1278 1275
1279 if (raid_map) { 1276 if (map_type & (BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6)) {
1280 /* RAID5/6 */ 1277 /* RAID5/6 */
1281 for (i = 0; i < nstripes; i++) { 1278 for (i = 0; i < nstripes; i++) {
1282 if (raid_map[i] == RAID6_Q_STRIPE || 1279 if (raid_map[i] == RAID6_Q_STRIPE ||
@@ -1350,6 +1347,7 @@ static int scrub_setup_recheck_block(struct scrub_block *original_sblock,
1350 BUG_ON(page_index >= SCRUB_PAGES_PER_RD_BIO); 1347 BUG_ON(page_index >= SCRUB_PAGES_PER_RD_BIO);
1351 1348
1352 nmirrors = min(scrub_nr_raid_mirrors(bbio), BTRFS_MAX_MIRRORS); 1349 nmirrors = min(scrub_nr_raid_mirrors(bbio), BTRFS_MAX_MIRRORS);
1350
1353 for (mirror_index = 0; mirror_index < nmirrors; 1351 for (mirror_index = 0; mirror_index < nmirrors;
1354 mirror_index++) { 1352 mirror_index++) {
1355 struct scrub_block *sblock; 1353 struct scrub_block *sblock;
@@ -1370,7 +1368,9 @@ leave_nomem:
1370 sblock->pagev[page_index] = page; 1368 sblock->pagev[page_index] = page;
1371 page->logical = logical; 1369 page->logical = logical;
1372 1370
1373 scrub_stripe_index_and_offset(logical, bbio->raid_map, 1371 scrub_stripe_index_and_offset(logical,
1372 bbio->map_type,
1373 bbio->raid_map,
1374 mapped_length, 1374 mapped_length,
1375 bbio->num_stripes - 1375 bbio->num_stripes -
1376 bbio->num_tgtdevs, 1376 bbio->num_tgtdevs,
@@ -1419,7 +1419,9 @@ static void scrub_bio_wait_endio(struct bio *bio, int error)
1419 1419
1420static inline int scrub_is_page_on_raid56(struct scrub_page *page) 1420static inline int scrub_is_page_on_raid56(struct scrub_page *page)
1421{ 1421{
1422 return page->recover && page->recover->bbio->raid_map; 1422 return page->recover &&
1423 (page->recover->bbio->map_type & (BTRFS_BLOCK_GROUP_RAID5 |
1424 BTRFS_BLOCK_GROUP_RAID6));
1423} 1425}
1424 1426
1425static int scrub_submit_raid56_bio_wait(struct btrfs_fs_info *fs_info, 1427static int scrub_submit_raid56_bio_wait(struct btrfs_fs_info *fs_info,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 0843bcd6304c..8933d70c3d53 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5453,6 +5453,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5453 } 5453 }
5454 5454
5455 *bbio_ret = bbio; 5455 *bbio_ret = bbio;
5456 bbio->map_type = map->type;
5456 bbio->num_stripes = num_stripes; 5457 bbio->num_stripes = num_stripes;
5457 bbio->max_errors = max_errors; 5458 bbio->max_errors = max_errors;
5458 bbio->mirror_num = mirror_num; 5459 bbio->mirror_num = mirror_num;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 4313e8ff91e5..83069dec6898 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -298,6 +298,7 @@ struct btrfs_bio {
298 atomic_t refs; 298 atomic_t refs;
299 atomic_t stripes_pending; 299 atomic_t stripes_pending;
300 struct btrfs_fs_info *fs_info; 300 struct btrfs_fs_info *fs_info;
301 u64 map_type; /* get from map_lookup->type */
301 bio_end_io_t *end_io; 302 bio_end_io_t *end_io;
302 struct bio *orig_bio; 303 struct bio *orig_bio;
303 unsigned long flags; 304 unsigned long flags;