Author: tsoome Date: Mon Mar 20 19:16:28 2017 New Revision: 315648 URL: https://svnweb.freebsd.org/changeset/base/315648
Log: libstand: verify value provided by nfs.read_size Implement simple value check and feedback. Reviewed by: allanjude, rpokala Approved by: allanjude (mentor) Differential Revision: https://reviews.freebsd.org/D8491 Modified: head/lib/libstand/nfs.c Modified: head/lib/libstand/nfs.c ============================================================================== --- head/lib/libstand/nfs.c Mon Mar 20 18:28:22 2017 (r315647) +++ head/lib/libstand/nfs.c Mon Mar 20 19:16:28 2017 (r315648) @@ -214,6 +214,38 @@ struct fs_ops nfs_fsops = { 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 = (int)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) @@ -269,16 +301,7 @@ nfs_getrootfh(struct iodesc *d, char *pa return (ntohl(repl->errno)); bcopy(repl->fh, fhp, sizeof(repl->fh)); - /* - * Improve boot performance over NFS - */ - if (getenv("nfs.read_size") != NULL) - nfs_read_size = strtol(getenv("nfs.read_size"), NULL, 0); - if (nfs_read_size < NFSREAD_MIN_SIZE) - nfs_read_size = NFSREAD_MIN_SIZE; - if (nfs_read_size > NFSREAD_MAX_SIZE) - nfs_read_size = NFSREAD_MAX_SIZE; - + set_nfs_read_size(); return (0); } @@ -885,6 +908,8 @@ nfs_getrootfh(struct iodesc *d, char *pa return (ntohl(repl->errno)); *fhlenp = ntohl(repl->fhsize); bcopy(repl->fh, fhp, *fhlenp); + + set_nfs_read_size(); return (0); } _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"