[PATCH] device-mapper statistics: basic
[linux-2.6-block.git] / drivers / md / dm.c
index fc335e09d0727b8d62e7679459acbe3248012d38..c47518386c917783dafbeb9f4199c51b616ccdcc 100644 (file)
@@ -55,6 +55,7 @@ union map_info *dm_get_mapinfo(struct bio *bio)
  */
 #define DMF_BLOCK_IO 0
 #define DMF_SUSPENDED 1
+#define DMF_FROZEN 2
 
 struct mapped_device {
        struct rw_semaphore io_lock;
@@ -292,7 +293,7 @@ struct dm_table *dm_get_table(struct mapped_device *md)
  * Decrements the number of outstanding ios that a bio has been
  * cloned into, completing the original io if necc.
  */
-static inline void dec_pending(struct dm_io *io, int error)
+static void dec_pending(struct dm_io *io, int error)
 {
        if (error)
                io->error = error;
@@ -572,10 +573,14 @@ static void __split_bio(struct mapped_device *md, struct bio *bio)
 static int dm_request(request_queue_t *q, struct bio *bio)
 {
        int r;
+       int rw = bio_data_dir(bio);
        struct mapped_device *md = q->queuedata;
 
        down_read(&md->io_lock);
 
+       disk_stat_inc(dm_disk(md), ios[rw]);
+       disk_stat_add(dm_disk(md), sectors[rw], bio_sectors(bio));
+
        /*
         * If we're suspended we have to queue
         * this io for later.
@@ -767,6 +772,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
        md->queue->backing_dev_info.congested_fn = dm_any_congested;
        md->queue->backing_dev_info.congested_data = md;
        blk_queue_make_request(md->queue, dm_request);
+       blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
        md->queue->unplug_fn = dm_unplug_all;
        md->queue->issue_flush_fn = dm_flush_all;
 
@@ -836,9 +842,9 @@ static void __set_size(struct mapped_device *md, sector_t size)
 {
        set_capacity(md->disk, size);
 
-       down(&md->suspended_bdev->bd_inode->i_sem);
+       mutex_lock(&md->suspended_bdev->bd_inode->i_mutex);
        i_size_write(md->suspended_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
-       up(&md->suspended_bdev->bd_inode->i_sem);
+       mutex_unlock(&md->suspended_bdev->bd_inode->i_mutex);
 }
 
 static int __bind(struct mapped_device *md, struct dm_table *t)
@@ -1021,6 +1027,8 @@ static int lock_fs(struct mapped_device *md)
                return r;
        }
 
+       set_bit(DMF_FROZEN, &md->flags);
+
        /* don't bdput right now, we don't want the bdev
         * to go away while it is locked.
         */
@@ -1029,8 +1037,12 @@ static int lock_fs(struct mapped_device *md)
 
 static void unlock_fs(struct mapped_device *md)
 {
+       if (!test_bit(DMF_FROZEN, &md->flags))
+               return;
+
        thaw_bdev(md->suspended_bdev, md->frozen_sb);
        md->frozen_sb = NULL;
+       clear_bit(DMF_FROZEN, &md->flags);
 }
 
 /*
@@ -1040,7 +1052,7 @@ static void unlock_fs(struct mapped_device *md)
  * dm_bind_table, dm_suspend must be called to flush any in
  * flight bios and ensure that any further io gets deferred.
  */
-int dm_suspend(struct mapped_device *md)
+int dm_suspend(struct mapped_device *md, int do_lockfs)
 {
        struct dm_table *map = NULL;
        DECLARE_WAITQUEUE(wait, current);
@@ -1064,9 +1076,11 @@ int dm_suspend(struct mapped_device *md)
        }
 
        /* Flush I/O to the device. */
-       r = lock_fs(md);
-       if (r)
-               goto out;
+       if (do_lockfs) {
+               r = lock_fs(md);
+               if (r)
+                       goto out;
+       }
 
        /*
         * First we set the BLOCK_IO flag so no more ios will be mapped.