]> err.no Git - linux-2.6/blobdiff - drivers/md/raid5.c
[PATCH] dm: add module ref counting
[linux-2.6] / drivers / md / raid5.c
index 8eded08411f3db10b0450bb53c807ab233638c8c..31843604049cdb7d6f916fee3861c1994869cf6d 100644 (file)
@@ -73,10 +73,8 @@ static void print_raid5_conf (raid5_conf_t *conf);
 static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
 {
        if (atomic_dec_and_test(&sh->count)) {
-               if (!list_empty(&sh->lru))
-                       BUG();
-               if (atomic_read(&conf->active_stripes)==0)
-                       BUG();
+               BUG_ON(!list_empty(&sh->lru));
+               BUG_ON(atomic_read(&conf->active_stripes)==0);
                if (test_bit(STRIPE_HANDLE, &sh->state)) {
                        if (test_bit(STRIPE_DELAYED, &sh->state))
                                list_add_tail(&sh->lru, &conf->delayed_list);
@@ -184,10 +182,8 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int
        raid5_conf_t *conf = sh->raid_conf;
        int i;
 
-       if (atomic_read(&sh->count) != 0)
-               BUG();
-       if (test_bit(STRIPE_HANDLE, &sh->state))
-               BUG();
+       BUG_ON(atomic_read(&sh->count) != 0);
+       BUG_ON(test_bit(STRIPE_HANDLE, &sh->state));
        
        CHECK_DEVLOCK();
        PRINTK("init_stripe called, stripe %llu\n", 
@@ -262,15 +258,14 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
                                                     < (conf->max_nr_stripes *3/4)
                                                     || !conf->inactive_blocked),
                                                    conf->device_lock,
-                                                   unplug_slaves(conf->mddev);
+                                                   unplug_slaves(conf->mddev)
                                        );
                                conf->inactive_blocked = 0;
                        } else
                                init_stripe(sh, sector, pd_idx, disks);
                } else {
                        if (atomic_read(&sh->count)) {
-                               if (!list_empty(&sh->lru))
-                                       BUG();
+                         BUG_ON(!list_empty(&sh->lru));
                        } else {
                                if (!test_bit(STRIPE_HANDLE, &sh->state))
                                        atomic_inc(&conf->active_stripes);
@@ -407,7 +402,7 @@ static int resize_stripes(raid5_conf_t *conf, int newsize)
                wait_event_lock_irq(conf->wait_for_stripe,
                                    !list_empty(&conf->inactive_list),
                                    conf->device_lock,
-                                   unplug_slaves(conf->mddev);
+                                   unplug_slaves(conf->mddev)
                        );
                osh = get_free_stripe(conf);
                spin_unlock_irq(&conf->device_lock);
@@ -465,8 +460,7 @@ static int drop_one_stripe(raid5_conf_t *conf)
        spin_unlock_irq(&conf->device_lock);
        if (!sh)
                return 0;
-       if (atomic_read(&sh->count))
-               BUG();
+       BUG_ON(atomic_read(&sh->count));
        shrink_buffers(sh, conf->pool_size);
        kmem_cache_free(conf->slab_cache, sh);
        atomic_dec(&conf->active_stripes);
@@ -882,8 +876,7 @@ static void compute_parity(struct stripe_head *sh, int method)
        ptr[0] = page_address(sh->dev[pd_idx].page);
        switch(method) {
        case READ_MODIFY_WRITE:
-               if (!test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags))
-                       BUG();
+               BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags));
                for (i=disks ; i-- ;) {
                        if (i==pd_idx)
                                continue;
@@ -896,7 +889,7 @@ static void compute_parity(struct stripe_head *sh, int method)
                                if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
                                        wake_up(&conf->wait_for_overlap);
 
-                               if (sh->dev[i].written) BUG();
+                               BUG_ON(sh->dev[i].written);
                                sh->dev[i].written = chosen;
                                check_xor();
                        }
@@ -912,7 +905,7 @@ static void compute_parity(struct stripe_head *sh, int method)
                                if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
                                        wake_up(&conf->wait_for_overlap);
 
-                               if (sh->dev[i].written) BUG();
+                               BUG_ON(sh->dev[i].written);
                                sh->dev[i].written = chosen;
                        }
                break;
@@ -995,8 +988,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
        if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9))
                goto overlap;
 
-       if (*bip && bi->bi_next && (*bip) != bi->bi_next)
-               BUG();
+       BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next);
        if (*bip)
                bi->bi_next = *bip;
        *bip = bi;
@@ -1430,8 +1422,7 @@ static void handle_stripe(struct stripe_head *sh)
                set_bit(STRIPE_HANDLE, &sh->state);
                if (failed == 0) {
                        char *pagea;
-                       if (uptodate != disks)
-                               BUG();
+                       BUG_ON(uptodate != disks);
                        compute_parity(sh, CHECK_PARITY);
                        uptodate--;
                        pagea = page_address(sh->dev[sh->pd_idx].page);
@@ -1743,6 +1734,7 @@ static int make_request(request_queue_t *q, struct bio * bi)
        sector_t logical_sector, last_sector;
        struct stripe_head *sh;
        const int rw = bio_data_dir(bi);
+       int remaining;
 
        if (unlikely(bio_barrier(bi))) {
                bio_endio(bi, bi->bi_size, -EOPNOTSUPP);
@@ -1852,7 +1844,9 @@ static int make_request(request_queue_t *q, struct bio * bi)
                        
        }
        spin_lock_irq(&conf->device_lock);
-       if (--bi->bi_phys_segments == 0) {
+       remaining = --bi->bi_phys_segments;
+       spin_unlock_irq(&conf->device_lock);
+       if (remaining == 0) {
                int bytes = bi->bi_size;
 
                if ( bio_data_dir(bi) == WRITE )
@@ -1860,7 +1854,6 @@ static int make_request(request_queue_t *q, struct bio * bi)
                bi->bi_size = 0;
                bi->bi_end_io(bi, bytes, 0);
        }
-       spin_unlock_irq(&conf->device_lock);
        return 0;
 }
 
@@ -2094,8 +2087,7 @@ static void raid5d (mddev_t *mddev)
 
                list_del_init(first);
                atomic_inc(&sh->count);
-               if (atomic_read(&sh->count)!= 1)
-                       BUG();
+               BUG_ON(atomic_read(&sh->count)!= 1);
                spin_unlock_irq(&conf->device_lock);
                
                handled++;