From 1ed34e88aa9edfbf5ef1e01d8d5a977262aff652 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 11 Jan 2002 12:12:46 +0000 Subject: [PATCH] o Add rename support to dmsetup. o Add support to use specified minor number to library and dmsetup. --- libdm/ioctl/libdevmapper.c | 2 +- libdm/ioctl/libdm-targets.h | 1 + libdm/libdevmapper.h | 2 +- libdm/libdm-common.c | 8 +++++++ tools/dmsetup.c | 42 +++++++++++++++++++++++++++++++++++-- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/libdm/ioctl/libdevmapper.c b/libdm/ioctl/libdevmapper.c index 0d39c93c7..bed81a10d 100644 --- a/libdm/ioctl/libdevmapper.c +++ b/libdm/ioctl/libdevmapper.c @@ -185,7 +185,7 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt) strncpy(dmi->name, dmt->dev_name, sizeof(dmi->name)); dmi->suspend = (dmt->type == DM_DEVICE_SUSPEND) ? 1 : 0; dmi->open_count = 0; - dmi->minor = -1; + dmi->minor = dmt->minor; dmi->read_only = dmt->read_only; dmi->target_count = count; diff --git a/libdm/ioctl/libdm-targets.h b/libdm/ioctl/libdm-targets.h index 92433665d..5a0e30f03 100644 --- a/libdm/ioctl/libdm-targets.h +++ b/libdm/ioctl/libdm-targets.h @@ -20,6 +20,7 @@ struct dm_task { struct target *head, *tail; int read_only; + int minor; struct dm_ioctl *dmi; char *newname; }; diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 67ddba8b2..7e3cf61c9 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -66,8 +66,8 @@ struct dm_info { int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi); int dm_task_set_ro(struct dm_task *dmt); - int dm_task_set_newname(struct dm_task *dmt, const char *newname); +int dm_task_set_minor(struct dm_task *dmt, int minor); /* * Use these to prepare for a create or reload. diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index 679fd71e7..ade0515f9 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -70,6 +70,7 @@ struct dm_task *dm_task_create(int type) memset(dmt, 0, sizeof(*dmt)); dmt->type = type; + dmt->minor = -1; return dmt; } @@ -105,6 +106,13 @@ int dm_task_set_name(struct dm_task *dmt, const char *name) return 1; } +int dm_task_set_minor(struct dm_task *dmt, int minor) +{ + dmt->minor = minor; + return 1; +} + + int dm_task_add_target(struct dm_task *dmt, uint64_t start, uint64_t size, diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 380bf01a4..a7328fbbb 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -28,10 +28,12 @@ */ enum { READ_ONLY = 0, + MINOR_ARG, NUM_SWITCHES }; static int _switches[NUM_SWITCHES]; +static int _values[NUM_SWITCHES]; /* @@ -105,6 +107,9 @@ static int _load(int task, const char *name, const char *file) if (_switches[READ_ONLY] && !dm_task_set_ro(dmt)) goto out; + if (_switches[MINOR_ARG] && !dm_task_set_minor(dmt, _values[MINOR_ARG])) + goto out; + if (!dm_task_run(dmt)) goto out; @@ -126,6 +131,30 @@ static int _reload(int argc, char **argv) return _load(DM_DEVICE_RELOAD, argv[1], argv[2]); } +static int _rename(int argc, char **argv) +{ + int r = 0; + struct dm_task *dmt; + + if (!(dmt = dm_task_create(DM_DEVICE_RENAME))) + return 0; + + if (!dm_task_set_name(dmt, argv[1])) + goto out; + + if (!dm_task_set_newname(dmt, argv[2])) + goto out; + + if (!dm_task_run(dmt)) + goto out; + + r = 1; + +out: + dm_task_destroy(dmt); + + return r; +} static int _simple(int task, const char *name) { @@ -226,6 +255,7 @@ static struct command _commands[] = { {"resume", "", 1, _resume}, {"reload", " ", 2, _reload}, {"info", "", 1, _info}, + {"rename", " ", 2, _rename}, {NULL, NULL, 0, NULL} }; @@ -258,17 +288,25 @@ static int _process_switches(int *argc, char ***argv) static struct option long_options[] = { {"read-only", 0, NULL, READ_ONLY}, + {"minor", 1, NULL, MINOR_ARG}, + {"", 0, NULL, 0} }; /* * Zero all the index counts. */ memset(&_switches, 0, sizeof(_switches)); + memset(&_values, 0, sizeof(_values)); - while ((c = getopt_long(*argc, *argv, "r", - long_options, &index)) != -1) + while ((c = getopt_long(*argc, *argv, "m:r", + long_options, &index)) != -1) { if (c == 'r' || index == READ_ONLY) _switches[READ_ONLY]++; + if (c == 'm' || index == MINOR_ARG) { + _switches[MINOR_ARG]++; + _values[MINOR_ARG] = atoi(optarg); + } + } *argv += optind; *argc -= optind;