From nobody@FreeBSD.org  Mon Aug  1 12:00:27 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id D8FDD1065774
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Aug 2011 12:00:27 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id C972B8FC1F
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Aug 2011 12:00:27 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p71C0RXx075177
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 1 Aug 2011 12:00:27 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p71C0RTS075176;
	Mon, 1 Aug 2011 12:00:27 GMT
	(envelope-from nobody)
Message-Id: <201108011200.p71C0RTS075176@red.freebsd.org>
Date: Mon, 1 Aug 2011 12:00:27 GMT
From: Svatopluk Kraus <onwahe@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] - divide by zero in mountnfs()
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         159351
>Category:       kern
>Synopsis:       [nfs] [patch] - divide by zero in mountnfs()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-fs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 01 12:10:05 UTC 2011
>Closed-Date:    
>Last-Modified:  Tue Nov 15 01:40:03 UTC 2011
>Originator:     Svatopluk Kraus
>Release:        current
>Organization:
>Environment:
>Description:
When nm_wcommitsize is initializing and desiredvnodes is less than 1000 a divide by zero happens.
>How-To-Repeat:

>Fix:
Index: sys/fs/nfsclient/nfs_clvfsops.c
===================================================================
--- sys/fs/nfsclient/nfs_clvfsops.c	(revision 224571)
+++ sys/fs/nfsclient/nfs_clvfsops.c	(working copy)
@@ -1238,7 +1238,7 @@
 		nmp->nm_rsize = NFS_RSIZE;
 		nmp->nm_readdirsize = NFS_READDIRSIZE;
 	}
-	nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000);
+	nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000 + 1);
 	nmp->nm_numgrps = NFS_MAXGRPS;
 	nmp->nm_readahead = NFS_DEFRAHEAD;
 	nmp->nm_tprintf_delay = nfs_tprintf_delay;

Index: sys/nfsclient/nfs_vfsops.c
===================================================================
--- sys/nfsclient/nfs_vfsops.c	(revision 224571)
+++ sys/nfsclient/nfs_vfsops.c	(working copy)
@@ -1244,7 +1244,7 @@
 		nmp->nm_wsize = NFS_WSIZE;
 		nmp->nm_rsize = NFS_RSIZE;
 	}
-	nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000);
+	nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000 + 1);
 	nmp->nm_readdirsize = NFS_READDIRSIZE;
 	nmp->nm_numgrps = NFS_MAXGRPS;
 	nmp->nm_readahead = NFS_DEFRAHEAD;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Aug 5 01:30:23 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=159351 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/159351: commit references a PR
Date: Tue, 15 Nov 2011 01:39:16 +0000 (UTC)

 Author: rmacklem
 Date: Tue Nov 15 01:39:02 2011
 New Revision: 227517
 URL: http://svn.freebsd.org/changeset/base/227517
 
 Log:
   Move the setting of the default value for nm_wcommitsize to
   before the nfs_decode_args() call in the new NFS client, so
   that a specfied command line value won't be overwritten.
   Also, modify the calculation for small values of desiredvnodes
   to avoid an unusually large value or a divide by zero crash.
   It seems that the default value for nm_wcommitsize is very
   conservative and may need to change at some time.
   
   PR:		kern/159351
   Submitted by:	onwahe at gmail.com (earlier version)
   Reviewed by:	jhb
   MFC after:	2 weeks
 
 Modified:
   head/sys/fs/nfsclient/nfs_clvfsops.c
 
 Modified: head/sys/fs/nfsclient/nfs_clvfsops.c
 ==============================================================================
 --- head/sys/fs/nfsclient/nfs_clvfsops.c	Mon Nov 14 23:01:08 2011	(r227516)
 +++ head/sys/fs/nfsclient/nfs_clvfsops.c	Tue Nov 15 01:39:02 2011	(r227517)
 @@ -1231,6 +1231,10 @@ mountnfs(struct nfs_args *argp, struct m
  	nmp->nm_timeo = NFS_TIMEO;
  	nmp->nm_retry = NFS_RETRANS;
  	nmp->nm_readahead = NFS_DEFRAHEAD;
 +	if (desiredvnodes >= 11000)
 +		nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000);
 +	else
 +		nmp->nm_wcommitsize = hibufspace / 10;
  
  	nfs_decode_args(mp, nmp, argp, hst, cred, td);
  
 @@ -1252,7 +1256,6 @@ mountnfs(struct nfs_args *argp, struct m
  		nmp->nm_rsize = NFS_RSIZE;
  		nmp->nm_readdirsize = NFS_READDIRSIZE;
  	}
 -	nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000);
  	nmp->nm_numgrps = NFS_MAXGRPS;
  	nmp->nm_tprintf_delay = nfs_tprintf_delay;
  	if (nmp->nm_tprintf_delay < 0)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
