linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / md / raid5.c
index 904d272..2dba305 100644 (file)
@@ -24,6 +24,8 @@
 #include <linux/bitops.h>
 #include <asm/atomic.h>
 
+#include <linux/raid/bitmap.h>
+
 /*
  * Stripe cache
  */
 #define STRIPE_SHIFT           (PAGE_SHIFT - 9)
 #define STRIPE_SECTORS         (STRIPE_SIZE>>9)
 #define        IO_THRESHOLD            1
-#define HASH_PAGES             1
-#define HASH_PAGES_ORDER       0
-#define NR_HASH                        (HASH_PAGES * PAGE_SIZE / sizeof(struct stripe_head *))
+#define NR_HASH                        (PAGE_SIZE / sizeof(struct hlist_head))
 #define HASH_MASK              (NR_HASH - 1)
 
-#define stripe_hash(conf, sect)        ((conf)->stripe_hashtbl[((sect) >> STRIPE_SHIFT) & HASH_MASK])
+#define stripe_hash(conf, sect)        (&((conf)->stripe_hashtbl[((sect) >> STRIPE_SHIFT) & HASH_MASK]))
 
 /* bio's attached to a stripe+device for I/O are linked together in bi_sector
  * order without overlap.  There may be several bio's per stripe+device, and
@@ -69,7 +69,7 @@
 
 static void print_raid5_conf (raid5_conf_t *conf);
 
-static inline void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
+static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
 {
        if (atomic_dec_and_test(&sh->count)) {
                if (!list_empty(&sh->lru))
@@ -79,8 +79,13 @@ static inline void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
                if (test_bit(STRIPE_HANDLE, &sh->state)) {
                        if (test_bit(STRIPE_DELAYED, &sh->state))
                                list_add_tail(&sh->lru, &conf->delayed_list);
-                       else
+                       else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
+                                conf->seq_write == sh->bm_seq)
+                               list_add_tail(&sh->lru, &conf->bitmap_list);
+                       else {
+                               clear_bit(STRIPE_BIT_DELAY, &sh->state);
                                list_add_tail(&sh->lru, &conf->handle_list);
+                       }
                        md_wakeup_thread(conf->mddev->thread);
                } else {
                        if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
@@ -91,7 +96,7 @@ static inline void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
                        list_add_tail(&sh->lru, &conf->inactive_list);
                        atomic_dec(&conf->active_stripes);
                        if (!conf->inactive_blocked ||
-                           atomic_read(&conf->active_stripes) < (NR_STRIPES*3/4))
+                           atomic_read(&conf->active_stripes) < (conf->max_nr_stripes*3/4))
                                wake_up(&conf->wait_for_stripe);
                }
        }
@@ -106,29 +111,21 @@ static void release_stripe(struct stripe_head *sh)
        spin_unlock_irqrestore(&conf->device_lock, flags);
 }
 
-static void remove_hash(struct stripe_head *sh)
+static inline void remove_hash(struct stripe_head *sh)
 {
        PRINTK("remove_hash(), stripe %llu\n", (unsigned long long)sh->sector);
 
-       if (sh->hash_pprev) {
-               if (sh->hash_next)
-                       sh->hash_next->hash_pprev = sh->hash_pprev;
-               *sh->hash_pprev = sh->hash_next;
-               sh->hash_pprev = NULL;
-       }
+       hlist_del_init(&sh->hash);
 }
 
-static __inline__ void insert_hash(raid5_conf_t *conf, struct stripe_head *sh)
+static void insert_hash(raid5_conf_t *conf, struct stripe_head *sh)
 {
-       struct stripe_head **shp = &stripe_hash(conf, sh->sector);
+       struct hlist_head *hp = stripe_hash(conf, sh->sector);
 
        PRINTK("insert_hash(), stripe %llu\n", (unsigned long long)sh->sector);
 
        CHECK_DEVLOCK();
-       if ((sh->hash_next = *shp) != NULL)
-               (*shp)->hash_pprev = &sh->hash_next;
-       *shp = sh;
-       sh->hash_pprev = shp;
+       hlist_add_head(&sh->hash, hp);
 }
 
 
@@ -160,7 +157,7 @@ static void shrink_buffers(struct stripe_head *sh, int num)
                if (!p)
                        continue;
                sh->dev[i].page = NULL;
-               page_cache_release(p);
+               put_page(p);
        }
 }
 
@@ -181,7 +178,7 @@ static int grow_buffers(struct stripe_head *sh, int num)
 
 static void raid5_build_block (struct stripe_head *sh, int i);
 
-static inline void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx)
+static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx)
 {
        raid5_conf_t *conf = sh->raid_conf;
        int disks = conf->raid_disks, i;
@@ -221,10 +218,11 @@ static inline void init_stripe(struct stripe_head *sh, sector_t sector, int pd_i
 static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector)
 {
        struct stripe_head *sh;
+       struct hlist_node *hn;
 
        CHECK_DEVLOCK();
        PRINTK("__find_stripe, sector %llu\n", (unsigned long long)sector);
-       for (sh = stripe_hash(conf, sector); sh; sh = sh->hash_next)
+       hlist_for_each_entry(sh, hn, stripe_hash(conf, sector), hash)
                if (sh->sector == sector)
                        return sh;
        PRINTK("__stripe %llu not in cache\n", (unsigned long long)sector);
@@ -244,6 +242,9 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
        spin_lock_irq(&conf->device_lock);
 
        do {
+               wait_event_lock_irq(conf->wait_for_stripe,
+                                   conf->quiesce == 0,
+                                   conf->device_lock, /* nothing */);
                sh = __find_stripe(conf, sector);
                if (!sh) {
                        if (!conf->inactive_blocked)
@@ -254,7 +255,8 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
                                conf->inactive_blocked = 1;
                                wait_event_lock_irq(conf->wait_for_stripe,
                                                    !list_empty(&conf->inactive_list) &&
-                                                   (atomic_read(&conf->active_stripes) < (NR_STRIPES *3/4)
+                                                   (atomic_read(&conf->active_stripes)
+                                                    < (conf->max_nr_stripes *3/4)
                                                     || !conf->inactive_blocked),
                                                    conf->device_lock,
                                                    unplug_slaves(conf->mddev);
@@ -283,9 +285,31 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
        return sh;
 }
 
-static int grow_stripes(raid5_conf_t *conf, int num)
+static int grow_one_stripe(raid5_conf_t *conf)
 {
        struct stripe_head *sh;
+       sh = kmem_cache_alloc(conf->slab_cache, GFP_KERNEL);
+       if (!sh)
+               return 0;
+       memset(sh, 0, sizeof(*sh) + (conf->raid_disks-1)*sizeof(struct r5dev));
+       sh->raid_conf = conf;
+       spin_lock_init(&sh->lock);
+
+       if (grow_buffers(sh, conf->raid_disks)) {
+               shrink_buffers(sh, conf->raid_disks);
+               kmem_cache_free(conf->slab_cache, sh);
+               return 0;
+       }
+       /* we just created an active stripe so... */
+       atomic_set(&sh->count, 1);
+       atomic_inc(&conf->active_stripes);
+       INIT_LIST_HEAD(&sh->lru);
+       release_stripe(sh);
+       return 1;
+}
+
+static int grow_stripes(raid5_conf_t *conf, int num)
+{
        kmem_cache_t *sc;
        int devs = conf->raid_disks;
 
@@ -298,48 +322,40 @@ static int grow_stripes(raid5_conf_t *conf, int num)
                return 1;
        conf->slab_cache = sc;
        while (num--) {
-               sh = kmem_cache_alloc(sc, GFP_KERNEL);
-               if (!sh)
-                       return 1;
-               memset(sh, 0, sizeof(*sh) + (devs-1)*sizeof(struct r5dev));
-               sh->raid_conf = conf;
-               spin_lock_init(&sh->lock);
-
-               if (grow_buffers(sh, conf->raid_disks)) {
-                       shrink_buffers(sh, conf->raid_disks);
-                       kmem_cache_free(sc, sh);
+               if (!grow_one_stripe(conf))
                        return 1;
-               }
-               /* we just created an active stripe so... */
-               atomic_set(&sh->count, 1);
-               atomic_inc(&conf->active_stripes);
-               INIT_LIST_HEAD(&sh->lru);
-               release_stripe(sh);
        }
        return 0;
 }
 
-static void shrink_stripes(raid5_conf_t *conf)
+static int drop_one_stripe(raid5_conf_t *conf)
 {
        struct stripe_head *sh;
 
-       while (1) {
-               spin_lock_irq(&conf->device_lock);
-               sh = get_free_stripe(conf);
-               spin_unlock_irq(&conf->device_lock);
-               if (!sh)
-                       break;
-               if (atomic_read(&sh->count))
-                       BUG();
-               shrink_buffers(sh, conf->raid_disks);
-               kmem_cache_free(conf->slab_cache, sh);
-               atomic_dec(&conf->active_stripes);
-       }
-       kmem_cache_destroy(conf->slab_cache);
+       spin_lock_irq(&conf->device_lock);
+       sh = get_free_stripe(conf);
+       spin_unlock_irq(&conf->device_lock);
+       if (!sh)
+               return 0;
+       if (atomic_read(&sh->count))
+               BUG();
+       shrink_buffers(sh, conf->raid_disks);
+       kmem_cache_free(conf->slab_cache, sh);
+       atomic_dec(&conf->active_stripes);
+       return 1;
+}
+
+static void shrink_stripes(raid5_conf_t *conf)
+{
+       while (drop_one_stripe(conf))
+               ;
+
+       if (conf->slab_cache)
+               kmem_cache_destroy(conf->slab_cache);
        conf->slab_cache = NULL;
 }
 
-static int raid5_end_read_request (struct bio * bi, unsigned int bytes_done,
+static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
                                   int error)
 {
        struct stripe_head *sh = bi->bi_private;
@@ -391,10 +407,36 @@ static int raid5_end_read_request (struct bio * bi, unsigned int bytes_done,
                }
 #else
                set_bit(R5_UPTODATE, &sh->dev[i].flags);
-#endif         
+#endif
+               if (test_bit(R5_ReadError, &sh->dev[i].flags)) {
+                       printk(KERN_INFO "raid5: read error corrected!!\n");
+                       clear_bit(R5_ReadError, &sh->dev[i].flags);
+                       clear_bit(R5_ReWrite, &sh->dev[i].flags);
+               }
+               if (atomic_read(&conf->disks[i].rdev->read_errors))
+                       atomic_set(&conf->disks[i].rdev->read_errors, 0);
        } else {
-               md_error(conf->mddev, conf->disks[i].rdev);
+               int retry = 0;
                clear_bit(R5_UPTODATE, &sh->dev[i].flags);
+               atomic_inc(&conf->disks[i].rdev->read_errors);
+               if (conf->mddev->degraded)
+                       printk(KERN_WARNING "raid5: read error not correctable.\n");
+               else if (test_bit(R5_ReWrite, &sh->dev[i].flags))
+                       /* Oh, no!!! */
+                       printk(KERN_WARNING "raid5: read error NOT corrected!!\n");
+               else if (atomic_read(&conf->disks[i].rdev->read_errors)
+                        > conf->max_nr_stripes)
+                       printk(KERN_WARNING
+                              "raid5: Too many read errors, failing device.\n");
+               else
+                       retry = 1;
+               if (retry)
+                       set_bit(R5_ReadError, &sh->dev[i].flags);
+               else {
+                       clear_bit(R5_ReadError, &sh->dev[i].flags);
+                       clear_bit(R5_ReWrite, &sh->dev[i].flags);
+                       md_error(conf->mddev, conf->disks[i].rdev);
+               }
        }
        rdev_dec_pending(conf->disks[i].rdev, conf->mddev);
 #if 0
@@ -477,19 +519,19 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
        raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
        PRINTK("raid5: error called\n");
 
-       if (!rdev->faulty) {
+       if (!test_bit(Faulty, &rdev->flags)) {
                mddev->sb_dirty = 1;
-               if (rdev->in_sync) {
+               if (test_bit(In_sync, &rdev->flags)) {
                        conf->working_disks--;
                        mddev->degraded++;
                        conf->failed_disks++;
-                       rdev->in_sync = 0;
+                       clear_bit(In_sync, &rdev->flags);
                        /*
                         * if recovery was running, make sure it aborts.
                         */
                        set_bit(MD_RECOVERY_ERR, &mddev->recovery);
                }
-               rdev->faulty = 1;
+               set_bit(Faulty, &rdev->flags);
                printk (KERN_ALERT
                        "raid5: Disk failure on %s, disabling device."
                        " Operation continuing on %d devices\n",
@@ -555,7 +597,7 @@ static sector_t raid5_compute_sector(sector_t r_sector, unsigned int raid_disks,
                        *dd_idx = (*pd_idx + 1 + *dd_idx) % raid_disks;
                        break;
                default:
-                       printk("raid5: unsupported algorithm %d\n",
+                       printk(KERN_ERR "raid5: unsupported algorithm %d\n",
                                conf->algorithm);
        }
 
@@ -596,7 +638,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
                        i -= (sh->pd_idx + 1);
                        break;
                default:
-                       printk("raid5: unsupported algorithm %d\n",
+                       printk(KERN_ERR "raid5: unsupported algorithm %d\n",
                                conf->algorithm);
        }
 
@@ -605,7 +647,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
 
        check = raid5_compute_sector (r_sector, raid_disks, data_disks, &dummy1, &dummy2, conf);
        if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) {
-               printk("compute_blocknr: map not correct\n");
+               printk(KERN_ERR "compute_blocknr: map not correct\n");
                return 0;
        }
        return r_sector;
@@ -688,7 +730,7 @@ static void compute_block(struct stripe_head *sh, int dd_idx)
                if (test_bit(R5_UPTODATE, &sh->dev[i].flags))
                        ptr[count++] = p;
                else
-                       printk("compute_block() %d, stripe %llu, %d"
+                       printk(KERN_ERR "compute_block() %d, stripe %llu, %d"
                                " not present\n", dd_idx,
                                (unsigned long long)sh->sector, i);
 
@@ -803,6 +845,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 {
        struct bio **bip;
        raid5_conf_t *conf = sh->raid_conf;
+       int firstwrite=0;
 
        PRINTK("adding bh b#%llu to stripe s#%llu\n",
                (unsigned long long)bi->bi_sector,
@@ -811,9 +854,11 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
 
        spin_lock(&sh->lock);
        spin_lock_irq(&conf->device_lock);
-       if (forwrite)
+       if (forwrite) {
                bip = &sh->dev[dd_idx].towrite;
-       else
+               if (*bip == NULL && sh->dev[dd_idx].written == NULL)
+                       firstwrite = 1;
+       } else
                bip = &sh->dev[dd_idx].toread;
        while (*bip && (*bip)->bi_sector < bi->bi_sector) {
                if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector)
@@ -836,6 +881,13 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
                (unsigned long long)bi->bi_sector,
                (unsigned long long)sh->sector, dd_idx);
 
+       if (conf->mddev->bitmap && firstwrite) {
+               sh->bm_seq = conf->seq_write;
+               bitmap_startwrite(conf->mddev->bitmap, sh->sector,
+                                 STRIPE_SECTORS, 0);
+               set_bit(STRIPE_BIT_DELAY, &sh->state);
+       }
+
        if (forwrite) {
                /* check if page is covered */
                sector_t sector = sh->dev[dd_idx].sector;
@@ -901,11 +953,11 @@ static void handle_stripe(struct stripe_head *sh)
        syncing = test_bit(STRIPE_SYNCING, &sh->state);
        /* Now to look around and see what can be done */
 
+       rcu_read_lock();
        for (i=disks; i--; ) {
                mdk_rdev_t *rdev;
                dev = &sh->dev[i];
                clear_bit(R5_Insync, &dev->flags);
-               clear_bit(R5_Syncio, &dev->flags);
 
                PRINTK("check %d: state 0x%lx read %p write %p written %p\n",
                        i, dev->flags, dev->toread, dev->towrite, dev->written);
@@ -944,13 +996,20 @@ static void handle_stripe(struct stripe_head *sh)
                                non_overwrite++;
                }
                if (dev->written) written++;
-               rdev = conf->disks[i].rdev; /* FIXME, should I be looking rdev */
-               if (!rdev || !rdev->in_sync) {
+               rdev = rcu_dereference(conf->disks[i].rdev);
+               if (!rdev || !test_bit(In_sync, &rdev->flags)) {
+                       /* The ReadError flag will just be confusing now */
+                       clear_bit(R5_ReadError, &dev->flags);
+                       clear_bit(R5_ReWrite, &dev->flags);
+               }
+               if (!rdev || !test_bit(In_sync, &rdev->flags)
+                   || test_bit(R5_ReadError, &dev->flags)) {
                        failed++;
                        failed_num = i;
                } else
                        set_bit(R5_Insync, &dev->flags);
        }
+       rcu_read_unlock();
        PRINTK("locked=%d uptodate=%d to_read=%d"
                " to_write=%d failed=%d failed_num=%d\n",
                locked, uptodate, to_read, to_write, failed, failed_num);
@@ -958,12 +1017,24 @@ static void handle_stripe(struct stripe_head *sh)
         * need to be failed
         */
        if (failed > 1 && to_read+to_write+written) {
-               spin_lock_irq(&conf->device_lock);
                for (i=disks; i--; ) {
+                       int bitmap_end = 0;
+
+                       if (test_bit(R5_ReadError, &sh->dev[i].flags)) {
+                               mdk_rdev_t *rdev;
+                               rcu_read_lock();
+                               rdev = rcu_dereference(conf->disks[i].rdev);
+                               if (rdev && test_bit(In_sync, &rdev->flags))
+                                       /* multiple read failures in one stripe */
+                                       md_error(conf->mddev, rdev);
+                               rcu_read_unlock();
+                       }
+
+                       spin_lock_irq(&conf->device_lock);
                        /* fail all writes first */
                        bi = sh->dev[i].towrite;
                        sh->dev[i].towrite = NULL;
-                       if (bi) to_write--;
+                       if (bi) { to_write--; bitmap_end = 1; }
 
                        if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
                                wake_up(&conf->wait_for_overlap);
@@ -981,6 +1052,7 @@ static void handle_stripe(struct stripe_head *sh)
                        /* and fail all 'written' */
                        bi = sh->dev[i].written;
                        sh->dev[i].written = NULL;
+                       if (bi) bitmap_end = 1;
                        while (bi && bi->bi_sector < sh->dev[i].sector + STRIPE_SECTORS) {
                                struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector);
                                clear_bit(BIO_UPTODATE, &bi->bi_flags);
@@ -993,7 +1065,8 @@ static void handle_stripe(struct stripe_head *sh)
                        }
 
                        /* fail any reads if this device is non-operational */
-                       if (!test_bit(R5_Insync, &sh->dev[i].flags)) {
+                       if (!test_bit(R5_Insync, &sh->dev[i].flags) ||
+                           test_bit(R5_ReadError, &sh->dev[i].flags)) {
                                bi = sh->dev[i].toread;
                                sh->dev[i].toread = NULL;
                                if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
@@ -1009,8 +1082,11 @@ static void handle_stripe(struct stripe_head *sh)
                                        bi = nextbi;
                                }
                        }
+                       spin_unlock_irq(&conf->device_lock);
+                       if (bitmap_end)
+                               bitmap_endwrite(conf->mddev->bitmap, sh->sector,
+                                               STRIPE_SECTORS, 0, 0);
                }
-               spin_unlock_irq(&conf->device_lock);
        }
        if (failed > 1 && syncing) {
                md_done_sync(conf->mddev, STRIPE_SECTORS,0);
@@ -1038,6 +1114,7 @@ static void handle_stripe(struct stripe_head *sh)
                         test_bit(R5_UPTODATE, &dev->flags) ) {
                        /* We can return any write requests */
                            struct bio *wbi, *wbi2;
+                           int bitmap_end = 0;
                            PRINTK("Return write for disc %d\n", i);
                            spin_lock_irq(&conf->device_lock);
                            wbi = dev->written;
@@ -1051,7 +1128,13 @@ static void handle_stripe(struct stripe_head *sh)
                                    }
                                    wbi = wbi2;
                            }
+                           if (dev->towrite == NULL)
+                                   bitmap_end = 1;
                            spin_unlock_irq(&conf->device_lock);
+                           if (bitmap_end)
+                                   bitmap_endwrite(conf->mddev->bitmap, sh->sector,
+                                                   STRIPE_SECTORS,
+                                                   !test_bit(STRIPE_DEGRADED, &sh->state), 0);
                    }
                }
        }
@@ -1093,9 +1176,6 @@ static void handle_stripe(struct stripe_head *sh)
                                        locked++;
                                        PRINTK("Reading block %d (sync=%d)\n", 
                                                i, syncing);
-                                       if (syncing)
-                                               md_sync_acct(conf->disks[i].rdev->bdev,
-                                                            STRIPE_SECTORS);
                                }
                        }
                }
@@ -1175,7 +1255,8 @@ static void handle_stripe(struct stripe_head *sh)
                                }
                        }
                /* now if nothing is locked, and if we have enough data, we can start a write request */
