mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Move full mknodes functionality from dmsetup into libdevmapper.
This commit is contained in:
parent
a78374ae0d
commit
22eb54036f
@ -929,6 +929,81 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _process_mapper_dir(struct dm_task *dmt)
|
||||
{
|
||||
struct dirent *dirent;
|
||||
DIR *d;
|
||||
const char *dir;
|
||||
int r = 1;
|
||||
|
||||
dir = dm_dir();
|
||||
if (!(d = opendir(dir))) {
|
||||
fprintf(stderr, "opendir %s: %s", dir, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((dirent = readdir(d))) {
|
||||
if (!strcmp(dirent->d_name, ".") ||
|
||||
!strcmp(dirent->d_name, "..") ||
|
||||
!strcmp(dirent->d_name, "control"))
|
||||
continue;
|
||||
dm_task_set_name(dmt, dirent->d_name);
|
||||
dm_task_run(dmt);
|
||||
}
|
||||
|
||||
if (closedir(d)) {
|
||||
fprintf(stderr, "closedir %s: %s", dir, strerror(errno));
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _process_all_v4(struct dm_task *dmt)
|
||||
{
|
||||
struct dm_task *task;
|
||||
struct dm_names *names;
|
||||
unsigned next = 0;
|
||||
int r = 1;
|
||||
|
||||
if (!(task = dm_task_create(DM_DEVICE_LIST)))
|
||||
return 0;
|
||||
|
||||
if (!dm_task_run(task)) {
|
||||
r = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(names = dm_task_get_names(task))) {
|
||||
r = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!names->dev)
|
||||
goto out;
|
||||
|
||||
do {
|
||||
names = (void *) names + next;
|
||||
if (!dm_task_set_name(dmt, names->name)) {
|
||||
r = 0;
|
||||
goto out;
|
||||
}
|
||||
if (!dm_task_run(dmt))
|
||||
r = 0;
|
||||
next = names->next;
|
||||
} while (next);
|
||||
|
||||
out:
|
||||
dm_task_destroy(task);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _mknodes_v4(struct dm_task *dmt)
|
||||
{
|
||||
(void) _process_mapper_dir(dmt);
|
||||
|
||||
return _process_all_v4(dmt);
|
||||
}
|
||||
|
||||
static int _create_and_load_v4(struct dm_task *dmt)
|
||||
{
|
||||
struct dm_task *task;
|
||||
@ -1016,6 +1091,9 @@ int dm_task_run(struct dm_task *dmt)
|
||||
if (dmt->type == DM_DEVICE_CREATE && dmt->head)
|
||||
return _create_and_load_v4(dmt);
|
||||
|
||||
if (dmt->type == DM_DEVICE_MKNODES && !dmt->dev_name)
|
||||
return _mknodes_v4(dmt);
|
||||
|
||||
if (!_open_control())
|
||||
return 0;
|
||||
|
||||
|
@ -325,40 +325,6 @@ static int _wait(int argc, char **argv, void *data)
|
||||
(argc == 3) ? atoi(argv[2]) : 0, 1);
|
||||
}
|
||||
|
||||
static int _process_mapper_dir(int argc, char **argv,
|
||||
int (*fn) (int argc, char **argv, void *data))
|
||||
{
|
||||
struct dirent *dirent;
|
||||
struct dm_names *names;
|
||||
DIR *d;
|
||||
const char *dir;
|
||||
int r = 1;
|
||||
|
||||
dir = dm_dir();
|
||||
if (!(d = opendir(dir))) {
|
||||
fprintf(stderr, "opendir %s: %s", dir, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((dirent = readdir(d))) {
|
||||
if (!strcmp(dirent->d_name, ".") ||
|
||||
!strcmp(dirent->d_name, "..") ||
|
||||
!strcmp(dirent->d_name, "control"))
|
||||
continue;
|
||||
/* Set up names->name for _info */
|
||||
names = (void *) dirent->d_name -
|
||||
((void *) &names->name - (void *) &names->dev);
|
||||
if (!fn(argc, argv, names))
|
||||
r = 0;
|
||||
}
|
||||
|
||||
if (closedir(d)) {
|
||||
fprintf(stderr, "closedir %s: %s", dir, strerror(errno));
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _process_all(int argc, char **argv,
|
||||
int (*fn) (int argc, char **argv, void *data))
|
||||
{
|
||||
@ -368,9 +334,6 @@ static int _process_all(int argc, char **argv,
|
||||
|
||||
struct dm_task *dmt;
|
||||
|
||||
if (!strcmp(argv[0], "mknodes"))
|
||||
r = _process_mapper_dir(argc, argv, fn);
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
|
||||
return 0;
|
||||
|
||||
@ -495,14 +458,34 @@ static int _targets(int argc, char **argv, void *data)
|
||||
|
||||
}
|
||||
|
||||
static int _mknodes(int argc, char **argv, void *data)
|
||||
{
|
||||
struct dm_task *dmt;
|
||||
int r = 0;
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_MKNODES)))
|
||||
return 0;
|
||||
|
||||
if (argc == 2 && !dm_task_set_name(dmt, argv[1]))
|
||||
goto out;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _info(int argc, char **argv, void *data)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
struct dm_task *dmt;
|
||||
struct dm_names *names = (struct dm_names *) data;
|
||||
char *name;
|
||||
int taskno;
|
||||
char *name = NULL;
|
||||
|
||||
if (argc == 1 && !data)
|
||||
return _process_all(argc, argv, _info);
|
||||
@ -512,22 +495,16 @@ static int _info(int argc, char **argv, void *data)
|
||||
else
|
||||
name = argv[1];
|
||||
|
||||
if (!strcmp(argv[0], "mknodes"))
|
||||
taskno = DM_DEVICE_MKNODES;
|
||||
else
|
||||
taskno = DM_DEVICE_INFO;
|
||||
|
||||
if (!(dmt = dm_task_create(taskno)))
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
|
||||
return 0;
|
||||
|
||||
if (!dm_task_set_name(dmt, name))
|
||||
if (name && !dm_task_set_name(dmt, name))
|
||||
goto out;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
|
||||
if (taskno == DM_DEVICE_INFO)
|
||||
_display_info(dmt);
|
||||
_display_info(dmt);
|
||||
|
||||
r = 1;
|
||||
|
||||
@ -640,10 +617,10 @@ static struct command _commands[] = {
|
||||
{"ls", "", 0, 0, _ls},
|
||||
{"info", "[<dev_name>]", 0, 1, _info},
|
||||
{"deps", "[<dev_name>]", 0, 1, _deps},
|
||||
{"mknodes", "[<dev_name>]", 0, 1, _info},
|
||||
{"status", "[<dev_name>]", 0, 1, _status},
|
||||
{"table", "[<dev_name>]", 0, 1, _status},
|
||||
{"wait", "<dev_name> [<event_nr>]", 1, 2, _wait},
|
||||
{"mknodes", "[<dev_name>]", 0, 1, _mknodes},
|
||||
{"targets", "", 0, 0, _targets},
|
||||
{"version", "", 0, 0, _version},
|
||||
{NULL, NULL, 0, 0, NULL}
|
||||
|
Loading…
Reference in New Issue
Block a user