Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebieder...
[linux-2.6-microblaze.git] / drivers / md / raid1.c
index e9e3308..4e99024 100644 (file)
@@ -126,8 +126,8 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
        if (!r1_bio)
                return NULL;
 
-       rps = kmalloc(sizeof(struct resync_pages) * pi->raid_disks,
-                     gfp_flags);
+       rps = kmalloc_array(pi->raid_disks, sizeof(struct resync_pages),
+                           gfp_flags);
        if (!rps)
                goto out_free_r1bio;
 
@@ -221,7 +221,7 @@ static void free_r1bio(struct r1bio *r1_bio)
        struct r1conf *conf = r1_bio->mddev->private;
 
        put_all_bios(conf, r1_bio);
-       mempool_free(r1_bio, conf->r1bio_pool);
+       mempool_free(r1_bio, &conf->r1bio_pool);
 }
 
 static void put_buf(struct r1bio *r1_bio)
@@ -236,7 +236,7 @@ static void put_buf(struct r1bio *r1_bio)
                        rdev_dec_pending(conf->mirrors[i].rdev, r1_bio->mddev);
        }
 
-       mempool_free(r1_bio, conf->r1buf_pool);
+       mempool_free(r1_bio, &conf->r1buf_pool);
 
        lower_barrier(conf, sect);
 }
@@ -385,10 +385,10 @@ static void close_write(struct r1bio *r1_bio)
                r1_bio->behind_master_bio = NULL;
        }
        /* clear the bitmap if all writes complete successfully */
-       bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
-                       r1_bio->sectors,
-                       !test_bit(R1BIO_Degraded, &r1_bio->state),
-                       test_bit(R1BIO_BehindIO, &r1_bio->state));
+       md_bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
+                          r1_bio->sectors,
+                          !test_bit(R1BIO_Degraded, &r1_bio->state),
+                          test_bit(R1BIO_BehindIO, &r1_bio->state));
        md_write_end(r1_bio->mddev);
 }
 
@@ -781,7 +781,7 @@ static int raid1_congested(struct mddev *mddev, int bits)
 static void flush_bio_list(struct r1conf *conf, struct bio *bio)
 {
        /* flush any pending bitmap writes to disk before proceeding w/ I/O */
-       bitmap_unplug(conf->mddev->bitmap);
+       md_bitmap_unplug(conf->mddev->bitmap);
        wake_up(&conf->wait_barrier);
 
        while (bio) { /* submit pending writes */
@@ -1178,7 +1178,7 @@ alloc_r1bio(struct mddev *mddev, struct bio *bio)
        struct r1conf *conf = mddev->private;
        struct r1bio *r1_bio;
 
-       r1_bio = mempool_alloc(conf->r1bio_pool, GFP_NOIO);
+       r1_bio = mempool_alloc(&conf->r1bio_pool, GFP_NOIO);
        /* Ensure no bio records IO_BLOCKED */
        memset(r1_bio->bios, 0, conf->raid_disks * sizeof(r1_bio->bios[0]));
        init_r1bio(r1_bio, mddev, bio);
@@ -1268,7 +1268,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
 
        if (max_sectors < bio_sectors(bio)) {
                struct bio *split = bio_split(bio, max_sectors,
-                                             gfp, conf->bio_split);
+                                             gfp, &conf->bio_split);
                bio_chain(split, bio);
                generic_make_request(bio);
                bio = split;
@@ -1278,7 +1278,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
 
        r1_bio->read_disk = rdisk;
 
-       read_bio = bio_clone_fast(bio, gfp, mddev->bio_set);
+       read_bio = bio_clone_fast(bio, gfp, &mddev->bio_set);
 
        r1_bio->bios[rdisk] = read_bio;
 
@@ -1439,7 +1439,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
 
        if (max_sectors < bio_sectors(bio)) {
                struct bio *split = bio_split(bio, max_sectors,
-                                             GFP_NOIO, conf->bio_split);
+                                             GFP_NOIO, &conf->bio_split);
                bio_chain(split, bio);
                generic_make_request(bio);
                bio = split;
@@ -1470,18 +1470,16 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
                                alloc_behind_master_bio(r1_bio, bio);
                        }
 
-                       bitmap_startwrite(bitmap, r1_bio->sector,
-                                         r1_bio->sectors,
-                                         test_bit(R1BIO_BehindIO,
-                                                  &r1_bio->state));
+                       md_bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors,
+                                            test_bit(R1BIO_BehindIO, &r1_bio->state));
                        first_clone = 0;
                }
 
                if (r1_bio->behind_master_bio)
                        mbio = bio_clone_fast(r1_bio->behind_master_bio,
-                                             GFP_NOIO, mddev->bio_set);
+                                             GFP_NOIO, &mddev->bio_set);
                else
