]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/md/dm.c
[PATCH] dm: store md name
[linux-2.6-omap-h63xx.git] / drivers / md / dm.c
index 88d60202b9db409bcfcc48069ef7bc49547172af..f140d499602a14f217a7dfc3d3bd85a6ef828ef7 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/mempool.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
+#include <linux/blktrace_api.h>
 
 static const char *_name = DM_NAME;
 
@@ -68,6 +69,7 @@ struct mapped_device {
 
        request_queue_t *queue;
        struct gendisk *disk;
+       char name[16];
 
        void *interface_ptr;
 
@@ -334,6 +336,8 @@ static void dec_pending(struct dm_io *io, int error)
                        /* nudge anyone waiting on suspend queue */
                        wake_up(&io->md->wait);
 
+               blk_add_trace_bio(io->md->queue, io->bio, BLK_TA_COMPLETE);
+
                bio_endio(io->bio, io->bio->bi_size, io->error);
                free_io(io->md, io);
        }
@@ -392,6 +396,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
                      struct target_io *tio)
 {
        int r;
+       sector_t sector;
 
        /*
         * Sanity checks.
@@ -407,10 +412,17 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
         * this io.
         */
        atomic_inc(&tio->io->io_count);
+       sector = clone->bi_sector;
        r = ti->type->map(ti, clone, &tio->info);
-       if (r > 0)
+       if (r > 0) {
                /* the bio has been remapped so dispatch it */
+
+               blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone, 
+                                   tio->io->bio->bi_bdev->bd_dev, sector, 
+                                   clone->bi_sector);
+
                generic_make_request(clone);
+       }
 
        else if (r < 0) {
                /* error the io and bail out */
@@ -533,30 +545,35 @@ static void __clone_and_map(struct clone_info *ci)
 
        } else {
                /*
-                * Create two copy bios to deal with io that has
-                * been split across a target.
+                * Handle a bvec that must be split between two or more targets.
                 */
                struct bio_vec *bv = bio->bi_io_vec + ci->idx;
+               sector_t remaining = to_sector(bv->bv_len);
+               unsigned int offset = 0;
 
-               clone = split_bvec(bio, ci->sector, ci->idx,
-                                  bv->bv_offset, max);
-               __map_bio(ti, clone, tio);
+               do {
+                       if (offset) {
+                               ti = dm_table_find_target(ci->map, ci->sector);
+                               max = max_io_len(ci->md, ci->sector, ti);
 
-               ci->sector += max;
-               ci->sector_count -= max;
-               ti = dm_table_find_target(ci->map, ci->sector);
-
-               len = to_sector(bv->bv_len) - max;
-               clone = split_bvec(bio, ci->sector, ci->idx,
-                                  bv->bv_offset + to_bytes(max), len);
-               tio = alloc_tio(ci->md);
-               tio->io = ci->io;
-               tio->ti = ti;
-               memset(&tio->info, 0, sizeof(tio->info));
-               __map_bio(ti, clone, tio);
+                               tio = alloc_tio(ci->md);
+                               tio->io = ci->io;
+                               tio->ti = ti;
+                               memset(&tio->info, 0, sizeof(tio->info));
+                       }
+
+                       len = min(remaining, max);
+
+                       clone = split_bvec(bio, ci->sector, ci->idx,
+                                          bv->bv_offset + offset, len);
+
+                       __map_bio(ti, clone, tio);
+
+                       ci->sector += len;
+                       ci->sector_count -= len;
+                       offset += to_bytes(len);
+               } while (remaining -= len);
 
-               ci->sector += len;
-               ci->sector_count -= len;
                ci->idx++;
        }
 }
@@ -807,13 +824,11 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
        md->queue->unplug_fn = dm_unplug_all;
        md->queue->issue_flush_fn = dm_flush_all;
 
-       md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
-                                    mempool_free_slab, _io_cache);
+       md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
        if (!md->io_pool)
                goto bad2;
 
-       md->tio_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
-                                     mempool_free_slab, _tio_cache);
+       md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
        if (!md->tio_pool)
                goto bad3;
 
@@ -828,6 +843,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
        md->disk->private_data = md;
        sprintf(md->disk->disk_name, "dm-%d", minor);
        add_disk(md->disk);
+       format_dev_t(md->name, MKDEV(_major, minor));
 
        atomic_set(&md->pending, 0);
        init_waitqueue_head(&md->wait);
@@ -1093,6 +1109,7 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
 {
        struct dm_table *map = NULL;
        DECLARE_WAITQUEUE(wait, current);
+       struct bio *def;
        int r = -EINVAL;
 
        down(&md->suspend_lock);
@@ -1152,9 +1169,11 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
        /* were we interrupted ? */
        r = -EINTR;
        if (atomic_read(&md->pending)) {
+               clear_bit(DMF_BLOCK_IO, &md->flags);
+               def = bio_list_get(&md->deferred);
+               __flush_deferred_io(md, def);
                up_write(&md->io_lock);
                unlock_fs(md);
-               clear_bit(DMF_BLOCK_IO, &md->flags);
                goto out;
        }
        up_write(&md->io_lock);