Merge branch 'for-linus-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/mason...
[cascardo/linux.git] / fs / btrfs / volumes.c
index e217035..bb0addc 100644 (file)
@@ -461,7 +461,7 @@ loop_lock:
                        sync_pending = 0;
                }
 
-               btrfsic_submit_bio(cur->bi_rw, cur);
+               btrfsic_submit_bio(cur);
                num_run++;
                batch_run++;
 
@@ -5318,7 +5318,7 @@ void btrfs_put_bbio(struct btrfs_bio *bbio)
                kfree(bbio);
 }
 
-static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
+static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op,
                             u64 logical, u64 *length,
                             struct btrfs_bio **bbio_ret,
                             int mirror_num, int need_raid_map)
@@ -5404,7 +5404,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                raid56_full_stripe_start *= full_stripe_len;
        }
 
-       if (rw & REQ_DISCARD) {
+       if (op == REQ_OP_DISCARD) {
                /* we don't discard raid56 yet */
                if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
                        ret = -EOPNOTSUPP;
@@ -5417,7 +5417,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                   For other RAID types and for RAID[56] reads, just allow a single
                   stripe (on a single disk). */
                if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
-                   (rw & REQ_WRITE)) {
+                   (op == REQ_OP_WRITE)) {
                        max_len = stripe_len * nr_data_stripes(map) -
                                (offset - raid56_full_stripe_start);
                } else {
@@ -5442,8 +5442,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                btrfs_dev_replace_set_lock_blocking(dev_replace);
 
        if (dev_replace_is_ongoing && mirror_num == map->num_stripes + 1 &&
-           !(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)) &&
-           dev_replace->tgtdev != NULL) {
+           op != REQ_OP_WRITE && op != REQ_OP_DISCARD &&
+           op != REQ_GET_READ_MIRRORS && dev_replace->tgtdev != NULL) {
                /*
                 * in dev-replace case, for repair case (that's the only
                 * case where the mirror is selected explicitly when
@@ -5530,15 +5530,17 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                            (offset + *length);
 
        if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
-               if (rw & REQ_DISCARD)
+               if (op == REQ_OP_DISCARD)
                        num_stripes = min_t(u64, map->num_stripes,
                                            stripe_nr_end - stripe_nr_orig);
                stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
                                &stripe_index);
-               if (!(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)))
+               if (op != REQ_OP_WRITE && op != REQ_OP_DISCARD &&
+                   op != REQ_GET_READ_MIRRORS)
                        mirror_num = 1;
        } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
-               if (rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS))
+               if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD ||
+                   op == REQ_GET_READ_MIRRORS)
                        num_stripes = map->num_stripes;
                else if (mirror_num)
                        stripe_index = mirror_num - 1;
@@ -5551,7 +5553,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                }
 
        } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
-               if (rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)) {
+               if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD ||
+                   op == REQ_GET_READ_MIRRORS) {
                        num_stripes = map->num_stripes;
                } else if (mirror_num) {
                        stripe_index = mirror_num - 1;
@@ -5565,9 +5568,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
                stripe_index *= map->sub_stripes;
 
-               if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS))
+               if (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS)
                        num_stripes = map->sub_stripes;
-               else if (rw & REQ_DISCARD)
+               else if (op == REQ_OP_DISCARD)
                        num_stripes = min_t(u64, map->sub_stripes *
                                            (stripe_nr_end - stripe_nr_orig),
                                            map->num_stripes);
@@ -5585,7 +5588,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
 
        } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
                if (need_raid_map &&
-                   ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) ||
+                   (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS ||
                     mirror_num > 1)) {
                        /* push stripe_nr back to the start of the full stripe */
                        stripe_nr = div_u64(raid56_full_stripe_start,
@@ -5613,8 +5616,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                        /* We distribute the parity blocks across stripes */
                        div_u64_rem(stripe_nr + stripe_index, map->num_stripes,
                                        &stripe_index);
-                       if (!(rw & (REQ_WRITE | REQ_DISCARD |
-                                   REQ_GET_READ_MIRRORS)) && mirror_num <= 1)
+                       if ((op != REQ_OP_WRITE && op != REQ_OP_DISCARD &&
+                           op != REQ_GET_READ_MIRRORS) && mirror_num <= 1)
                                mirror_num = 1;
                }
        } else {
@@ -5637,9 +5640,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
 
        num_alloc_stripes = num_stripes;
        if (dev_replace_is_ongoing) {
-               if (rw & (REQ_WRITE | REQ_DISCARD))
+               if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD)
                        num_alloc_stripes <<= 1;
-               if (rw & REQ_GET_READ_MIRRORS)
+               if (op == REQ_GET_READ_MIRRORS)
                        num_alloc_stripes++;
                tgtdev_indexes = num_stripes;
        }
@@ -5654,7 +5657,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
 
        /* build raid_map */
        if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK &&
-           need_raid_map && ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) ||
+           need_raid_map &&
+           ((op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS) ||
            mirror_num > 1)) {
                u64 tmp;
                unsigned rot;
@@ -5679,7 +5683,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                                RAID6_Q_STRIPE;
        }
 
