From hrs@allbsd.org  Tue Sep 26 15:44:01 2006
Return-Path: <hrs@allbsd.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9605A16A555
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 26 Sep 2006 15:44:01 +0000 (UTC)
	(envelope-from hrs@allbsd.org)
Received: from mail.allbsd.org (vlsi00.si.noda.tus.ac.jp [133.31.130.32])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6E43343D69
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 26 Sep 2006 15:42:34 +0000 (GMT)
	(envelope-from hrs@allbsd.org)
Received: from delta.allbsd.org (p4159-ipbf315funabasi.chiba.ocn.ne.jp [122.16.242.159])
	(authenticated bits=128)
	by mail.allbsd.org (8.13.1/8.13.4) with ESMTP id k8QFgK3u057066
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Sep 2006 00:42:33 +0900 (JST)
	(envelope-from hrs@allbsd.org)
Received: from alph.allbsd.org (alph.allbsd.org [192.168.0.10])
	by delta.allbsd.org (8.13.4/8.13.4) with ESMTP id k8QFfhjW080751
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Sep 2006 00:41:44 +0900 (JST)
	(envelope-from hrs@alph.d.allbsd.org)
Received: from alph.allbsd.org (localhost [127.0.0.1])
	by alph.allbsd.org (8.13.4/8.13.4) with ESMTP id k8QFfhYC036510
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Sep 2006 00:41:43 +0900 (JST)
	(envelope-from hrs@alph.d.allbsd.org)
Received: (from hrs@localhost)
	by alph.allbsd.org (8.13.4/8.13.4/Submit) id k8QFfhUU036509;
	Wed, 27 Sep 2006 00:41:43 +0900 (JST)
	(envelope-from hrs)
Message-Id: <200609261541.k8QFfhUU036509@alph.allbsd.org>
Date: Wed, 27 Sep 2006 00:41:43 +0900 (JST)
From: Hiroki Sato <hrs@freebsd.org>
Reply-To: Hiroki Sato <hrs@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: nfsstat(1) should use %u instead of %d to display NFS stats
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         103682
>Category:       bin
>Synopsis:       [patch] [request] nfsstat(1) should use %u instead of %d to display NFS stats
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 26 15:50:16 GMT 2006
>Closed-Date:    
>Last-Modified:  Sun Jan 27 10:38:25 UTC 2008
>Originator:     Hiroki Sato
>Release:        FreeBSD 6.1-RELEASE i386
>Organization:
Tokyo University of Science
>Environment:
System: FreeBSD unknown.allbsd.org 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Tue May 16 23:08:51 JST 2006     hrs@unknown.allbsd.org:/usr/obj/usr/src/sys/UNKNOWN  i386

>Description:
	Although nfsstat(1) uses %d in printf() to display the NFS stats,
	on a busy NFS server/client the stat numbers can become more than
	2147483647 (2^31 - 1, 32-bit int case) and negative numbers are
	printed.  The numbers should be interpreted as unsigned int, and
	displayed by using %u instead.

>How-To-Repeat:
	Use nfsstat(1) on a busy NFS server/client.
>Fix:
	A patch is attached.  Also, I think it is better to change members	
	in struct nfsstats/nfsrvstats from int to uint64_t or so if possible.

Index: nfsstat.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/nfsstat/nfsstat.c,v
retrieving revision 1.21
diff -u -r1.21 nfsstat.c
--- nfsstat.c	11 Jul 2004 17:37:33 -0000	1.21
+++ nfsstat.c	26 Sep 2006 14:58:49 -0000
@@ -224,7 +224,7 @@
 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
 			"Getattr", "Setattr", "Lookup", "Readlink", "Read",
 			"Write", "Create", "Remove");
-		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u %9u %9u %9u %9u\n",
 			nfsstats.rpccnt[NFSPROC_GETATTR],
 			nfsstats.rpccnt[NFSPROC_SETATTR],
 			nfsstats.rpccnt[NFSPROC_LOOKUP],
@@ -236,7 +236,7 @@
 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
 			"Rename", "Link", "Symlink", "Mkdir", "Rmdir",
 			"Readdir", "RdirPlus", "Access");
-		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u %9u %9u %9u %9u\n",
 			nfsstats.rpccnt[NFSPROC_RENAME],
 			nfsstats.rpccnt[NFSPROC_LINK],
 			nfsstats.rpccnt[NFSPROC_SYMLINK],
