From 761e0a63e1044ccfd693b8e94cdd88df65a5b3b7 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 6 Mar 2002 14:38:25 +0000 Subject: [PATCH] o Add support for getting dependencies for a device. o dmsetup dependencies --- libdm/ioctl/libdevmapper.c | 24 +++++++++++++++++--- libdm/libdevmapper.h | 11 ++++++++- tools/dmsetup.c | 46 +++++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/libdm/ioctl/libdevmapper.c b/libdm/ioctl/libdevmapper.c index e11810a66..12f511fc5 100644 --- a/libdm/ioctl/libdevmapper.c +++ b/libdm/ioctl/libdevmapper.c @@ -43,7 +43,7 @@ void dm_task_destroy(struct dm_task *dmt) free(dmt); } -int dm_task_get_driver_version(struct dm_task *dmt, char *version, +int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size) { if (!dmt->dmi) @@ -75,6 +75,11 @@ int dm_task_get_info(struct dm_task *dmt, struct dm_info *info) return 1; } +struct dm_deps *dm_task_get_deps(struct dm_task *dmt) +{ + return (struct dm_deps *) (((void *) dmt->dmi) + dmt->dmi->data_start); +} + int dm_task_set_ro(struct dm_task *dmt) { dmt->read_only = 1; @@ -92,8 +97,8 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname) } struct target *create_target(uint64_t start, - uint64_t len, - const char *type, const char *params) + uint64_t len, + const char *type, const char *params) { struct target *t = malloc(sizeof(*t)); @@ -171,6 +176,8 @@ static void *_add_target(struct target *t, void *out, void *end) static struct dm_ioctl *_flatten(struct dm_task *dmt) { + const size_t min_size = 16 * 1024; + struct dm_ioctl *dmi; struct target *t; size_t len = sizeof(struct dm_ioctl); @@ -191,6 +198,13 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt) if (dmt->newname) len += strlen(dmt->newname) + 1; + /* + * Give len a minimum size so that we have space to store + * dependencies or status information. + */ + if (len < min_size) + len = min_size; + if (!(dmi = malloc(len))) return NULL; @@ -276,6 +290,10 @@ int dm_task_run(struct dm_task *dmt) command = DM_INFO; break; + case DM_DEVICE_DEPS: + command = DM_DEP; + break; + case DM_DEVICE_RENAME: command = DM_RENAME; break; diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 53789feeb..3d3cd8e12 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -39,6 +39,7 @@ enum { DM_DEVICE_RESUME, DM_DEVICE_INFO, + DM_DEVICE_DEPS, DM_DEVICE_RENAME, DM_DEVICE_VERSION, @@ -66,10 +67,18 @@ struct dm_info { unsigned int target_count; }; +struct dm_deps { + unsigned int count; + dev_t device[0]; +}; + int dm_get_library_version(char *version, size_t size); -int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size); +int dm_task_get_driver_version(struct dm_task *dmt, char *version, + size_t size); int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi); +struct dm_deps *dm_task_get_deps(struct dm_task *dmt); + 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); diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 87834ac23..a4c905cc4 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -18,6 +18,7 @@ #include #include #include +#include #define LINE_SIZE 1024 @@ -171,7 +172,7 @@ static int _version(int argc, char **argv) if (!dm_task_run(dmt)) goto out; - if (!dm_task_get_driver_version(dmt, (char *)&version, + if (!dm_task_get_driver_version(dmt, (char *)&version, sizeof(version))) goto out; @@ -264,6 +265,48 @@ static int _info(int argc, char **argv) return r; } +static int _deps(int argc, char **argv) +{ + int r = 0, i; + struct dm_deps *deps; + + /* remove */ + struct dm_task *dmt; + struct dm_info info; + + if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) + return 0; + + if (!dm_task_set_name(dmt, argv[1])) + goto out; + + if (!dm_task_run(dmt)) + goto out; + + if (!(deps = dm_task_get_deps(dmt))) + goto out; + + if (!info.exists) { + printf("Device does not exist.\n"); + r = 1; + goto out; + } + + printf("%d dependencies\t:", deps->count); + + for (i = 0; i < deps->count; i++) + printf(" (%d, %d)", + (int) MAJOR(deps->device[i]), + (int) MINOR(deps->device[i])); + printf("\n"); + + r = 1; + + out: + dm_task_destroy(dmt); + return r; +} + /* * dispatch table @@ -284,6 +327,7 @@ static struct command _commands[] = { {"resume", "", 1, _resume}, {"reload", " ", 2, _reload}, {"info", "", 1, _info}, + {"dependencies", "", 1, _deps}, {"rename", " ", 2, _rename}, {"version", "", 0, _version}, {NULL, NULL, 0, NULL}