WorkStruct: make allyesconfig
[sfrench/cifs-2.6.git] / drivers / md / dm-raid1.c
index be48cedf986bb5e9ead2b3fb91800941950b9be2..fc8cbb168e3ed2d5f8ae53bcec7762d0cc53008b 100644 (file)
@@ -24,6 +24,7 @@
 
 static struct workqueue_struct *_kmirrord_wq;
 static struct work_struct _kmirrord_work;
+static DECLARE_WAIT_QUEUE_HEAD(_kmirrord_recovery_stopped);
 
 static inline void wake(void)
 {
@@ -83,6 +84,7 @@ struct region_hash {
        struct list_head *buckets;
 
        spinlock_t region_lock;
+       atomic_t recovery_in_flight;
        struct semaphore recovery_count;
        struct list_head clean_regions;
        struct list_head quiesced_regions;
@@ -191,6 +193,7 @@ static int rh_init(struct region_hash *rh, struct mirror_set *ms,
 
        spin_lock_init(&rh->region_lock);
        sema_init(&rh->recovery_count, 0);
+       atomic_set(&rh->recovery_in_flight, 0);
        INIT_LIST_HEAD(&rh->clean_regions);
        INIT_LIST_HEAD(&rh->quiesced_regions);
        INIT_LIST_HEAD(&rh->recovered_regions);
@@ -255,7 +258,9 @@ static struct region *__rh_alloc(struct region_hash *rh, region_t region)
        struct region *reg, *nreg;
 
        read_unlock(&rh->hash_lock);
-       nreg = mempool_alloc(rh->region_pool, GFP_NOIO);
+       nreg = mempool_alloc(rh->region_pool, GFP_ATOMIC);
+       if (unlikely(!nreg))
+               nreg = kmalloc(sizeof(struct region), GFP_NOIO);
        nreg->state = rh->log->type->in_sync(rh->log, region, 1) ?
                RH_CLEAN : RH_NOSYNC;
        nreg->rh = rh;
@@ -380,6 +385,8 @@ static void rh_update_states(struct region_hash *rh)
                rh->log->type->clear_region(rh->log, reg->key);
                rh->log->type->complete_resync_work(rh->log, reg->key, 1);
                dispatch_bios(rh->ms, &reg->delayed_bios);
+               if (atomic_dec_and_test(&rh->recovery_in_flight))
+                       wake_up_all(&_kmirrord_recovery_stopped);
                up(&rh->recovery_count);
                mempool_free(reg, rh->region_pool);
        }
@@ -500,11 +507,21 @@ static int __rh_recovery_prepare(struct region_hash *rh)
 
 static void rh_recovery_prepare(struct region_hash *rh)
 {
-       while (!down_trylock(&rh->recovery_count))
+       /* Extra reference to avoid race with rh_stop_recovery */
+       atomic_inc(&rh->recovery_in_flight);
+
+       while (!down_trylock(&rh->recovery_count)) {
+               atomic_inc(&rh->recovery_in_flight);
                if (__rh_recovery_prepare(rh) <= 0) {
+                       atomic_dec(&rh->recovery_in_flight);
                        up(&rh->recovery_count);
                        break;
                }
+       }
+
+       /* Drop the extra reference */
+       if (atomic_dec_and_test(&rh->recovery_in_flight))
+               wake_up_all(&_kmirrord_recovery_stopped);
 }
 
 /*
@@ -866,7 +883,7 @@ static void do_mirror(struct mirror_set *ms)
        do_writes(ms, &writes);
 }
 
-static void do_work(void *ignored)
+static void do_work(struct work_struct *ignored)
 {
        struct mirror_set *ms;
 
@@ -1175,6 +1192,11 @@ static void mirror_postsuspend(struct dm_target *ti)
        struct dirty_log *log = ms->rh.log;
 
        rh_stop_recovery(&ms->rh);
+
+       /* Wait for all I/O we generated to complete */
+       wait_event(_kmirrord_recovery_stopped,
+                  !atomic_read(&ms->rh.recovery_in_flight));
+
        if (log->type->suspend && log->type->suspend(log))
                /* FIXME: need better error handling */
                DMWARN("log suspend failed");
@@ -1211,9 +1233,9 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
                break;
 
        case STATUSTYPE_TABLE:
-               DMEMIT("%d ", ms->nr_mirrors);
+               DMEMIT("%d", ms->nr_mirrors);
                for (m = 0; m < ms->nr_mirrors; m++)
-                       DMEMIT("%s %llu ", ms->mirror[m].dev->name,
+                       DMEMIT(" %s %llu", ms->mirror[m].dev->name,
                                (unsigned long long)ms->mirror[m].offset);
        }
 
@@ -1247,7 +1269,7 @@ static int __init dm_mirror_init(void)
                dm_dirty_log_exit();
                return r;
        }
-       INIT_WORK(&_kmirrord_work, do_work, NULL);
+       INIT_WORK(&_kmirrord_work, do_work);
 
        r = dm_register_target(&mirror_target);
        if (r < 0) {