1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

Add --target <target_type> filter to dmsetup table/status.

Fix dmsetup getopt_long usage.
This commit is contained in:
Alasdair Kergon 2005-05-16 14:53:23 +00:00
parent 6b4f3d63b8
commit 6250023583
3 changed files with 42 additions and 22 deletions

View File

@ -1,5 +1,7 @@
Version 1.01.02 - Version 1.01.02 -
============================= =============================
Add --target <target_type> filter to dmsetup table/status.
Fix dmsetup getopt_long usage.
Version 1.01.01 - 29 Mar 2005 Version 1.01.01 - 29 Mar 2005
============================= =============================

View File

@ -40,10 +40,10 @@ dmsetup \- low level logical volume management
.B dmsetup deps .B dmsetup deps
.I [device_name] .I [device_name]
.br .br
.B dmsetup status .B dmsetup status [--target target_type]
.I [device_name] .I [device_name]
.br .br
.B dmsetup table .B dmsetup table [--target target_type]
.I [device_name] .I [device_name]
.br .br
.B dmsetup wait .B dmsetup wait
@ -172,9 +172,12 @@ Un-suspends a device.
If an inactive table has been loaded, it becomes live. If an inactive table has been loaded, it becomes live.
Postponed I/O then gets re-queued for processing. Postponed I/O then gets re-queued for processing.
.IP \fBstatus .IP \fBstatus
.I [--target target_type]
.I [device_name] .I [device_name]
.br .br
Outputs status information for each of the device's targets. Outputs status information for each of the device's targets.
With --target, only information relating to the specified target type
is displayed.
.IP \fBsuspend .IP \fBsuspend
.I device_name .I device_name
.br .br
@ -182,10 +185,13 @@ Suspends a device. Any I/O that has already been mapped by the device
but has not yet completed will be flushed. Any further I/O to that but has not yet completed will be flushed. Any further I/O to that
device will be postponed for as long as the device is suspended. device will be postponed for as long as the device is suspended.
.IP \fBtable .IP \fBtable
.I [--target target_type]
.I [device_name] .I [device_name]
.br .br
Outputs the current table for the device in a format that can be fed Outputs the current table for the device in a format that can be fed
back in using the create or load commands. back in using the create or load commands.
With --target, only information relating to the specified target type
is displayed.
.IP \fBtargets .IP \fBtargets
.br .br
Displays the names and versions of the currently-loaded targets. Displays the names and versions of the currently-loaded targets.

View File

