svn commit: r258909 - in head: sbin/mdconfig sys/dev/md sys/sys
Edward Tomasz Napierala
trasz at FreeBSD.org
Wed Dec 4 07:38:25 UTC 2013
Author: trasz
Date: Wed Dec 4 07:38:23 2013
New Revision: 258909
URL: http://svnweb.freebsd.org/changeset/base/258909
Log:
Add "null" backend to mdconfig(8). This does exactly what the name
suggests, and is somewhat useful for benchmarking.
MFC after: 1 month
No objections from: kib
Sponsored by: The FreeBSD Foundation
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 Wed Dec 4 05:06:56 2013 (r258908)
+++ head/sbin/mdconfig/mdconfig.8 Wed Dec 4 07:38:23 2013 (r258909)
@@ -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.
Modified: head/sbin/mdconfig/mdconfig.c
==============================================================================
--- head/sbin/mdconfig/mdconfig.c Wed Dec 4 05:06:56 2013 (r258908)
+++ head/sbin/mdconfig/mdconfig.c Wed Dec 4 07:38:23 2013 (r258909)
@@ -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 {
Modified: head/sys/dev/md/md.c
==============================================================================
--- head/sys/dev/md/md.c Wed Dec 4 05:06:56 2013 (r258908)
+++ head/sys/dev/md/md.c Wed Dec 4 07:38:23 2013 (r258909)
@@ -908,6 +908,22 @@ mdstart_swap(struct md_s *sc, struct bio
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)
{
@@ -1027,6 +1043,7 @@ mdinit(struct md_s *sc)
pp->flags |= G_PF_ACCEPT_UNMAPPED;
break;
case MD_PRELOAD:
+ case MD_NULL:
break;
}
sc->gp = gp;
@@ -1245,6 +1262,7 @@ mdresize(struct md_s *sc, struct md_ioct
switch (sc->type) {
case MD_VNODE:
+ case MD_NULL:
break;
case MD_SWAP:
if (mdio->md_mediasize <= 0 ||
@@ -1339,6 +1357,19 @@ mdcreate_swap(struct md_s *sc, struct md
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)
@@ -1371,6 +1402,7 @@ xmdctlioctl(struct cdev *dev, u_long cmd
case MD_PRELOAD:
case MD_VNODE:
case MD_SWAP:
+ case MD_NULL:
break;
default:
return (EINVAL);
@@ -1416,6 +1448,10 @@ xmdctlioctl(struct cdev *dev, u_long cmd
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);
@@ -1586,6 +1622,9 @@ g_md_dumpconf(struct sbuf *sb, const cha
case MD_SWAP:
type = "swap";
break;
+ case MD_NULL:
+ type = "null";
+ break;
default:
type = "unknown";
break;
Modified: head/sys/sys/mdioctl.h
==============================================================================
--- head/sys/sys/mdioctl.h Wed Dec 4 05:06:56 2013 (r258908)
+++ head/sys/sys/mdioctl.h Wed Dec 4 07:38:23 2013 (r258909)
@@ -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.
More information about the svn-src-head
mailing list