NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/48426



The following reply was made to PR kern/48426; it has been noted by GNATS.

From: Dimitris Karagkasidis <dimitris%gatoni.gr@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: kern/48426
Date: Thu, 24 Apr 2014 20:12:36 +0200

 This is a multi-part message in MIME format.
 --------------020808060203020807030806
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 After some more investigation and talks on #netbsd-code, I have come to
 conclusion that making signed integers unsgined in `struct nfsstats` will
 not entirely solve the issue. The problem lies entirely in the presentation
 layer of /usr/bin/nfsstat.
 
 /usr/bin/nfsstats is using the "d" converstion specifier when printing
 the counter values to stdout. According to printf(3), the "d" conversion
 specifier is converting any arguments to signed decimal, even if the
 argument was declared as unsigned.
 
 In order to reproduce the issue while avoiding the generation of excessive
 NFS usage, I wrote the following kernel module that manually sets the
 counters in `struct nfsstats` to arbitrary values:
 
 ---
 /*
   * repr_nfsstats.c
   * PoC to reproduce kern/48426
   */
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
 #include <nfs/rpcv2.h>
 #include <nfs/nfs.h>
 
 MODULE(MODULE_CLASS_MISC, repr_nfsstats, NULL);
 
 extern struct nfsstats nfsstats;
 
 void
 set_nfsstats(int value)
 {
      int i;
 
      for (i = 0; i < NFSSTATS_NPROCS; i++) {
          nfsstats.rpccnt[i] = value;
          nfsstats.srvrpccnt[i] = value;
      }
 
      nfsstats.attrcache_hits = value;
      nfsstats.attrcache_misses = value;
      nfsstats.lookupcache_hits = value;
      nfsstats.lookupcache_misses = value;
      nfsstats.direofcache_hits = value;
      nfsstats.direofcache_misses = value;
      nfsstats.biocache_reads = value;
      nfsstats.read_bios = value;
      nfsstats.read_physios = value;
      nfsstats.biocache_writes = value;
      nfsstats.write_bios = value;
      nfsstats.write_physios = value;
      nfsstats.biocache_readlinks = value;
      nfsstats.readlink_bios = value;
      nfsstats.biocache_readdirs = value;
      nfsstats.readdir_bios = value;
      nfsstats.rpcretries = value;
      nfsstats.srvrpc_errs = value;
      nfsstats.srv_errs = value;
      nfsstats.rpcrequests = value;
      nfsstats.rpctimeouts = value;
      nfsstats.rpcunexpected = value;
      nfsstats.rpcinvalid = value;
      nfsstats.srvcache_inproghits = value;
      nfsstats.srvcache_idemdonehits = value;
      nfsstats.srvcache_nonidemdonehits = value;
      nfsstats.srvcache_misses = value;
      nfsstats.__srvnqnfs_leases = value;
      nfsstats.__srvnqnfs_maxleases = value;
      nfsstats.__srvnqnfs_getleases = value;
      nfsstats.srvvop_writes = value;
 }
 
 int
 repr_nfsstats_modcmd(modcmd_t cmd, void *data)
 {
      switch(cmd) {
      case MODULE_CMD_INIT:
          // Set counters to LONG_MAX+1
          set_nfsstats(2147483648);
          break;
      case MODULE_CMD_FINI:
          set_nfsstats(0);
          break;
      case MODULE_CMD_STAT:
          return ENOTTY;
          break;
      default:
          return ENOTTY;
      }
      return (0);
 }
 ---
 
 These are the results before and after loading the module:
 
 ---
 netbsd# /usr/bin/nfsstat
 Client Info:
 RPC Counts: (0 calls)
        null         getattr         setattr          lookup          access
           0  0%           0  0%           0  0%           0  0%           0  0%
    readlink            read           write          create           mkdir
           0  0%           0  0%           0  0%           0  0%           0  0%
     symlink           mknod          remove           rmdir          rename
           0  0%           0  0%           0  0%           0  0%           0  0%
        link         readdir     readdirplus          fsstat          fsinfo
           0  0%           0  0%           0  0%           0  0%           0  0%
    pathconf          commit
           0  0%           0  0%
 RPC Info:
     timeout         invalid      unexpected         retries        requests
           0               0               0               0               0
 Cache Info:
   attrcache     lookupcache            read           write        readlink
           0  0%           0  0%           0  0%           0  0%           0  0%
     readdir     direofcache
           0  0%           0  0%
 
 Server Info:
 RPC Counts: (0 calls)
        null         getattr         setattr          lookup          access
           0  0%           0  0%           0  0%           0  0%           0  0%
    readlink            read           write          create           mkdir
           0  0%           0  0%           0  0%           0  0%           0  0%
     symlink           mknod          remove           rmdir          rename
           0  0%           0  0%           0  0%           0  0%           0  0%
        link         readdir     readdirplus          fsstat          fsinfo
           0  0%           0  0%           0  0%           0  0%           0  0%
    pathconf          commit
           0  0%           0  0%
 Server Errors:
 RPC errors          faults
           0               0
 Server Cache Stats:
 inprogress            idem        non-idem          misses
           0               0               0               0
 Server Write Gathering:
      writes       write RPC       OPs saved
           0               0               0  0%
 netbsd# modload ./repr_nfsstats.kmod
 netbsd# /usr/bin/nfsstat
 Client Info:
 RPC Counts: (-49392123904 calls)
        null         getattr         setattr          lookup          access
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
    readlink            read           write          create           mkdir
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
     symlink           mknod          remove           rmdir          rename
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
        link         readdir     readdirplus          fsstat          fsinfo
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
    pathconf          commit
 -2147483648  4%  -2147483648  4%
 RPC Info:
     timeout         invalid      unexpected         retries        requests
 -2147483648     -2147483648     -2147483648     -2147483648     -2147483648
 Cache Info:
   attrcache     lookupcache            read           write        readlink
 -2147483648  0%  -2147483648  0%           0  0%           0  0%           0  
