From ad21a5585cf309ef7bd12ded353774c3f2fc2faa Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 11 Mar 2002 22:44:36 +0000 Subject: [PATCH] Let dmsetup store the uuid on device creation. --- libdm/ioctl/libdevmapper.c | 6 ++++++ libdm/ioctl/libdm-targets.h | 2 ++ libdm/libdevmapper.h | 1 + libdm/libdm-common.c | 19 ++++++++++++++++++- tools/dmsetup.c | 36 ++++++++++++++++++++---------------- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/libdm/ioctl/libdevmapper.c b/libdm/ioctl/libdevmapper.c index 1d9076dec..3a88a1a80 100644 --- a/libdm/ioctl/libdevmapper.c +++ b/libdm/ioctl/libdevmapper.c @@ -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); diff --git a/libdm/ioctl/libdm-targets.h b/libdm/ioctl/libdm-targets.h index 5a0e30f03..b8d21a8cc 100644 --- a/libdm/ioctl/libdm-targets.h +++ b/libdm/ioctl/libdm-targets.h @@ -23,5 +23,7 @@ struct dm_task { int minor; struct dm_ioctl *dmi; char *newname; + + char *uuid; }; diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index a47e264c2..bc97b8ac1 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -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. diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index b6d61db52..5c97e85ae 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -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; diff --git a/tools/dmsetup.c b/tools/dmsetup.c index fe6e2e141..4faf98682 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -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", " ", 2, _create}, - {"remove", "", 1, _remove}, - {"remove_all", "", 0, _remove_all}, - {"suspend", "", 1, _suspend}, - {"resume", "", 1, _resume}, - {"reload", " ", 2, _reload}, - {"info", "", 1, _info}, - {"deps", "", 1, _deps}, - {"rename", " ", 2, _rename}, - {"version", "", 0, _version}, - {NULL, NULL, 0, NULL} + {"create", " []", 2, 3, _create}, + {"remove", "", 1, 1, _remove}, + {"remove_all", "", 0, 0, _remove_all}, + {"suspend", "", 1, 1, _suspend}, + {"resume", "", 1, 1, _resume}, + {"reload", " ", 2, 2, _reload}, + {"info", "", 1, 1, _info}, + {"deps", "", 1, 1, _deps}, + {"rename", " ", 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);