-       if (rw & REQ_DISCARD) {
+       if (op == REQ_OP_DISCARD) {
                u32 factor = 0;
                u32 sub_stripes = 0;
                u64 stripes_per_dev = 0;
@@ -5759,14 +5763,15 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                }
        }
 
-       if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS))
+       if (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS)
                max_errors = btrfs_chunk_max_errors(map);
 
        if (bbio->raid_map)
                sort_parity_stripes(bbio, num_stripes);
 
        tgtdev_indexes = 0;
-       if (dev_replace_is_ongoing && (rw & (REQ_WRITE | REQ_DISCARD)) &&
+       if (dev_replace_is_ongoing &&
+          (op == REQ_OP_WRITE || op == REQ_OP_DISCARD) &&
            dev_replace->tgtdev != NULL) {
                int index_where_to_add;
                u64 srcdev_devid = dev_replace->srcdev->devid;
@@ -5801,7 +5806,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                        }
                }
                num_stripes = index_where_to_add;
-       } else if (dev_replace_is_ongoing && (rw & REQ_GET_READ_MIRRORS) &&
+       } else if (dev_replace_is_ongoing && (op == REQ_GET_READ_MIRRORS) &&
                   dev_replace->tgtdev != NULL) {
                u64 srcdev_devid = dev_replace->srcdev->devid;
                int index_srcdev = 0;
@@ -5873,21 +5878,21 @@ out:
        return ret;
 }
 
