[PATCH] x86_64: Move ondemand timer into own work queue
[safe/jmp/linux-2.6] / drivers / md / raid1.c
index 181c961..4070eff 100644 (file)
@@ -176,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);
 
@@ -190,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;
@@ -306,6 +306,7 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
        r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
        int mirror, behind = test_bit(R1BIO_BehindIO, &r1_bio->state);
        conf_t *conf = mddev_to_conf(r1_bio->mddev);
+       struct bio *to_put = NULL;
 
        if (bio->bi_size)
                return 1;
@@ -314,15 +315,17 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
                if (r1_bio->bios[mirror] == bio)
                        break;
 
-       if (error == -ENOTSUPP && test_bit(R1BIO_Barrier, &r1_bio->state)) {
+       if (error == -EOPNOTSUPP && test_bit(R1BIO_Barrier, &r1_bio->state)) {
                set_bit(BarriersNotsupp, &conf->mirrors[mirror].rdev->flags);
                set_bit(R1BIO_BarrierRetry, &r1_bio->state);
                r1_bio->mddev->barriers_work = 0;
+               /* Don't rdev_dec_pending in this branch - keep it for the retry */
        } else {
                /*
                 * this branch is our 'one mirror IO has finished' event handler:
                 */
                r1_bio->bios[mirror] = NULL;
+               to_put = bio;
                if (!uptodate) {
                        md_error(r1_bio->mddev, conf->mirrors[mirror].rdev);
                        /* an I/O failed, we can't clear the bitmap */
@@ -363,6 +366,7 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
                                }
                        }
                }
+               rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
        }
        /*
         *
@@ -372,11 +376,9 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
        if (atomic_dec_and_test(&r1_bio->remaining)) {
                if (test_bit(R1BIO_BarrierRetry, &r1_bio->state)) {
                        reschedule_retry(r1_bio);
-                       /* Don't dec_pending yet, we want to hold
-                        * the reference over the retry
-                        */
-                       return 0;
+                       goto out;
                }
+               /* it really is the end of this request */
                if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
                        /* free extra copy of the data pages */
                        int i = bio->bi_vcnt;
@@ -391,11 +393,10 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
                md_write_end(r1_bio->mddev);
                raid_end_bio_io(r1_bio);
        }
+ out:
+       if (to_put)
+               bio_put(to_put);
 
-       if (r1_bio->bios[mirror]==NULL)
-               bio_put(bio);
-
-       rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
        return 0;
 }
 
@@ -750,18 +751,24 @@ static int make_request(request_queue_t *q, struct bio * bio)
        const int rw = bio_data_dir(bio);
        int do_barriers;
 
-       if (unlikely(!mddev->barriers_work && bio_barrier(bio))) {
-               bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
-               return 0;
-       }
-
        /*
         * Register the new request and wait if the reconstruction
         * thread has put up a bar for new requests.
         * Continue immediately if no resync is active currently.
+        * We test barriers_work *after* md_write_start as md_write_start
+        * may cause the first superblock write, and that will check out
+        * if barriers work.
         */
+
        md_write_start(mddev, bio); /* wait on superblock update early */
 
+       if (unlikely(!mddev->barriers_work && bio_barrier(bio))) {
+               if (rw == WRITE)
+                       md_write_end(mddev);
+               bio_endio(bio, bio->bi_size, -EOPNOTSUPP);
+               return 0;
+       }
+
        wait_barrier(conf);
 
        disk_stat_inc(mddev->gendisk, ios[rw]);
@@ -857,7 +864,7 @@ static int make_request(request_queue_t *q, struct bio * bio)
        atomic_set(&r1_bio->remaining, 0);
        atomic_set(&r1_bio->behind_remaining, 0);
 
-       do_barriers = bio->bi_rw & BIO_RW_BARRIER;
+       do_barriers = bio_barrier(bio);
        if (do_barriers)
                set_bit(R1BIO_Barrier, &r1_bio->state);
 
@@ -1132,8 +1139,19 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
                        mirror = i;
                        break;
                }
-       if (!uptodate)
+       if (!uptodate) {
+               int sync_blocks = 0;
+               sector_t s = r1_bio->sector;
+               long sectors_to_go = r1_bio->sectors;
+               /* make sure these bits doesn't get cleared. */
+               do {
+                       bitmap_end_sync(mddev->bitmap, r1_bio->sector,
+                                       &sync_blocks, 1);
+                       s += sync_blocks;
+                       sectors_to_go -= sync_blocks;
+               } while (sectors_to_go > 0);
                md_error(mddev, conf->mirrors[mirror].rdev);
+       }
 
        update_head_pos(mirror, r1_bio);
 
