From ebe789d61c70e3c9dc31441e9d59f051b40ba30b Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Mon, 3 Mar 2003 13:05:00 +0000 Subject: [PATCH] Add a "-S sectorsize" option to enable Kirk to find a bug :-) --- sbin/mdconfig/mdconfig.8 | 3 +++ sbin/mdconfig/mdconfig.c | 9 +++++++-- sys/dev/md/md.c | 8 +++++++- sys/sys/mdioctl.h | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sbin/mdconfig/mdconfig.8 b/sbin/mdconfig/mdconfig.8 index 3b3583e986be..2ed1bdd6ad21 100644 --- a/sbin/mdconfig/mdconfig.8 +++ b/sbin/mdconfig/mdconfig.8 @@ -57,6 +57,7 @@ .Oc .Op Fl s Ar size .Op Fl f Ar file +.Op Fl S Ar sectorsize .Op Fl u Ar unit .Nm .Fl d @@ -111,6 +112,8 @@ or .Cm g which denotes kilobyte, megabyte and gigabyte respectively. +.It Fl S Ar sectorsize +Sectorsize to use for malloc backed device. .It Fl o Oo Cm no Oc Ns Ar option Set or reset options. .Bl -tag -width indent diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index f92e6a989c16..8ead3ad61391 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -37,7 +37,7 @@ void usage() { fprintf(stderr, "usage:\n"); - fprintf(stderr, "\tmdconfig -a -t type [-o [no]option]... [ -f file] [-s size] [-u unit]\n"); + fprintf(stderr, "\tmdconfig -a -t type [-o [no]option]... [ -f file] [-s size] [-S sectorsize] [-u unit]\n"); fprintf(stderr, "\tmdconfig -d -u unit\n"); fprintf(stderr, "\tmdconfig -l [-u unit]\n"); fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n"); @@ -54,7 +54,7 @@ main(int argc, char **argv) int cmdline = 0; for (;;) { - ch = getopt(argc, argv, "ab:df:lo:s:t:u:"); + ch = getopt(argc, argv, "ab:df:lo:s:S:t:u:"); if (ch == -1) break; switch (ch) { @@ -130,6 +130,11 @@ main(int argc, char **argv) else errx(1, "Unknown option."); break; + case 'S': + if (cmdline != 2) + usage(); + mdio.md_secsize = strtoul(optarg, &p, 0); + break; case 's': if (cmdline != 2) usage(); diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index c03d10eeb6a5..7b754cba3313 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -746,6 +746,8 @@ mdcreate_malloc(struct md_ioctl *mdio) return (EINVAL); if (mdio->md_options & ~(MD_AUTOUNIT | MD_COMPRESS | MD_RESERVE)) return (EINVAL); + if (mdio->md_secsize != 0 && !powerof2(mdio->md_secsize)) + return (EINVAL); /* Compression doesn't make sense if we have reserved space */ if (mdio->md_options & MD_RESERVE) mdio->md_options &= ~MD_COMPRESS; @@ -760,8 +762,12 @@ mdcreate_malloc(struct md_ioctl *mdio) return (EBUSY); } sc->type = MD_MALLOC; - sc->secsize = DEV_BSIZE; + if (mdio->md_secsize != 0) + sc->secsize = mdio->md_secsize; + else + sc->secsize = DEV_BSIZE; sc->nsect = mdio->md_size; + sc->nsect /= (sc->secsize / DEV_BSIZE); sc->flags = mdio->md_options & (MD_COMPRESS | MD_FORCE); sc->indir = dimension(sc->nsect); sc->uma = uma_zcreate(sc->name, sc->secsize, diff --git a/sys/sys/mdioctl.h b/sys/sys/mdioctl.h index 15a70e138def..89b95221f89c 100644 --- a/sys/sys/mdioctl.h +++ b/sys/sys/mdioctl.h @@ -53,7 +53,7 @@ enum md_types {MD_MALLOC, MD_PRELOAD, MD_VNODE, MD_SWAP}; * Ioctl definitions for memory disk pseudo-device. */ -#define MDNPAD 100 +#define MDNPAD 99 struct md_ioctl { unsigned md_version; /* Structure layout version */ unsigned md_unit; /* unit number */ @@ -62,6 +62,7 @@ struct md_ioctl { unsigned md_size; /* size of disk in DEV_BSIZE units */ unsigned md_options; /* options */ u_int64_t md_base; /* base address */ + int md_secsize; /* sectorsize */ int md_pad[MDNPAD]; /* padding for future ideas */ };