svn commit: r322969 - in head: sbin/mdconfig sys/dev/md sys/sys
Maxim Sobolev
sobomax at FreeBSD.org
Mon Aug 28 15:54:09 UTC 2017
Author: sobomax
Date: Mon Aug 28 15:54:07 2017
New Revision: 322969
URL: https://svnweb.freebsd.org/changeset/base/322969
Log:
Add ability to label md(4) devices.
This feature comes from the fact that we rely memory-backed md(4)
in our build process heavily. However, if the build goes haywire
the allocated resources (i.e. swap and memory-backed md(4)'s) need
to be purged. It is extremely useful to have ability to attach
arbitrary labels to each of the virtual disks so that they can
be identified and GC'ed if neecessary.
MFC after: 4 weeks
Differential Revision: https://reviews.freebsd.org/D10457
Modified:
head/sbin/mdconfig/mdconfig.8
head/sbin/mdconfig/mdconfig.c
head/sys/dev/md/md.c
head/sys/sys/mdioctl.h
Modified: head/sbin/mdconfig/mdconfig.8
==============================================================================
--- head/sbin/mdconfig/mdconfig.8 Mon Aug 28 14:49:26 2017 (r322968)
+++ head/sbin/mdconfig/mdconfig.8 Mon Aug 28 15:54:07 2017 (r322969)
@@ -37,7 +37,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 10, 2015
+.Dd August 28, 2017
.Dt MDCONFIG 8
.Os
.Sh NAME
@@ -55,6 +55,7 @@
.Op Fl u Ar unit
.Op Fl x Ar sectors/track
.Op Fl y Ar heads/cylinder
+.Op Fl L Ar label
.Nm
.Fl d
.Fl u Ar unit
@@ -189,6 +190,12 @@ and
options can be used to specify a synthetic geometry.
This is useful for constructing bootable images for later download to
other devices.
+.It Fl L Ar label
+Associate a label (arbitrary string) with the new memory disk.
+The label can then be inspected with
+.Bd -literal -offset indent
+.Nm Fl l v
+.Ed
.It Fl o Oo Cm no Oc Ns Ar option
Set or reset options.
.Bl -tag -width indent
Modified: head/sbin/mdconfig/mdconfig.c
==============================================================================
--- head/sbin/mdconfig/mdconfig.c Mon Aug 28 14:49:26 2017 (r322968)
+++ head/sbin/mdconfig/mdconfig.c Mon Aug 28 15:54:07 2017 (r322969)
@@ -79,7 +79,7 @@ usage(void)
fprintf(stderr,
"usage: mdconfig -a -t type [-n] [-o [no]option] ... [-f file]\n"
-" [-s size] [-S sectorsize] [-u unit]\n"
+" [-s size] [-S sectorsize] [-u unit] [-L label]\n"
" [-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"
@@ -102,15 +102,17 @@ main(int argc, char **argv)
bzero(&mdio, sizeof(mdio));
mdio.md_file = malloc(PATH_MAX);
- if (mdio.md_file == NULL)
+ mdio.md_label = malloc(PATH_MAX);
+ if (mdio.md_file == NULL || mdio.md_label == NULL)
err(1, "could not allocate memory");
vflag = 0;
bzero(mdio.md_file, PATH_MAX);
+ bzero(mdio.md_label, PATH_MAX);
if (argc == 1)
usage();
- while ((ch = getopt(argc, argv, "ab:df:lno:rs:S:t:u:vx:y:")) != -1) {
+ while ((ch = getopt(argc, argv, "ab:df:lno:rs:S:t:u:vx:y:L:")) != -1) {
switch (ch) {
case 'a':
if (action != UNSET && action != ATTACH)
@@ -243,6 +245,9 @@ main(int argc, char **argv)
case 'y':
mdio.md_fwheads = strtoul(optarg, &p, 0);
break;
+ case 'L':
+ strlcpy(mdio.md_label, optarg, PATH_MAX);
+ break;
default:
usage();
}
@@ -422,7 +427,8 @@ md_list(const char *units, int opt, const char *fflag)
struct gclass *gcl;
void *sq;
int retcode, ffound, ufound;
- char *type, *file, *length;
+ char *length;
+ const char *type, *file, *label;
type = file = length = NULL;
@@ -477,10 +483,14 @@ md_list(const char *units, int opt, const char *fflag)
printf("\t%s\t", type);
if (length != NULL)
md_prthumanval(length);
- if (file != NULL) {
- printf("\t%s", file);
- file = NULL;
- }
+ if (file == NULL)
+ file = "-";
+ printf("\t%s", file);
+ file = NULL;
+ label = geom_config_get(gc, "label");
+ if (label == NULL)
+ label = "";
+ printf("\t%s", label);
}
opt |= OPT_DONE;
if ((opt & OPT_LIST) && !(opt & OPT_VERBOSE))
Modified: head/sys/dev/md/md.c
==============================================================================
--- head/sys/dev/md/md.c Mon Aug 28 14:49:26 2017 (r322968)
+++ head/sys/dev/md/md.c Mon Aug 28 15:54:07 2017 (r322969)
@@ -226,6 +226,7 @@ struct md_s {
/* MD_VNODE related fields */
struct vnode *vnode;
char file[PATH_MAX];
+ char label[PATH_MAX];
struct ucred *cred;
/* MD_SWAP related fields */
@@ -1645,6 +1646,11 @@ xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr
}
if (sc == NULL)
return (error);
+ if (mdio->md_label != NULL)
+ error = copyinstr(mdio->md_label, sc->label,
+ sizeof(sc->label), NULL);
+ if (error != 0)
+ goto err_after_new;
if (mdio->md_options & MD_AUTOUNIT)
mdio->md_unit = sc->unit;
sc->mediasize = mdio->md_mediasize;
@@ -1676,6 +1682,7 @@ xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr
error = mdcreate_null(sc, mdio, td);
break;
}
+err_after_new:
if (error != 0) {
mddestroy(sc, td);
return (error);
@@ -1721,6 +1728,11 @@ xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr
mdio->md_options = sc->flags;
mdio->md_mediasize = sc->mediasize;
mdio->md_sectorsize = sc->sectorsize;
+ error = 0;
+ if (mdio->md_label != NULL) {
+ error = copyout(sc->label, mdio->md_label,
+ strlen(sc->label) + 1);
+ }
if (sc->type == MD_VNODE ||
(sc->type == MD_PRELOAD && mdio->md_file != NULL))
error = copyout(sc->file, mdio->md_file,
@@ -1873,6 +1885,7 @@ g_md_dumpconf(struct sbuf *sb, const char *indent, str
if ((mp->type == MD_VNODE && mp->vnode != NULL) ||
(mp->type == MD_PRELOAD && mp->file[0] != '\0'))
sbuf_printf(sb, " file %s", mp->file);
+ sbuf_printf(sb, " label %s", mp->label);
} else {
sbuf_printf(sb, "%s<unit>%d</unit>\n", indent,
mp->unit);
@@ -1897,6 +1910,9 @@ g_md_dumpconf(struct sbuf *sb, const char *indent, str
g_conf_printf_escaped(sb, "%s", mp->file);
sbuf_printf(sb, "</file>\n");
}
+ sbuf_printf(sb, "%s<label>", indent);
+ g_conf_printf_escaped(sb, "%s", mp->label);
+ sbuf_printf(sb, "</label>\n");
}
}
}
Modified: head/sys/sys/mdioctl.h
==============================================================================
--- head/sys/sys/mdioctl.h Mon Aug 28 14:49:26 2017 (r322968)
+++ head/sys/sys/mdioctl.h Mon Aug 28 15:54:07 2017 (r322969)
@@ -49,7 +49,7 @@ enum md_types {MD_MALLOC, MD_PRELOAD, MD_VNODE, MD_SWA
* Ioctl definitions for memory disk pseudo-device.
*/
-#define MDNPAD 97
+#define MDNPAD 96
struct md_ioctl {
unsigned md_version; /* Structure layout version */
unsigned md_unit; /* unit number */
@@ -61,6 +61,7 @@ struct md_ioctl {
u_int64_t md_base; /* base address */
int md_fwheads; /* firmware heads */
int md_fwsectors; /* firmware sectors */
+ char *md_label; /* label of the device */
int md_pad[MDNPAD]; /* padding for future ideas */
};
More information about the svn-src-head
mailing list