]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/md/dm-raid1.c
[SCSI] scsi: Handle device_add failure in scsi_alloc_target
[linux-2.6-omap-h63xx.git] / drivers / md / dm-raid1.c
index b08df8b9b2cad8994a8d5c739c3943f1548cc17d..6cfa8d435d55733b7b8f0c9671b8791d090b7643 100644 (file)
@@ -122,7 +122,7 @@ static inline sector_t region_to_sector(struct region_hash *rh, region_t region)
 /* FIXME move this */
 static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw);
 
-static void *region_alloc(unsigned int __nocast gfp_mask, void *pool_data)
+static void *region_alloc(gfp_t gfp_mask, void *pool_data)
 {
        return kmalloc(sizeof(struct region), gfp_mask);
 }
@@ -375,16 +375,20 @@ static void rh_inc(struct region_hash *rh, region_t region)
 
        read_lock(&rh->hash_lock);
        reg = __rh_find(rh, region);
-       if (reg->state == RH_CLEAN) {
-               rh->log->type->mark_region(rh->log, reg->key);
 
-               spin_lock_irq(&rh->region_lock);
+       spin_lock_irq(&rh->region_lock);
+       atomic_inc(&reg->pending);
+
+       if (reg->state == RH_CLEAN) {
                reg->state = RH_DIRTY;
                list_del_init(&reg->list);      /* take off the clean list */
                spin_unlock_irq(&rh->region_lock);
-       }
 
-       atomic_inc(&reg->pending);
+               rh->log->type->mark_region(rh->log, reg->key);
+       } else
+               spin_unlock_irq(&rh->region_lock);
+
+
        read_unlock(&rh->hash_lock);
 }
 
@@ -406,17 +410,17 @@ static void rh_dec(struct region_hash *rh, region_t region)
        reg = __rh_lookup(rh, region);
        read_unlock(&rh->hash_lock);
 
+       spin_lock_irqsave(&rh->region_lock, flags);
        if (atomic_dec_and_test(&reg->pending)) {
-               spin_lock_irqsave(&rh->region_lock, flags);
                if (reg->state == RH_RECOVERING) {
                        list_add_tail(&reg->list, &rh->quiesced_regions);
                } else {
                        reg->state = RH_CLEAN;
                        list_add(&reg->list, &rh->clean_regions);
                }
-               spin_unlock_irqrestore(&rh->region_lock, flags);
                should_wake = 1;
        }
+       spin_unlock_irqrestore(&rh->region_lock, flags);
 
        if (should_wake)
                wake();
@@ -558,6 +562,8 @@ struct mirror_set {
        region_t nr_regions;
        int in_sync;
 
+       struct mirror *default_mirror;  /* Default mirror */
+
        unsigned int nr_mirrors;
        struct mirror mirror[0];
 };
@@ -607,7 +613,7 @@ static int recover(struct mirror_set *ms, struct region *reg)
        unsigned long flags = 0;
 
        /* fill in the source */
-       m = ms->mirror + DEFAULT_MIRROR;
+       m = ms->default_mirror;
        from.bdev = m->dev->bdev;
        from.sector = m->offset + region_to_sector(reg->rh, reg->key);
        if (reg->key == (ms->nr_regions - 1)) {
@@ -623,7 +629,7 @@ static int recover(struct mirror_set *ms, struct region *reg)
 
        /* fill in the destinations */
        for (i = 0, dest = to; i < ms->nr_mirrors; i++) {
-               if (i == DEFAULT_MIRROR)
+               if (&ms->mirror[i] == ms->default_mirror)
                        continue;
 
                m = ms->mirror + i;
@@ -678,7 +684,7 @@ static void do_recovery(struct mirror_set *ms)
 static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
 {
        /* FIXME: add read balancing */
-       return ms->mirror + DEFAULT_MIRROR;
+       return ms->default_mirror;
 }
 
 /*
@@ -705,7 +711,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
                if (rh_in_sync(&ms->rh, region, 0))
                        m = choose_mirror(ms, bio->bi_sector);
                else
-                       m = ms->mirror + DEFAULT_MIRROR;
+                       m = ms->default_mirror;
 
                map_bio(ms, m, bio);
                generic_make_request(bio);
@@ -829,7 +835,7 @@ static void do_writes(struct mirror_set *ms, struct bio_list *writes)
                rh_delay(&ms->rh, bio);
 
        while ((bio = bio_list_pop(&nosync))) {
-               map_bio(ms, ms->mirror + DEFAULT_MIRROR, bio);
+               map_bio(ms, ms->default_mirror, bio);
                generic_make_request(bio);
        }
 }
@@ -896,6 +902,7 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,
        ms->nr_mirrors = nr_mirrors;
        ms->nr_regions = dm_sector_div_up(ti->len, region_size);
        ms->in_sync = 0;
+       ms->default_mirror = &ms->mirror[DEFAULT_MIRROR];
 
        if (rh_init(&ms->rh, ms, dl, region_size, ms->nr_regions)) {
                ti->error = "dm-mirror: Error creating dirty region hash";