Skip to contentSkip to conversation

nfs-utils: make nfsstat read and print stats as unsigned integers

PATCH In review Jeff Layton 2 participants 3 messages Apr 16, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs-utils: make nfsstat read and print stats as unsigned integers

The nfsstat program reads /proc/net/rpc/* files to gets info about calls. This info is output as unsigned numbers (at least on any relatively recent kernel). When nfsstat prints these numbers, they are printed as signed integers. When the call counters reach 2^31, things start being printed as negative numbers.

This patch changes nfsstat to read and print all counters as unsigned integers. Tested by hacking up a kernel to initialize call counters to 2^31+1.

Thanks to Takafumi Miki for the initial version of this patch.

---
 utils/nfsstat/nfsstat.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
utils/nfsstat/nfsstat.c +3 -3
index aa6c961..36ad8ce 100644
@@ -539,7 +539,7 @@ print_numbers(const char *hdr, unsigned int *info, unsigned int nr)
 
 	fputs(hdr, stdout);
 	for (i = 0; i < nr; i++)
-		printf("%s%-8d", i? "   " : "", info[i]);
+		printf("%s%-8u", i? "   " : "", info[i]);
 	printf("\n");
 }
 
@@ -562,7 +562,7 @@ print_callstats(const char *hdr, const char **names,
 		printf("\n");
 		for (j = 0; j < 6 && i + j < nr; j++) {
 			pct = ((unsigned long long) info[i+j]*100)/total;
-			printf("%-8d%3llu%% ", info[i+j], pct);
+			printf("%-8u%3llu%% ", info[i+j], pct);
 		}
 		printf("\n");
 	}
@@ -604,7 +604,7 @@ parse_raw_statfile(const char *name, struct statinfo *statp)
 		for (i = 0; i < cnt; i++) {
 			if (!(sp = strtok(NULL, " \t")))
 				break;
-			ip->valptr[i] = atoi(sp);
+			ip->valptr[i] = (unsigned int) strtoul(sp, NULL, 0);
 			total += ip->valptr[i];
 		}
 		ip->valptr[cnt - 1] = total;
Signature · 1 line
1.5.3.6
#1 lore raw
	hello, jeff,

	i think one other place that could use a signed->unsigned fix is 

in parse_pretty_statfile(), where "sum" is declared as signed but actually represents an unsigned total.

	thanks,

	d
	.
Quoted 56 lines · Jeff Layton

The nfsstat program reads /proc/net/rpc/* files to gets info about calls. This info is output as unsigned numbers (at least on any relatively recent kernel). When nfsstat prints these numbers, they are printed as signed integers. When the call counters reach 2^31, things start being printed as negative numbers.

This patch changes nfsstat to read and print all counters as unsigned integers. Tested by hacking up a kernel to initialize call counters to 2^31+1.

Thanks to Takafumi Miki for the initial version of this patch.

---
 utils/nfsstat/nfsstat.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
utils/nfsstat/nfsstat.c +3 -3
index aa6c961..36ad8ce 100644
@@ -539,7 +539,7 @@ print_numbers(const char *hdr, unsigned int *info, unsigned int nr)
 
 	fputs(hdr, stdout);
 	for (i = 0; i < nr; i++)
-		printf("%s%-8d", i? "   " : "", info[i]);
+		printf("%s%-8u", i? "   " : "", info[i]);
 	printf("\n");
 }
 
@@ -562,7 +562,7 @@ print_callstats(const char *hdr, const char **names,
 		printf("\n");
 		for (j = 0; j < 6 && i + j < nr; j++) {
 			pct = ((unsigned long long) info[i+j]*100)/total;
-			printf("%-8d%3llu%% ", info[i+j], pct);
+			printf("%-8u%3llu%% ", info[i+j], pct);
 		}
 		printf("\n");
 	}
@@ -604,7 +604,7 @@ parse_raw_statfile(const char *name, struct statinfo *statp)
 		for (i = 0; i < cnt; i++) {
 			if (!(sp = strtok(NULL, " \t")))
 				break;
-			ip->valptr[i] = atoi(sp);
+			ip->valptr[i] = (unsigned int) strtoul(sp, NULL, 0);
 			total += ip->valptr[i];
 		}
 		ip->valptr[cnt - 1] = total;
Signature · 6 lines
1.5.3.6

_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
#2 lore raw
Quoted 11 lines · On Wed, 16 Apr 2008 12:29:26 -0400 (EDT) "david m. richter"…
	hello, jeff,

	i think one other place that could use a signed->unsigned fix is 

in parse_pretty_statfile(), where "sum" is declared as signed but actually represents an unsigned total.

	thanks,

	d
	.

Thanks, Dave. Good catch. I'll respin and repost...

Signature · 1 line
Jeff Layton <[email protected]>