return r;
}
-static int _create(int argc, char **argv)
+static int _create(int argc, char **argv, void *data)
{
if (argc == 1)
return _load(DM_DEVICE_CREATE, argv[1], NULL, NULL);
(argc == 3) ? argv[3] : NULL);
}
-static int _reload(int argc, char **argv)
+static int _reload(int argc, char **argv, void *data)
{
return _load(DM_DEVICE_RELOAD, argv[1], argv[2], NULL);
}
-static int _rename(int argc, char **argv)
+static int _rename(int argc, char **argv, void *data)
{
int r = 0;
struct dm_task *dmt;
return r;
}
-static int _version(int argc, char **argv)
+static int _version(int argc, char **argv, void *data)
{
int r = 0;
struct dm_task *dmt;
return r;
}
-static int _remove_all(int argc, char **argv)
+static int _remove_all(int argc, char **argv, void *data)
{
return _simple(DM_DEVICE_REMOVE_ALL, "", 0);
}
-static int _remove(int argc, char **argv)
+static int _remove(int argc, char **argv, void *data)
{
return _simple(DM_DEVICE_REMOVE, argv[1], 0);
}
-static int _suspend(int argc, char **argv)
+static int _suspend(int argc, char **argv, void *data)
{
return _simple(DM_DEVICE_SUSPEND, argv[1], 1);
}
-static int _resume(int argc, char **argv)
+static int _resume(int argc, char **argv, void *data)
{
return _simple(DM_DEVICE_RESUME, argv[1], 1);
}
-static int _clear(int argc, char **argv)
+static int _clear(int argc, char **argv, void *data)
{
return _simple(DM_DEVICE_CLEAR, argv[1], 1);
}
-static int _wait(int argc, char **argv)
+static int _wait(int argc, char **argv, void *data)
{
return _simple(DM_DEVICE_WAITEVENT, argv[1], 2);
}
-static int _status(int argc, char **argv)
+static int _process_all(int argc, char **argv,
+ int (*fn)(int argc, char **argv, void *data))
+{
+ int r = 0;
+ struct dm_names *names;
+ unsigned next = 0;
+
+ struct dm_task *dmt;
+
+ if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
+ return 0;
+
+ if (!dm_task_run(dmt))
+ goto out;
+
+ if (!(names = dm_task_get_names(dmt)))
+ goto out;
+
+ r = 1;
+ if (!names->dev) {
+ printf("No devices found\n");
+ goto out;
+ }
+
+ do {
+ names = (void *) names + next;
+ if (!fn(argc, argv, (void *)names))
+ r = 0;
+ next = names->next;
+ } while (next);
+
+ out:
+ dm_task_destroy(dmt);
+ return r;
+}
+
+static int _status(int argc, char **argv, void *data)
{
int r = 0;
struct dm_task *dmt;
char *target_type = NULL;
char *params;
int cmd;
+ struct dm_names *names = (struct dm_names *)data;
+ char *name;
+
+ if (argc == 1 && !data)
+ return _process_all(argc, argv, _status);
+
+ if (data)
+ name = names->name;
+ else
+ name = argv[1];
if (!strcmp(argv[0], "status"))
cmd = DM_DEVICE_STATUS;
if (!(dmt = dm_task_create(cmd)))
return 0;
- if (!dm_task_set_name(dmt, argv[1]))
+ if (!dm_task_set_name(dmt, name))
goto out;
if (!dm_task_run(dmt))
do {
next = dm_get_next_target(dmt, next, &start, &length,
&target_type, ¶ms);
+ if (data && !_switches[VERBOSE_ARG])
+ printf("%s: ", name);
if (target_type) {
printf("%" PRIu64 " %" PRIu64 " %s %s\n",
start, length, target_type, params);
}
} while (next);
+ if (data && _switches[VERBOSE_ARG])
+ printf("\n");
+
r = 1;
out:
}
-static int _info(int argc, char **argv)
+static int _info(int argc, char **argv, void *data)
{
int r = 0;
- /* remove <dev_name> */
struct dm_task *dmt;
+ struct dm_names *names = (struct dm_names *)data;
+ char *name;
+
+ if (argc == 1 && !data)
+ return _process_all(argc, argv, _info);
+
+ if (data)
+ name = names->name;
+ else
+ name = argv[1];
if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
return 0;
- if (!dm_task_set_name(dmt, argv[1]))
+ if (!dm_task_set_name(dmt, name))
goto out;
if (!dm_task_run(dmt))
goto out;
_display_info(dmt);
+
r = 1;
out:
return r;
}
-static int _deps(int argc, char **argv)
+static int _deps(int argc, char **argv, void *data)
{
int r = 0;
uint32_t i;
struct dm_deps *deps;
-
- /* remove <dev_name> */
struct dm_task *dmt;
struct dm_info info;
+ struct dm_names *names = (struct dm_names *)data;
+ char *name;
+
+ if (argc == 1 && !data)
+ return _process_all(argc, argv, _deps);
+
+ if (data)
+ name = names->name;
+ else
+ name = argv[1];
if (!(dmt = dm_task_create(DM_DEVICE_DEPS)))
return 0;
- if (!dm_task_set_name(dmt, argv[1]))
+ if (!dm_task_set_name(dmt, name))
goto out;
if (!dm_task_run(dmt))
if (_switches[VERBOSE_ARG])
_display_info(dmt);
+ if (data && !_switches[VERBOSE_ARG])
+ printf("%s: ", name);
printf("%d dependencies\t:", deps->count);
for (i = 0; i < deps->count; i++)
(int) MINOR(deps->device[i]));
printf("\n");
+ if (data && _switches[VERBOSE_ARG])
+ printf("\n");
+
r = 1;
out:
return r;
}
-static int _ls(int argc, char **argv)
+static int _display_name(int argc, char **argv, void *data)
{
- int r = 0;
- struct dm_names *names;
- unsigned next = 0;
-
- struct dm_task *dmt;
+ struct dm_names *names = (struct dm_names *)data;
- if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
- return 0;
+ printf("%s\t(%d, %d)\n", names->name,
+ (int) MAJOR(names->dev), (int) MINOR(names->dev));
- if (!dm_task_run(dmt))
- goto out;
-
- if (!(names = dm_task_get_names(dmt)))
- goto out;
-
- r = 1;
- if (!names->dev) {
- printf("No devices found\n");
- goto out;
- }
-
- do {
- names = (void *) names + next;
- printf("%s\t(%d, %d)\n", names->name,
- (int) MAJOR(names->dev), (int) MINOR(names->dev));
- next = names->next;
- } while (next);
+ return 1;
+}
- out:
- dm_task_destroy(dmt);
- return r;
+static int _ls(int argc, char **argv, void *data)
+{
+ return _process_all(argc, argv, _display_name);
}
/*
* dispatch table
*/
-typedef int (*command_fn) (int argc, char **argv);
+typedef int (*command_fn) (int argc, char **argv, void *data);
struct command {
const char *name;
{"reload", "<dev_name> <table_file>", 2, 2, _reload},
{"rename", "<dev_name> <new_name>", 2, 2, _rename},
{"ls", "", 0, 0, _ls},
- {"info", "<dev_name>", 1, 1, _info},
- {"deps", "<dev_name>", 1, 1, _deps},
- {"status", "<dev_name>", 1, 1, _status},
- {"table", "<dev_name>", 1, 1, _status},
+ {"info", "[<dev_name>]", 0, 1, _info},
+ {"deps", "[<dev_name>]", 0, 1, _deps},
+ {"status", "[<dev_name>]", 0, 1, _status},
+ {"table", "[<dev_name>]", 0, 1, _status},
{"wait", "<dev_name>", 1, 1, _wait},
{"version", "", 0, 0, _version},
{NULL, NULL, 0, 0, NULL}
}
doit:
- if (!c->fn(argc, argv)) {
+ if (!c->fn(argc, argv, NULL)) {
fprintf(stderr, "Command failed\n");
exit(1);
}