diff options
author | Maxim Sobolev <sobomax@FreeBSD.org> | 2017-08-28 15:54:07 +0000 |
---|---|---|
committer | Maxim Sobolev <sobomax@FreeBSD.org> | 2017-08-28 15:54:07 +0000 |
commit | f7ca2bbe447a5224efb4078fdd1d29910f495b91 (patch) | |
tree | cb56738fbda43529121c81ce104b97435b0fe35d /sys/dev/md/md.c | |
parent | 505f20a67b7448f332704d03ab3ceb0b83a0bf87 (diff) | |
download | src-f7ca2bbe447a5224efb4078fdd1d29910f495b91.tar.gz src-f7ca2bbe447a5224efb4078fdd1d29910f495b91.zip |
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
Notes
Notes:
svn path=/head/; revision=322969
Diffstat (limited to 'sys/dev/md/md.c')
-rw-r--r-- | sys/dev/md/md.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index 6a85dc449bd7..d9c41f130235 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -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, int flags, struct thread } 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, int flags, struct thread 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, int flags, struct thread 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, struct g_geom *gp, 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, struct g_geom *gp, 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"); } } } |