Subject: bin/20435: iostat -x drive selection is not work.
To: None <gnats-bugs@gnats.netbsd.org>
From: None <koie@suri.co.jp>
List: netbsd-bugs
Date: 02/19/2003 19:36:57
>Number: 20435
>Category: bin
>Synopsis: iostat -x drive selection is not work.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Feb 19 19:37:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: KOIE Hidetaka
>Release: 1.6N
>Organization:
surigiken
>Environment:
NetBSD skipjack.koie.org 1.6N NetBSD 1.6N (TP235) #0: Mon Feb 17 20:14:07 JST 2003 koie@skipjack.koie.org:/usr/src/sys/arch/i386/compile/TP235 i386
>Description:
"iostat -x" shows all devices even if a drive is specified.
(For reference, Solaris8 does)
#Original
> iostat -x wd0
device read KB/t r/s time MB/s write KB/t w/s time MB/s
wd0 3.84 10 0.04 0.04 54.63 1 0.04 0.07
fd0 0.00 0 0.00 0.00 0.00 0 0.00 0.00
md0 0.00 0 0.00 0.00 0.00 0 0.00 0.00
#Patched version
> ./iostat -x wd0 #patched version
device read KB/t r/s time MB/s write KB/t w/s time MB/s
wd0 3.84 10 0.04 0.04 54.63 1 0.04 0.07
>
#Solaris8
% iostat -x sd0
extended device statistics
device r/s w/s kr/s kw/s wait actv svc_t %w %b
fd0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
sd0 0.1 0.1 0.5 0.4 0.0 0.0 7.5 0 0
sd1 3.1 1.4 23.1 2.5 0.0 0.0 10.6 0 2
sd2 5.1 6.2 39.5 168.5 0.0 0.2 15.0 0 5
sd6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
nfs1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
%
>How-To-Repeat:
iostat -x wd0 wd0 1 2
>Fix:
Index: iostat.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/iostat/iostat.c,v
retrieving revision 1.32
diff -p -u -r1.32 iostat.c
--- iostat.c 2002/11/02 06:35:30 1.32
+++ iostat.c 2003/02/20 03:35:08
@@ -99,6 +99,7 @@ char *nlistf, *memf;
int hz, reps, interval;
static int todo = 0;
+static int ndrives;
#define ISSET(x, a) ((x) & (a))
#define SHOW_CPU 1<<0
@@ -333,6 +334,9 @@ disk_statsx(double etime)
double atime, kbps;
for (dn = 0; dn < dk_ndrive; ++dn) {
+ if (!cur.dk_select[dn])
+ continue;
+
(void)printf("%-8.8s", cur.dk_name[dn]);
/* average read Kbytes per transfer */
@@ -381,7 +385,7 @@ disk_statsx(double etime)
* Our caller prints a newline; we need one for every line
* except the last.
*/
- if (dn < dk_ndrive -1)
+ if (ndrives > 1 && dn < dk_ndrive)
(void)printf("\n");
}
}
@@ -447,7 +451,7 @@ display(void)
static void
selectdrives(int argc, char *argv[])
{
- int i, ndrives;
+ int i;
/*
* Choose drives to be displayed. Priority goes to (in order) drives
@@ -458,10 +462,6 @@ selectdrives(int argc, char *argv[])
* The backward compatibility #ifdefs permit the syntax:
* iostat [ drives ] [ interval [ count ] ]
*/
- if (ISSET(todo, SHOW_STATS_X)) {
- for (i = 0; i < dk_ndrive; i++)
- cur.dk_select[i] = 1;
- }
#define BACKWARD_COMPATIBILITY
for (ndrives = 0; *argv; ++argv) {
@@ -469,13 +469,14 @@ selectdrives(int argc, char *argv[])
if (isdigit(**argv))
break;
#endif
- if (!ISSET(todo, SHOW_STATS_X))
- for (i = 0; i < dk_ndrive; i++) {
- if (strcmp(cur.dk_name[i], *argv))
- continue;
- cur.dk_select[i] = 1;
- ++ndrives;
- }
+ for (i = 0; i < dk_ndrive; i++) {
+ if (cur.dk_select[i])
+ continue;
+ if (strcmp(cur.dk_name[i], *argv))
+ continue;
+ cur.dk_select[i] = 1;
+ ++ndrives;
+ }
}
#ifdef BACKWARD_COMPATIBILITY
if (*argv) {
@@ -493,11 +494,13 @@ selectdrives(int argc, char *argv[])
interval = 1;
/* Pick up to 4 drives if none specified. */
- if (ndrives == 0)
- for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
+ if (ndrives == 0) {
+ int maxdrives = ISSET(todo, SHOW_STATS_X) ? dk_ndrive : 4;
+ for (i = 0; i < dk_ndrive && ndrives < maxdrives; i++) {
if (cur.dk_select[i])
continue;
cur.dk_select[i] = 1;
++ndrives;
}
+ }
}
>Release-Note:
>Audit-Trail:
>Unformatted: