From 0fe9eaa24c28e798af3a4dbadad0ef55385b97f6 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 7 Jan 2002 22:01:39 +0000 Subject: [PATCH] tidying --- kernel/common/dm-table.c | 4 ++-- kernel/common/dm.c.in | 33 ++++++++++++++++++++------------- kernel/common/dm.h | 2 +- kernel/ioctl/dm-ioctl.c | 12 +++++++----- lib/ioctl/libdevmapper.c | 2 ++ 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/kernel/common/dm-table.c b/kernel/common/dm-table.c index 6efd73a..1d9efec 100644 --- a/kernel/common/dm-table.c +++ b/kernel/common/dm-table.c @@ -336,7 +336,7 @@ void dm_table_put_device(struct dm_table *t, struct dm_dev *dd) /* * Adds a target to the map */ -int dm_table_add_target(struct dm_table *t, offset_t high, +int dm_table_add_target(struct dm_table *t, offset_t highs, struct target_type *type, void *private) { int r, n; @@ -345,7 +345,7 @@ int dm_table_add_target(struct dm_table *t, offset_t high, return r; n = t->num_targets++; - t->highs[n] = high; + t->highs[n] = highs; t->targets[n].type = type; t->targets[n].private = private; diff --git a/kernel/common/dm.c.in b/kernel/common/dm.c.in index 2884af4..596b342 100644 --- a/kernel/common/dm.c.in +++ b/kernel/common/dm.c.in @@ -19,6 +19,7 @@ static const char *_name = DM_NAME; static const char *_version = @DM_VERSION@; static const char *_email = "lvm-devel@lists.sistina.com"; +static int major = 0; static int _major = 0; struct io_hook { @@ -45,6 +46,8 @@ static devfs_handle_t _dev_dir; static int request(request_queue_t *q, int rw, struct buffer_head *bh); static int dm_user_bmap(struct inode *inode, struct lv_bmap *lvb); +static void __free_dev(struct mapped_device *md); + /* * Shortcuts to lock/unlock the global _dev_lock */ @@ -81,6 +84,7 @@ static int __init local_init(void) 0, 0, NULL, NULL))) return -ENOMEM; + _major = major; r = devfs_register_blkdev(_major, _name, &dm_blk_dops); if (r < 0) { DMERR("register_blkdev failed"); @@ -118,6 +122,7 @@ static void local_exit(void) blk_size[_major] = NULL; blksize_size[_major] = NULL; hardsect_size[_major] = NULL; + _major = 0; DMINFO("%s cleaned up", _version); } @@ -593,7 +598,7 @@ static struct mapped_device *alloc_dev(int minor) return md; } -static void free_dev(struct mapped_device *md) +static void __free_dev(struct mapped_device *md) { kfree(md); } @@ -682,7 +687,7 @@ static struct mapped_device *__get_by_name(const char *name) return NULL; } -static int check_name(const char *name) +static int __check_name(const char *name) { if (strchr(name, '/')) { DMWARN("invalid device name"); @@ -709,12 +714,13 @@ int dm_create(const char *name, int minor, struct dm_table *table, if (minor >= MAX_DEVICES) return -ENXIO; - if (!(md = alloc_dev(minor))) + md = alloc_dev(minor); + if (!md) return -ENXIO; dm_lock_w(); - if (check_name(name) < 0) { + if (__check_name(name) < 0) { r = -EINVAL; goto err; } @@ -736,8 +742,8 @@ int dm_create(const char *name, int minor, struct dm_table *table, return 0; err: + __free_dev(md); dm_unlock_w(); - free_dev(md); return r; } @@ -754,17 +760,18 @@ int dm_destroy(struct mapped_device *md) dm_unlock_r(); return -EPERM; } + dm_unlock_r(); fsync_dev(md->dev); - dm_unlock_r(); dm_lock_w(); - if (md->use_count) { + if (md->suspended || md->use_count) { dm_unlock_w(); return -EPERM; } - if ((r = unregister_device(md))) { + r = unregister_device(md); + if (r) { dm_unlock_w(); return r; } @@ -772,11 +779,10 @@ int dm_destroy(struct mapped_device *md) minor = MINOR(md->dev); _devs[minor] = 0; __unbind(md); + __free_dev(md); dm_unlock_w(); - free_dev(md); - return 0; } @@ -827,7 +833,8 @@ int dm_swap_table(struct mapped_device *md, struct dm_table *table) __unbind(md); - if ((r = __bind(md, table))) { + r = __bind(md, table); + if (r) { dm_unlock_w(); return r; } @@ -928,8 +935,8 @@ struct block_device_operations dm_blk_dops = { module_init(dm_init); module_exit(dm_exit); -MODULE_PARM(_major, "i"); -MODULE_PARM_DESC(_major, "The major number of the device mapper"); +MODULE_PARM(major, "i"); +MODULE_PARM_DESC(major, "The major number of the device mapper"); MODULE_DESCRIPTION(DM_NAME " driver"); MODULE_AUTHOR("Joe Thornber "); MODULE_LICENSE("GPL"); diff --git a/kernel/common/dm.h b/kernel/common/dm.h index f47ceba..e7acadb 100644 --- a/kernel/common/dm.h +++ b/kernel/common/dm.h @@ -135,7 +135,7 @@ int dm_resume(struct mapped_device *md); int dm_table_create(struct dm_table **result); void dm_table_destroy(struct dm_table *t); -int dm_table_add_target(struct dm_table *t, offset_t high, +int dm_table_add_target(struct dm_table *t, offset_t highs, struct target_type *type, void *private); int dm_table_complete(struct dm_table *t); diff --git a/kernel/ioctl/dm-ioctl.c b/kernel/ioctl/dm-ioctl.c index bf36245..b623fa3 100644 --- a/kernel/ioctl/dm-ioctl.c +++ b/kernel/ioctl/dm-ioctl.c @@ -21,7 +21,7 @@ static int copy_params(struct dm_ioctl *user, struct dm_ioctl **result) if (copy_from_user(&tmp, user, sizeof(tmp))) return -EFAULT; - if (!(dmi = vmalloc(tmp.data_size))) + if (!(dmi = (struct dm_ioctl *) vmalloc(tmp.data_size))) return -ENOMEM; if (copy_from_user(dmi, user, tmp.data_size)) @@ -89,7 +89,7 @@ static int populate_table(struct dm_table *table, struct dm_ioctl *args) char *params, *argv[MAX_ARGS]; struct target_type *ttype; void *context, *begin, *end; - offset_t high = 0; + offset_t highs = 0; if (!args->target_count) { DMWARN("populate_table: no targets specified"); @@ -129,8 +129,8 @@ static int populate_table(struct dm_table *table, struct dm_ioctl *args) } /* Add the target to the table */ - high = spec->sector_start + (spec->length - 1); - if (dm_table_add_target(table, high, ttype, context)) + highs = spec->sector_start + (spec->length - 1); + if (dm_table_add_target(table, highs, ttype, context)) PARSE_ERROR("internal error adding target to table"); first = 0; @@ -210,12 +210,14 @@ static int remove(struct dm_ioctl *param) static int suspend(struct dm_ioctl *param) { + int r; struct mapped_device *md = dm_get(param->name); if (!md) return -ENXIO; - return param->suspend ? dm_suspend(md) : dm_resume(md); + r = param->suspend ? dm_suspend(md) : dm_resume(md); + return r; } static int reload(struct dm_ioctl *param) diff --git a/lib/ioctl/libdevmapper.c b/lib/ioctl/libdevmapper.c index e8f165e..ad00554 100644 --- a/lib/ioctl/libdevmapper.c +++ b/lib/ioctl/libdevmapper.c @@ -157,6 +157,8 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt) if (!(dmi = malloc(len))) return NULL; + memset(dmi, 0, len); + strncpy(dmi->version, DM_IOCTL_VERSION, sizeof(dmi->version)); dmi->data_size = len; strncpy(dmi->name, dmt->dev_name, sizeof(dmi->name)); -- 2.43.5