- Add "-f file" support to listing mode (-l). When a -f option is
specified, only md(4) devices which have the specified file as backing store are displayed. - Use MD_NAME instead of "md". - Use _PATH_DEV instead of "/dev/". MFC after: 1 week
This commit is contained in:
parent
9dbb63fe03
commit
b78ae23fdd
@ -41,7 +41,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd November 3, 2012
|
||||
.Dd June 20, 2013
|
||||
.Dt MDCONFIG 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -72,6 +72,7 @@
|
||||
.Fl l
|
||||
.Op Fl n
|
||||
.Op Fl v
|
||||
.Op Fl f Ar file
|
||||
.Op Fl u Ar unit
|
||||
.Nm
|
||||
.Ar file
|
||||
@ -131,6 +132,19 @@ List configured devices.
|
||||
If given with
|
||||
.Fl u ,
|
||||
display details about that particular device.
|
||||
If given with
|
||||
.Fl f Ar file ,
|
||||
display
|
||||
.Xr md 4
|
||||
device names of which
|
||||
.Ar file
|
||||
is used as the backing store.
|
||||
If both of
|
||||
.Fl u
|
||||
and
|
||||
.Fl f
|
||||
options are specified,
|
||||
display devices which match the two conditions.
|
||||
If the
|
||||
.Fl v
|
||||
option is specified, show all details.
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <libgeom.h>
|
||||
#include <libutil.h>
|
||||
#include <paths.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -59,9 +60,9 @@ static int nflag;
|
||||
|
||||
static void usage(void);
|
||||
static void md_set_file(const char *);
|
||||
static int md_find(char *, const char *);
|
||||
static int md_query(char *name);
|
||||
static int md_list(char *units, int opt);
|
||||
static int md_find(const char *, const char *);
|
||||
static int md_query(const char *, const int, const char *);
|
||||
static int md_list(const char *, int, const char *);
|
||||
static char *geom_config_get(struct gconf *g, const char *name);
|
||||
static void md_prthumanval(char *length);
|
||||
|
||||
@ -82,7 +83,7 @@ usage(void)
|
||||
" [-x sectors/track] [-y heads/cylinder]\n"
|
||||
" mdconfig -d -u unit [-o [no]force]\n"
|
||||
" mdconfig -r -u unit -s size [-o [no]force]\n"
|
||||
" mdconfig -l [-v] [-n] [-u unit]\n"
|
||||
" mdconfig -l [-v] [-n] [-f file] [-u unit]\n"
|
||||
" mdconfig file\n");
|
||||
fprintf(stderr, "\t\ttype = {malloc, vnode, swap}\n");
|
||||
fprintf(stderr, "\t\toption = {cluster, compress, reserve}\n");
|
||||
@ -215,7 +216,7 @@ main(int argc, char **argv)
|
||||
errx(1, "unknown suffix on -s argument");
|
||||
break;
|
||||
case 'u':
|
||||
if (!strncmp(optarg, "/dev/", 5))
|
||||
if (!strncmp(optarg, _PATH_DEV, 5))
|
||||
optarg += 5;
|
||||
if (!strncmp(optarg, MD_NAME, sizeof(MD_NAME) - 1))
|
||||
optarg += sizeof(MD_NAME) - 1;
|
||||
@ -298,8 +299,8 @@ main(int argc, char **argv)
|
||||
errx(1, "-x can only be used with -a");
|
||||
if (mdio.md_fwheads != 0)
|
||||
errx(1, "-y can only be used with -a");
|
||||
if (fflag != NULL)
|
||||
errx(1, "-f can only be used with -a");
|
||||
if (fflag != NULL && action != LIST)
|
||||
errx(1, "-f can only be used with -a and -l");
|
||||
if (tflag != NULL)
|
||||
errx(1, "-t can only be used with -a");
|
||||
if (argc > 0)
|
||||
@ -333,14 +334,14 @@ main(int argc, char **argv)
|
||||
if (!kld_isloaded("g_md") && kld_load("geom_md") == -1)
|
||||
err(1, "failed to load geom_md module");
|
||||
|
||||
fd = open("/dev/" MDCTL_NAME, O_RDWR, 0);
|
||||
fd = open(_PATH_DEV MDCTL_NAME, O_RDWR, 0);
|
||||
if (fd < 0)
|
||||
err(1, "open(/dev/%s)", MDCTL_NAME);
|
||||
err(1, "open(%s%s)", _PATH_DEV, MDCTL_NAME);
|
||||
|
||||
if (action == ATTACH) {
|
||||
i = ioctl(fd, MDIOCATTACH, &mdio);
|
||||
if (i < 0)
|
||||
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
||||
err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME);
|
||||
if (mdio.md_options & MD_AUTOUNIT)
|
||||
printf("%s%d\n", nflag ? "" : MD_NAME, mdio.md_unit);
|
||||
} else if (action == DETACH) {
|
||||
@ -348,22 +349,22 @@ main(int argc, char **argv)
|
||||
errx(1, "-d requires -u");
|
||||
i = ioctl(fd, MDIOCDETACH, &mdio);
|
||||
if (i < 0)
|
||||
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
||||
err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME);
|
||||
} else if (action == RESIZE) {
|
||||
if (mdio.md_options & MD_AUTOUNIT)
|
||||
errx(1, "-r requires -u");
|
||||
i = ioctl(fd, MDIOCRESIZE, &mdio);
|
||||
if (i < 0)
|
||||
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
||||
err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME);
|
||||
} else if (action == LIST) {
|
||||
if (mdio.md_options & MD_AUTOUNIT) {
|
||||
/*
|
||||
* Listing all devices. This is why we pass NULL
|
||||
* together with OPT_LIST.
|
||||
*/
|
||||
md_list(NULL, OPT_LIST | vflag);
|
||||
md_list(NULL, OPT_LIST | vflag, fflag);
|
||||
} else
|
||||
return (md_query(uflag));
|
||||
return (md_query(uflag, vflag, fflag));
|
||||
} else
|
||||
usage();
|
||||
close(fd);
|
||||
@ -397,7 +398,7 @@ md_set_file(const char *fn)
|
||||
* between list and query mode.
|
||||
*/
|
||||
static int
|
||||
md_list(char *units, int opt)
|
||||
md_list(const char *units, int opt, const char *fflag)
|
||||
{
|
||||
struct gmesh gm;
|
||||
struct gprovider *pp;
|
||||
@ -441,15 +442,20 @@ md_list(char *units, int opt)
|
||||
found = 1;
|
||||
}
|
||||
gc = &pp->lg_config;
|
||||
if (nflag && strncmp(pp->lg_name, "md", 2) == 0)
|
||||
type = geom_config_get(gc, "type");
|
||||
if (strcmp(type, "vnode") == 0) {
|
||||
file = geom_config_get(gc, "file");
|
||||
if (fflag != NULL &&
|
||||
strcmp(fflag, file) != 0)
|
||||
continue;
|
||||
}
|
||||
if (nflag && strncmp(pp->lg_name, MD_NAME, 2) == 0)
|
||||
printf("%s", pp->lg_name + 2);
|
||||
else
|
||||
printf("%s", pp->lg_name);
|
||||
|
||||
if (opt & OPT_VERBOSE || opt & OPT_UNIT) {
|
||||
type = geom_config_get(gc, "type");
|
||||
if (strcmp(type, "vnode") == 0)
|
||||
file = geom_config_get(gc, "file");
|
||||
if (opt & OPT_VERBOSE ||
|
||||
((opt & OPT_UNIT) && fflag == NULL)) {
|
||||
length = geom_config_get(gc, "length");
|
||||
printf("\t%s\t", type);
|
||||
if (length != NULL)
|
||||
@ -497,7 +503,7 @@ geom_config_get(struct gconf *g, const char *name)
|
||||
* otherwise.
|
||||
*/
|
||||
static int
|
||||
md_find(char *list, const char *name)
|
||||
md_find(const char *list, const char *name)
|
||||
{
|
||||
int ret;
|
||||
char num[16];
|
||||
@ -508,7 +514,7 @@ md_find(char *list, const char *name)
|
||||
if (ptr == NULL)
|
||||
return (-1);
|
||||
for (p = ptr; (u = strsep(&p, ",")) != NULL;) {
|
||||
if (strncmp(u, "/dev/", 5) == 0)
|
||||
if (strncmp(u, _PATH_DEV, 5) == 0)
|
||||
u += 5;
|
||||
/* Just in case user specified number instead of full name */
|
||||
snprintf(num, sizeof(num), "md%s", u);
|
||||
@ -538,8 +544,8 @@ md_prthumanval(char *length)
|
||||
}
|
||||
|
||||
static int
|
||||
md_query(char *name)
|
||||
md_query(const char *name, const int opt, const char *fflag)
|
||||
{
|
||||
|
||||
return (md_list(name, OPT_UNIT));
|
||||
return (md_list(name, opt | OPT_UNIT, fflag));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user