btrfs: use named constant for bdev blocksize
authorDavid Sterba <dsterba@suse.com>
Thu, 15 Jun 2017 23:48:05 +0000 (01:48 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 16 Aug 2017 14:12:04 +0000 (16:12 +0200)
Superblock is read and written using buffer heads, we need to set the
bdev blocksize. The magic constant has been hardcoded in several places,
so replace it with a named constant.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/check-integrity.c
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/volumes.c

index 11d37c94ce058b6c7f09bfb1a546038b85977eb0..7d65d98d2790d2c3ea69ea320298fe589e8eb4b0 100644 (file)
@@ -795,12 +795,12 @@ static int btrfsic_process_superblock_dev_mirror(
        dev_bytenr = btrfs_sb_offset(superblock_mirror_num);
        if (dev_bytenr + BTRFS_SUPER_INFO_SIZE > device->commit_total_bytes)
                return -1;
-       bh = __bread(superblock_bdev, dev_bytenr / 4096,
+       bh = __bread(superblock_bdev, dev_bytenr / BTRFS_BDEV_BLOCKSIZE,
                     BTRFS_SUPER_INFO_SIZE);
        if (NULL == bh)
                return -1;
        super_tmp = (struct btrfs_super_block *)
-           (bh->b_data + (dev_bytenr & 4095));
+           (bh->b_data + (dev_bytenr & (BTRFS_BDEV_BLOCKSIZE - 1)));
 
        if (btrfs_super_bytenr(super_tmp) != dev_bytenr ||
            btrfs_super_magic(super_tmp) != BTRFS_MAGIC ||
@@ -2758,7 +2758,7 @@ int btrfsic_submit_bh(int op, int op_flags, struct buffer_head *bh)
            (op == REQ_OP_WRITE) && bh->b_size > 0) {
                u64 dev_bytenr;
 
-               dev_bytenr = 4096 * bh->b_blocknr;
+               dev_bytenr = BTRFS_BDEV_BLOCKSIZE * bh->b_blocknr;
                if (dev_state->state->print_mask &
                    BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH)
                        pr_info("submit_bh(op=0x%x,0x%x, blocknr=%llu (bytenr %llu), size=%zu, data=%p, bdev=%p)\n",
index b72711ad7121fd2eb6661c05f74ee15c051a3e78..9b1f4ef54438cf9b27009d5981df8e84685b4601 100644 (file)
@@ -2694,8 +2694,8 @@ int open_ctree(struct super_block *sb,
        btrfs_init_balance(fs_info);
        btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work);
 
-       sb->s_blocksize = 4096;
-       sb->s_blocksize_bits = blksize_bits(4096);
+       sb->s_blocksize = BTRFS_BDEV_BLOCKSIZE;
+       sb->s_blocksize_bits = blksize_bits(BTRFS_BDEV_BLOCKSIZE);
 
        btrfs_init_btree_inode(fs_info);
 
@@ -3316,7 +3316,7 @@ int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
        if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode))
                return -EINVAL;
 
-       bh = __bread(bdev, bytenr / 4096, BTRFS_SUPER_INFO_SIZE);
+       bh = __bread(bdev, bytenr / BTRFS_BDEV_BLOCKSIZE, BTRFS_SUPER_INFO_SIZE);
        /*
         * If we fail to read from the underlying devices, as of now
         * the best option we have is to mark it EIO.
@@ -3409,7 +3409,7 @@ static int write_dev_supers(struct btrfs_device *device,
                btrfs_csum_final(crc, sb->csum);
 
                /* One reference for us, and we leave it for the caller */
-               bh = __getblk(device->bdev, bytenr / 4096,
+               bh = __getblk(device->bdev, bytenr / BTRFS_BDEV_BLOCKSIZE,
                              BTRFS_SUPER_INFO_SIZE);
                if (!bh) {
                        btrfs_err(device->fs_info,
@@ -3468,7 +3468,8 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors)
                    device->commit_total_bytes)
                        break;
 
-               bh = __find_get_block(device->bdev, bytenr / 4096,
+               bh = __find_get_block(device->bdev,
+                                     bytenr / BTRFS_BDEV_BLOCKSIZE,
                                      BTRFS_SUPER_INFO_SIZE);
                if (!bh) {
                        errors++;
index b5d0c4cef819295635e837a19b936a7a1632a871..7f7c35d6347a39107ee0d43e4160b7ca7efabdc8 100644 (file)
 #define BTRFS_SUPER_MIRROR_MAX  3
 #define BTRFS_SUPER_MIRROR_SHIFT 12
 
+/*
+ * Fixed blocksize for all devices, applies to specific ways of reading
+ * metadata like superblock. Must meet the set_blocksize requirements.
+ *
+ * Do not change.
+ */
+#define BTRFS_BDEV_BLOCKSIZE   (4096)
+
 enum btrfs_wq_endio_type {
        BTRFS_WQ_ENDIO_DATA = 0,
        BTRFS_WQ_ENDIO_METADATA = 1,
index 3a43a9cc6183cd16daec9dfbd12bb91ef3928996..12bd04a4104fa4afefad2e88ffddfcb69d2f0190 100644 (file)
@@ -303,7 +303,7 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder,
 
        if (flush)
                filemap_write_and_wait((*bdev)->bd_inode->i_mapping);
-       ret = set_blocksize(*bdev, 4096);
+       ret = set_blocksize(*bdev, BTRFS_BDEV_BLOCKSIZE);
        if (ret) {
                blkdev_put(*bdev, flags);
                goto error;
@@ -2395,7 +2395,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
        device->is_tgtdev_for_dev_replace = 0;
        device->mode = FMODE_EXCL;
        device->dev_stats_valid = 1;
-       set_blocksize(device->bdev, 4096);
+       set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
 
        if (seeding_dev) {
                sb->s_flags &= ~MS_RDONLY;
@@ -2598,7 +2598,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
        device->is_tgtdev_for_dev_replace = 1;
        device->mode = FMODE_EXCL;
        device->dev_stats_valid = 1;
-       set_blocksize(device->bdev, 4096);
+       set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE);
        device->fs_devices = fs_info->fs_devices;
        list_add(&device->dev_list, &fs_info->fs_devices->devices);
        fs_info->fs_devices->num_devices++;