1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

o Add support for getting dependencies for a device.

o  dmsetup dependencies <dev>
This commit is contained in:
Joe Thornber 2002-03-06 14:38:25 +00:00
parent c021b9bb83
commit 761e0a63e1
3 changed files with 76 additions and 5 deletions

View File

@ -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;

View File

@ -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);

View File

@ -18,6 +18,7 @@
#include <errno.h>
#include <unistd.h>
#include <getopt.h>
#include <linux/kdev_t.h>
#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 <dev_name> */
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", "<dev_name>", 1, _resume},
{"reload", "<dev_name> <table_file>", 2, _reload},
{"info", "<dev_name>", 1, _info},
{"dependencies", "<dev_name>", 1, _deps},
{"rename", "<dev_name> <new_name>", 2, _rename},
{"version", "", 0, _version},
{NULL, NULL, 0, NULL}