]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/md/raid5.c
[MIPS] Further sparsification for 32-bit compat code.
[mv-sheeva.git] / drivers / md / raid5.c
index 9fc50487e2edd539b6e06209c9ac628e7b380f4b..2dba305daf3c887799453caefae8d5a36535de4b 100644 (file)
 #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
@@ -71,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))
@@ -113,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);
 }
 
 
@@ -188,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;
@@ -228,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);
@@ -359,7 +350,8 @@ static void shrink_stripes(raid5_conf_t *conf)
        while (drop_one_stripe(conf))
                ;
 
-       kmem_cache_destroy(conf->slab_cache);
+       if (conf->slab_cache)
+               kmem_cache_destroy(conf->slab_cache);
        conf->slab_cache = NULL;
 }
 
@@ -1409,6 +1401,9 @@ 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)
@@ -1421,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)) {
@@ -1437,7 +1432,7 @@ static inline void raid5_activate_delayed(raid5_conf_t *conf)
        }
 }
 
-static inline void activate_bit_delay(raid5_conf_t *conf)
+static void activate_bit_delay(raid5_conf_t *conf)
 {
        /* device_lock is held */
        struct list_head head;
@@ -1835,9 +1830,8 @@ static int run(mddev_t *mddev)
 
        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);
@@ -1972,9 +1966,7 @@ static int run(mddev_t *mddev)
 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;
@@ -1991,7 +1983,7 @@ static int stop(mddev_t *mddev)
        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);
@@ -2019,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);
@@ -2199,9 +2191,10 @@ static void raid5_quiesce(mddev_t *mddev, int state)
        }
 }
 
-static mdk_personality_t raid5_personality=
+static struct mdk_personality raid5_personality =
 {
        .name           = "raid5",
+       .level          = 5,
        .owner          = THIS_MODULE,
        .make_request   = make_request,
        .run            = run,
@@ -2216,17 +2209,42 @@ static mdk_personality_t raid5_personality=
        .quiesce        = raid5_quiesce,
 };
 
-static int __init raid5_init (void)
+static struct mdk_personality raid4_personality =
 {
-       return register_md_personality (RAID5, &raid5_personality);
+       .name           = "raid4",
+       .level          = 4,
+       .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 int __init raid5_init(void)
+{
+       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");