diff options
author | Toomas Soome <tsoome@me.com> | 2016-11-09 20:53:03 +0200 |
---|---|---|
committer | Dan McDonald <danmcd@omniti.com> | 2017-01-20 10:53:06 -0500 |
commit | b68080e04b742cedcb289c561db3fd1b9ca6fd03 (patch) | |
tree | f39ea230f940f6ff5f30b788055f68685a4b346e /usr/src/boot/lib/libstand | |
parent | ed5fe2f85936728de7ab82b44e9b9742c976d436 (diff) | |
download | illumos-joyent-b68080e04b742cedcb289c561db3fd1b9ca6fd03.tar.gz |
7559 pxeboot: Add nfs.read_size tunable.
Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Dan McDonald <danmcd@omniti.com>
Diffstat (limited to 'usr/src/boot/lib/libstand')
-rw-r--r-- | usr/src/boot/lib/libstand/nfs.c | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/usr/src/boot/lib/libstand/nfs.c b/usr/src/boot/lib/libstand/nfs.c index 29f8ecf514..d6b129adf2 100644 --- a/usr/src/boot/lib/libstand/nfs.c +++ b/usr/src/boot/lib/libstand/nfs.c @@ -29,13 +29,13 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/time.h> #include <sys/socket.h> #include <sys/stat.h> #include <string.h> +#include <stddef.h> #include <netinet/in.h> #include <netinet/in_systm.h> @@ -50,7 +50,8 @@ __FBSDID("$FreeBSD$"); #define NFS_DEBUGxx -#define NFSREAD_SIZE 1024 +#define NFSREAD_MIN_SIZE 1024 +#define NFSREAD_MAX_SIZE 4096 /* Define our own NFS attributes without NQNFS stuff. */ #ifdef OLD_NFSV2 @@ -83,7 +84,7 @@ struct nfs_read_repl { n_long errno; struct nfsv2_fattrs fa; n_long count; - u_char data[NFSREAD_SIZE]; + u_char data[NFSREAD_MAX_SIZE]; }; #ifndef NFS_NOSYMLINK @@ -210,6 +211,40 @@ struct fs_ops nfs_fsops = { nfs_readdir }; +static int nfs_read_size = NFSREAD_MIN_SIZE; + +/* + * Improve boot performance over NFS + */ +static void +set_nfs_read_size(void) +{ + char *env, *end; + char buf[10]; + + if ((env = getenv("nfs.read_size")) != NULL) { + errno = 0; + nfs_read_size = strtol(env, &end, 0); + if (errno != 0 || *env == '\0' || *end != '\0') { + printf("%s: bad value: \"%s\", defaulting to %d\n", + "nfs.read_size", env, NFSREAD_MIN_SIZE); + nfs_read_size = NFSREAD_MIN_SIZE; + } + } + if (nfs_read_size < NFSREAD_MIN_SIZE) { + printf("%s: bad value: \"%d\", defaulting to %d\n", + "nfs.read_size", nfs_read_size, NFSREAD_MIN_SIZE); + nfs_read_size = NFSREAD_MIN_SIZE; + } + if (nfs_read_size > NFSREAD_MAX_SIZE) { + printf("%s: bad value: \"%d\", defaulting to %d\n", + "nfs.read_size", nfs_read_size, NFSREAD_MIN_SIZE); + nfs_read_size = NFSREAD_MAX_SIZE; + } + snprintf(buf, sizeof (buf), "%d", nfs_read_size); + setenv("nfs.read_size", buf, 1); +} + #ifdef OLD_NFSV2 /* * Fetch the root file handle (call mount daemon) @@ -264,6 +299,8 @@ nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp) if (repl->errno) return (ntohl(repl->errno)); bcopy(repl->fh, fhp, sizeof(repl->fh)); + + set_nfs_read_size(); return (0); } @@ -401,11 +438,11 @@ nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len) bcopy(d->fh, args->fh, NFS_FHSIZE); args->off = htonl((n_long)off); - if (len > NFSREAD_SIZE) - len = NFSREAD_SIZE; + if (len > nfs_read_size) + len = nfs_read_size; args->len = htonl((n_long)len); args->xxx = htonl((n_long)0); - hlen = sizeof(*repl) - NFSREAD_SIZE; + hlen = offsetof(struct nfs_read_rpl, data[0]); cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ, args, sizeof(*args), @@ -870,6 +907,8 @@ nfs_getrootfh(struct iodesc *d, char *path, uint32_t *fhlenp, u_char *fhp) return (ntohl(repl->errno)); *fhlenp = ntohl(repl->fhsize); bcopy(repl->fh, fhp, *fhlenp); + + set_nfs_read_size(); return (0); } @@ -1025,7 +1064,7 @@ nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len) uint32_t count; uint32_t eof; uint32_t len; - u_char data[NFSREAD_SIZE]; + u_char data[NFSREAD_MAX_SIZE]; } *repl; struct { uint32_t h[RPC_HEADER_WORDS]; @@ -1048,10 +1087,10 @@ nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len) pos = roundup(d->fhsize, sizeof(uint32_t)) / sizeof(uint32_t); args->fhoffcnt[pos++] = 0; args->fhoffcnt[pos++] = htonl((uint32_t)off); - if (len > NFSREAD_SIZE) - len = NFSREAD_SIZE; + if (len > nfs_read_size) + len = nfs_read_size; args->fhoffcnt[pos] = htonl((uint32_t)len); - hlen = sizeof(*repl) - NFSREAD_SIZE; + hlen = offsetof(struct repl, data[0]); cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_READ, args, 4 * sizeof(uint32_t) + roundup(d->fhsize, sizeof(uint32_t)), |