]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/md/raid1.c
[PATCH] device-mapper log bitset: fix big endian find_next_zero_bit
[linux-2.6-omap-h63xx.git] / drivers / md / raid1.c
index bbe0b817572b3608008878a5539f8fd8bc638d3e..d39f584cd8b3000d048f3f83007a9dc3ec672a1e 100644 (file)
@@ -47,7 +47,6 @@
  */
 #define        NR_RAID1_BIOS 256
 
-static mdk_personality_t raid1_personality;
 
 static void unplug_slaves(mddev_t *mddev);
 
@@ -61,10 +60,8 @@ static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
        int size = offsetof(r1bio_t, bios[pi->raid_disks]);
 
        /* allocate a r1bio with room for raid_disks entries in the bios array */
-       r1_bio = kmalloc(size, gfp_flags);
-       if (r1_bio)
-               memset(r1_bio, 0, size);
-       else
+       r1_bio = kzalloc(size, gfp_flags);
+       if (!r1_bio)
                unplug_slaves(pi->mddev);
 
        return r1_bio;
@@ -139,7 +136,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
 out_free_pages:
        for (i=0; i < RESYNC_PAGES ; i++)
                for (j=0 ; j < pi->raid_disks; j++)
-                       put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page);
+                       safe_put_page(r1_bio->bios[j]->bi_io_vec[i].bv_page);
        j = -1;
 out_free_bio:
        while ( ++j < pi->raid_disks )
@@ -159,7 +156,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data)
                        if (j == 0 ||
                            r1bio->bios[j]->bi_io_vec[i].bv_page !=
                            r1bio->bios[0]->bi_io_vec[i].bv_page)
-                               put_page(r1bio->bios[j]->bi_io_vec[i].bv_page);
+                               safe_put_page(r1bio->bios[j]->bi_io_vec[i].bv_page);
                }
        for (i=0 ; i < pi->raid_disks; i++)
                bio_put(r1bio->bios[i]);
@@ -179,7 +176,7 @@ static void put_all_bios(conf_t *conf, r1bio_t *r1_bio)
        }
 }
 
-static inline void free_r1bio(r1bio_t *r1_bio)
+static void free_r1bio(r1bio_t *r1_bio)
 {
        conf_t *conf = mddev_to_conf(r1_bio->mddev);
 
@@ -193,7 +190,7 @@ static inline void free_r1bio(r1bio_t *r1_bio)
        mempool_free(r1_bio, conf->r1bio_pool);
 }
 
-static inline void put_buf(r1bio_t *r1_bio)
+static void put_buf(r1bio_t *r1_bio)
 {
        conf_t *conf = mddev_to_conf(r1_bio->mddev);
        int i;
@@ -384,7 +381,7 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
                        /* free extra copy of the data pages */
                        int i = bio->bi_vcnt;
                        while (i--)
-                               put_page(bio->bi_io_vec[i].bv_page);
+                               safe_put_page(bio->bi_io_vec[i].bv_page);
                }
                /* clear the bitmap if all writes complete successfully */
                bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
@@ -530,7 +527,7 @@ static int read_balance(conf_t *conf, r1bio_t *r1_bio)
                        /* cannot risk returning a device that failed
                         * before we inc'ed nr_pending
                         */
-                       atomic_dec(&rdev->nr_pending);
+                       rdev_dec_pending(rdev, conf->mddev);
                        goto retry;
                }
                conf->next_seq_sect = this_sector + sectors;