-int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
+int btrfs_map_block(struct btrfs_fs_info *fs_info, int op,
                      u64 logical, u64 *length,
                      struct btrfs_bio **bbio_ret, int mirror_num)
 {
-       return __btrfs_map_block(fs_info, rw, logical, length, bbio_ret,
+       return __btrfs_map_block(fs_info, op, logical, length, bbio_ret,
                                 mirror_num, 0);
 }
 
 /* For Scrub/replace */
-int btrfs_map_sblock(struct btrfs_fs_info *fs_info, int rw,
+int btrfs_map_sblock(struct btrfs_fs_info *fs_info, int op,
                     u64 logical, u64 *length,
                     struct btrfs_bio **bbio_ret, int mirror_num,
                     int need_raid_map)
 {
-       return __btrfs_map_block(fs_info, rw, logical, length, bbio_ret,
+       return __btrfs_map_block(fs_info, op, logical, length, bbio_ret,
                                 mirror_num, need_raid_map);
 }
 
@@ -6001,7 +6006,7 @@ static void btrfs_end_bio(struct bio *bio)
                        BUG_ON(stripe_index >= bbio->num_stripes);
                        dev = bbio->stripes[stripe_index].dev;
                        if (dev->bdev) {
-                               if (bio->bi_rw & WRITE)
+                               if (bio_op(bio) == REQ_OP_WRITE)
                                        btrfs_dev_stat_inc(dev,
                                                BTRFS_DEV_STAT_WRITE_ERRS);
                                else
@@ -6055,7 +6060,7 @@ static void btrfs_end_bio(struct bio *bio)
  */
 static noinline void btrfs_schedule_bio(struct btrfs_root *root,
                                        struct btrfs_device *device,
-                                       int rw, struct bio *bio)
+                                       struct bio *bio)
 {
        int should_queue = 1;
        struct btrfs_pending_bios *pending_bios;
@@ -6066,9 +6071,9 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root,
        }
 
        /* don't bother with additional async steps for reads, right now */
-       if (!(rw & REQ_WRITE)) {
+       if (bio_op(bio) == REQ_OP_READ) {
                bio_get(bio);
-               btrfsic_submit_bio(rw, bio);
+               btrfsic_submit_bio(bio);
                bio_put(bio);
                return;
        }
@@ -6082,7 +6087,6 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root,
        atomic_inc(&root->fs_info->nr_async_bios);
        WARN_ON(bio->bi_next);
        bio->bi_next = NULL;
-       bio->bi_rw |= rw;
 
        spin_lock(&device->io_lock);
        if (bio->bi_rw & REQ_SYNC)
@@ -6108,7 +6112,7 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root,
 
 static void submit_stripe_bio(struct btrfs_root *root, struct btrfs_bio *bbio,
                              struct bio *bio, u64 physical, int dev_nr,
-                             int rw, int async)
+                             int async)
 {
        struct btrfs_device *dev = bbio->stripes[dev_nr].dev;
 
@@ -6122,8 +6126,8 @@ static void submit_stripe_bio(struct btrfs_root *root, struct btrfs_bio *bbio,
 
                rcu_read_lock();
                name = rcu_dereference(dev->name);
-               pr_debug("btrfs_map_bio: rw %d, sector=%llu, dev=%lu "
-                        "(%s id %llu), size=%u\n", rw,
+               pr_debug("btrfs_map_bio: rw %d 0x%x, sector=%llu, dev=%lu "
+                        "(%s id %llu), size=%u\n", bio_op(bio), bio->bi_rw,
                         (u64)bio->bi_iter.bi_sector, (u_long)dev->bdev->bd_dev,
                         name->str, dev->devid, bio->bi_iter.bi_size);
                rcu_read_unlock();
@@ -6134,9 +6138,9 @@ static void submit_stripe_bio(struct btrfs_root *root, struct btrfs_bio *bbio,
        btrfs_bio_counter_inc_noblocked(root->fs_info);
 
        if (async)
-               btrfs_schedule_bio(root, dev, rw, bio);
+               btrfs_schedule_bio(root, dev, bio);
        else
-               btrfsic_submit_bio(rw, bio);
+               btrfsic_submit_bio(bio);
 }
 
 static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)
@@ -6153,7 +6157,7 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)
        }
 }
 
-int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
+int btrfs_map_bio(struct btrfs_root *root, struct bio *bio,
                  int mirror_num, int async_submit)
 {
        struct btrfs_device *dev;
@@ -6170,8 +6174,8 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
        map_length = length;
 
        btrfs_bio_counter_inc_blocked(root->fs_info);
-       ret = __btrfs_map_block(root->fs_info, rw, logical, &map_length, &bbio,
-                             mirror_num, 1);
+       ret = __btrfs_map_block(root->fs_info, bio_op(bio), logical,
+                               &map_length, &bbio, mirror_num, 1);
        if (ret) {
                btrfs_bio_counter_dec(root->fs_info);
                return ret;
@@ -6185,10 +6189,10 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
        atomic_set(&bbio->stripes_pending, bbio->num_stripes);
 
        if ((bbio->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
-           ((rw & WRITE) || (mirror_num > 1))) {
+           ((bio_op(bio) == REQ_OP_WRITE) || (mirror_num > 1))) {
                /* In this case, map_length has been set to the length of
                   a single stripe; not the whole write */
-               if (rw & WRITE) {
+               if (bio_op(bio) == REQ_OP_WRITE) {
                        ret = raid56_parity_write(root, bio, bbio, map_length);
                } else {
                        ret = raid56_parity_recover(root, bio, bbio, map_length,
@@ -6207,7 +6211,8 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
 
        for (dev_nr = 0; dev_nr < total_devs; dev_nr++) {
                dev = bbio->stripes[dev_nr].dev;
-               if (!dev || !dev->bdev || (rw & WRITE && !dev->writeable)) {
+               if (!dev || !dev->bdev ||
+                   (bio_op(bio) == REQ_OP_WRITE && !dev->writeable)) {
                        bbio_error(bbio, first_bio, logical);
                        continue;
                }
@@ -6219,7 +6224,7 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
                        bio = first_bio;
 
                submit_stripe_bio(root, bbio, bio,
-                                 bbio->stripes[dev_nr].physical, dev_nr, rw,
+                                 bbio->stripes[dev_nr].physical, dev_nr,
                                  async_submit);
        }
        btrfs_bio_counter_dec(root->fs_info);