aboutsummaryrefslogtreecommitdiff
path: root/sbin/mdconfig/mdconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/mdconfig/mdconfig.c')
-rw-r--r--sbin/mdconfig/mdconfig.c111
1 files changed, 86 insertions, 25 deletions
diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c
index 740f800e3e79..4b03dd81e591 100644
--- a/sbin/mdconfig/mdconfig.c
+++ b/sbin/mdconfig/mdconfig.c
@@ -56,7 +56,7 @@
static struct md_ioctl mdio;
static enum {UNSET, ATTACH, DETACH, RESIZE, LIST} action = UNSET;
-static int nflag;
+static int md_fd, nflag;
static void usage(void) __dead2;
static void md_set_file(const char *);
@@ -65,6 +65,7 @@ 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);
+static void print_options(const char *s, const char *);
#define OPT_VERBOSE 0x01
#define OPT_UNIT 0x02
@@ -86,11 +87,11 @@ usage(void)
" mdconfig -l [-v] [-n] [-f file] [-u unit]\n"
" mdconfig file\n");
fprintf(stderr, "\t\ttype = {malloc, vnode, swap}\n");
- fprintf(stderr, "\t\toption = {cache, cluster, compress, force,\n");
- fprintf(stderr, "\t\t mustdealloc, readonly, reserve, ro,\n");
- fprintf(stderr, "\t\t verify}\n");
+ fprintf(stderr, "\t\toption = {async, cache, compress,\n");
+ fprintf(stderr, "\t\t force, mustdealloc, readonly, ro,\n");
+ fprintf(stderr, "\t\t reserve, verify}\n");
fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%db (B),\n");
- fprintf(stderr, "\t\t %%dk (kB), %%dm (MB), %%dg (GB), \n");
+ fprintf(stderr, "\t\t %%dk (kB), %%dm (MB), %%dg (GB),\n");
fprintf(stderr, "\t\t %%dt (TB), or %%dp (PB)\n");
exit(1);
}
@@ -98,7 +99,7 @@ usage(void)
int
main(int argc, char **argv)
{
- int ch, fd, i, vflag;
+ int ch, i, vflag;
char *p;
char *fflag = NULL, *sflag = NULL, *tflag = NULL, *uflag = NULL;
@@ -155,13 +156,13 @@ main(int argc, char **argv)
mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS;
} else if (!strcmp(optarg, "vnode")) {
mdio.md_type = MD_VNODE;
- mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS;
+ mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS;
} else if (!strcmp(optarg, "swap")) {
mdio.md_type = MD_SWAP;
- mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS;
+ mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS;
} else if (!strcmp(optarg, "null")) {
mdio.md_type = MD_NULL;
- mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS;
+ mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS;
} else
errx(1, "unknown type: %s", optarg);
break;
@@ -181,10 +182,15 @@ main(int argc, char **argv)
mdio.md_options |= MD_CACHE;
else if (!strcmp(optarg, "nocache"))
mdio.md_options &= ~MD_CACHE;
- else if (!strcmp(optarg, "cluster"))
- mdio.md_options |= MD_CLUSTER;
- else if (!strcmp(optarg, "nocluster"))
- mdio.md_options &= ~MD_CLUSTER;
+ /*
+ * For backwards-compatibility, continue to recognize
+ * "cluster"
+ */
+ else if (!strcmp(optarg, "cluster") ||
+ !strcmp(optarg, "nocluster"))
+ {
+ warnx("Option cluster is ignored");
+ }
else if (!strcmp(optarg, "compress"))
mdio.md_options |= MD_COMPRESS;
else if (!strcmp(optarg, "nocompress"))
@@ -281,13 +287,11 @@ main(int argc, char **argv)
if (fflag != NULL || argc > 0) {
/* Imply ``-t vnode'' */
mdio.md_type = MD_VNODE;
- mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT |
- MD_COMPRESS;
+ mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS;
} else if (sflag != NULL) {
/* Imply ``-t swap'' */
mdio.md_type = MD_SWAP;
- mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT |
- MD_COMPRESS;
+ mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS;
} else
errx(1, "unable to determine type");
}
@@ -366,12 +370,12 @@ 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(_PATH_DEV MDCTL_NAME, O_RDWR, 0);
- if (fd < 0)
+ md_fd = open(_PATH_DEV MDCTL_NAME, O_RDWR, 0);
+ if (md_fd < 0)
err(1, "open(%s%s)", _PATH_DEV, MDCTL_NAME);
if (action == ATTACH) {
- i = ioctl(fd, MDIOCATTACH, &mdio);
+ i = ioctl(md_fd, MDIOCATTACH, &mdio);
if (i < 0)
err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME);
if (mdio.md_options & MD_AUTOUNIT)
@@ -379,13 +383,13 @@ main(int argc, char **argv)
} else if (action == DETACH) {
if (mdio.md_options & MD_AUTOUNIT)
errx(1, "-d requires -u");
- i = ioctl(fd, MDIOCDETACH, &mdio);
+ i = ioctl(md_fd, MDIOCDETACH, &mdio);
if (i < 0)
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);
+ i = ioctl(md_fd, MDIOCRESIZE, &mdio);
if (i < 0)
err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME);
} else if (action == LIST) {
@@ -399,11 +403,67 @@ main(int argc, char **argv)
return (md_query(uflag, vflag, fflag));
} else
usage();
- close(fd);
+ close(md_fd);
return (0);
}
static void
+print_options(const char *dev, const char *file)
+{
+ struct md_ioctl mdiox;
+ int unit;
+ const char *sep = "";
+
+ if (sscanf(dev, "md%d", &unit) != 1)
+ err(1, "invalid device: %s", dev);
+
+ memset(&mdiox, 0, sizeof(mdiox));
+ mdiox.md_version = MDIOVERSION;
+ mdiox.md_unit = unit;
+ mdiox.md_file = file[0] == '-' ? NULL : strdup(file);
+
+ if (ioctl(md_fd, MDIOCQUERY, &mdiox) < 0)
+ err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME);
+
+ if (mdiox.md_file != NULL)
+ free(mdiox.md_file);
+
+ printf("\t");
+ if (mdiox.md_options & MD_ASYNC) {
+ printf("%sasync", sep);
+ sep = ",";
+ }
+ if (mdiox.md_options & MD_CACHE) {
+ printf("%scache", sep);
+ sep = ",";
+ }
+ if (mdiox.md_options & MD_COMPRESS) {
+ printf("%scompress", sep);
+ sep = ",";
+ }
+ if (mdiox.md_options & MD_FORCE) {
+ printf("%sforce", sep);
+ sep = ",";
+ }
+ if (mdiox.md_options & MD_READONLY) {
+ printf("%sreadonly", sep);
+ sep = ",";
+ }
+ if (mdiox.md_options & MD_RESERVE) {
+ printf("%sreserve", sep);
+ sep = ",";
+ }
+ if (mdiox.md_options & MD_VERIFY) {
+ printf("%sverify", sep);
+ sep = ",";
+ }
+ if (mdiox.md_options & MD_MUSTDEALLOC) {
+ printf("%smustdealloc", sep);
+ sep = ",";
+ }
+}
+
+static void
md_set_file(const char *fn)
{
struct stat sb;
@@ -500,11 +560,12 @@ md_list(const char *units, int opt, const char *fflag)
if (file == NULL)
file = "-";
printf("\t%s", file);
- file = NULL;
label = geom_config_get(gc, "label");
if (label == NULL)
- label = "";
+ label = "-";
printf("\t%s", label);
+ print_options(pp->lg_name, file);
+ file = label = NULL;
}
opt |= OPT_DONE;
if ((opt & OPT_LIST) && !(opt & OPT_VERBOSE))