@@ -711,13 +708,11 @@ static struct page **alloc_behind_pages(struct bio *bio)
 {
        int i;
        struct bio_vec *bvec;
-       struct page **pages = kmalloc(bio->bi_vcnt * sizeof(struct page *),
+       struct page **pages = kzalloc(bio->bi_vcnt * sizeof(struct page *),
                                        GFP_NOIO);
        if (unlikely(!pages))
                goto do_sync_io;
 
-       memset(pages, 0, bio->bi_vcnt * sizeof(struct page *));
-
        bio_for_each_segment(bvec, bio, i) {
                pages[i] = alloc_page(GFP_NOIO);
                if (unlikely(!pages[i]))
@@ -835,7 +830,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
                    !test_bit(Faulty, &rdev->flags)) {
                        atomic_inc(&rdev->nr_pending);
                        if (test_bit(Faulty, &rdev->flags)) {
-                               atomic_dec(&rdev->nr_pending);
+                               rdev_dec_pending(rdev, mddev);
                                r1_bio->bios[i] = NULL;
                        } else
                                r1_bio->bios[i] = bio;
@@ -1181,6 +1176,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
                        if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&
                            test_bit(BIO_UPTODATE, &r1_bio->bios[primary]->bi_flags)) {
                                r1_bio->bios[primary]->bi_end_io = NULL;
+                               rdev_dec_pending(conf->mirrors[primary].rdev, mddev);
                                break;
                        }
                r1_bio->read_disk = primary;
@@ -1198,9 +1194,10 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
                                                break;
                                if (j >= 0)
                                        mddev->resync_mismatches += r1_bio->sectors;
-                               if (j < 0 || test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
+                               if (j < 0 || test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) {
                                        sbio->bi_end_io = NULL;
-                               else {
+                                       rdev_dec_pending(conf->mirrors[i].rdev, mddev);
+                               } else {
                                        /* fixup the bio for reuse */
                                        sbio->bi_vcnt = vcnt;
                                        sbio->bi_size = r1_bio->sectors << 9;
@@ -1258,6 +1255,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
                        } while (!success && d != r1_bio->read_disk);
 
                        if (success) {
+                               int start = d;
                                /* write it back and re-read */
                                set_bit(R1BIO_Uptodate, &r1_bio->state);
                                while (d != r1_bio->read_disk) {
@@ -1267,18 +1265,28 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
                                        if (r1_bio->bios[d]->bi_end_io != end_sync_read)
                                                continue;
                                        rdev = conf->mirrors[d].rdev;
+                                       atomic_add(s, &rdev->corrected_errors);
                                        if (sync_page_io(rdev->bdev,
                                                         sect + rdev->data_offset,
                                                         s<<9,
                                                         bio->bi_io_vec[idx].bv_page,
-                                                        WRITE) == 0 ||
-                                           sync_page_io(rdev->bdev,
+                                                        WRITE) == 0)
+                                               md_error(mddev, rdev);
+                               }
+                               d = start;
+                               while (d != r1_bio->read_disk) {
+                                       if (d == 0)
+                                               d = conf->raid_disks;
+                                       d--;
+                                       if (r1_bio->bios[d]->bi_end_io != end_sync_read)
+                                               continue;
+                                       rdev = conf->mirrors[d].rdev;
+                                       if (sync_page_io(rdev->bdev,
                                                         sect + rdev->data_offset,
                                                         s<<9,
                                                         bio->bi_io_vec[idx].bv_page,
-                                                        READ) == 0) {
+                                                        READ) == 0)
                                                md_error(mddev, rdev);
-                                       }
                                }
                        } else {
                                char b[BDEVNAME_SIZE];
@@ -1450,22 +1458,35 @@ static void raid1d(mddev_t *mddev)
 
                                if (success) {
                                        /* write it back and re-read */
+                                       int start = d;
                                        while (d != r1_bio->read_disk) {
                                                if (d==0)
                                                        d = conf->raid_disks;
                                                d--;
                                                rdev = conf->mirrors[d].rdev;
+                                               atomic_add(s, &rdev->corrected_errors);
                                                if (rdev &&
                                                    test_bit(In_sync, &rdev->flags)) {
                                                        if (sync_page_io(rdev->bdev,
                                                                         sect + rdev->data_offset,
-                                                                        s<<9, conf->tmppage, WRITE) == 0 ||
-                                                           sync_page_io(rdev->bdev,
+                                                                        s<<9, conf->tmppage, WRITE) == 0)
+                                                               /* Well, this device is dead */
+                                                               md_error(mddev, rdev);
+                                               }
+                                       }
+                                       d = start;
+                                       while (d != r1_bio->read_disk) {
+                                               if (d==0)
+                                                       d = conf->raid_disks;
+                                               d--;
+                                               rdev = conf->mirrors[d].rdev;
+                                               if (rdev &&
+                                                   test_bit(In_sync, &rdev->flags)) {
+                                                       if (sync_page_io(rdev->bdev,
                                                                         sect + rdev->data_offset,
-                                                                        s<<9, conf->tmppage, READ) == 0) {
+                                                                        s<<9, conf->tmppage, READ) == 0)
                                                                /* Well, this device is dead */
                                                                md_error(mddev, rdev);
-                                                       }
                                                }
                                        }
                                } else {
@@ -1770,19 +1791,16 @@ static int run(mddev_t *mddev)
         * bookkeeping area. [whatever we allocate in run(),
         * should be freed in stop()]
         */
-       conf = kmalloc(sizeof(conf_t), GFP_KERNEL);
+       conf = kzalloc(sizeof(conf_t), GFP_KERNEL);
        mddev->private = conf;
        if (!conf)
                goto out_no_mem;
 
-       memset(conf, 0, sizeof(*conf));
-       conf->mirrors = kmalloc(sizeof(struct mirror_info)*mddev->raid_disks, 
+       conf->mirrors = kzalloc(sizeof(struct mirror_info)*mddev->raid_disks,
                                 GFP_KERNEL);
        if (!conf->mirrors)
                goto out_no_mem;
 
-       memset(conf->mirrors, 0, sizeof(struct mirror_info)*mddev->raid_disks);
-
        conf->tmppage = alloc_page(GFP_KERNEL);
        if (!conf->tmppage)
                goto out_no_mem;
@@ -1893,7 +1911,7 @@ out_free_conf:
                if (conf->r1bio_pool)
                        mempool_destroy(conf->r1bio_pool);
                kfree(conf->mirrors);
-               put_page(conf->tmppage);
+               safe_put_page(conf->tmppage);
                kfree(conf->poolinfo);
                kfree(conf);
                mddev->private = NULL;
@@ -1992,13 +2010,12 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
                kfree(newpoolinfo);
                return -ENOMEM;
        }
-       newmirrors = kmalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL);
+       newmirrors = kzalloc(sizeof(struct mirror_info) * raid_disks, GFP_KERNEL);
        if (!newmirrors) {
                kfree(newpoolinfo);
                mempool_destroy(newpool);
                return -ENOMEM;
        }
-       memset(newmirrors, 0, sizeof(struct mirror_info)*raid_disks);
 
        raise_barrier(conf);
 
@@ -2044,9 +2061,10 @@ static void raid1_quiesce(mddev_t *mddev, int state)
 }
 
 
-static mdk_personality_t raid1_personality =
+static struct mdk_personality raid1_personality =
 {
        .name           = "raid1",
+       .level          = 1,
        .owner          = THIS_MODULE,
        .make_request   = make_request,
        .run            = run,
@@ -2064,15 +2082,17 @@ static mdk_personality_t raid1_personality =
 
 static int __init raid_init(void)
 {
-       return register_md_personality(RAID1, &raid1_personality);
+       return register_md_personality(&raid1_personality);
 }
 
 static void raid_exit(void)
 {
-       unregister_md_personality(RAID1);
+       unregister_md_personality(&raid1_personality);
 }
 
 module_init(raid_init);
 module_exit(raid_exit);
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("md-personality-3"); /* RAID1 */
+MODULE_ALIAS("md-raid1");
+MODULE_ALIAS("md-level-1");