aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/md.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r--drivers/md/md.c81
1 files changed, 38 insertions, 43 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 3276edde7576..5590cb54b584 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -356,7 +356,7 @@ static inline sector_t calc_dev_sboffset(struct block_device *bdev)
356 356
357static sector_t calc_num_sectors(mdk_rdev_t *rdev, unsigned chunk_size) 357static sector_t calc_num_sectors(mdk_rdev_t *rdev, unsigned chunk_size)
358{ 358{
359 sector_t num_sectors = rdev->sb_offset * 2; 359 sector_t num_sectors = rdev->sb_start;
360 360
361 if (chunk_size) 361 if (chunk_size)
362 num_sectors &= ~((sector_t)chunk_size/512 - 1); 362 num_sectors &= ~((sector_t)chunk_size/512 - 1);
@@ -383,7 +383,7 @@ static void free_disk_sb(mdk_rdev_t * rdev)
383 put_page(rdev->sb_page); 383 put_page(rdev->sb_page);
384 rdev->sb_loaded = 0; 384 rdev->sb_loaded = 0;
385 rdev->sb_page = NULL; 385 rdev->sb_page = NULL;
386 rdev->sb_offset = 0; 386 rdev->sb_start = 0;
387 rdev->size = 0; 387 rdev->size = 0;
388 } 388 }
389} 389}
@@ -529,7 +529,7 @@ static int read_disk_sb(mdk_rdev_t * rdev, int size)
529 return 0; 529 return 0;
530 530
531 531
532 if (!sync_page_io(rdev->bdev, rdev->sb_offset<<1, size, rdev->sb_page, READ)) 532 if (!sync_page_io(rdev->bdev, rdev->sb_start, size, rdev->sb_page, READ))
533 goto fail; 533 goto fail;
534 rdev->sb_loaded = 1; 534 rdev->sb_loaded = 1;
535 return 0; 535 return 0;
@@ -666,16 +666,14 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
666 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; 666 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
667 mdp_super_t *sb; 667 mdp_super_t *sb;
668 int ret; 668 int ret;
669 sector_t sb_offset;
670 669
671 /* 670 /*
672 * Calculate the position of the superblock, 671 * Calculate the position of the superblock (512byte sectors),
673 * it's at the end of the disk. 672 * it's at the end of the disk.
674 * 673 *
675 * It also happens to be a multiple of 4Kb. 674 * It also happens to be a multiple of 4Kb.
676 */ 675 */
677 sb_offset = calc_dev_sboffset(rdev->bdev) / 2; 676 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
678 rdev->sb_offset = sb_offset;
679 677
680 ret = read_disk_sb(rdev, MD_SB_BYTES); 678 ret = read_disk_sb(rdev, MD_SB_BYTES);
681 if (ret) return ret; 679 if (ret) return ret;
@@ -1007,10 +1005,10 @@ super_90_rdev_size_change(mdk_rdev_t *rdev, unsigned long long size)
1007 size *= 2; /* convert to sectors */ 1005 size *= 2; /* convert to sectors */
1008 if (rdev->mddev->bitmap_offset) 1006 if (rdev->mddev->bitmap_offset)
1009 return 0; /* can't move bitmap */ 1007 return 0; /* can't move bitmap */
1010 rdev->sb_offset = calc_dev_sboffset(rdev->bdev) / 2; 1008 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
1011 if (!size || size > rdev->sb_offset*2) 1009 if (!size || size > rdev->sb_start)
1012 size = rdev->sb_offset*2; 1010 size = rdev->sb_start;
1013 md_super_write(rdev->mddev, rdev, rdev->sb_offset << 1, rdev->sb_size, 1011 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size,
1014 rdev->sb_page); 1012 rdev->sb_page);
1015 md_super_wait(rdev->mddev); 1013 md_super_wait(rdev->mddev);
1016 return size/2; /* kB for sysfs */ 1014 return size/2; /* kB for sysfs */
@@ -1048,12 +1046,12 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1048{ 1046{
1049 struct mdp_superblock_1 *sb; 1047 struct mdp_superblock_1 *sb;
1050 int ret; 1048 int ret;
1051 sector_t sb_offset; 1049 sector_t sb_start;
1052 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; 1050 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
1053 int bmask; 1051 int bmask;
1054 1052
1055 /* 1053 /*
1056 * Calculate the position of the superblock. 1054 * Calculate the position of the superblock in 512byte sectors.
1057 * It is always aligned to a 4K boundary and 1055 * It is always aligned to a 4K boundary and
1058 * depeding on minor_version, it can be: 1056 * depeding on minor_version, it can be:
1059 * 0: At least 8K, but less than 12K, from end of device 1057 * 0: At least 8K, but less than 12K, from end of device
@@ -1062,22 +1060,20 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1062 */ 1060 */
1063 switch(minor_version) { 1061 switch(minor_version) {
1064 case 0: 1062 case 0:
1065 sb_offset = rdev->bdev->bd_inode->i_size >> 9; 1063 sb_start = rdev->bdev->bd_inode->i_size >> 9;
1066 sb_offset -= 8*2; 1064 sb_start -= 8*2;
1067 sb_offset &= ~(sector_t)(4*2-1); 1065 sb_start &= ~(sector_t)(4*2-1);
1068 /* convert from sectors to K */
1069 sb_offset /= 2;
1070 break; 1066 break;
1071 case 1: 1067 case 1:
1072 sb_offset = 0; 1068 sb_start = 0;
1073 break; 1069 break;
1074 case 2: 1070 case 2:
1075 sb_offset = 4; 1071 sb_start = 8;
1076 break; 1072 break;
1077 default: 1073 default:
1078 return -EINVAL; 1074 return -EINVAL;
1079 } 1075 }
1080 rdev->sb_offset = sb_offset; 1076 rdev->sb_start = sb_start;
1081 1077
1082 /* superblock is rarely larger than 1K, but it can be larger, 1078 /* superblock is rarely larger than 1K, but it can be larger,
1083 * and it is safe to read 4k, so we do that 1079 * and it is safe to read 4k, so we do that
@@ -1091,7 +1087,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1091 if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || 1087 if (sb->magic != cpu_to_le32(MD_SB_MAGIC) ||
1092 sb->major_version != cpu_to_le32(1) || 1088 sb->major_version != cpu_to_le32(1) ||
1093 le32_to_cpu(sb->max_dev) > (4096-256)/2 || 1089 le32_to_cpu(sb->max_dev) > (4096-256)/2 ||
1094 le64_to_cpu(sb->super_offset) != (rdev->sb_offset<<1) || 1090 le64_to_cpu(sb->super_offset) != rdev->sb_start ||
1095 (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0) 1091 (le32_to_cpu(sb->feature_map) & ~MD_FEATURE_ALL) != 0)
1096 return -EINVAL; 1092 return -EINVAL;
1097 1093
@@ -1127,7 +1123,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1127 rdev->sb_size = (rdev->sb_size | bmask) + 1; 1123 rdev->sb_size = (rdev->sb_size | bmask) + 1;
1128 1124
1129 if (minor_version 1125 if (minor_version
1130 && rdev->data_offset < sb_offset + (rdev->sb_size/512)) 1126 && rdev->data_offset < sb_start + (rdev->sb_size/512))
1131 return -EINVAL; 1127 return -EINVAL;
1132 1128
1133 if (sb->level == cpu_to_le32(LEVEL_MULTIPATH)) 1129 if (sb->level == cpu_to_le32(LEVEL_MULTIPATH))
@@ -1163,7 +1159,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1163 if (minor_version) 1159 if (minor_version)
1164 rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2; 1160 rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2;
1165 else 1161 else
1166 rdev->size = rdev->sb_offset; 1162 rdev->size = rdev->sb_start / 2;
1167 if (rdev->size < le64_to_cpu(sb->data_size)/2) 1163 if (rdev->size < le64_to_cpu(sb->data_size)/2)
1168 return -EINVAL; 1164 return -EINVAL;
1169 rdev->size = le64_to_cpu(sb->data_size)/2; 1165 rdev->size = le64_to_cpu(sb->data_size)/2;
@@ -1350,7 +1346,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, unsigned long long size)
1350 if (size && size < rdev->mddev->size) 1346 if (size && size < rdev->mddev->size)
1351 return 0; /* component must fit device */ 1347 return 0; /* component must fit device */
1352 size *= 2; /* convert to sectors */ 1348 size *= 2; /* convert to sectors */
1353 if (rdev->sb_offset < rdev->data_offset/2) { 1349 if (rdev->sb_start < rdev->data_offset) {
1354 /* minor versions 1 and 2; superblock before data */ 1350 /* minor versions 1 and 2; superblock before data */
1355 max_size = (rdev->bdev->bd_inode->i_size >> 9); 1351 max_size = (rdev->bdev->bd_inode->i_size >> 9);
1356 max_size -= rdev->data_offset; 1352 max_size -= rdev->data_offset;
@@ -1361,19 +1357,19 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, unsigned long long size)
1361 return 0; 1357 return 0;
1362 } else { 1358 } else {
1363 /* minor version 0; superblock after data */ 1359 /* minor version 0; superblock after data */
1364 sector_t sb_offset; 1360 sector_t sb_start;
1365 sb_offset = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; 1361 sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2;
1366 sb_offset &= ~(sector_t)(4*2 - 1); 1362 sb_start &= ~(sector_t)(4*2 - 1);
1367 max_size = rdev->size*2 + sb_offset - rdev->sb_offset*2; 1363 max_size = rdev->size*2 + sb_start - rdev->sb_start;
1368 if (!size || size > max_size) 1364 if (!size || size > max_size)
1369 size = max_size; 1365 size = max_size;
1370 rdev->sb_offset = sb_offset/2; 1366 rdev->sb_start = sb_start;
1371 } 1367 }
1372 sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page); 1368 sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page);
1373 sb->data_size = cpu_to_le64(size); 1369 sb->data_size = cpu_to_le64(size);
1374 sb->super_offset = rdev->sb_offset*2; 1370 sb->super_offset = rdev->sb_start;
1375 sb->sb_csum = calc_sb_1_csum(sb); 1371 sb->sb_csum = calc_sb_1_csum(sb);
1376 md_super_write(rdev->mddev, rdev, rdev->sb_offset << 1, rdev->sb_size, 1372 md_super_write(rdev->mddev, rdev, rdev->sb_start, rdev->sb_size,
1377 rdev->sb_page); 1373 rdev->sb_page);
1378 md_super_wait(rdev->mddev); 1374 md_super_wait(rdev->mddev);
1379 return size/2; /* kB for sysfs */ 1375 return size/2; /* kB for sysfs */
@@ -1810,11 +1806,11 @@ repeat:
1810 dprintk("%s ", bdevname(rdev->bdev,b)); 1806 dprintk("%s ", bdevname(rdev->bdev,b));
1811 if (!test_bit(Faulty, &rdev->flags)) { 1807 if (!test_bit(Faulty, &rdev->flags)) {
1812 md_super_write(mddev,rdev, 1808 md_super_write(mddev,rdev,
1813 rdev->sb_offset<<1, rdev->sb_size, 1809 rdev->sb_start, rdev->sb_size,
1814 rdev->sb_page); 1810 rdev->sb_page);
1815 dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", 1811 dprintk(KERN_INFO "(write) %s's sb offset: %llu\n",
1816 bdevname(rdev->bdev,b), 1812 bdevname(rdev->bdev,b),
1817 (unsigned long long)rdev->sb_offset); 1813 (unsigned long long)rdev->sb_start);
1818 rdev->sb_events = mddev->events; 1814 rdev->sb_events = mddev->events;
1819 1815
1820 } else 1816 } else
@@ -3577,16 +3573,16 @@ static int do_md_run(mddev_t * mddev)
3577 * We don't want the data to overlap the metadata, 3573 * We don't want the data to overlap the metadata,
3578 * Internal Bitmap issues has handled elsewhere. 3574 * Internal Bitmap issues has handled elsewhere.
3579 */ 3575 */
3580 if (rdev->data_offset < rdev->sb_offset) { 3576 if (rdev->data_offset < rdev->sb_start) {
3581 if (mddev->size && 3577 if (mddev->size &&
3582 rdev->data_offset + mddev->size*2 3578 rdev->data_offset + mddev->size*2
3583 > rdev->sb_offset*2) { 3579 > rdev->sb_start) {
3584 printk("md: %s: data overlaps metadata\n", 3580 printk("md: %s: data overlaps metadata\n",
3585 mdname(mddev)); 3581 mdname(mddev));
3586 return -EINVAL; 3582 return -EINVAL;
3587 } 3583 }
3588 } else { 3584 } else {
3589 if (rdev->sb_offset*2 + rdev->sb_size/512 3585 if (rdev->sb_start + rdev->sb_size/512
3590 > rdev->data_offset) { 3586 > rdev->data_offset) {
3591 printk("md: %s: metadata overlaps data\n", 3587 printk("md: %s: metadata overlaps data\n",
3592 mdname(mddev)); 3588 mdname(mddev));
@@ -4355,9 +4351,9 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
4355 4351
4356 if (!mddev->persistent) { 4352 if (!mddev->persistent) {
4357 printk(KERN_INFO "md: nonpersistent superblock ...\n"); 4353 printk(KERN_INFO "md: nonpersistent superblock ...\n");
4358 rdev->sb_offset = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; 4354 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
4359 } else 4355 } else
4360 rdev->sb_offset = calc_dev_sboffset(rdev->bdev) / 2; 4356 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
4361 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; 4357 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2;
4362 4358
4363 err = bind_rdev_to_array(rdev, mddev); 4359 err = bind_rdev_to_array(rdev, mddev);
@@ -4424,10 +4420,9 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
4424 } 4420 }
4425 4421
4426 if (mddev->persistent) 4422 if (mddev->persistent)
4427 rdev->sb_offset = calc_dev_sboffset(rdev->bdev) / 2; 4423 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
4428 else 4424 else
4429 rdev->sb_offset = 4425 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
4430 rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
4431 4426
4432 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; 4427 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2;
4433 4428
@@ -4628,7 +4623,7 @@ static int update_size(mddev_t *mddev, sector_t num_sectors)
4628 * linear and raid0 always use whatever space is available. We can only 4623 * linear and raid0 always use whatever space is available. We can only
4629 * consider changing this number if no resync or reconstruction is 4624 * consider changing this number if no resync or reconstruction is
4630 * happening, and if the new size is acceptable. It must fit before the 4625 * happening, and if the new size is acceptable. It must fit before the
4631 * sb_offset or, if that is <data_offset, it must fit before the size 4626 * sb_start or, if that is <data_offset, it must fit before the size
4632 * of each device. If num_sectors is zero, we find the largest size 4627 * of each device. If num_sectors is zero, we find the largest size
4633 * that fits. 4628 * that fits.
4634 4629