-               if (locked == 0 && (rcw == 0 ||rmw == 0)) {
+               if (locked == 0 && (rcw == 0 ||rmw == 0) &&
+                   !test_bit(STRIPE_BIT_DELAY, &sh->state)) {
                        PRINTK("Computing parity...\n");
                        compute_parity(sh, rcw==0 ? RECONSTRUCT_WRITE : READ_MODIFY_WRITE);
                        /* now every locked buffer is ready to be written */
@@ -1201,7 +1282,7 @@ static void handle_stripe(struct stripe_head *sh)
         * is available
         */
        if (syncing && locked == 0 &&
-           !test_bit(STRIPE_INSYNC, &sh->state) && failed <= 1) {
+           !test_bit(STRIPE_INSYNC, &sh->state)) {
                set_bit(STRIPE_HANDLE, &sh->state);
                if (failed == 0) {
                        char *pagea;
@@ -1214,33 +1295,57 @@ static void handle_stripe(struct stripe_head *sh)
                            !memcmp(pagea, pagea+4, STRIPE_SIZE-4)) {
                                /* parity is correct (on disc, not in buffer any more) */
                                set_bit(STRIPE_INSYNC, &sh->state);
+                       } else {
+                               conf->mddev->resync_mismatches += STRIPE_SECTORS;
+                               if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
+                                       /* don't try to repair!! */
+                                       set_bit(STRIPE_INSYNC, &sh->state);
+                               else {
+                                       compute_block(sh, sh->pd_idx);
+                                       uptodate++;
+                               }
                        }
                }
                if (!test_bit(STRIPE_INSYNC, &sh->state)) {
+                       /* either failed parity check, or recovery is happening */
                        if (failed==0)
                                failed_num = sh->pd_idx;
-                       /* should be able to compute the missing block and write it to spare */
-                       if (!test_bit(R5_UPTODATE, &sh->dev[failed_num].flags)) {
-                               if (uptodate+1 != disks)
-                                       BUG();
-                               compute_block(sh, failed_num);
-                               uptodate++;
-                       }
-                       if (uptodate != disks)
-                               BUG();
                        dev = &sh->dev[failed_num];
+                       BUG_ON(!test_bit(R5_UPTODATE, &dev->flags));
+                       BUG_ON(uptodate != disks);
+
                        set_bit(R5_LOCKED, &dev->flags);
                        set_bit(R5_Wantwrite, &dev->flags);
+                       clear_bit(STRIPE_DEGRADED, &sh->state);
                        locked++;
                        set_bit(STRIPE_INSYNC, &sh->state);
-                       set_bit(R5_Syncio, &dev->flags);
                }
        }
        if (syncing && locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) {
                md_done_sync(conf->mddev, STRIPE_SECTORS,1);
                clear_bit(STRIPE_SYNCING, &sh->state);
        }
-       
+
+       /* If the failed drive is just a ReadError, then we might need to progress
+        * the repair/check process
+        */
+       if (failed == 1 && ! conf->mddev->ro &&
+           test_bit(R5_ReadError, &sh->dev[failed_num].flags)
+           && !test_bit(R5_LOCKED, &sh->dev[failed_num].flags)
+           && test_bit(R5_UPTODATE, &sh->dev[failed_num].flags)
+               ) {
+               dev = &sh->dev[failed_num];
+               if (!test_bit(R5_ReWrite, &dev->flags)) {
+                       set_bit(R5_Wantwrite, &dev->flags);
+                       set_bit(R5_ReWrite, &dev->flags);
+                       set_bit(R5_LOCKED, &dev->flags);
+               } else {
+                       /* let's read it back */
+                       set_bit(R5_Wantread, &dev->flags);
+                       set_bit(R5_LOCKED, &dev->flags);
+               }
+       }
+
        spin_unlock(&sh->lock);
 
        while ((bi=return_bi)) {
@@ -1271,15 +1376,15 @@ static void handle_stripe(struct stripe_head *sh)
                        bi->bi_end_io = raid5_end_read_request;
  
                rcu_read_lock();
-               rdev = conf->disks[i].rdev;
-               if (rdev && rdev->faulty)
+               rdev = rcu_dereference(conf->disks[i].rdev);
+               if (rdev && test_bit(Faulty, &rdev->flags))
                        rdev = NULL;
                if (rdev)
                        atomic_inc(&rdev->nr_pending);
                rcu_read_unlock();
  
                if (rdev) {
-                       if (test_bit(R5_Syncio, &sh->dev[i].flags))
+                       if (syncing)
                                md_sync_acct(rdev->bdev, STRIPE_SECTORS);
 
                        bi->bi_bdev = rdev->bdev;
@@ -1296,8 +1401,13 @@ static void handle_stripe(struct stripe_head *sh)
                        bi->bi_io_vec[0].bv_offset = 0;
                        bi->bi_size = STRIPE_SIZE;
                        bi->bi_next = NULL;
+                       if (rw == WRITE &&
+                           test_bit(R5_ReWrite, &sh->dev[i].flags))
+                               atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
                        generic_make_request(bi);
                } else {
+                       if (rw == 1)
+                               set_bit(STRIPE_DEGRADED, &sh->state);
                        PRINTK("skip op %ld on disc %d for sector %llu\n",
                                bi->bi_rw, i, (unsigned long long)sh->sector);
                        clear_bit(R5_LOCKED, &sh->dev[i].flags);
@@ -1306,7 +1416,7 @@ static void handle_stripe(struct stripe_head *sh)
        }
 }
 
-static inline void raid5_activate_delayed(raid5_conf_t *conf)
+static void raid5_activate_delayed(raid5_conf_t *conf)
 {
        if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) {
                while (!list_empty(&conf->delayed_list)) {
@@ -1322,6 +1432,20 @@ static inline void raid5_activate_delayed(raid5_conf_t *conf)
        }
 }
 
+static void activate_bit_delay(raid5_conf_t *conf)
+{
+       /* device_lock is held */
+       struct list_head head;
+       list_add(&head, &conf->bitmap_list);
+       list_del_init(&conf->bitmap_list);
+       while (!list_empty(&head)) {
+               struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru);
+               list_del_init(&sh->lru);
+               atomic_inc(&sh->count);
+               __release_stripe(conf, sh);
+       }
+}
+
 static void unplug_slaves(mddev_t *mddev)
 {
        raid5_conf_t *conf = mddev_to_conf(mddev);
@@ -1329,8 +1453,8 @@ static void unplug_slaves(mddev_t *mddev)
 
        rcu_read_lock();
        for (i=0; i<mddev->raid_disks; i++) {
-               mdk_rdev_t *rdev = conf->disks[i].rdev;
-               if (rdev && !rdev->faulty && atomic_read(&rdev->nr_pending)) {
+               mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev);
+               if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
                        request_queue_t *r_queue = bdev_get_queue(rdev->bdev);
 
                        atomic_inc(&rdev->nr_pending);
@@ -1352,12 +1476,12 @@ static void raid5_unplug_device(request_queue_t *q)
        raid5_conf_t *conf = mddev_to_conf(mddev);
        unsigned long flags;
 
-       if (!conf) return;
-
        spin_lock_irqsave(&conf->device_lock, flags);
 
-       if (blk_remove_plug(q))
+       if (blk_remove_plug(q)) {
+               conf->seq_flush++;
                raid5_activate_delayed(conf);
+       }
        md_wakeup_thread(mddev->thread);
 
        spin_unlock_irqrestore(&conf->device_lock, flags);
@@ -1374,8 +1498,8 @@ static int raid5_issue_flush(request_queue_t *q, struct gendisk *disk,
 
        rcu_read_lock();
        for (i=0; i<mddev->raid_disks && ret == 0; i++) {
-               mdk_rdev_t *rdev = conf->disks[i].rdev;
-               if (rdev && !rdev->faulty) {
+               mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev);
+               if (rdev && !test_bit(Faulty, &rdev->flags)) {
                        struct block_device *bdev = rdev->bdev;
                        request_queue_t *r_queue = bdev_get_queue(bdev);
 
@@ -1412,21 +1536,23 @@ static int make_request (request_queue_t *q, struct bio * bi)
        sector_t new_sector;
        sector_t logical_sector, last_sector;
        struct stripe_head *sh;
+       const int rw = bio_data_dir(bi);
 
-       if (bio_data_dir(bi)==WRITE) {
-               disk_stat_inc(mddev->gendisk, writes);
-               disk_stat_add(mddev->gendisk, write_sectors, bio_sectors(bi));
-       } else {
-               disk_stat_inc(mddev->gendisk, reads);
-               disk_stat_add(mddev->gendisk, read_sectors, bio_sectors(bi));
+       if (unlikely(bio_barrier(bi))) {
+               bio_endio(bi, bi->bi_size, -EOPNOTSUPP);
+               return 0;
        }
 
+       md_write_start(mddev, bi);
+
+       disk_stat_inc(mddev->gendisk, ios[rw]);
+       disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bi));
+
        logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
        last_sector = bi->bi_sector + (bi->bi_size>>9);
        bi->bi_next = NULL;
        bi->bi_phys_segments = 1;       /* over-loaded to count active stripes */
-       if ( bio_data_dir(bi) == WRITE )
-               md_write_start(mddev);
+
        for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
                DEFINE_WAIT(w);
                
@@ -1477,7 +1603,7 @@ static int make_request (request_queue_t *q, struct bio * bi)
 }
 
 /* FIXME go_faster isn't used */
-static int sync_request (mddev_t *mddev, sector_t sector_nr, int go_faster)
+static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster)
 {
        raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
        struct stripe_head *sh;
@@ -1489,10 +1615,20 @@ static int sync_request (mddev_t *mddev, sector_t sector_nr, int go_faster)
        sector_t first_sector;
        int raid_disks = conf->raid_disks;
        int data_disks = raid_disks-1;
+       sector_t max_sector = mddev->size << 1;
+       int sync_blocks;
 
-       if (sector_nr >= mddev->size <<1) {
+       if (sector_nr >= max_sector) {
                /* just being told to finish up .. nothing much to do */
                unplug_slaves(mddev);
+
+               if (mddev->curr_resync < max_sector) /* aborted */
+                       bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
+                                       &sync_blocks, 1);
+               else /* compelted sync */
+                       conf->fullsync = 0;
+               bitmap_close_sync(mddev->bitmap);
+
                return 0;
        }
        /* if there is 1 or more failed drives and we are trying
@@ -1500,10 +1636,18 @@ static int sync_request (mddev_t *mddev, sector_t sector_nr, int go_faster)
         * nothing we can do.
         */
        if (mddev->degraded >= 1 && test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
-               int rv = (mddev->size << 1) - sector_nr;
-               md_done_sync(mddev, rv, 1);
+               sector_t rv = (mddev->size << 1) - sector_nr;
+               *skipped = 1;
                return rv;
        }
+       if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
+           !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) &&
+           !conf->fullsync && sync_blocks >= STRIPE_SECTORS) {
+               /* we can skip this block, and probably more */
+               sync_blocks /= STRIPE_SECTORS;
+               *skipped = 1;
+               return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
+       }
 
        x = sector_nr;
        chunk_offset = sector_div(x, sectors_per_chunk);
@@ -1518,9 +1662,9 @@ static int sync_request (mddev_t *mddev, sector_t sector_nr, int go_faster)
                /* make sure we don't swamp the stripe cache if someone else
                 * is trying to get access 
                 */
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(1);
+               schedule_timeout_uninterruptible(1);
        }