-                       mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
+                       mbio = bio_clone_fast(bio, GFP_NOIO, &mddev->bio_set);
 
                if (r1_bio->behind_master_bio) {
                        if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
@@ -1657,8 +1655,7 @@ static void close_sync(struct r1conf *conf)
                _allow_barrier(conf, idx);
        }
 
-       mempool_destroy(conf->r1buf_pool);
-       conf->r1buf_pool = NULL;
+       mempool_exit(&conf->r1buf_pool);
 }
 
 static int raid1_spare_active(struct mddev *mddev)
@@ -1881,8 +1878,7 @@ static void end_sync_write(struct bio *bio)
                long sectors_to_go = r1_bio->sectors;
                /* make sure these bits doesn't get cleared. */
                do {
-                       bitmap_end_sync(mddev->bitmap, s,
-                                       &sync_blocks, 1);
+                       md_bitmap_end_sync(mddev->bitmap, s, &sync_blocks, 1);
                        s += sync_blocks;
                        sectors_to_go -= sync_blocks;
                } while (sectors_to_go > 0);
@@ -2348,10 +2344,10 @@ static int narrow_write_error(struct r1bio *r1_bio, int i)
                if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
                        wbio = bio_clone_fast(r1_bio->behind_master_bio,
                                              GFP_NOIO,
-                                             mddev->bio_set);
+                                             &mddev->bio_set);
                } else {
                        wbio = bio_clone_fast(r1_bio->master_bio, GFP_NOIO,
-                                             mddev->bio_set);
+                                             &mddev->bio_set);
                }
 
                bio_set_op_attrs(wbio, REQ_OP_WRITE, 0);
@@ -2450,7 +2446,6 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio)
        struct mddev *mddev = conf->mddev;
        struct bio *bio;
        struct md_rdev *rdev;
-       sector_t bio_sector;
 
        clear_bit(R1BIO_ReadError, &r1_bio->state);
        /* we got a read error. Maybe the drive is bad.  Maybe just
@@ -2463,7 +2458,6 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio)
         */
 
        bio = r1_bio->bios[r1_bio->read_disk];
-       bio_sector = conf->mirrors[r1_bio->read_disk].rdev->data_offset + r1_bio->sector;
        bio_put(bio);
        r1_bio->bios[r1_bio->read_disk] = NULL;
 
@@ -2474,6 +2468,8 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio)
                fix_read_error(conf, r1_bio->read_disk,
                               r1_bio->sector, r1_bio->sectors);
                unfreeze_array(conf);
+       } else if (mddev->ro == 0 && test_bit(FailFast, &rdev->flags)) {
+               md_error(mddev, rdev);
        } else {
                r1_bio->bios[r1_bio->read_disk] = IO_BLOCKED;
        }
@@ -2564,17 +2560,15 @@ static int init_resync(struct r1conf *conf)
        int buffs;
 
        buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