@ -62,6 +62,7 @@ enum {
NOOPENCOUNT_ARG, NOOPENCOUNT_ARG,
NOTABLE_ARG, NOTABLE_ARG,
OPTIONS_ARG, OPTIONS_ARG,
TARGET_ARG,
UUID_ARG, UUID_ARG,
VERBOSE_ARG, VERBOSE_ARG,
VERSION_ARG, VERSION_ARG,
@ -72,6 +73,7 @@ static int _switches[NUM_SWITCHES];
static int _values[NUM_SWITCHES]; static int _values[NUM_SWITCHES];
static char *_uuid; static char *_uuid;
static char *_fields; static char *_fields;
static char *_target;
/* /*
* Commands * Commands
@ -609,6 +611,7 @@ static int _status(int argc, char **argv, void *data)
int cmd; int cmd;
struct dm_names *names = (struct dm_names *) data; struct dm_names *names = (struct dm_names *) data;
char *name = NULL; char *name = NULL;
int matched = 0;
if (data) if (data)
name = names->name; name = names->name;
@ -636,13 +639,16 @@ static int _status(int argc, char **argv, void *data)
if (!dm_task_run(dmt)) if (!dm_task_run(dmt))
goto out; goto out;
if (_switches[VERBOSE_ARG])
_display_info(dmt);
/* Fetch targets and print 'em */ /* Fetch targets and print 'em */
do { do {
next = dm_get_next_target(dmt, next, &start, &length, next = dm_get_next_target(dmt, next, &start, &length,
&target_type, &params); &target_type, &params);
/* Skip if target type doesn't match */
if (_switches[TARGET_ARG] && target_type &&
strcmp(target_type, _target))
continue;
if (!matched && _switches[VERBOSE_ARG])
_display_info(dmt);
if (data && !_switches[VERBOSE_ARG]) if (data && !_switches[VERBOSE_ARG])
printf("%s: ", name); printf("%s: ", name);
if (target_type) { if (target_type) {
@ -650,9 +656,10 @@ static int _status(int argc, char **argv, void *data)
start, length, target_type, params); start, length, target_type, params);
} }
printf("\n"); printf("\n");
matched = 1;
} while (next); } while (next);
if (data && _switches[VERBOSE_ARG]) if (data && _switches[VERBOSE_ARG] && matched)
printf("\n"); printf("\n");
r = 1; r = 1;
@ -867,8 +874,8 @@ static struct command _commands[] = {
{"ls", "", 0, 0, _ls}, {"ls", "", 0, 0, _ls},
{"info", "[<device>]", 0, 1, _info}, {"info", "[<device>]", 0, 1, _info},
{"deps", "[<device>]", 0, 1, _deps}, {"deps", "[<device>]", 0, 1, _deps},
{"status", "[<device>]", 0, 1, _status}, {"status", "[<device>] [--target <target_type>]", 0, 1, _status},
{"table", "[<device>]", 0, 1, _status}, {"table", "[<device>] [--target <target_type>]", 0, 1, _status},
{"wait", "<device> [<event_nr>]", 0, 2, _wait}, {"wait", "<device> [<event_nr>]", 0, 2, _wait},
{"mknodes", "[<device>]", 0, 1, _mknodes}, {"mknodes", "[<device>]", 0, 1, _mknodes},
{"targets", "", 0, 0, _targets}, {"targets", "", 0, 0, _targets},
@ -905,22 +912,23 @@ static struct command *_find_command(const char *name)
static int _process_switches(int *argc, char ***argv) static int _process_switches(int *argc, char ***argv)
{ {
char *base, *namebase; char *base, *namebase;
int ind; static int ind;
int c; int c;
#ifdef HAVE_GETOPTLONG #ifdef HAVE_GETOPTLONG
static struct option long_options[] = { static struct option long_options[] = {
{"readonly", 0, NULL, READ_ONLY}, {"readonly", 0, &ind, READ_ONLY},
{"columns", 0, NULL, COLS_ARG}, {"columns", 0, &ind, COLS_ARG},
{"major", 1, NULL, MAJOR_ARG}, {"major", 1, &ind, MAJOR_ARG},
{"minor", 1, NULL, MINOR_ARG}, {"minor", 1, &ind, MINOR_ARG},
{"noheadings", 0, NULL, NOHEADINGS_ARG}, {"noheadings", 0, &ind, NOHEADINGS_ARG},
{"noopencount", 0, NULL, NOOPENCOUNT_ARG}, {"noopencount", 0, &ind, NOOPENCOUNT_ARG},
{"notable", 0, NULL, NOTABLE_ARG}, {"notable", 0, &ind, NOTABLE_ARG},
{"options", 1, NULL, OPTIONS_ARG}, {"options", 1, &ind, OPTIONS_ARG},
{"uuid", 1, NULL, UUID_ARG}, {"target", 1, &ind, TARGET_ARG},
{"verbose", 1, NULL, VERBOSE_ARG}, {"uuid", 1, &ind, UUID_ARG},
{"version", 0, NULL, VERSION_ARG}, {"verbose", 1, &ind, VERBOSE_ARG},
{"version", 0, &ind, VERSION_ARG},
{"", 0, NULL, 0} {"", 0, NULL, 0}
}; };
#else #else
@ -969,8 +977,8 @@ static int _process_switches(int *argc, char ***argv)
optarg = 0; optarg = 0;
optind = OPTIND_INIT; optind = OPTIND_INIT;
while ((c = GETOPTLONG_FN(*argc, *argv, "cCj:m:no:ru:v", while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCj:m:no:ru:v",
long_options, &ind)) != -1) { long_options, NULL)) != -1) {
if (c == 'c' || c == 'C' || ind == COLS_ARG) if (c == 'c' || c == 'C' || ind == COLS_ARG)
_switches[COLS_ARG]++; _switches[COLS_ARG]++;
if (c == 'r' || ind == READ_ONLY) if (c == 'r' || ind == READ_ONLY)
@ -995,6 +1003,10 @@ static int _process_switches(int *argc, char ***argv)
_switches[UUID_ARG]++; _switches[UUID_ARG]++;
_uuid = optarg; _uuid = optarg;
} }
if ((ind == TARGET_ARG)) {
_switches[TARGET_ARG]++;
_target = optarg;
}
if ((ind == NOHEADINGS_ARG)) if ((ind == NOHEADINGS_ARG))
_switches[NOHEADINGS_ARG]++; _switches[NOHEADINGS_ARG]++;
if ((ind == NOOPENCOUNT_ARG)) if ((ind == NOOPENCOUNT_ARG))