Merge tag 'staging-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[firefly-linux-kernel-4.4.55.git] / drivers / md / raid1.c
index 55de4f6f7eaf47a4633e231d0943f3766f66aee5..5dd0c2e59ab98cf246bae49556d956163b20005b 100644 (file)
@@ -494,7 +494,6 @@ static void raid1_end_write_request(struct bio *bio, int error)
                bio_put(to_put);
 }
 
-
 /*
  * This routine returns the disk from which the requested read should
  * be done. There is a per-array 'next expected sequential IO' sector
@@ -702,11 +701,10 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
        return best_disk;
 }
 
-static int raid1_mergeable_bvec(struct request_queue *q,
+static int raid1_mergeable_bvec(struct mddev *mddev,
                                struct bvec_merge_data *bvm,
                                struct bio_vec *biovec)
 {
-       struct mddev *mddev = q->queuedata;
        struct r1conf *conf = mddev->private;
        sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
        int max = biovec->bv_len;
@@ -735,7 +733,7 @@ static int raid1_mergeable_bvec(struct request_queue *q,
 
 }
 
-int md_raid1_congested(struct mddev *mddev, int bits)
+static int raid1_congested(struct mddev *mddev, int bits)
 {
        struct r1conf *conf = mddev->private;
        int i, ret = 0;
@@ -764,15 +762,6 @@ int md_raid1_congested(struct mddev *mddev, int bits)
        rcu_read_unlock();
        return ret;
 }
-EXPORT_SYMBOL_GPL(md_raid1_congested);
-
-static int raid1_congested(void *data, int bits)
-{
-       struct mddev *mddev = data;
-
-       return mddev_congested(mddev, bits) ||
-               md_raid1_congested(mddev, bits);
-}
 
 static void flush_pending_writes(struct r1conf *conf)
 {
@@ -901,18 +890,18 @@ static sector_t wait_barrier(struct r1conf *conf, struct bio *bio)
                 * However if there are already pending
                 * requests (preventing the barrier from
                 * rising completely), and the
-                * pre-process bio queue isn't empty,
+                * per-process bio queue isn't empty,
                 * then don't wait, as we need to empty
-                * that queue to get the nr_pending
-                * count down.
+                * that queue to allow conf->start_next_window
+                * to increase.
                 */
                wait_event_lock_irq(conf->wait_barrier,
                                    !conf->array_frozen &&
                                    (!conf->barrier ||
-                                   ((conf->start_next_window <
-                                     conf->next_resync + RESYNC_SECTORS) &&
-                                    current->bio_list &&
-                                    !bio_list_empty(current->bio_list))),
+                                    ((conf->start_next_window <
+                                      conf->next_resync + RESYNC_SECTORS) &&
+                                     current->bio_list &&
+                                     !bio_list_empty(current->bio_list))),
                                    conf->resync_lock);
                conf->nr_waiting--;
        }
@@ -1001,8 +990,7 @@ static void unfreeze_array(struct r1conf *conf)
        spin_unlock_irq(&conf->resync_lock);
 }
 
-
-/* duplicate the data pages for behind I/O 
+/* duplicate the data pages for behind I/O
  */
 static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio)
 {
@@ -1471,7 +1459,6 @@ static void status(struct seq_file *seq, struct mddev *mddev)
        seq_printf(seq, "]");
 }
 
-
 static void error(struct mddev *mddev, struct md_rdev *rdev)
 {
        char b[BDEVNAME_SIZE];
@@ -1565,7 +1552,7 @@ static int raid1_spare_active(struct mddev *mddev)
        unsigned long flags;
 
        /*
-        * Find all failed disks within the RAID1 configuration 
+        * Find all failed disks within the RAID1 configuration
         * and mark them readable.
         * Called under mddev lock, so rcu protection not needed.
         */
@@ -1606,7 +1593,6 @@ static int raid1_spare_active(struct mddev *mddev)
        return count;
 }
 
-
 static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
 {
        struct r1conf *conf = mddev->private;
@@ -1735,7 +1721,6 @@ abort:
        return err;
 }
 
-
 static void end_sync_read(struct bio *bio, int error)
 {
        struct r1bio *r1_bio = bio->bi_private;
@@ -1947,7 +1932,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
        return 1;
 }
 
-static int process_checks(struct r1bio *r1_bio)
+static void process_checks(struct r1bio *r1_bio)
 {
        /* We have read all readable devices.  If we haven't
         * got the block, then there is no hope left.
@@ -2039,7 +2024,6 @@ static int process_checks(struct r1bio *r1_bio)
 
                bio_copy_data(sbio, pbio);
        }
-       return 0;
 }
 
 static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
@@ -2057,8 +2041,8 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
                        return;
 
        if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
-               if (process_checks(r1_bio) < 0)
-                       return;
+               process_checks(r1_bio);
+
        /*
         * schedule writes
         */
@@ -2458,7 +2442,6 @@ static void raid1d(struct md_thread *thread)
        blk_finish_plug(&plug);
 }
 
