1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 10:25:13 +03:00

dmsetup mknodes

This commit is contained in:
Alasdair Kergon 2003-11-13 13:14:28 +00:00
parent f7dd6d8446
commit 2864846d91
4 changed files with 96 additions and 23 deletions

View File

@ -79,6 +79,7 @@ static struct cmd_data _cmd_data_v4[] = {
{"waitevent", DM_DEV_WAIT, {4, 0, 0}},
{"names", DM_LIST_DEVICES, {4, 0, 0}},
{"clear", DM_TABLE_CLEAR, {4, 0, 0}},
{"mknodes", DM_DEV_STATUS, {4, 0, 0}},
};
/* *INDENT-ON* */
@ -483,6 +484,14 @@ static int _dm_task_run_v1(struct dm_task *dmt)
rename_dev_node(dmt->dev_name, dmt->newname);
break;
case DM_DEVICE_MKNODES:
if (dmi->flags & DM_EXISTS_FLAG)
add_dev_node(dmt->dev_name, MAJOR(dmi->dev),
MINOR(dmi->dev));
else
rm_dev_node(dmt->dev_name);
break;
case DM_DEVICE_STATUS:
case DM_DEVICE_TABLE:
if (!_unmarshal_status_v1(dmt, dmi))
@ -1011,7 +1020,8 @@ int dm_task_run(struct dm_task *dmt)
log_debug("dm %s %s %s %s", _cmd_data_v4[dmt->type].name, dmi->name,
dmi->uuid, dmt->newname ? dmt->newname : "");
if (ioctl(_control_fd, command, dmi) < 0) {
if (errno == ENXIO && dmt->type == DM_DEVICE_INFO) {
if (errno == ENXIO && ((dmt->type == DM_DEVICE_INFO) ||
(dmt->type == DM_DEVICE_MKNODES))) {
dmi->flags &= ~DM_EXISTS_FLAG; /* FIXME */
goto ignore_error;
}
@ -1038,6 +1048,14 @@ int dm_task_run(struct dm_task *dmt)
rename_dev_node(dmt->dev_name, dmt->newname);
break;
case DM_DEVICE_MKNODES:
if (dmi->flags & DM_EXISTS_FLAG)
add_dev_node(dmt->dev_name, MAJOR(dmi->dev),
MINOR(dmi->dev));
else
rm_dev_node(dmt->dev_name);
break;
case DM_DEVICE_STATUS:
case DM_DEVICE_TABLE:
case DM_DEVICE_WAITEVENT:

View File

@ -102,7 +102,9 @@ static struct cmd_data _cmd_data_v1[] = {
{ "status", DM_TARGET_STATUS_V1, {1, 0, 0} },
{ "table", DM_TARGET_STATUS_V1, {1, 0, 0} },
{ "waitevent", DM_TARGET_WAIT_V1, {1, 0, 0} },
{ "names", 0, {4, 0, 0} }
{ "names", 0, {4, 0, 0} },
{ "clear", 0, {4, 0, 0} },
{ "mknodes", 0, {4, 0, 0} },
};
/* *INDENT-ON* */

View File

@ -55,7 +55,9 @@ enum {
DM_DEVICE_LIST,
DM_DEVICE_CLEAR
DM_DEVICE_CLEAR,
DM_DEVICE_MKNODES
};
struct dm_task;

View File

@ -10,6 +10,8 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#ifdef HAVE_GETOPTLONG
@ -172,7 +174,7 @@ static int _load(int task, const char *name, const char *file, const char *uuid)
if (!_switches[NOTABLE_ARG] && !_parse_file(dmt, file))
goto out;
if (_switches[READ_ONLY] && !dm_task_set_ro(dmt))
goto out;
@ -209,7 +211,7 @@ static int _reload(int argc, char **argv, void *data)
return 0;
}
return _load(DM_DEVICE_RELOAD, argv[1],
return _load(DM_DEVICE_RELOAD, argv[1],
(argc == 3) ? argv[2] : NULL, NULL);
}
@ -320,25 +322,65 @@ static int _wait(int argc, char **argv, void *data)
return _simple(DM_DEVICE_WAITEVENT, argv[1], 2);
}
static int _process_all(int argc, char **argv,
int (*fn)(int argc, char **argv, void *data))
static int _process_mapper_dir(int argc, char **argv,
int (*fn) (int argc, char **argv, void *data))
{
int r = 0;
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))
{
int r = 1;
struct dm_names *names;
unsigned next = 0;
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;
if (!dm_task_run(dmt))
if (!dm_task_run(dmt)) {
r = 0;
goto out;
}
if (!(names = dm_task_get_names(dmt)))
if (!(names = dm_task_get_names(dmt))) {
r = 0;
goto out;
}
r = 1;
if (!names->dev) {
printf("No devices found\n");
goto out;
@ -346,7 +388,7 @@ static int _process_all(int argc, char **argv,
do {
names = (void *) names + next;
if (!fn(argc, argv, (void *)names))
if (!fn(argc, argv, (void *) names))
r = 0;
next = names->next;
} while (next);
@ -365,7 +407,7 @@ static int _status(int argc, char **argv, void *data)
char *target_type = NULL;
char *params;
int cmd;
struct dm_names *names = (struct dm_names *)data;
struct dm_names *names = (struct dm_names *) data;
char *name;
if (argc == 1 && !data)
@ -376,10 +418,10 @@ static int _status(int argc, char **argv, void *data)
else
name = argv[1];
if (!strcmp(argv[0], "status"))
cmd = DM_DEVICE_STATUS;
else
if (!strcmp(argv[0], "table"))
cmd = DM_DEVICE_TABLE;
else
cmd = DM_DEVICE_STATUS;
if (!(dmt = dm_task_create(cmd)))
return 0;
@ -421,8 +463,9 @@ static int _info(int argc, char **argv, void *data)
int r = 0;
struct dm_task *dmt;
struct dm_names *names = (struct dm_names *)data;
struct dm_names *names = (struct dm_names *) data;
char *name;
int taskno;
if (argc == 1 && !data)
return _process_all(argc, argv, _info);
@ -432,7 +475,12 @@ static int _info(int argc, char **argv, void *data)
else
name = argv[1];
if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
if (!strcmp(argv[0], "mknodes"))
taskno = DM_DEVICE_MKNODES;
else
taskno = DM_DEVICE_INFO;
if (!(dmt = dm_task_create(taskno)))
return 0;
if (!dm_task_set_name(dmt, name))
@ -441,7 +489,8 @@ static int _info(int argc, char **argv, void *data)
if (!dm_task_run(dmt))
goto out;
_display_info(dmt);
if (taskno == DM_DEVICE_INFO)
_display_info(dmt);
r = 1;
@ -457,7 +506,7 @@ static int _deps(int argc, char **argv, void *data)
struct dm_deps *deps;
struct dm_task *dmt;
struct dm_info info;
struct dm_names *names = (struct dm_names *)data;
struct dm_names *names = (struct dm_names *) data;
char *name;
if (argc == 1 && !data)
@ -514,7 +563,7 @@ static int _deps(int argc, char **argv, void *data)
static int _display_name(int argc, char **argv, void *data)
{
struct dm_names *names = (struct dm_names *)data;
struct dm_names *names = (struct dm_names *) data;
printf("%s\t(%d, %d)\n", names->name,
(int) MAJOR(names->dev), (int) MINOR(names->dev));
@ -554,6 +603,7 @@ 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>", 1, 1, _wait},
@ -567,7 +617,8 @@ static void _usage(FILE *out)
fprintf(out, "Usage:\n\n");
fprintf(out, "dmsetup [--version] [-v|--verbose [-v|--verbose ...]]\n"
" [-r|--readonly] [-j|--major <major>] [-m|--minor <minor>]\n\n");
" [-r|--readonly] [-j|--major <major>] "
"[-m|--minor <minor>]\n\n");
for (i = 0; _commands[i].name; i++)
fprintf(out, "\t%s %s\n", _commands[i].name, _commands[i].help);
return;
@ -613,7 +664,7 @@ static int _process_switches(int *argc, char ***argv)
optarg = 0;
optind = OPTIND_INIT;
while ((c = GETOPTLONG_FN(*argc, *argv, "j:m:nru:v",
long_options, &ind)) != -1) {
long_options, &ind)) != -1) {
if (c == 'r' || ind == READ_ONLY)
_switches[READ_ONLY]++;
if (c == 'j' || ind == MAJOR_ARG) {