aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2015-08-14 06:32:58 -0400
committerDavid Sterba <dsterba@suse.com>2015-10-01 11:29:38 -0400
commit29c36d72535deb3d8961b3fb4b6a565190a6c63b (patch)
tree173364b301384a61a2ba336f8354770e645d981a
parentd74a625987a134b00749e3912bdb6d3ac83fd71d (diff)
Btrfs: add btrfs_read_dev_one_super() to read one specific SB
This uses a chunk of code from btrfs_read_dev_super() and creates a function called btrfs_read_dev_one_super() so that next patch can use it for scratch superblock. Signed-off-by: Anand Jain <anand.jain@oracle.com> [renamed bufhead to bh] Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/disk-io.c53
-rw-r--r--fs/btrfs/disk-io.h2
2 files changed, 35 insertions, 20 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 0f8e33f2bcea..c7c739f420b5 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3188,6 +3188,37 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
3188 put_bh(bh); 3188 put_bh(bh);
3189} 3189}
3190 3190
3191int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
3192 struct buffer_head **bh_ret)
3193{
3194 struct buffer_head *bh;
3195 struct btrfs_super_block *super;
3196 u64 bytenr;
3197
3198 bytenr = btrfs_sb_offset(copy_num);
3199 if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode))
3200 return -EINVAL;
3201
3202 bh = __bread(bdev, bytenr / 4096, BTRFS_SUPER_INFO_SIZE);
3203 /*
3204 * If we fail to read from the underlying devices, as of now
3205 * the best option we have is to mark it EIO.
3206 */
3207 if (!bh)
3208 return -EIO;
3209
3210 super = (struct btrfs_super_block *)bh->b_data;
3211 if (btrfs_super_bytenr(super) != bytenr ||
3212 btrfs_super_magic(super) != BTRFS_MAGIC) {
3213 brelse(bh);
3214 return -EINVAL;
3215 }
3216
3217 *bh_ret = bh;
3218 return 0;
3219}
3220
3221
3191struct buffer_head *btrfs_read_dev_super(struct block_device *bdev) 3222struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
3192{ 3223{
3193 struct buffer_head *bh; 3224 struct buffer_head *bh;
@@ -3195,7 +3226,6 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
3195 struct btrfs_super_block *super; 3226 struct btrfs_super_block *super;
3196 int i; 3227 int i;
3197 u64 transid = 0; 3228 u64 transid = 0;
3198 u64 bytenr;
3199 int ret = -EINVAL; 3229 int ret = -EINVAL;
3200 3230
3201 /* we would like to check all the supers, but that would make 3231 /* we would like to check all the supers, but that would make
@@ -3204,28 +3234,11 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
3204 * later supers, using BTRFS_SUPER_MIRROR_MAX instead 3234 * later supers, using BTRFS_SUPER_MIRROR_MAX instead
3205 */ 3235 */
3206 for (i = 0; i < 1; i++) { 3236 for (i = 0; i < 1; i++) {
3207 bytenr = btrfs_sb_offset(i); 3237 ret = btrfs_read_dev_one_super(bdev, i, &bh);
3208 if (bytenr + BTRFS_SUPER_INFO_SIZE >= 3238 if (ret)
3209 i_size_read(bdev->bd_inode))
3210 break;
3211 bh = __bread(bdev, bytenr / 4096,
3212 BTRFS_SUPER_INFO_SIZE);
3213 /*
3214 * If we fail to read from the underlying devices, as of now
3215 * the best option we have is to mark it EIO.
3216 */
3217 if (!bh) {
3218 ret = -EIO;
3219 continue; 3239 continue;
3220 }
3221 3240
3222 super = (struct btrfs_super_block *)bh->b_data; 3241 super = (struct btrfs_super_block *)bh->b_data;
3223 if (btrfs_super_bytenr(super) != bytenr ||
3224 btrfs_super_magic(super) != BTRFS_MAGIC) {
3225 brelse(bh);
3226 ret = -EINVAL;
3227 continue;
3228 }
3229 3242
3230 if (!latest || btrfs_super_generation(super) > transid) { 3243 if (!latest || btrfs_super_generation(super) > transid) {
3231 brelse(latest); 3244 brelse(latest);
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index bdfb479ea859..adeb31830b9c 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -60,6 +60,8 @@ void close_ctree(struct btrfs_root *root);
60int write_ctree_super(struct btrfs_trans_handle *trans, 60int write_ctree_super(struct btrfs_trans_handle *trans,
61 struct btrfs_root *root, int max_mirrors); 61 struct btrfs_root *root, int max_mirrors);
62struct buffer_head *btrfs_read_dev_super(struct block_device *bdev); 62struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
63int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
64 struct buffer_head **bh_ret);
63int btrfs_commit_super(struct btrfs_root *root); 65int btrfs_commit_super(struct btrfs_root *root);
64struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, 66struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
65 u64 bytenr); 67 u64 bytenr);