1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +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}}, {"waitevent", DM_DEV_WAIT, {4, 0, 0}},
{"names", DM_LIST_DEVICES, {4, 0, 0}}, {"names", DM_LIST_DEVICES, {4, 0, 0}},
{"clear", DM_TABLE_CLEAR, {4, 0, 0}}, {"clear", DM_TABLE_CLEAR, {4, 0, 0}},
{"mknodes", DM_DEV_STATUS, {4, 0, 0}},
}; };
/* *INDENT-ON* */ /* *INDENT-ON* */
@ -483,6 +484,14 @@ static int _dm_task_run_v1(struct dm_task *dmt)
rename_dev_node(dmt->dev_name, dmt->newname); rename_dev_node(dmt->dev_name, dmt->newname);
break; 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_STATUS:
case DM_DEVICE_TABLE: case DM_DEVICE_TABLE:
if (!_unmarshal_status_v1(dmt, dmi)) 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, log_debug("dm %s %s %s %s", _cmd_data_v4[dmt->type].name, dmi->name,
dmi->uuid, dmt->newname ? dmt->newname : ""); dmi->uuid, dmt->newname ? dmt->newname : "");
if (ioctl(_control_fd, command, dmi) < 0) { 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 */ dmi->flags &= ~DM_EXISTS_FLAG; /* FIXME */
goto ignore_error; goto ignore_error;
} }
@ -1038,6 +1048,14 @@ int dm_task_run(struct dm_task *dmt)
rename_dev_node(dmt->dev_name, dmt->newname); rename_dev_node(dmt->dev_name, dmt->newname);
break; 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_STATUS:
case DM_DEVICE_TABLE: case DM_DEVICE_TABLE:
case DM_DEVICE_WAITEVENT: 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} }, { "status", DM_TARGET_STATUS_V1, {1, 0, 0} },
{ "table", DM_TARGET_STATUS_V1, {1, 0, 0} }, { "table", DM_TARGET_STATUS_V1, {1, 0, 0} },
{ "waitevent", DM_TARGET_WAIT_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* */ /* *INDENT-ON* */

View File

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

View File

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