11558Srgrimes/* 21558Srgrimes * Copyright (c) 1989, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * This code is derived from software contributed to Berkeley by 61558Srgrimes * Rick Macklem at The University of Guelph. 71558Srgrimes * 81558Srgrimes * Redistribution and use in source and binary forms, with or without 91558Srgrimes * modification, are permitted provided that the following conditions 101558Srgrimes * are met: 111558Srgrimes * 1. Redistributions of source code must retain the above copyright 121558Srgrimes * notice, this list of conditions and the following disclaimer. 131558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141558Srgrimes * notice, this list of conditions and the following disclaimer in the 151558Srgrimes * documentation and/or other materials provided with the distribution. 161558Srgrimes * 4. Neither the name of the University nor the names of its contributors 171558Srgrimes * may be used to endorse or promote products derived from this software 181558Srgrimes * without specific prior written permission. 191558Srgrimes * 201558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301558Srgrimes * SUCH DAMAGE. 311558Srgrimes */ 321558Srgrimes 33114589Sobrien#if 0 341558Srgrimes#ifndef lint 3537667Scharnierstatic const char copyright[] = 361558Srgrimes"@(#) Copyright (c) 1989, 1993\n\ 371558Srgrimes The Regents of the University of California. All rights reserved.\n"; 38100635Speter#endif 391558Srgrimes 401558Srgrimes#ifndef lint 4123684Speterstatic char sccsid[] = "@(#)nfsiod.c 8.4 (Berkeley) 5/3/95"; 4237667Scharnier#endif 43100635Speter#endif 44114589Sobrien#include <sys/cdefs.h> 45114589Sobrien__FBSDID("$FreeBSD$"); 461558Srgrimes 471558Srgrimes#include <sys/param.h> 481558Srgrimes#include <sys/syslog.h> 491558Srgrimes#include <sys/wait.h> 50101651Smux#include <sys/linker.h> 512999Swollman#include <sys/mount.h> 52100635Speter#include <sys/sysctl.h> 531558Srgrimes 541558Srgrimes#include <err.h> 551558Srgrimes#include <stdio.h> 561558Srgrimes#include <stdlib.h> 571558Srgrimes#include <unistd.h> 581558Srgrimes 5996954Speter#define MAXNFSDCNT 20 601558Srgrimes 6196954Speterstatic void 6296954Speterusage(void) 6396954Speter{ 6496954Speter (void)fprintf(stderr, "usage: nfsiod [-n num_servers]\n"); 6596954Speter exit(1); 6696954Speter} 671558Srgrimes 681558Srgrimesint 6996954Spetermain(int argc, char *argv[]) 701558Srgrimes{ 71100635Speter int ch; 72101651Smux struct xvfsconf vfc; 7323684Speter int error; 74100635Speter unsigned int iodmin, iodmax, num_servers; 7596954Speter size_t len; 761558Srgrimes 7723684Speter error = getvfsbyname("nfs", &vfc); 78101651Smux if (error) { 79101676Smux if (kldload("nfs") == -1) 80101651Smux err(1, "kldload(nfs)"); 8123684Speter error = getvfsbyname("nfs", &vfc); 822999Swollman } 8396954Speter if (error) 842999Swollman errx(1, "NFS support is not available in the running kernel"); 852999Swollman 8696954Speter num_servers = 0; 8724359Simp while ((ch = getopt(argc, argv, "n:")) != -1) 881558Srgrimes switch (ch) { 891558Srgrimes case 'n': 901558Srgrimes num_servers = atoi(optarg); 9196954Speter if (num_servers < 1) { 92201015Sru warnx("nfsiod count %u; reset to %d", 9396954Speter num_servers, 1); 9496954Speter num_servers = 1; 951558Srgrimes } 9696954Speter if (num_servers > MAXNFSDCNT) { 97201015Sru warnx("nfsiod count %u; reset to %d", 9896954Speter num_servers, MAXNFSDCNT); 9996954Speter num_servers = MAXNFSDCNT; 10096954Speter } 1011558Srgrimes break; 1021558Srgrimes case '?': 1031558Srgrimes default: 1041558Srgrimes usage(); 1051558Srgrimes } 1061558Srgrimes argc -= optind; 1071558Srgrimes argv += optind; 1081558Srgrimes 10996954Speter if (argc > 0) 1101558Srgrimes usage(); 1111558Srgrimes 11296954Speter len = sizeof iodmin; 11396954Speter error = sysctlbyname("vfs.nfs.iodmin", &iodmin, &len, NULL, 0); 11496954Speter if (error < 0) 11596954Speter err(1, "sysctlbyname(\"vfs.nfs.iodmin\")"); 11696954Speter len = sizeof iodmax; 11796954Speter error = sysctlbyname("vfs.nfs.iodmax", &iodmax, &len, NULL, 0); 11896954Speter if (error < 0) 119144757Sbrooks err(1, "sysctlbyname(\"vfs.nfs.iodmax\")"); 120201015Sru if (num_servers == 0) { /* no change */ 121201015Sru printf("vfs.nfs.iodmin=%u\nvfs.nfs.iodmax=%u\n", 122201015Sru iodmin, iodmax); 123201015Sru exit(0); 124201015Sru } 12596954Speter /* Catch the case where we're lowering num_servers below iodmin */ 12696954Speter if (iodmin > num_servers) { 12796954Speter iodmin = num_servers; 12896954Speter error = sysctlbyname("vfs.nfs.iodmin", NULL, 0, &iodmin, 12996954Speter sizeof iodmin); 13096954Speter if (error < 0) 13196954Speter err(1, "sysctlbyname(\"vfs.nfs.iodmin\")"); 1321558Srgrimes } 13396954Speter iodmax = num_servers; 13496954Speter error = sysctlbyname("vfs.nfs.iodmax", NULL, 0, &iodmax, sizeof iodmax); 13596954Speter if (error < 0) 13696954Speter err(1, "sysctlbyname(\"vfs.nfs.iodmax\")"); 137100635Speter exit (0); 1381558Srgrimes} 1391558Srgrimes 140