+       bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0);
        spin_lock(&sh->lock);   
        set_bit(STRIPE_SYNCING, &sh->state);
        clear_bit(STRIPE_INSYNC, &sh->state);
@@ -1548,13 +1692,21 @@ static void raid5d (mddev_t *mddev)
        PRINTK("+++ raid5d active\n");
 
        md_check_recovery(mddev);
-       md_handle_safemode(mddev);
 
        handled = 0;
        spin_lock_irq(&conf->device_lock);
        while (1) {
                struct list_head *first;
 
+               if (conf->seq_flush - conf->seq_write > 0) {
+                       int seq = conf->seq_flush;
+                       spin_unlock_irq(&conf->device_lock);
+                       bitmap_unplug(mddev->bitmap);
+                       spin_lock_irq(&conf->device_lock);
+                       conf->seq_write = seq;
+                       activate_bit_delay(conf);
+               }
+
                if (list_empty(&conf->handle_list) &&
                    atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD &&
                    !blk_queue_plugged(mddev->queue) &&
@@ -1588,7 +1740,75 @@ static void raid5d (mddev_t *mddev)
        PRINTK("--- raid5d inactive\n");
 }
 
-static int run (mddev_t *mddev)
+static ssize_t
+raid5_show_stripe_cache_size(mddev_t *mddev, char *page)
+{
+       raid5_conf_t *conf = mddev_to_conf(mddev);
+       if (conf)
+               return sprintf(page, "%d\n", conf->max_nr_stripes);
+       else
+               return 0;
+}
+
+static ssize_t
+raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
+{
+       raid5_conf_t *conf = mddev_to_conf(mddev);
+       char *end;
+       int new;
+       if (len >= PAGE_SIZE)
+               return -EINVAL;
+       if (!conf)
+               return -ENODEV;
+
+       new = simple_strtoul(page, &end, 10);
+       if (!*page || (*end && *end != '\n') )
+               return -EINVAL;
+       if (new <= 16 || new > 32768)
+               return -EINVAL;
+       while (new < conf->max_nr_stripes) {
+               if (drop_one_stripe(conf))
+                       conf->max_nr_stripes--;
+               else
+                       break;
+       }
+       while (new > conf->max_nr_stripes) {
+               if (grow_one_stripe(conf))
+                       conf->max_nr_stripes++;
+               else break;
+       }
+       return len;
+}
+
+static struct md_sysfs_entry
+raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR,
+                               raid5_show_stripe_cache_size,
+                               raid5_store_stripe_cache_size);
+
+static ssize_t
+stripe_cache_active_show(mddev_t *mddev, char *page)
+{
+       raid5_conf_t *conf = mddev_to_conf(mddev);
+       if (conf)
+               return sprintf(page, "%d\n", atomic_read(&conf->active_stripes));
+       else
+               return 0;
+}
+
+static struct md_sysfs_entry
+raid5_stripecache_active = __ATTR_RO(stripe_cache_active);
+
+static struct attribute *raid5_attrs[] =  {
+       &raid5_stripecache_size.attr,
+       &raid5_stripecache_active.attr,
+       NULL,
+};
+static struct attribute_group raid5_attrs_group = {
+       .name = NULL,
+       .attrs = raid5_attrs,
+};
+
+static int run(mddev_t *mddev)
 {
        raid5_conf_t *conf;
        int raid_disk, memory;
@@ -1597,27 +1817,28 @@ static int run (mddev_t *mddev)
        struct list_head *tmp;
 
        if (mddev->level != 5 && mddev->level != 4) {
-               printk("raid5: %s: raid level not set to 4/5 (%d)\n", mdname(mddev), mddev->level);
+               printk(KERN_ERR "raid5: %s: raid level not set to 4/5 (%d)\n",
+                      mdname(mddev), mddev->level);
                return -EIO;
        }
 
-       mddev->private = kmalloc (sizeof (raid5_conf_t)
-                                 + mddev->raid_disks * sizeof(struct disk_info),
-                                 GFP_KERNEL);
+       mddev->private = kzalloc(sizeof (raid5_conf_t)
+                                + mddev->raid_disks * sizeof(struct disk_info),
+                                GFP_KERNEL);
        if ((conf = mddev->private) == NULL)
                goto abort;
-       memset (conf, 0, sizeof (*conf) + mddev->raid_disks * sizeof(struct disk_info) );
+
        conf->mddev = mddev;
 
-       if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL)
+       if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL)
                goto abort;
