patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / md / dm.c
index bdfcbe0..03381e0 100644 (file)
@@ -80,7 +80,7 @@ struct mapped_device {
        /*
         * Event handling.
         */
-       uint32_t event_nr;
+       atomic_t event_nr;
        wait_queue_head_t eventq;
 
        /*
@@ -93,7 +93,7 @@ struct mapped_device {
 static kmem_cache_t *_io_cache;
 static kmem_cache_t *_tio_cache;
 
-static __init int local_init(void)
+static int __init local_init(void)
 {
        int r;
 
@@ -369,6 +369,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
                struct dm_io *io = tio->io;
                free_tio(tio->io->md, tio);
                dec_pending(io, -EIO);
+               bio_put(clone);
        }
 }
 
@@ -662,6 +663,8 @@ static int next_free_minor(unsigned int *minor)
        return r;
 }
 
+static struct block_device_operations dm_blk_dops;
+
 /*
  * Allocate and initialise a blank device with a given minor.
  */
@@ -684,6 +687,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
        init_rwsem(&md->lock);
        rwlock_init(&md->map_lock);
        atomic_set(&md->holders, 1);
+       atomic_set(&md->event_nr, 0);
 
        md->queue = blk_alloc_queue(GFP_KERNEL);
        if (!md->queue)
@@ -753,10 +757,8 @@ static void event_callback(void *context)
 {
        struct mapped_device *md = (struct mapped_device *) context;
 
-       down_write(&md->lock);
-       md->event_nr++;
+       atomic_inc(&md->event_nr);;
        wake_up(&md->eventq);
-       up_write(&md->lock);
 }
 
 static void __set_size(struct gendisk *disk, sector_t size)
@@ -1054,35 +1056,13 @@ int dm_resume(struct mapped_device *md)
  *---------------------------------------------------------------*/
 uint32_t dm_get_event_nr(struct mapped_device *md)
 {
-       uint32_t r;
-
-       down_read(&md->lock);
-       r = md->event_nr;
-       up_read(&md->lock);
-
-       return r;
+       return atomic_read(&md->event_nr);
 }
 
-int dm_add_wait_queue(struct mapped_device *md, wait_queue_t *wq,
-                     uint32_t event_nr)
+int dm_wait_event(struct mapped_device *md, int event_nr)
 {
-       down_write(&md->lock);
-       if (event_nr != md->event_nr) {
-               up_write(&md->lock);
-               return 1;
-       }
-
-       add_wait_queue(&md->eventq, wq);
-       up_write(&md->lock);
-
-       return 0;
-}
-
-void dm_remove_wait_queue(struct mapped_device *md, wait_queue_t *wq)
-{
-       down_write(&md->lock);
-       remove_wait_queue(&md->eventq, wq);
-       up_write(&md->lock);
+       return wait_event_interruptible(md->eventq,
+                       (event_nr != atomic_read(&md->event_nr)));
 }
 
 /*
@@ -1099,7 +1079,7 @@ int dm_suspended(struct mapped_device *md)
        return test_bit(DMF_SUSPENDED, &md->flags);
 }
 
-struct block_device_operations dm_blk_dops = {
+static struct block_device_operations dm_blk_dops = {
        .open = dm_blk_open,
        .release = dm_blk_close,
        .owner = THIS_MODULE