mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o Add rename support to dmsetup.
o Add support to use specified minor number to library and dmsetup.
This commit is contained in:
parent
4c0d6e283a
commit
1ed34e88aa
@ -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;
|
||||
|
@ -20,6 +20,7 @@ struct dm_task {
|
||||
struct target *head, *tail;
|
||||
|
||||
int read_only;
|
||||
int minor;
|
||||
struct dm_ioctl *dmi;
|
||||
char *newname;
|
||||
};
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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", "<dev_name>", 1, _resume},
|
||||
{"reload", "<dev_name> <table_file>", 2, _reload},
|
||||
{"info", "<dev_name>", 1, _info},
|
||||
{"rename", "<dev_name> <new_name>", 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;
|
||||
|
Loading…
Reference in New Issue
Block a user