@@ -1265,6 +1283,7 @@ 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,
@@ -1389,15 +1408,19 @@ static void raid1d(mddev_t *mddev)
                        unplug = 1;
                } else if (test_bit(R1BIO_BarrierRetry, &r1_bio->state)) {
                        /* some requests in the r1bio were BIO_RW_BARRIER
-                        * requests which failed with -ENOTSUPP.  Hohumm..
+                        * requests which failed with -EOPNOTSUPP.  Hohumm..
                         * Better resubmit without the barrier.
                         * We know which devices to resubmit for, because
                         * all others have had their bios[] entry cleared.
+                        * We already have a nr_pending reference on these rdevs.
                         */
                        int i;
                        clear_bit(R1BIO_BarrierRetry, &r1_bio->state);
                        clear_bit(R1BIO_Barrier, &r1_bio->state);
                        for (i=0; i < conf->raid_disks; i++)
+                               if (r1_bio->bios[i])
+                                       atomic_inc(&r1_bio->remaining);
+                       for (i=0; i < conf->raid_disks; i++)
                                if (r1_bio->bios[i]) {
                                        struct bio_vec *bvec;
                                        int j;
@@ -1463,6 +1486,7 @@ static void raid1d(mddev_t *mddev)
                                                        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,
@@ -1539,8 +1563,7 @@ static int init_resync(conf_t *conf)
        int buffs;
 
        buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
-       if (conf->r1buf_pool)
-               BUG();
+       BUG_ON(conf->r1buf_pool);
        conf->r1buf_pool = mempool_create(buffs, r1buf_pool_alloc, r1buf_pool_free,
                                          conf->poolinfo);
        if (!conf->r1buf_pool)
@@ -1713,8 +1736,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
                            !conf->fullsync &&
                            !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
                                break;
-                       if (sync_blocks < (PAGE_SIZE>>9))
-                               BUG();
+                       BUG_ON(sync_blocks < (PAGE_SIZE>>9));
                        if (len > (sync_blocks<<9))
                                len = sync_blocks<<9;
                }
@@ -1784,6 +1806,11 @@ static int run(mddev_t *mddev)
                       mdname(mddev), mddev->level);
                goto out;
        }
+       if (mddev->reshape_position != MaxSector) {
+               printk("raid1: %s: reshape_position set but not supported\n",
+                      mdname(mddev));
+               goto out;
+       }
        /*
         * copy the already verified devices into our private RAID1
         * bookkeeping area. [whatever we allocate in run(),
@@ -1966,7 +1993,7 @@ static int raid1_resize(mddev_t *mddev, sector_t sectors)
        return 0;
 }
 
-static int raid1_reshape(mddev_t *mddev, int raid_disks)
+static int raid1_reshape(mddev_t *mddev)
 {
        /* We need to:
         * 1/ resize the r1bio_pool
@@ -1983,10 +2010,22 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
        struct pool_info *newpoolinfo;
        mirror_info_t *newmirrors;
        conf_t *conf = mddev_to_conf(mddev);
-       int cnt;
+       int cnt, raid_disks;
 
        int d, d2;
 
+       /* Cannot change chunk_size, layout, or level */
+       if (mddev->chunk_size != mddev->new_chunk ||
+           mddev->layout != mddev->new_layout ||
+           mddev->level != mddev->new_level) {
+               mddev->new_chunk = mddev->chunk_size;
+               mddev->new_layout = mddev->layout;
+               mddev->new_level = mddev->level;
+               return -EINVAL;
+       }
+
+       raid_disks = mddev->raid_disks + mddev->delta_disks;
+
        if (raid_disks < conf->raid_disks) {
                cnt=0;
                for (d= 0; d < conf->raid_disks; d++)
@@ -2033,6 +2072,7 @@ static int raid1_reshape(mddev_t *mddev, int raid_disks)
 
        mddev->degraded += (raid_disks - conf->raid_disks);
        conf->raid_disks = mddev->raid_disks = raid_disks;
+       mddev->delta_disks = 0;
 
        conf->last_used = 0; /* just make sure it is in-range */
        lower_barrier(conf);
@@ -2074,7 +2114,7 @@ static struct mdk_personality raid1_personality =
        .spare_active   = raid1_spare_active,
        .sync_request   = sync_request,
        .resize         = raid1_resize,
-       .reshape        = raid1_reshape,
+       .check_reshape  = raid1_reshape,
        .quiesce        = raid1_quiesce,
 };