0%
     readdir     direofcache
           0  0%  -2147483648  0%
 
 Server Info:
 RPC Counts: (-49392123904 calls)
        null         getattr         setattr          lookup          access
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
    readlink            read           write          create           mkdir
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
     symlink           mknod          remove           rmdir          rename
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
        link         readdir     readdirplus          fsstat          fsinfo
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
    pathconf          commit
 -2147483648  4%  -2147483648  4%
 Server Errors:
 RPC errors          faults
 -2147483648     -2147483648
 Server Cache Stats:
 inprogress            idem        non-idem          misses
 -2147483648     -2147483648     -2147483648     -2147483648
 Server Write Gathering:
      writes       write RPC       OPs saved
 -2147483648     -2147483648               0  0%
 ---
 
 By changing "d" conversion specifier to "u", nfsstat counters will never
 be negative. These are the results of nfsstat after the application of the
 patch listed in the bottom of this PR:
 
 ---
 netbsd# ./nfsstat
 Client Info:
 RPC Counts: (18446744024317427712 calls)
        null         getattr         setattr          lookup          access
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
    readlink            read           write          create           mkdir
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
     symlink           mknod          remove           rmdir          rename
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
        link         readdir     readdirplus          fsstat          fsinfo
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
    pathconf          commit
 2147483648  4%  2147483648  4%
 RPC Info:
     timeout         invalid      unexpected         retries        requests
 2147483648      2147483648      2147483648      2147483648      2147483648
 Cache Info:
   attrcache     lookupcache            read           write        readlink
 2147483648  0%  2147483648  0%           0  0%           0  0%           0  0%
     readdir     direofcache
           0  0%  2147483648  0%
 
 Server Info:
 RPC Counts: (18446744024317427712 calls)
        null         getattr         setattr          lookup          access
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
    readlink            read           write          create           mkdir
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
     symlink           mknod          remove           rmdir          rename
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
        link         readdir     readdirplus          fsstat          fsinfo
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
    pathconf          commit
 2147483648  4%  2147483648  4%
 Server Errors:
 RPC errors          faults
 2147483648      2147483648
 Server Cache Stats:
 inprogress            idem        non-idem          misses
 2147483648      2147483648      2147483648      2147483648
 Server Write Gathering:
      writes       write RPC       OPs saved
 2147483648      2147483648               0  0%
 ---
 
 This is my suggested patch to resolve the issue:
 
 Index: nfsstat.c
 ===================================================================
 RCS file: /cvsroot/src/usr.bin/nfsstat/nfsstat.c,v
 retrieving revision 1.24
 diff -u -r1.24 nfsstat.c
 --- nfsstat.c  6 Sep 2011 18:19:58 -0000       1.24
 +++ nfsstat.c  24 Apr 2014 17:48:26 -0000
 @@ -217,13 +217,13 @@
                for (i = 0; i < NFS_NPROCS; i++)
                        total += nfsstats.rpccnt[i];
                printf("Client Info:\n");
 -              printf("RPC Counts: (%lld call%s)\n", (long long)total,
 +              printf("RPC Counts: (%llu call%s)\n", (long long)total,
                    total == 1 ? "" : "s");
   
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "null", "getattr", "setattr", "lookup", "access");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_NULL]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_GETATTR]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_SETATTR]),
 @@ -232,7 +232,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "readlink", "read", "write", "create", "mkdir");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READLINK]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READ]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_WRITE]),
 @@ -241,7 +241,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "symlink", "mknod", "remove", "rmdir", "rename");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_SYMLINK]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_MKNOD]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_REMOVE]),
 @@ -250,7 +250,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "link", "readdir", "readdirplus", "fsstat", "fsinfo");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_LINK]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READDIR]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READDIRPLUS]),
 @@ -258,14 +258,14 @@
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_FSINFO]));
                printf("%10s  %14s\n",
                    "pathconf", "commit");
 -              printf("%10d %2d%%  %10d %2d%%\n",
 +              printf("%10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_PATHCONF]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_COMMIT]));
   
                printf("RPC Info:\n");
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "timeout", "invalid", "unexpected", "retries", "requests");
 -              printf("%10d  %14d  %14d  %14d  %14d\n",
 +              printf("%10u  %14u  %14u  %14u  %14u\n",
                    nfsstats.rpctimeouts,
                    nfsstats.rpcinvalid,
                    nfsstats.rpcunexpected,
 @@ -276,7 +276,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "attrcache", "lookupcache", "read", "write", "readlink");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    NUMPCT(nfsstats.attrcache_hits,
                        nfsstats.attrcache_misses),
                    NUMPCT(nfsstats.lookupcache_hits,
 @@ -289,7 +289,7 @@
                        nfsstats.readlink_bios));
                printf("%10s  %14s\n",
                    "readdir", "direofcache");
 -              printf("%10d %2d%%  %10d %2d%%\n",
 +              printf("%10u %2u%%  %10u %2u%%\n",
                    NUMPCT(nfsstats.biocache_readdirs - nfsstats.readdir_bios,
                        nfsstats.readdir_bios),
                    NUMPCT(nfsstats.direofcache_hits,
 @@ -304,13 +304,13 @@
                for (i = 0; i < NFS_NPROCS; i++)
                        total += nfsstats.srvrpccnt[i];
                printf("Server Info:\n");
 -              printf("RPC Counts: (%lld call%s)\n", (long long)total,
 +              printf("RPC Counts: (%llu call%s)\n", (long long)total,
                    total == 1 ? "" : "s");
   
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "null", "getattr", "setattr", "lookup", "access");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_NULL]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_GETATTR]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_SETATTR]),
 @@ -319,7 +319,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "readlink", "read", "write", "create", "mkdir");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READLINK]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READ]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_WRITE]),
 @@ -328,7 +328,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "symlink", "mknod", "remove", "rmdir", "rename");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_SYMLINK]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_MKNOD]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_REMOVE]),
 @@ -337,7 +337,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "link", "readdir", "readdirplus", "fsstat", "fsinfo");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_LINK]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READDIR]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READDIRPLUS]),
 @@ -345,20 +345,20 @@
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_FSINFO]));
                printf("%10s  %14s\n",
                    "pathconf", "commit");
 -              printf("%10d %2d%%  %10d %2d%%\n",
 +              printf("%10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_PATHCONF]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_COMMIT]));
   
                printf("Server Errors:\n");
                printf("%10s  %14s\n",
                    "RPC errors", "faults");
 -              printf("%10d  %14d\n",
 +              printf("%10u  %14u\n",
                    nfsstats.srvrpc_errs,
                    nfsstats.srv_errs);
                printf("Server Cache Stats:\n");
                printf("%10s  %14s  %14s  %14s\n",
                    "inprogress", "idem", "non-idem", "misses");
 -              printf("%10d  %14d  %14d  %14d\n",
 +              printf("%10u  %14u  %14u  %14u\n",
                    nfsstats.srvcache_inproghits,
                    nfsstats.srvcache_idemdonehits,
                    nfsstats.srvcache_nonidemdonehits,
 @@ -366,7 +366,7 @@
                printf("Server Write Gathering:\n");
                printf("%10s  %14s  %14s\n",
                    "writes", "write RPC", "OPs saved");
 -              printf("%10d  %14d  %14d %2d%%\n",
 +              printf("%10u  %14u  %14u %2u%%\n",
                    nfsstats.srvvop_writes,
                    nfsstats.srvrpccnt[NFSPROC_WRITE],
                    NUMPCT(
 @@ -422,14 +422,14 @@
                if (printall || clientinfo) {
                        printf("Client:");
                        for (i = 0; i < NSHORTPROC; i++)
 -                              printf(" %7d",
 +                              printf(" %7u",
                                    current.client[i] - last.client[i]);
                        printf("\n");
                }
                if (printall || serverinfo) {
                        printf("Server:");
                        for (i = 0; i < NSHORTPROC; i++)
 -                              printf(" %7d",
 +                              printf(" %7u",
                                    current.server[i] - last.server[i]);
                        printf("\n");
                }
 
 
 
 --------------020808060203020807030806
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 <html>
   <head>
 
     <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
   </head>
   <body bgcolor="#FFFFFF" text="#000000">
     <meta http-equiv="content-type" content="text/html;
       charset=ISO-8859-1">
     <pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; 
font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 
auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; 
word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; 
white-space: pre-wrap;">After some more investigation and talks on 
#netbsd-code, I have come to
 conclusion that making signed integers unsgined in `struct nfsstats` will
 not entirely solve the issue. The problem lies entirely in the presentation
 layer of /usr/bin/nfsstat.
 
 /usr/bin/nfsstats is using the "d" converstion specifier when printing
 the counter values to stdout. According to printf(3), the "d" conversion
 specifier is converting any arguments to signed decimal, even if the
 argument was declared as unsigned.
 
 In order to reproduce the issue while avoiding the generation of excessive
 NFS usage, I wrote the following kernel module that manually sets the
 counters in `struct nfsstats` to arbitrary values:
 
 ---
 /*
  * repr_nfsstats.c
  * PoC to reproduce kern/48426
  */
 #include &lt;sys/param.h&gt;
 #include &lt;sys/kernel.h&gt;
 #include &lt;sys/module.h&gt;
 #include &lt;nfs/rpcv2.h&gt;
 #include &lt;nfs/nfs.h&gt;
 
 MODULE(MODULE_CLASS_MISC, repr_nfsstats, NULL);
 
 extern struct nfsstats nfsstats;
 
 void
 set_nfsstats(int value)
 {
     int i;
 
     for (i = 0; i &lt; NFSSTATS_NPROCS; i++) {
         nfsstats.rpccnt[i] = value;
         nfsstats.srvrpccnt[i] = value;
     }
 
     nfsstats.attrcache_hits = value;
     nfsstats.attrcache_misses = value;
     nfsstats.lookupcache_hits = value;
     nfsstats.lookupcache_misses = value;
     nfsstats.direofcache_hits = value;
     nfsstats.direofcache_misses = value;
     nfsstats.biocache_reads = value;
     nfsstats.read_bios = value;
     nfsstats.read_physios = value;
     nfsstats.biocache_writes = value;
     nfsstats.write_bios = value;
     nfsstats.write_physios = value;
     nfsstats.biocache_readlinks = value;
     nfsstats.readlink_bios = value;
     nfsstats.biocache_readdirs = value;
     nfsstats.readdir_bios = value;
     nfsstats.rpcretries = value;
     nfsstats.srvrpc_errs = value;
     nfsstats.srv_errs = value;
     nfsstats.rpcrequests = value;
     nfsstats.rpctimeouts = value;
     nfsstats.rpcunexpected = value;
     nfsstats.rpcinvalid = value;
     nfsstats.srvcache_inproghits = value;
     nfsstats.srvcache_idemdonehits = value;
     nfsstats.srvcache_nonidemdonehits = value;
     nfsstats.srvcache_misses = value;
     nfsstats.__srvnqnfs_leases = value;
     nfsstats.__srvnqnfs_maxleases = value;
     nfsstats.__srvnqnfs_getleases = value;
     nfsstats.srvvop_writes = value;
 }
 
 int
 repr_nfsstats_modcmd(modcmd_t cmd, void *data)
 {
     switch(cmd) {
     case MODULE_CMD_INIT:
         // Set counters to LONG_MAX+1
         set_nfsstats(2147483648);
         break;
     case MODULE_CMD_FINI:
         set_nfsstats(0);
         break;
     case MODULE_CMD_STAT:
         return ENOTTY;
         break;
     default:
         return ENOTTY;
     }
     return (0);
 }
 ---
 
 These are the results before and after loading the module:
 
 ---
 netbsd# /usr/bin/nfsstat
 Client Info:
 RPC Counts: (0 calls)
       null         getattr         setattr          lookup          access
          0  0%           0  0%           0  0%           0  0%           0  0%
   readlink            read           write          create           mkdir
          0  0%           0  0%           0  0%           0  0%           0  0%
    symlink           mknod          remove           rmdir          rename
          0  0%           0  0%           0  0%           0  0%           0  0%
       link         readdir     readdirplus          fsstat          fsinfo
          0  0%           0  0%           0  0%           0  0%           0  0%
   pathconf          commit
          0  0%           0  0%
 RPC Info:
    timeout         invalid      unexpected         retries        requests
          0               0               0               0               0
 Cache Info:
  attrcache     lookupcache            read           write        readlink
          0  0%           0  0%           0  0%           0  0%           0  0%
    readdir     direofcache
          0  0%           0  0%
 
 Server Info:
 RPC Counts: (0 calls)
       null         getattr         setattr          lookup          access
          0  0%           0  0%           0  0%           0  0%           0  0%
   readlink            read           write          create           mkdir
          0  0%           0  0%           0  0%           0  0%           0  0%
    symlink           mknod          remove           rmdir          rename
          0  0%           0  0%           0  0%           0  0%           0  0%
       link         readdir     readdirplus          fsstat          fsinfo
          0  0%           0  0%           0  0%           0  0%           0  0%
   pathconf          commit
          0  0%           0  0%
 Server Errors:
 RPC errors          faults
          0               0
 Server Cache Stats:
 inprogress            idem        non-idem          misses
          0               0               0               0
 Server Write Gathering:
     writes       write RPC       OPs saved
          0               0               0  0%
 netbsd# modload ./repr_nfsstats.kmod 
 netbsd# /usr/bin/nfsstat
 Client Info:
 RPC Counts: (-49392123904 calls)
       null         getattr         setattr          lookup          access
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
   readlink            read           write          create           mkdir
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
    symlink           mknod          remove           rmdir          rename
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
       link         readdir     readdirplus          fsstat          fsinfo
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
   pathconf          commit
 -2147483648  4%  -2147483648  4%
 RPC Info:
    timeout         invalid      unexpected         retries        requests
 -2147483648     -2147483648     -2147483648     -2147483648     -2147483648
 Cache Info:
  attrcache     lookupcache            read           write        readlink
 -2147483648  0%  -2147483648  0%           0  0%           0  0%           0  
0%
    readdir     direofcache
          0  0%  -2147483648  0%
 
 Server Info:
 RPC Counts: (-49392123904 calls)
       null         getattr         setattr          lookup          access
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
   readlink            read           write          create           mkdir
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
    symlink           mknod          remove           rmdir          rename
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
       link         readdir     readdirplus          fsstat          fsinfo
 -2147483648  4%  -2147483648  4%  -2147483648  4%  -2147483648  4%  
-2147483648  4%
   pathconf          commit
 -2147483648  4%  -2147483648  4%
 Server Errors:
 RPC errors          faults
 -2147483648     -2147483648
 Server Cache Stats:
 inprogress            idem        non-idem          misses
 -2147483648     -2147483648     -2147483648     -2147483648
 Server Write Gathering:
     writes       write RPC       OPs saved
 -2147483648     -2147483648               0  0%
 ---
 
 By changing "d" conversion specifier to "u", nfsstat counters will never
 be negative. These are the results of nfsstat after the application of the
 patch listed in the bottom of this PR:
 
 ---
 netbsd# ./nfsstat
 Client Info:
 RPC Counts: (18446744024317427712 calls)
       null         getattr         setattr          lookup          access
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
   readlink            read           write          create           mkdir
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
    symlink           mknod          remove           rmdir          rename
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
       link         readdir     readdirplus          fsstat          fsinfo
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
   pathconf          commit
 2147483648  4%  2147483648  4%
 RPC Info:
    timeout         invalid      unexpected         retries        requests
 2147483648      2147483648      2147483648      2147483648      2147483648
 Cache Info:
  attrcache     lookupcache            read           write        readlink
 2147483648  0%  2147483648  0%           0  0%           0  0%           0  0%
    readdir     direofcache
          0  0%  2147483648  0%
 
 Server Info:
 RPC Counts: (18446744024317427712 calls)
       null         getattr         setattr          lookup          access
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
   readlink            read           write          create           mkdir
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
    symlink           mknod          remove           rmdir          rename
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
       link         readdir     readdirplus          fsstat          fsinfo
 2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%  2147483648  4%
   pathconf          commit
 2147483648  4%  2147483648  4%
 Server Errors:
 RPC errors          faults
 2147483648      2147483648
 Server Cache Stats:
 inprogress            idem        non-idem          misses
 2147483648      2147483648      2147483648      2147483648
 Server Write Gathering:
     writes       write RPC       OPs saved
 2147483648      2147483648               0  0%
 ---
 
 This is my suggested patch to resolve the issue:
 
 Index: nfsstat.c
 ===================================================================
 RCS file: /cvsroot/src/usr.bin/nfsstat/nfsstat.c,v
 retrieving revision 1.24
 diff -u -r1.24 nfsstat.c
 --- nfsstat.c  6 Sep 2011 18:19:58 -0000       1.24
 +++ nfsstat.c  24 Apr 2014 17:48:26 -0000
 @@ -217,13 +217,13 @@
                for (i = 0; i &lt; NFS_NPROCS; i++)
                        total += nfsstats.rpccnt[i];
                printf("Client <a class="moz-txt-link-freetext" 
href="Info:\n">Info:\n</a>");
 -              printf("RPC Counts: (%lld call%s)\n", (long long)total,
 +              printf("RPC Counts: (%llu call%s)\n", (long long)total,
                    total == 1 ? "" : "s");
  
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "null", "getattr", "setattr", "lookup", "access");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_NULL]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_GETATTR]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_SETATTR]),
 @@ -232,7 +232,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "readlink", "read", "write", "create", "mkdir");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READLINK]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READ]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_WRITE]),
 @@ -241,7 +241,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "symlink", "mknod", "remove", "rmdir", "rename");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_SYMLINK]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_MKNOD]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_REMOVE]),
 @@ -250,7 +250,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "link", "readdir", "readdirplus", "fsstat", "fsinfo");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_LINK]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READDIR]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_READDIRPLUS]),
 @@ -258,14 +258,14 @@
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_FSINFO]));
                printf("%10s  %14s\n",
                    "pathconf", "commit");
 -              printf("%10d %2d%%  %10d %2d%%\n",
 +              printf("%10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_PATHCONF]),
                    RPCSTAT(nfsstats.rpccnt[NFSPROC_COMMIT]));
  
                printf("RPC <a class="moz-txt-link-freetext" 
href="Info:\n">Info:\n</a>");
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "timeout", "invalid", "unexpected", "retries", "requests");
 -              printf("%10d  %14d  %14d  %14d  %14d\n",
 +              printf("%10u  %14u  %14u  %14u  %14u\n",
                    nfsstats.rpctimeouts,
                    nfsstats.rpcinvalid,
                    nfsstats.rpcunexpected,
 @@ -276,7 +276,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "attrcache", "lookupcache", "read", "write", "readlink");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    NUMPCT(nfsstats.attrcache_hits,
                        nfsstats.attrcache_misses),
                    NUMPCT(nfsstats.lookupcache_hits,
 @@ -289,7 +289,7 @@
                        nfsstats.readlink_bios));
                printf("%10s  %14s\n",
                    "readdir", "direofcache");
 -              printf("%10d %2d%%  %10d %2d%%\n",
 +              printf("%10u %2u%%  %10u %2u%%\n",
                    NUMPCT(nfsstats.biocache_readdirs - nfsstats.readdir_bios,
                        nfsstats.readdir_bios),
                    NUMPCT(nfsstats.direofcache_hits,
 @@ -304,13 +304,13 @@
                for (i = 0; i &lt; NFS_NPROCS; i++)
                        total += nfsstats.srvrpccnt[i];
                printf("Server <a class="moz-txt-link-freetext" 
href="Info:\n">Info:\n</a>");
 -              printf("RPC Counts: (%lld call%s)\n", (long long)total,
 +              printf("RPC Counts: (%llu call%s)\n", (long long)total,
                    total == 1 ? "" : "s");
  
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "null", "getattr", "setattr", "lookup", "access");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_NULL]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_GETATTR]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_SETATTR]),
 @@ -319,7 +319,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "readlink", "read", "write", "create", "mkdir");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READLINK]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READ]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_WRITE]),
 @@ -328,7 +328,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "symlink", "mknod", "remove", "rmdir", "rename");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_SYMLINK]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_MKNOD]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_REMOVE]),
 @@ -337,7 +337,7 @@
                printf("%10s  %14s  %14s  %14s  %14s\n",
                    "link", "readdir", "readdirplus", "fsstat", "fsinfo");
                printf(
 -          "%10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%  %10d %2d%%\n",
 +          "%10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_LINK]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READDIR]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_READDIRPLUS]),
 @@ -345,20 +345,20 @@
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_FSINFO]));
                printf("%10s  %14s\n",
                    "pathconf", "commit");
 -              printf("%10d %2d%%  %10d %2d%%\n",
 +              printf("%10u %2u%%  %10u %2u%%\n",
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_PATHCONF]),
                    RPCSTAT(nfsstats.srvrpccnt[NFSPROC_COMMIT]));
  
                printf("Server Errors:\n");
                printf("%10s  %14s\n",
                    "RPC errors", "faults");
 -              printf("%10d  %14d\n",
 +              printf("%10u  %14u\n",
                    nfsstats.srvrpc_errs,
                    nfsstats.srv_errs);
                printf("Server Cache Stats:\n");
                printf("%10s  %14s  %14s  %14s\n",
                    "inprogress", "idem", "non-idem", "misses");
 -              printf("%10d  %14d  %14d  %14d\n",
 +              printf("%10u  %14u  %14u  %14u\n",
                    nfsstats.srvcache_inproghits,
                    nfsstats.srvcache_idemdonehits,
                    nfsstats.srvcache_nonidemdonehits,
 @@ -366,7 +366,7 @@
                printf("Server Write Gathering:\n");
                printf("%10s  %14s  %14s\n",
                    "writes", "write RPC", "OPs saved");
 -              printf("%10d  %14d  %14d %2d%%\n",
 +              printf("%10u  %14u  %14u %2u%%\n",
                    nfsstats.srvvop_writes,
                    nfsstats.srvrpccnt[NFSPROC_WRITE],
                    NUMPCT(
 @@ -422,14 +422,14 @@
                if (printall || clientinfo) {
                        printf("Client:");
                        for (i = 0; i &lt; NSHORTPROC; i++)
 -                              printf(" %7d",
 +                              printf(" %7u",
                                    current.client[i] - last.client[i]);
                        printf("\n");
                }
                if (printall || serverinfo) {
                        printf("Server:");
                        for (i = 0; i &lt; NSHORTPROC; i++)
 -                              printf(" %7d",
 +                              printf(" %7u",
                                    current.server[i] - last.server[i]);
                        printf("\n");
                }
 </pre>
     <br class="Apple-interchange-newline">
   </body>
 </html>
 
 --------------020808060203020807030806--
 



Home | Main Index | Thread Index | Old Index