Add "-n" argument, which causes mdconfig to simply print the unit
number X, rather than mdX, making it easier to script tests that use md devices but don't want to make assumptions about any existing md use (such as in diskless environments).
This commit is contained in:
parent
7ddc2528b7
commit
f79c46d3f4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=116194
@ -51,6 +51,7 @@
|
|||||||
.Nm
|
.Nm
|
||||||
.Fl a
|
.Fl a
|
||||||
.Fl t Ar type
|
.Fl t Ar type
|
||||||
|
.Op Fl n
|
||||||
.Oo
|
.Oo
|
||||||
.Fl o
|
.Fl o
|
||||||
.Oo Cm no Oc Ns Ar option
|
.Oo Cm no Oc Ns Ar option
|
||||||
@ -64,6 +65,7 @@
|
|||||||
.Fl u Ar unit
|
.Fl u Ar unit
|
||||||
.Nm
|
.Nm
|
||||||
.Fl l
|
.Fl l
|
||||||
|
.Op Fl n
|
||||||
.Op Fl u Ar unit
|
.Op Fl u Ar unit
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
@ -103,6 +105,9 @@ devices. If the
|
|||||||
.Fl u
|
.Fl u
|
||||||
option is used in conjuction with this, the output is limited to
|
option is used in conjuction with this, the output is limited to
|
||||||
information on the specified device.
|
information on the specified device.
|
||||||
|
.It Fl n
|
||||||
|
When printing md device names, print only the unit number without the
|
||||||
|
md prefix.
|
||||||
.It Fl s Ar size
|
.It Fl s Ar size
|
||||||
Size of the memory disk.
|
Size of the memory disk.
|
||||||
.Ar Size
|
.Ar Size
|
||||||
|
@ -33,13 +33,15 @@ struct md_ioctl mdio;
|
|||||||
|
|
||||||
enum {UNSET, ATTACH, DETACH, LIST} action = UNSET;
|
enum {UNSET, ATTACH, DETACH, LIST} action = UNSET;
|
||||||
|
|
||||||
|
int nflag;
|
||||||
|
|
||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage:\n");
|
fprintf(stderr, "usage:\n");
|
||||||
fprintf(stderr, "\tmdconfig -a -t type [-o [no]option]... [ -f file] [-s size] [-S sectorsize] [-u unit]\n");
|
fprintf(stderr, "\tmdconfig -a -t type [-n] [-o [no]option]... [ -f file] [-s size] [-S sectorsize] [-u unit]\n");
|
||||||
fprintf(stderr, "\tmdconfig -d -u unit\n");
|
fprintf(stderr, "\tmdconfig -d -u unit\n");
|
||||||
fprintf(stderr, "\tmdconfig -l [-u unit]\n");
|
fprintf(stderr, "\tmdconfig -l [-n] [-u unit]\n");
|
||||||
fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n");
|
fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n");
|
||||||
fprintf(stderr, "\t\toption = {cluster, compress, reserve}\n");
|
fprintf(stderr, "\t\toption = {cluster, compress, reserve}\n");
|
||||||
fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%dk (kB), %%dm (MB) or %%dg (GB)\n");
|
fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%dk (kB), %%dm (MB) or %%dg (GB)\n");
|
||||||
@ -54,7 +56,7 @@ main(int argc, char **argv)
|
|||||||
int cmdline = 0;
|
int cmdline = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ch = getopt(argc, argv, "ab:df:lo:s:S:t:u:x:y:");
|
ch = getopt(argc, argv, "ab:df:lno:s:S:t:u:x:y:");
|
||||||
if (ch == -1)
|
if (ch == -1)
|
||||||
break;
|
break;
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@ -78,6 +80,9 @@ main(int argc, char **argv)
|
|||||||
mdio.md_options = MD_AUTOUNIT;
|
mdio.md_options = MD_AUTOUNIT;
|
||||||
cmdline = 3;
|
cmdline = 3;
|
||||||
break;
|
break;
|
||||||
|
case 'n':
|
||||||
|
nflag = 1;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
if (cmdline != 1)
|
if (cmdline != 1)
|
||||||
usage();
|
usage();
|
||||||
@ -202,7 +207,7 @@ main(int argc, char **argv)
|
|||||||
if (i < 0)
|
if (i < 0)
|
||||||
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
||||||
if (mdio.md_options & MD_AUTOUNIT)
|
if (mdio.md_options & MD_AUTOUNIT)
|
||||||
printf("%s%d\n", MD_NAME, mdio.md_unit);
|
printf("%s%d\n", nflag ? "" : MD_NAME, mdio.md_unit);
|
||||||
} else if (action == DETACH) {
|
} else if (action == DETACH) {
|
||||||
if (mdio.md_options & MD_AUTOUNIT)
|
if (mdio.md_options & MD_AUTOUNIT)
|
||||||
usage();
|
usage();
|
||||||
@ -230,7 +235,8 @@ list(const int fd)
|
|||||||
if (ioctl(fd, MDIOCLIST, &mdio) < 0)
|
if (ioctl(fd, MDIOCLIST, &mdio) < 0)
|
||||||
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
||||||
for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) {
|
for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) {
|
||||||
printf("%smd%d", unit > 0 ? " " : "", mdio.md_pad[unit + 1]);
|
printf("%s%s%d", unit > 0 ? " " : "",
|
||||||
|
nflag ? "" : MD_NAME, mdio.md_pad[unit + 1]);
|
||||||
}
|
}
|
||||||
if (mdio.md_pad[0] - unit > 0)
|
if (mdio.md_pad[0] - unit > 0)
|
||||||
printf(" ... %d more", mdio.md_pad[0] - unit);
|
printf(" ... %d more", mdio.md_pad[0] - unit);
|
||||||
|
Loading…
Reference in New Issue
Block a user