-       BUG_ON(conf->r1buf_pool);
-       conf->r1buf_pool = mempool_create(buffs, r1buf_pool_alloc, r1buf_pool_free,
-                                         conf->poolinfo);
-       if (!conf->r1buf_pool)
-               return -ENOMEM;
-       return 0;
+       BUG_ON(mempool_initialized(&conf->r1buf_pool));
+
+       return mempool_init(&conf->r1buf_pool, buffs, r1buf_pool_alloc,
+                           r1buf_pool_free, conf->poolinfo);
 }
 
 static struct r1bio *raid1_alloc_init_r1buf(struct r1conf *conf)
 {
-       struct r1bio *r1bio = mempool_alloc(conf->r1buf_pool, GFP_NOIO);
+       struct r1bio *r1bio = mempool_alloc(&conf->r1buf_pool, GFP_NOIO);
        struct resync_pages *rps;
        struct bio *bio;
        int i;
@@ -2617,7 +2611,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
        int idx = sector_to_idx(sector_nr);
        int page_idx = 0;
 
-       if (!conf->r1buf_pool)
+       if (!mempool_initialized(&conf->r1buf_pool))
                if (init_resync(conf))
                        return 0;
 
@@ -2629,12 +2623,12 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
                 * We can find the current addess in mddev->curr_resync
                 */
                if (mddev->curr_resync < max_sector) /* aborted */
-                       bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
-                                               &sync_blocks, 1);
+                       md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
+                                          &sync_blocks, 1);
                else /* completed sync */
                        conf->fullsync = 0;
 
