summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2015-10-18 14:52:31 +0000
committertrasz <trasz@FreeBSD.org>2015-10-18 14:52:31 +0000
commitd3fb3a1ab26c790031581aa03fda3c00b29cfd4c (patch)
treef6bf76dab2947b461680cebbbc5ae5fa1048b68c
parent71228bfa842cbb3ff7cba8a27f18794bc9a46995 (diff)
downloadFreeBSD-src-d3fb3a1ab26c790031581aa03fda3c00b29cfd4c.zip
FreeBSD-src-d3fb3a1ab26c790031581aa03fda3c00b29cfd4c.tar.gz
MFC r258909:
Tweak mdconfig(8) manual page, in particular revise the EXAMPLES section. This removes stuff that doesn't really belong there, and simplifies examples for the basic operations. Sponsored by: The FreeBSD Foundation
-rw-r--r--sbin/mdconfig/mdconfig.84
-rw-r--r--sbin/mdconfig/mdconfig.c10
-rw-r--r--sys/dev/md/md.c39
-rw-r--r--sys/sys/mdioctl.h2
4 files changed, 50 insertions, 5 deletions
diff --git a/sbin/mdconfig/mdconfig.8 b/sbin/mdconfig/mdconfig.8
index d9a0d1f..1faba2b 100644
--- a/sbin/mdconfig/mdconfig.8
+++ b/sbin/mdconfig/mdconfig.8
@@ -41,7 +41,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 26, 2013
+.Dd November 30, 2013
.Dt MDCONFIG 8
.Os
.Sh NAME
@@ -122,6 +122,8 @@ Using
backing is generally preferred instead of using
.Cm malloc
backing.
+.It Cm null
+Bitsink; all writes do nothing, all reads return zeroes.
.El
.It Fl f Ar file
Filename to use for the vnode type memory disk.
diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c
index 4257dd7..d741c77 100644
--- a/sbin/mdconfig/mdconfig.c
+++ b/sbin/mdconfig/mdconfig.c
@@ -155,6 +155,9 @@ main(int argc, char **argv)
} else if (!strcmp(optarg, "swap")) {
mdio.md_type = MD_SWAP;
mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS;
+ } else if (!strcmp(optarg, "null")) {
+ mdio.md_type = MD_NULL;
+ mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS;
} else
errx(1, "unknown type: %s", optarg);
break;
@@ -287,9 +290,10 @@ main(int argc, char **argv)
}
}
- if ((mdio.md_type == MD_MALLOC || mdio.md_type == MD_SWAP) &&
- sflag == NULL)
- errx(1, "must specify -s for -t malloc or -t swap");
+ if ((mdio.md_type == MD_MALLOC || mdio.md_type == MD_SWAP ||
+ mdio.md_type == MD_NULL) && sflag == NULL)
+ errx(1, "must specify -s for -t malloc, -t swap, "
+ "or -t null");
if (mdio.md_type == MD_VNODE && mdio.md_file[0] == '\0')
errx(1, "must specify -f for -t vnode");
} else {
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index a2c7a78..dccd5b3 100644
--- a/sys/dev/md/md.c
+++ b/sys/dev/md/md.c
@@ -911,6 +911,22 @@ mdstart_swap(struct md_s *sc, struct bio *bp)
return (rv != VM_PAGER_ERROR ? 0 : ENOSPC);
}
+static int
+mdstart_null(struct md_s *sc, struct bio *bp)
+{
+
+ switch (bp->bio_cmd) {
+ case BIO_READ:
+ bzero(bp->bio_data, bp->bio_length);
+ cpu_flush_dcache(bp->bio_data, bp->bio_length);
+ break;
+ case BIO_WRITE:
+ break;
+ }
+ bp->bio_resid = 0;
+ return (0);
+}
+
static void
md_kthread(void *arg)
{
@@ -1030,6 +1046,7 @@ mdinit(struct md_s *sc)
pp->flags |= G_PF_ACCEPT_UNMAPPED;
break;
case MD_PRELOAD:
+ case MD_NULL:
break;
}
sc->gp = gp;
@@ -1248,6 +1265,7 @@ mdresize(struct md_s *sc, struct md_ioctl *mdio)
switch (sc->type) {
case MD_VNODE:
+ case MD_NULL:
break;
case MD_SWAP:
if (mdio->md_mediasize <= 0 ||
@@ -1342,6 +1360,19 @@ mdcreate_swap(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
return (error);
}
+static int
+mdcreate_null(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
+{
+
+ /*
+ * Range check. Disallow negative sizes or any size less then the
+ * size of a page. Then round to a page.
+ */
+ if (sc->mediasize <= 0 || (sc->mediasize % PAGE_SIZE) != 0)
+ return (EDOM);
+
+ return (0);
+}
static int
xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
@@ -1374,6 +1405,7 @@ xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread
case MD_PRELOAD:
case MD_VNODE:
case MD_SWAP:
+ case MD_NULL:
break;
default:
return (EINVAL);
@@ -1419,6 +1451,10 @@ xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread
sc->start = mdstart_swap;
error = mdcreate_swap(sc, mdio, td);
break;
+ case MD_NULL:
+ sc->start = mdstart_null;
+ error = mdcreate_null(sc, mdio, td);
+ break;
}
if (error != 0) {
mddestroy(sc, td);
@@ -1589,6 +1625,9 @@ g_md_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
case MD_SWAP:
type = "swap";
break;
+ case MD_NULL:
+ type = "null";
+ break;
default:
type = "unknown";
break;
diff --git a/sys/sys/mdioctl.h b/sys/sys/mdioctl.h
index 5efae79..acbfa4b 100644
--- a/sys/sys/mdioctl.h
+++ b/sys/sys/mdioctl.h
@@ -43,7 +43,7 @@
#ifndef _SYS_MDIOCTL_H_
#define _SYS_MDIOCTL_H_
-enum md_types {MD_MALLOC, MD_PRELOAD, MD_VNODE, MD_SWAP};
+enum md_types {MD_MALLOC, MD_PRELOAD, MD_VNODE, MD_SWAP, MD_NULL};
/*
* Ioctl definitions for memory disk pseudo-device.
OpenPOWER on IntegriCloud