-       memset(conf->stripe_hashtbl, 0, HASH_PAGES * PAGE_SIZE);
 
        spin_lock_init(&conf->device_lock);
        init_waitqueue_head(&conf->wait_for_stripe);
        init_waitqueue_head(&conf->wait_for_overlap);
        INIT_LIST_HEAD(&conf->handle_list);
        INIT_LIST_HEAD(&conf->delayed_list);
+       INIT_LIST_HEAD(&conf->bitmap_list);
        INIT_LIST_HEAD(&conf->inactive_list);
        atomic_set(&conf->active_stripes, 0);
        atomic_set(&conf->preread_active_stripes, 0);
@@ -1633,7 +1854,7 @@ static int run (mddev_t *mddev)
 
                disk->rdev = rdev;
 
-               if (rdev->in_sync) {
+               if (test_bit(In_sync, &rdev->flags)) {
                        char b[BDEVNAME_SIZE];
                        printk(KERN_INFO "raid5: device %s operational as raid"
                                " disk %d\n", bdevname(rdev->bdev,b),
@@ -1655,6 +1876,7 @@ static int run (mddev_t *mddev)
 
        /* device size must be a multiple of chunk size */
        mddev->size &= ~(mddev->chunk_size/1024 -1);
+       mddev->resync_max_sectors = mddev->size << 1;
 
        if (!conf->chunk_size || conf->chunk_size % 4) {
                printk(KERN_ERR "raid5: invalid chunk size %d for %s\n",
@@ -1676,10 +1898,17 @@ static int run (mddev_t *mddev)
 
        if (mddev->degraded == 1 &&
            mddev->recovery_cp != MaxSector) {
-               printk(KERN_ERR 
-                       "raid5: cannot start dirty degraded array for %s\n",
-                       mdname(mddev));
-               goto abort;
+               if (mddev->ok_start_degraded)
+                       printk(KERN_WARNING
+                              "raid5: starting dirty degraded array: %s"
+                              "- data corruption possible.\n",
+                              mdname(mddev));
+               else {
+                       printk(KERN_ERR
+                              "raid5: cannot start dirty degraded array for %s\n",
+                              mdname(mddev));
+                       goto abort;
+               }
        }
 
        {
@@ -1691,7 +1920,7 @@ static int run (mddev_t *mddev)
                        goto abort;
                }
        }
-memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
+       memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
                 conf->raid_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
        if (grow_stripes(conf, conf->max_nr_stripes)) {
                printk(KERN_ERR 
@@ -1721,12 +1950,13 @@ memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
         */
        {
                int stripe = (mddev->raid_disks-1) * mddev->chunk_size
-                       / PAGE_CACHE_SIZE;
+                       / PAGE_SIZE;
                if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
                        mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
        }
 
        /* Ok, everything is just fine now */
+       sysfs_create_group(&mddev->kobj, &raid5_attrs_group);
 
        mddev->queue->unplug_fn = raid5_unplug_device;
        mddev->queue->issue_flush_fn = raid5_issue_flush;
@@ -1736,9 +1966,7 @@ memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
 abort:
        if (conf) {
                print_raid5_conf(conf);
-               if (conf->stripe_hashtbl)
-                       free_pages((unsigned long) conf->stripe_hashtbl,
-                                                       HASH_PAGES_ORDER);
+               kfree(conf->stripe_hashtbl);
                kfree(conf);
        }
        mddev->private = NULL;
@@ -1748,15 +1976,16 @@ abort:
 
 
 
-static int stop (mddev_t *mddev)
+static int stop(mddev_t *mddev)
 {
        raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
 
        md_unregister_thread(mddev->thread);
        mddev->thread = NULL;
        shrink_stripes(conf);
-       free_pages((unsigned long) conf->stripe_hashtbl, HASH_PAGES_ORDER);
+       kfree(conf->stripe_hashtbl);
        blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
+       sysfs_remove_group(&mddev->kobj, &raid5_attrs_group);
        kfree(conf);
        mddev->private = NULL;
        return 0;
@@ -1782,12 +2011,12 @@ static void print_sh (struct stripe_head *sh)
 static void printall (raid5_conf_t *conf)
 {
        struct stripe_head *sh;
+       struct hlist_node *hn;
        int i;
 
        spin_lock_irq(&conf->device_lock);
        for (i = 0; i < NR_HASH; i++) {
-               sh = conf->stripe_hashtbl[i];
-               for (; sh; sh = sh->hash_next) {
+               hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) {
                        if (sh->raid_conf != conf)
                                continue;
                        print_sh(sh);
@@ -1807,7 +2036,7 @@ static void status (struct seq_file *seq, mddev_t *mddev)
        for (i = 0; i < conf->raid_disks; i++)
                seq_printf (seq, "%s",
                               conf->disks[i].rdev &&
-                              conf->disks[i].rdev->in_sync ? "U" : "_");
+                              test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_");
        seq_printf (seq, "]");
 #if RAID5_DEBUG
 #define D(x) \
@@ -1834,7 +2063,7 @@ static void print_raid5_conf (raid5_conf_t *conf)
                tmp = conf->disks + i;
                if (tmp->rdev)
                printk(" disk %d, o:%d, dev:%s\n",
-                       i, !tmp->rdev->faulty,
+                       i, !test_bit(Faulty, &tmp->rdev->flags),
                        bdevname(tmp->rdev->bdev,b));
        }
 }
@@ -1848,12 +2077,12 @@ static int raid5_spare_active(mddev_t *mddev)
        for (i = 0; i < conf->raid_disks; i++) {
                tmp = conf->disks + i;
                if (tmp->rdev
-                   && !tmp->rdev->faulty
-                   && !tmp->rdev->in_sync) {
+                   && !test_bit(Faulty, &tmp->rdev->flags)
+                   && !test_bit(In_sync, &tmp->rdev->flags)) {
                        mddev->degraded--;
                        conf->failed_disks--;
                        conf->working_disks++;
-                       tmp->rdev->in_sync = 1;
+                       set_bit(In_sync, &tmp->rdev->flags);
                }
        }
        print_raid5_conf(conf);
@@ -1870,7 +2099,7 @@ static int raid5_remove_disk(mddev_t *mddev, int number)
        print_raid5_conf(conf);
        rdev = p->rdev;
        if (rdev) {
-               if (rdev->in_sync ||
+               if (test_bit(In_sync, &rdev->flags) ||
                    atomic_read(&rdev->nr_pending)) {
                        err = -EBUSY;
                        goto abort;
@@ -1905,10 +2134,12 @@ static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
         */
        for (disk=0; disk < mddev->raid_disks; disk++)
                if ((p=conf->disks + disk)->rdev == NULL) {
-                       rdev->in_sync = 0;
+                       clear_bit(In_sync, &rdev->flags);
                        rdev->raid_disk = disk;
                        found = 1;
-                       p->rdev = rdev;
+                       if (rdev->saved_raid_disk != disk)
+                               conf->fullsync = 1;
+                       rcu_assign_pointer(p->rdev, rdev);
                        break;
                }
        print_raid5_conf(conf);
@@ -1933,12 +2164,55 @@ static int raid5_resize(mddev_t *mddev, sector_t sectors)
                set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
        }
        mddev->size = sectors /2;
+       mddev->resync_max_sectors = sectors;
        return 0;
 }
 
-static mdk_personality_t raid5_personality=
+static void raid5_quiesce(mddev_t *mddev, int state)
+{
+       raid5_conf_t *conf = mddev_to_conf(mddev);
+
+       switch(state) {
+       case 1: /* stop all writes */
+               spin_lock_irq(&conf->device_lock);
+               conf->quiesce = 1;
+               wait_event_lock_irq(conf->wait_for_stripe,
+                                   atomic_read(&conf->active_stripes) == 0,
+                                   conf->device_lock, /* nothing */);
+               spin_unlock_irq(&conf->device_lock);
+               break;
+
+       case 0: /* re-enable writes */
+               spin_lock_irq(&conf->device_lock);
+               conf->quiesce = 0;
+               wake_up(&conf->wait_for_stripe);
+               spin_unlock_irq(&conf->device_lock);
+               break;
+       }
+}
+
+static struct mdk_personality raid5_personality =
 {
        .name           = "raid5",
+       .level          = 5,
+       .owner          = THIS_MODULE,
+       .make_request   = make_request,
+       .run            = run,
+       .stop           = stop,
+       .status         = status,
+       .error_handler  = error,
+       .hot_add_disk   = raid5_add_disk,
+       .hot_remove_disk= raid5_remove_disk,
+       .spare_active   = raid5_spare_active,
+       .sync_request   = sync_request,
+       .resize         = raid5_resize,
+       .quiesce        = raid5_quiesce,
+};
+
+static struct mdk_personality raid4_personality =
+{
+       .name           = "raid4",
+       .level          = 4,
        .owner          = THIS_MODULE,
        .make_request   = make_request,
        .run            = run,
@@ -1950,19 +2224,27 @@ static mdk_personality_t raid5_personality=
        .spare_active   = raid5_spare_active,
        .sync_request   = sync_request,
        .resize         = raid5_resize,
+       .quiesce        = raid5_quiesce,
 };
 
-static int __init raid5_init (void)
+static int __init raid5_init(void)
 {
-       return register_md_personality (RAID5, &raid5_personality);
+       register_md_personality(&raid5_personality);
+       register_md_personality(&raid4_personality);
+       return 0;
 }
 
-static void raid5_exit (void)
+static void raid5_exit(void)
 {
-       unregister_md_personality (RAID5);
+       unregister_md_personality(&raid5_personality);
+       unregister_md_personality(&raid4_personality);
 }
 
 module_init(raid5_init);
 module_exit(raid5_exit);
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("md-personality-4"); /* RAID5 */
+MODULE_ALIAS("md-raid5");
+MODULE_ALIAS("md-raid4");
+MODULE_ALIAS("md-level-5");
+MODULE_ALIAS("md-level-4");