mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Let dmsetup store the uuid on device creation.
This commit is contained in:
parent
251502f9a1
commit
ad21a5585c
@ -40,6 +40,9 @@ void dm_task_destroy(struct dm_task *dmt)
|
||||
if (dmt->dmi)
|
||||
free(dmt->dmi);
|
||||
|
||||
if (dmt->uuid)
|
||||
free(dmt->uuid);
|
||||
|
||||
free(dmt);
|
||||
}
|
||||
|
||||
@ -225,6 +228,9 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
|
||||
dmi->dev = MKDEV(0, dmt->minor);
|
||||
}
|
||||
|
||||
if (dmt->uuid)
|
||||
strncpy(dmi->uuid, dmt->uuid, sizeof(dmi->uuid));
|
||||
|
||||
dmi->target_count = count;
|
||||
|
||||
b = (void *) (dmi + 1);
|
||||
|
@ -23,5 +23,7 @@ struct dm_task {
|
||||
int minor;
|
||||
struct dm_ioctl *dmi;
|
||||
char *newname;
|
||||
|
||||
char *uuid;
|
||||
};
|
||||
|
||||
|
@ -52,6 +52,7 @@ struct dm_task *dm_task_create(int type);
|
||||
void dm_task_destroy(struct dm_task *dmt);
|
||||
|
||||
int dm_task_set_name(struct dm_task *dmt, const char *name);
|
||||
int dm_task_set_uuid(struct dm_task *dmt, const char *uuid);
|
||||
|
||||
/*
|
||||
* Retrieve attributes after an info.
|
||||
|
@ -86,8 +86,10 @@ int dm_task_set_name(struct dm_task *dmt, const char *name)
|
||||
char path[PATH_MAX];
|
||||
struct stat st1, st2;
|
||||
|
||||
if (dmt->dev_name)
|
||||
if (dmt->dev_name) {
|
||||
free(dmt->dev_name);
|
||||
dmt->dev_name = NULL;
|
||||
}
|
||||
|
||||
/* If path was supplied, remove it if it points to the same device
|
||||
* as its last component.
|
||||
@ -112,6 +114,21 @@ int dm_task_set_name(struct dm_task *dmt, const char *name)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_task_set_uuid(struct dm_task *dmt, const char *uuid)
|
||||
{
|
||||
if (dmt->uuid) {
|
||||
free(dmt->uuid);
|
||||
dmt->uuid = NULL;
|
||||
}
|
||||
|
||||
if (!(dmt->uuid = strdup(uuid))) {
|
||||
log_error("dm_task_set_uuid: strdup(%s) failed", uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_task_set_minor(struct dm_task *dmt, int minor)
|
||||
{
|
||||
dmt->minor = minor;
|
||||
|
@ -89,7 +89,7 @@ static int _parse_file(struct dm_task *dmt, const char *file)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _load(int task, const char *name, const char *file)
|
||||
static int _load(int task, const char *name, const char *file, const char *uuid)
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
@ -100,6 +100,9 @@ static int _load(int task, const char *name, const char *file)
|
||||
if (!dm_task_set_name(dmt, name))
|
||||
goto out;
|
||||
|
||||
if (uuid && !dm_task_set_uuid(dmt, uuid))
|
||||
goto out;
|
||||
|
||||
if (!_parse_file(dmt, file))
|
||||
goto out;
|
||||
|
||||
@ -122,12 +125,12 @@ static int _load(int task, const char *name, const char *file)
|
||||
|
||||
static int _create(int argc, char **argv)
|
||||
{
|
||||
return _load(DM_DEVICE_CREATE, argv[1], argv[2]);
|
||||
return _load(DM_DEVICE_CREATE, argv[1], argv[2], argv[3]);
|
||||
}
|
||||
|
||||
static int _reload(int argc, char **argv)
|
||||
{
|
||||
return _load(DM_DEVICE_RELOAD, argv[1], argv[2]);
|
||||
return _load(DM_DEVICE_RELOAD, argv[1], argv[2], NULL);
|
||||
}
|
||||
|
||||
static int _rename(int argc, char **argv)
|
||||
@ -321,22 +324,23 @@ typedef int (*command_fn) (int argc, char **argv);
|
||||
struct command {
|
||||
char *name;
|
||||
char *help;
|
||||
int num_args;
|
||||
int min_args;
|
||||
int max_args;
|
||||
command_fn fn;
|
||||
};
|
||||
|
||||
static struct command _commands[] = {
|
||||
{"create", "<dev_name> <table_file>", 2, _create},
|
||||
{"remove", "<dev_name>", 1, _remove},
|
||||
{"remove_all", "", 0, _remove_all},
|
||||
{"suspend", "<dev_name>", 1, _suspend},
|
||||
{"resume", "<dev_name>", 1, _resume},
|
||||
{"reload", "<dev_name> <table_file>", 2, _reload},
|
||||
{"info", "<dev_name>", 1, _info},
|
||||
{"deps", "<dev_name>", 1, _deps},
|
||||
{"rename", "<dev_name> <new_name>", 2, _rename},
|
||||
{"version", "", 0, _version},
|
||||
{NULL, NULL, 0, NULL}
|
||||
{"create", "<dev_name> <table_file> [<uuid>]", 2, 3, _create},
|
||||
{"remove", "<dev_name>", 1, 1, _remove},
|
||||
{"remove_all", "", 0, 0, _remove_all},
|
||||
{"suspend", "<dev_name>", 1, 1, _suspend},
|
||||
{"resume", "<dev_name>", 1, 1, _resume},
|
||||
{"reload", "<dev_name> <table_file>", 2, 2, _reload},
|
||||
{"info", "<dev_name>", 1, 1, _info},
|
||||
{"deps", "<dev_name>", 1, 1, _deps},
|
||||
{"rename", "<dev_name> <new_name>", 2, 2, _rename},
|
||||
{"version", "", 0, 0, _version},
|
||||
{NULL, NULL, 0, 0, NULL}
|
||||
};
|
||||
|
||||
static void _usage(FILE * out)
|
||||
@ -412,7 +416,7 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (argc != c->num_args + 1) {
|
||||
if (argc < c->min_args + 1 || argc > c->max_args + 1) {
|
||||
fprintf(stderr, "Incorrect number of arguments\n");
|
||||
_usage(stderr);
|
||||
exit(1);
|
||||
|
Loading…
Reference in New Issue
Block a user