-               bitmap_close_sync(mddev->bitmap);
+               md_bitmap_close_sync(mddev->bitmap);
                close_sync(conf);
 
                if (mddev_is_clustered(mddev)) {
@@ -2654,7 +2648,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
        /* before building a request, check if we can skip these blocks..
         * This call the bitmap_start_sync doesn't actually record anything
         */
-       if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
+       if (!md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
            !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
                /* We can skip this block, and probably several more */
                *skipped = 1;
@@ -2672,7 +2666,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
         * sector_nr + two times RESYNC_SECTORS
         */
 
-       bitmap_cond_end_sync(mddev->bitmap, sector_nr,
+       md_bitmap_cond_end_sync(mddev->bitmap, sector_nr,
                mddev_is_clustered(mddev) && (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high));
 
 
@@ -2831,8 +2825,8 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
                if (len == 0)
                        break;
                if (sync_blocks == 0) {
-                       if (!bitmap_start_sync(mddev->bitmap, sector_nr,
-                                              &sync_blocks, still_degraded) &&
+                       if (!md_bitmap_start_sync(mddev->bitmap, sector_nr,
+                                                 &sync_blocks, still_degraded) &&
                            !conf->fullsync &&
                            !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
                                break;
@@ -2939,9 +2933,9 @@ static struct r1conf *setup_conf(struct mddev *mddev)
        if (!conf->barrier)
                goto abort;
 
-       conf->mirrors = kzalloc(sizeof(struct raid1_info)
-                               * mddev->raid_disks * 2,
-                                GFP_KERNEL);
+       conf->mirrors = kzalloc(array3_size(sizeof(struct raid1_info),
+                                           mddev->raid_disks, 2),
+                               GFP_KERNEL);
        if (!conf->mirrors)
                goto abort;
 
@@ -2953,14 +2947,13 @@ static struct r1conf *setup_conf(struct mddev *mddev)
        if (!conf->poolinfo)
                goto abort;
        conf->poolinfo->raid_disks = mddev->raid_disks * 2;
-       conf->r1bio_pool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
-                                         r1bio_pool_free,
-                                         conf->poolinfo);
-       if (!conf->r1bio_pool)
+       err = mempool_init(&conf->r1bio_pool, NR_RAID1_BIOS, r1bio_pool_alloc,
+                          r1bio_pool_free, conf->poolinfo);
+       if (err)
                goto abort;
 
-       conf->bio_split = bioset_create(BIO_POOL_SIZE, 0, 0);
-       if (!conf->bio_split)
+       err = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0);
+       if (err)
                goto abort;
 
        conf->poolinfo->mddev = mddev;
@@ -3033,7 +3026,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
 
  abort:
        if (conf) {
-               mempool_destroy(conf->r1bio_pool);
+               mempool_exit(&conf->r1bio_pool);
                kfree(conf->mirrors);
                safe_put_page(conf->tmppage);
                kfree(conf->poolinfo);
@@ -3041,8 +3034,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
                kfree(conf->nr_waiting);
                kfree(conf->nr_queued);
                kfree(conf->barrier);
-               if (conf->bio_split)
-                       bioset_free(conf->bio_split);
+               bioset_exit(&conf->bio_split);
                kfree(conf);
        }
        return ERR_PTR(err);
@@ -3144,7 +3136,7 @@ static void raid1_free(struct mddev *mddev, void *priv)
 {
        struct r1conf *conf = priv;
 
-       mempool_destroy(conf->r1bio_pool);
+       mempool_exit(&conf->r1bio_pool);
        kfree(conf->mirrors);
        safe_put_page(conf->tmppage);
        kfree(conf->poolinfo);
@@ -3152,8 +3144,7 @@ static void raid1_free(struct mddev *mddev, void *priv)
        kfree(conf->nr_waiting);
        kfree(conf->nr_queued);
        kfree(conf->barrier);
-       if (conf->bio_split)
-               bioset_free(conf->bio_split);
+       bioset_exit(&conf->bio_split);
        kfree(conf);
 }
 
@@ -3171,7 +3162,7 @@ static int raid1_resize(struct mddev *mddev, sector_t sectors)
            mddev->array_sectors > newsize)
                return -EINVAL;
        if (mddev->bitmap) {
-               int ret = bitmap_resize(mddev->bitmap, newsize, 0, 0);
+               int ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0);
                if (ret)
                        return ret;
        }
@@ -3199,13 +3190,17 @@ static int raid1_reshape(struct mddev *mddev)
         * At the same time, we "pack" the devices so that all the missing
         * devices have the higher raid_disk numbers.
         */
-       mempool_t *newpool, *oldpool;
+       mempool_t newpool, oldpool;
        struct pool_info *newpoolinfo;
        struct raid1_info *newmirrors;
        struct r1conf *conf = mddev->private;
        int cnt, raid_disks;
        unsigned long flags;
        int d, d2;
+       int ret;
+
+       memset(&newpool, 0, sizeof(newpool));
+       memset(&oldpool, 0, sizeof(oldpool));
 
        /* Cannot change chunk_size, layout, or level */
        if (mddev->chunk_sectors != mddev->new_chunk_sectors ||
@@ -3237,17 +3232,18 @@ static int raid1_reshape(struct mddev *mddev)
        newpoolinfo->mddev = mddev;
        newpoolinfo->raid_disks = raid_disks * 2;
 
-       newpool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
-                                r1bio_pool_free, newpoolinfo);
-       if (!newpool) {
+       ret = mempool_init(&newpool, NR_RAID1_BIOS, r1bio_pool_alloc,
+                          r1bio_pool_free, newpoolinfo);
+       if (ret) {
                kfree(newpoolinfo);
-               return -ENOMEM;
+               return ret;
        }
-       newmirrors = kzalloc(sizeof(struct raid1_info) * raid_disks * 2,
+       newmirrors = kzalloc(array3_size(sizeof(struct raid1_info),
+                                        raid_disks, 2),
                             GFP_KERNEL);
        if (!newmirrors) {
                kfree(newpoolinfo);
-               mempool_destroy(newpool);
+               mempool_exit(&newpool);
                return -ENOMEM;
        }
 
@@ -3287,7 +3283,7 @@ static int raid1_reshape(struct mddev *mddev)
        set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
        md_wakeup_thread(mddev->thread);
 
-       mempool_destroy(oldpool);
+       mempool_exit(&oldpool);
        return 0;
 }