md/raid4: permit raid0 takeover
[safe/jmp/linux-2.6] / drivers / md / raid1.c
index eebce16..cb2da87 100644 (file)
@@ -773,9 +773,8 @@ do_sync_io:
        return NULL;
 }
 
-static int make_request(struct request_queue *q, struct bio * bio)
+static int make_request(mddev_t *mddev, struct bio * bio)
 {
-       mddev_t *mddev = q->queuedata;
        conf_t *conf = mddev->private;
        mirror_info_t *mirror;
        r1bio_t *r1_bio;
@@ -858,6 +857,15 @@ static int make_request(struct request_queue *q, struct bio * bio)
                }
                mirror = conf->mirrors + rdisk;
 
+               if (test_bit(WriteMostly, &mirror->rdev->flags) &&
+                   bitmap) {
+                       /* Reading from a write-mostly device must
+                        * take care not to over-take any writes
+                        * that are 'behind'
+                        */
+                       wait_event(bitmap->behind_wait,
+                                  atomic_read(&bitmap->behind_writes) == 0);
+               }
                r1_bio->read_disk = rdisk;
 
                read_bio = bio_clone(bio, GFP_NOIO);
@@ -935,10 +943,14 @@ static int make_request(struct request_queue *q, struct bio * bio)
                set_bit(R1BIO_Degraded, &r1_bio->state);
        }
 
-       /* do behind I/O ? */
+       /* do behind I/O ?
+        * Not if there are too many, or cannot allocate memory,
+        * or a reader on WriteMostly is waiting for behind writes 
+        * to flush */
        if (bitmap &&
            (atomic_read(&bitmap->behind_writes)
             < mddev->bitmap_info.max_write_behind) &&
+           !waitqueue_active(&bitmap->behind_wait) &&
            (behind_pages = alloc_behind_pages(bio)) != NULL)
                set_bit(R1BIO_BehindIO, &r1_bio->state);
 
@@ -1690,10 +1702,10 @@ static void raid1d(mddev_t *mddev)
                                r1_bio->bios[r1_bio->read_disk] = bio;
                                rdev = conf->mirrors[disk].rdev;
                                if (printk_ratelimit())
-                                       printk(KERN_ERR "raid1: %s: redirecting sector %llu to"
-                                              " another mirror\n",
-                                              bdevname(rdev->bdev,b),
-                                              (unsigned long long)r1_bio->sector);
+                                       printk(KERN_ERR "raid1: redirecting sector %llu to"
+                                              " other mirror: %s\n",
+                                              (unsigned long long)r1_bio->sector,
+                                              bdevname(rdev->bdev,b));
                                bio->bi_sector = r1_bio->sector + rdev->data_offset;
                                bio->bi_bdev = rdev->bdev;
                                bio->bi_end_io = raid1_end_read_request;
@@ -2145,15 +2157,13 @@ static int stop(mddev_t *mddev)
 {
        conf_t *conf = mddev->private;
        struct bitmap *bitmap = mddev->bitmap;
-       int behind_wait = 0;
 
        /* wait for behind writes to complete */
-       while (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
-               behind_wait++;
-               printk(KERN_INFO "raid1: behind writes in progress on device %s, waiting to stop (%d)\n", mdname(mddev), behind_wait);
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(HZ); /* wait a second */
+       if (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
+               printk(KERN_INFO "raid1: behind writes in progress on device %s, 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);
        }
 
        raise_barrier(conf);