#include <linux/init.h>
#include <linux/module.h>
-#include <linux/mutex.h>
#include <linux/moduleparam.h>
#include <linux/blkpg.h>
#include <linux/bio.h>
#include <linux/mempool.h>
#include <linux/slab.h>
#include <linux/idr.h>
-#include <linux/hdreg.h>
-#include <linux/blktrace_api.h>
static const char *_name = DM_NAME;
request_queue_t *queue;
struct gendisk *disk;
- char name[16];
void *interface_ptr;
*/
struct super_block *frozen_sb;
struct block_device *suspended_bdev;
-
- /* forced geometry settings */
- struct hd_geometry geometry;
};
#define MIN_IOS 256
return 0;
}
-static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
-{
- struct mapped_device *md = bdev->bd_disk->private_data;
-
- return dm_get_geometry(md, geo);
-}
-
static inline struct dm_io *alloc_io(struct mapped_device *md)
{
return mempool_alloc(md->io_pool, GFP_NOIO);
return t;
}
-/*
- * Get the geometry associated with a dm device
- */
-int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)
-{
- *geo = md->geometry;
-
- return 0;
-}
-
-/*
- * Set the geometry of a device.
- */
-int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo)
-{
- sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors;
-
- if (geo->start > sz) {
- DMWARN("Start sector is beyond the geometry limits.");
- return -EINVAL;
- }
-
- md->geometry = *geo;
-
- return 0;
-}
-
/*-----------------------------------------------------------------
* CRUD START:
* A more elegant soln is in the works that uses the queue
/* 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);
}
struct target_io *tio)
{
int r;
- sector_t sector;
/*
* Sanity checks.
* 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 */
/*-----------------------------------------------------------------
* An IDR is used to keep track of allocated minor numbers.
*---------------------------------------------------------------*/
-static DEFINE_MUTEX(_minor_lock);
+static DECLARE_MUTEX(_minor_lock);
static DEFINE_IDR(_minor_idr);
static void free_minor(unsigned int minor)
{
- mutex_lock(&_minor_lock);
+ down(&_minor_lock);
idr_remove(&_minor_idr, minor);
- mutex_unlock(&_minor_lock);
+ up(&_minor_lock);
}
/*
if (minor >= (1 << MINORBITS))
return -EINVAL;
- mutex_lock(&_minor_lock);
+ down(&_minor_lock);
if (idr_find(&_minor_idr, minor)) {
r = -EBUSY;
}
out:
- mutex_unlock(&_minor_lock);
+ up(&_minor_lock);
return r;
}
int r;
unsigned int m;
- mutex_lock(&_minor_lock);
+ down(&_minor_lock);
r = idr_pre_get(&_minor_idr, GFP_KERNEL);
if (!r) {
*minor = m;
out:
- mutex_unlock(&_minor_lock);
+ up(&_minor_lock);
return r;
}
return NULL;
}
+ if (!try_module_get(THIS_MODULE))
+ goto bad0;
+
/* get a minor number for the dev */
r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor);
if (r < 0)
md->queue->unplug_fn = dm_unplug_all;
md->queue->issue_flush_fn = dm_flush_all;
- md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
+ md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
+ mempool_free_slab, _io_cache);
if (!md->io_pool)
goto bad2;
- md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
+ md->tio_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
+ mempool_free_slab, _tio_cache);
if (!md->tio_pool)
goto bad3;
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);
bad3:
mempool_destroy(md->io_pool);
bad2:
- blk_cleanup_queue(md->queue);
+ blk_put_queue(md->queue);
free_minor(minor);
bad1:
+ module_put(THIS_MODULE);
+ bad0:
kfree(md);
return NULL;
}
del_gendisk(md->disk);
free_minor(minor);
put_disk(md->disk);
- blk_cleanup_queue(md->queue);
+ blk_put_queue(md->queue);
+ module_put(THIS_MODULE);
kfree(md);
}
sector_t size;
size = dm_table_get_size(t);
-
- /*
- * Wipe any geometry if the size of the table changed.
- */
- if (size != get_capacity(md->disk))
- memset(&md->geometry, 0, sizeof(md->geometry));
-
__set_size(md, size);
if (size == 0)
return 0;
if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
return NULL;
- mutex_lock(&_minor_lock);
+ down(&_minor_lock);
md = idr_find(&_minor_idr, minor);
if (!md || (dm_disk(md)->first_minor != minor))
md = NULL;
- mutex_unlock(&_minor_lock);
+ up(&_minor_lock);
return md;
}
return md;
}
-void *dm_get_mdptr(struct mapped_device *md)
+void *dm_get_mdptr(dev_t dev)
{
- return md->interface_ptr;
+ struct mapped_device *md;
+ void *mdptr = NULL;
+
+ md = dm_find_md(dev);
+ if (md)
+ mdptr = md->interface_ptr;
+ return mdptr;
}
void dm_set_mdptr(struct mapped_device *md, void *ptr)
void dm_put(struct mapped_device *md)
{
- struct dm_table *map;
+ struct dm_table *map = dm_get_table(md);
if (atomic_dec_and_test(&md->holders)) {
- map = dm_get_table(md);
if (!dm_suspended(md)) {
dm_table_presuspend_targets(map);
dm_table_postsuspend_targets(map);
}
__unbind(md);
- dm_table_put(map);
free_dev(md);
}
+
+ dm_table_put(map);
}
/*
static struct block_device_operations dm_blk_dops = {
.open = dm_blk_open,
.release = dm_blk_close,
- .getgeo = dm_blk_getgeo,
.owner = THIS_MODULE
};