-
 static int init_resync(struct r1conf *conf)
 {
        int buffs;
@@ -2722,7 +2705,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
                                                /* remove last page from this bio */
                                                bio->bi_vcnt--;
                                                bio->bi_iter.bi_size -= len;
-                                               bio->bi_flags &= ~(1<< BIO_SEG_VALID);
+                                               __clear_bit(BIO_SEG_VALID, &bio->bi_flags);
                                        }
                                        goto bio_full;
                                }
@@ -2889,7 +2872,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
        return ERR_PTR(err);
 }
 
-static int stop(struct mddev *mddev);
+static void raid1_free(struct mddev *mddev, void *priv);
 static int run(struct mddev *mddev)
 {
        struct r1conf *conf;
@@ -2911,7 +2894,7 @@ static int run(struct mddev *mddev)
        /*
         * copy the already verified devices into our private RAID1
         * bookkeeping area. [whatever we allocate in run(),
-        * should be freed in stop()]
+        * should be freed in raid1_free()]
         */
        if (mddev->private == NULL)
                conf = setup_conf(mddev);
@@ -2947,9 +2930,9 @@ static int run(struct mddev *mddev)
                printk(KERN_NOTICE "md/raid1:%s: not clean"
                       " -- starting background reconstruction\n",
                       mdname(mddev));
-       printk(KERN_INFO 
+       printk(KERN_INFO
                "md/raid1:%s: active with %d out of %d mirrors\n",
-               mdname(mddev), mddev->raid_disks - mddev->degraded, 
+               mdname(mddev), mddev->raid_disks - mddev->degraded,
                mddev->raid_disks);
 
        /*
@@ -2962,10 +2945,6 @@ static int run(struct mddev *mddev)
        md_set_array_sectors(mddev, raid1_size(mddev, 0, 0));
 
        if (mddev->queue) {
-               mddev->queue->backing_dev_info.congested_fn = raid1_congested;
-               mddev->queue->backing_dev_info.congested_data = mddev;
-               blk_queue_merge_bvec(mddev->queue, raid1_mergeable_bvec);
-
                if (discard_supported)
                        queue_flag_set_unlocked(QUEUE_FLAG_DISCARD,
                                                mddev->queue);
@@ -2975,37 +2954,23 @@ static int run(struct mddev *mddev)
        }
 
        ret =  md_integrity_register(mddev);
-       if (ret)
-               stop(mddev);
+       if (ret) {
+               md_unregister_thread(&mddev->thread);
+               raid1_free(mddev, conf);
+       }
        return ret;
 }
 
-static int stop(struct mddev *mddev)
+static void raid1_free(struct mddev *mddev, void *priv)
 {
-       struct r1conf *conf = mddev->private;
-       struct bitmap *bitmap = mddev->bitmap;
+       struct r1conf *conf = priv;
 
-       /* wait for behind writes to complete */
-       if (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
-               printk(KERN_INFO "md/raid1:%s: behind writes in progress - waiting to stop.\n",
-                      mdname(mddev));
-               /* need to kick something here to make sure I/O goes? */
-               wait_event(bitmap->behind_wait,
-                          atomic_read(&bitmap->behind_writes) == 0);
-       }
-
-       freeze_array(conf, 0);
-       unfreeze_array(conf);
-
-       md_unregister_thread(&mddev->thread);
        if (conf->r1bio_pool)
                mempool_destroy(conf->r1bio_pool);
        kfree(conf->mirrors);
        safe_put_page(conf->tmppage);
        kfree(conf->poolinfo);
        kfree(conf);
-       mddev->private = NULL;
-       return 0;
 }
 
 static int raid1_resize(struct mddev *mddev, sector_t sectors)
@@ -3188,7 +3153,7 @@ static struct md_personality raid1_personality =
        .owner          = THIS_MODULE,
        .make_request   = make_request,
        .run            = run,
-       .stop           = stop,
+       .free           = raid1_free,
        .status         = status,
        .error_handler  = error,
        .hot_add_disk   = raid1_add_disk,
@@ -3200,6 +3165,8 @@ static struct md_personality raid1_personality =
        .check_reshape  = raid1_reshape,
        .quiesce        = raid1_quiesce,
        .takeover       = raid1_takeover,
+       .congested      = raid1_congested,
+       .mergeable_bvec = raid1_mergeable_bvec,
 };
 
 static int __init raid_init(void)