@@ -247,7 +247,7 @@
 			nfsstats.rpccnt[NFSPROC_ACCESS]);
 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
 			"Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
-		printf("%9d %9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u %9u\n",
 			nfsstats.rpccnt[NFSPROC_MKNOD],
 			nfsstats.rpccnt[NFSPROC_FSSTAT],
 			nfsstats.rpccnt[NFSPROC_FSINFO],
@@ -257,7 +257,7 @@
 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
 			"TimedOut", "Invalid", "X Replies", "Retries", 
 			"Requests");
-		printf("%9d %9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u %9u\n",
 			nfsstats.rpctimeouts,
 			nfsstats.rpcinvalid,
 			nfsstats.rpcunexpected,
@@ -268,10 +268,10 @@
 			"Attr Hits", "Misses", "Lkup Hits", "Misses");
 		printf(" %9.9s %9.9s %9.9s %9.9s\n",
 			"BioR Hits", "Misses", "BioW Hits", "Misses");
-		printf("%9d %9d %9d %9d",
+		printf("%9u %9u %9u %9u",
 			nfsstats.attrcache_hits, nfsstats.attrcache_misses,
 			nfsstats.lookupcache_hits, nfsstats.lookupcache_misses);
-		printf(" %9d %9d %9d %9d\n",
+		printf(" %9u %9u %9u %9u\n",
 			nfsstats.biocache_reads-nfsstats.read_bios,
 			nfsstats.read_bios,
 			nfsstats.biocache_writes-nfsstats.write_bios,
@@ -279,12 +279,12 @@
 		printf("%9.9s %9.9s %9.9s %9.9s",
 			"BioRLHits", "Misses", "BioD Hits", "Misses");
 		printf(" %9.9s %9.9s\n", "DirE Hits", "Misses");
-		printf("%9d %9d %9d %9d",
+		printf("%9u %9u %9u %9u",
 			nfsstats.biocache_readlinks-nfsstats.readlink_bios,
 			nfsstats.readlink_bios,
 			nfsstats.biocache_readdirs-nfsstats.readdir_bios,
 			nfsstats.readdir_bios);
-		printf(" %9d %9d\n",
+		printf(" %9u %9u\n",
 			nfsstats.direofcache_hits, nfsstats.direofcache_misses);
 	}
 	if (serverOnly && !nfsrvstatsp) {
@@ -296,7 +296,7 @@
 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
 			"Getattr", "Setattr", "Lookup", "Readlink", "Read",
 			"Write", "Create", "Remove");
-		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u %9u %9u %9u %9u\n",
 			nfsrvstats.srvrpccnt[NFSPROC_GETATTR],
 			nfsrvstats.srvrpccnt[NFSPROC_SETATTR],
 			nfsrvstats.srvrpccnt[NFSPROC_LOOKUP],
@@ -308,7 +308,7 @@
 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
 			"Rename", "Link", "Symlink", "Mkdir", "Rmdir",
 			"Readdir", "RdirPlus", "Access");
-		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u %9u %9u %9u %9u\n",
 			nfsrvstats.srvrpccnt[NFSPROC_RENAME],
 			nfsrvstats.srvrpccnt[NFSPROC_LINK],
 			nfsrvstats.srvrpccnt[NFSPROC_SYMLINK],
@@ -319,7 +319,7 @@
 			nfsrvstats.srvrpccnt[NFSPROC_ACCESS]);
 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
 			"Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
-		printf("%9d %9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u %9u\n",
 			nfsrvstats.srvrpccnt[NFSPROC_MKNOD],
 			nfsrvstats.srvrpccnt[NFSPROC_FSSTAT],
 			nfsrvstats.srvrpccnt[NFSPROC_FSINFO],
@@ -332,7 +332,7 @@
 		printf("Server Cache Stats:\n");
 		printf("%9.9s %9.9s %9.9s %9.9s\n",
 			"Inprog", "Idem", "Non-idem", "Misses");
-		printf("%9d %9d %9d %9d\n",
+		printf("%9u %9u %9u %9u\n",
 			nfsrvstats.srvcache_inproghits,
 			nfsrvstats.srvcache_idemdonehits,
 			nfsrvstats.srvcache_nonidemdonehits,
@@ -340,7 +340,7 @@
 		printf("Server Write Gathering:\n");
 		printf("%9.9s %9.9s %9.9s\n",
 			"WriteOps", "WriteRPC", "Opsaved");
-		printf("%9d %9d %9d\n",
+		printf("%9u %9u %9u\n",
 			nfsrvstats.srvvop_writes,
 			nfsrvstats.srvrpccnt[NFSPROC_WRITE],
 			nfsrvstats.srvrpccnt[NFSPROC_WRITE] - 

>Release-Note:
>Audit-Trail:

From: Maxim Konovalov <maxim@macomnet.ru>
To: Hiroki Sato <hrs@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/103682: nfsstat(1) should use %u instead of %d to display
 NFS stats
Date: Tue, 26 Sep 2006 21:57:48 +0400 (MSD)

 Hello,
 
 Does your patch differ from bin/37424 one?  Which PR we should close?
 
 -- 
 Maxim Konovalov

From: Hiroki Sato <hrs@FreeBSD.org>
To: maxim@macomnet.ru
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/103682: nfsstat(1) should use %u instead of %d to display
 NFS stats
Date: Wed, 27 Sep 2006 03:54:59 +0900 (JST)

 ----Security_Multipart(Wed_Sep_27_03_54_59_2006_530)--
 Content-Type: Text/Plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 Maxim Konovalov <maxim@macomnet.ru> wrote
   in <20060926215625.D17113@mp2.macomnet.net>:
 
 ma> Does your patch differ from bin/37424 one?  Which PR we should close?
 
  Oh, I did not notice that.  The two PRs seem semantically identical,
  but bin/37424's patch is against very old source files in 2002 and cannot
  be applied to today's -CURRENT.
 
 --
 | Hiroki SATO
 
 ----Security_Multipart(Wed_Sep_27_03_54_59_2006_530)--
 Content-Type: application/pgp-signature
 Content-Transfer-Encoding: 7bit
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.2 (FreeBSD)
 
 iD8DBQBFGXeDTyzT2CeTzy0RAr+oAJ91D8ilrGXv+ZjMzHstB3amML3JFQCfXNTO
 WIi6TLZKKhDu6i260dfdfCY=
 =mkua
 -----END PGP SIGNATURE-----
 
 ----Security_Multipart(Wed_Sep_27_03_54_59_2006_530)----

From: Maxim Konovalov <maxim@macomnet.ru>
To: Hiroki Sato <hrs@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/103682: nfsstat(1) should use %u instead of %d to display
 NFS stats
Date: Tue, 26 Sep 2006 23:01:09 +0400 (MSD)

 On Wed, 27 Sep 2006, 03:54+0900, Hiroki Sato wrote:
 
 > Maxim Konovalov <maxim@macomnet.ru> wrote
 >   in <20060926215625.D17113@mp2.macomnet.net>:
 >
 > ma> Does your patch differ from bin/37424 one?  Which PR we should close?
 >
 >  Oh, I did not notice that.  The two PRs seem semantically identical,
 >  but bin/37424's patch is against very old source files in 2002 and cannot
 >  be applied to today's -CURRENT.
 
 OK, I closed it.
 
 -- 
 Maxim Konovalov

From: Bruce Evans <bde@zeta.org.au>
To: Hiroki Sato <hrs@freebsd.org>
Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Subject: Re: bin/103682: nfsstat(1) should use %u instead of %d to display
 NFS stats
Date: Wed, 27 Sep 2006 06:04:19 +1000 (EST)

 On Wed, 27 Sep 2006, Hiroki Sato wrote:
 
 >> Description:
 > 	Although nfsstat(1) uses %d in printf() to display the NFS stats,
 > 	on a busy NFS server/client the stat numbers can become more than
 > 	2147483647 (2^31 - 1, 32-bit int case) and negative numbers are
 > 	printed.  The numbers should be interpreted as unsigned int, and
 > 	displayed by using %u instead.
 
 I prefer to keep using %d.  One extra bit only keeps things working for
 twice as long (either in uptime or code lifetime).  Overflow to negative
 values normally gives obvious garbage, but overflow to bits that aren't
 there gives garbage.
 
 >> How-To-Repeat:
 > 	Use nfsstat(1) on a busy NFS server/client.
 >> Fix:
 > 	A patch is attached.  Also, I think it is better to change members
 > 	in struct nfsstats/nfsrvstats from int to uint64_t or so if possible.
 
 The counters really are ints, so overflow at 2^31 - 1 technically gives
 undefined behaviour.
 
 The code lifetime for these counters as ints expired many years ago.
 They should be changed to int64_t's to avoid sign extension bugs.
 
 Bruce
>Unformatted:
