87 |
|
#include <stdio.h> |
88 |
|
#include <time.h> |
89 |
|
#define VALID_FS_TYPES {"vxfs", "hfs"} |
90 |
+ |
#define DISK_BATCH 30 |
91 |
|
#endif |
92 |
|
|
93 |
|
static void disk_stat_init(sg_fs_stats *d) { |
317 |
|
long long rbytes = 0, wbytes = 0; |
318 |
|
struct dirent *dinfo = NULL; |
319 |
|
struct stat lstatinfo; |
320 |
< |
struct pst_diskinfo pstat_diskinfo; |
320 |
> |
struct pst_diskinfo pstat_diskinfo[DISK_BATCH]; |
321 |
|
char fullpathbuf[1024] = {0}; |
322 |
|
dev_t diskid; |
323 |
|
DIR *dh = NULL; |
324 |
< |
int disknum = 0; |
324 |
> |
int diskidx = 0; |
325 |
> |
int num, i; |
326 |
|
#endif |
327 |
|
#ifdef SOLARIS |
328 |
|
kstat_ctl_t *kc; |
372 |
|
num_diskio=0; |
373 |
|
|
374 |
|
#ifdef HPUX |
375 |
< |
|
376 |
< |
/* The "128" here is arbitrary, it can be increased to any number |
377 |
< |
at the expense of only more system calls to pstat(). */ |
378 |
< |
for (disknum = 0; disknum < 128; disknum++) { |
379 |
< |
if (pstat_getdisk(&pstat_diskinfo, sizeof(pstat_diskinfo), 1, disknum) == -1) { |
375 |
> |
while (1) { |
376 |
> |
num = pstat_getdisk(pstat_diskinfo, sizeof pstat_diskinfo[0], |
377 |
> |
DISK_BATCH, diskidx); |
378 |
> |
if (num == -1) { |
379 |
> |
sg_set_error_with_errno(SG_ERROR_PSTAT, |
380 |
> |
"pstat_getdisk"); |
381 |
> |
return NULL; |
382 |
> |
} else if (num == 0) { |
383 |
|
break; |
384 |
|
} |
385 |
|
|
386 |
< |
if (pstat_diskinfo.psd_idx != disknum) { |
387 |
< |
continue; |
383 |
< |
} |
386 |
> |
for (i = 0; i < num; i++) { |
387 |
> |
struct pst_diskinfo *di = &pstat_diskinfo[i]; |
388 |
|
|
389 |
< |
/* Skip "disabled" disks.. */ |
390 |
< |
if (pstat_diskinfo.psd_status == 0) { |
387 |
< |
continue; |
388 |
< |
} |
389 |
< |
|
390 |
< |
/* We can't seperate the reads from the writes, we'll |
391 |
< |
just give half to each. */ |
392 |
< |
rbytes = wbytes = (pstat_diskinfo.psd_dkwds * 64); |
393 |
< |
|
394 |
< |
/* Skip unused disks. */ |
395 |
< |
if (rbytes == 0 && wbytes == 0) { |
396 |
< |
continue; |
397 |
< |
} |
398 |
< |
|
399 |
< |
if (VECTOR_RESIZE(diskio_stats, num_diskio + 1) < 0) { |
400 |
< |
return NULL; |
401 |
< |
} |
402 |
< |
|
403 |
< |
diskio_stats_ptr = diskio_stats + num_diskio; |
404 |
< |
|
405 |
< |
diskio_stats_ptr->read_bytes = rbytes; |
406 |
< |
diskio_stats_ptr->write_bytes = wbytes; |
407 |
< |
|
408 |
< |
diskio_stats_ptr->systime = time(NULL); |
409 |
< |
|
410 |
< |
num_diskio++; |
411 |
< |
|
412 |
< |
if (diskio_stats_ptr->disk_name == NULL) { |
413 |
< |
dh = opendir("/dev/dsk"); |
414 |
< |
if (dh == NULL) { |
389 |
> |
/* Skip "disabled" disks. */ |
390 |
> |
if (di->psd_status == 0) { |
391 |
|
continue; |
392 |
|
} |
393 |
< |
|
394 |
< |
diskid = (pstat_diskinfo.psd_dev.psd_major << 24) | pstat_diskinfo.psd_dev.psd_minor; |
395 |
< |
while (1) { |
396 |
< |
dinfo = readdir(dh); |
397 |
< |
if (dinfo == NULL) { |
398 |
< |
break; |
399 |
< |
} |
400 |
< |
snprintf(fullpathbuf, sizeof(fullpathbuf), "/dev/dsk/%s", dinfo->d_name); |
401 |
< |
if (lstat(fullpathbuf, &lstatinfo) < 0) { |
393 |
> |
|
394 |
> |
/* We can't seperate the reads from the writes, we'll |
395 |
> |
just give the same to each. */ |
396 |
> |
rbytes = wbytes = di->psd_dkwds / 2; |
397 |
> |
|
398 |
> |
/* Skip unused disks. */ |
399 |
> |
if (rbytes == 0 && wbytes == 0) { |
400 |
> |
continue; |
401 |
> |
} |
402 |
> |
|
403 |
> |
if (VECTOR_RESIZE(diskio_stats, num_diskio + 1) < 0) { |
404 |
> |
return NULL; |
405 |
> |
} |
406 |
> |
|
407 |
> |
diskio_stats_ptr = diskio_stats + num_diskio; |
408 |
> |
|
409 |
> |
diskio_stats_ptr->read_bytes = rbytes; |
410 |
> |
diskio_stats_ptr->write_bytes = wbytes; |
411 |
> |
|
412 |
> |
diskio_stats_ptr->systime = time(NULL); |
413 |
> |
|
414 |
> |
num_diskio++; |
415 |
> |
|
416 |
> |
if (diskio_stats_ptr->disk_name == NULL) { |
417 |
> |
dh = opendir("/dev/dsk"); |
418 |
> |
if (dh == NULL) { |
419 |
|
continue; |
420 |
|
} |
421 |
< |
|
422 |
< |
if (lstatinfo.st_rdev == diskid) { |
423 |
< |
if (sg_update_string(&diskio_stats_ptr->disk_name, dinfo->d_name) < 0) { |
421 |
> |
|
422 |
> |
diskid = (di->psd_dev.psd_major << 24) | di->psd_dev.psd_minor; |
423 |
> |
while (1) { |
424 |
> |
dinfo = readdir(dh); |
425 |
> |
if (dinfo == NULL) { |
426 |
> |
break; |
427 |
> |
} |
428 |
> |
snprintf(fullpathbuf, sizeof(fullpathbuf), "/dev/dsk/%s", dinfo->d_name); |
429 |
> |
if (lstat(fullpathbuf, &lstatinfo) < 0) { |
430 |
> |
continue; |
431 |
> |
} |
432 |
> |
|
433 |
> |
if (lstatinfo.st_rdev == diskid) { |
434 |
> |
if (sg_update_string(&diskio_stats_ptr->disk_name, dinfo->d_name) < 0) { |
435 |
> |
return NULL; |
436 |
> |
} |
437 |
> |
break; |
438 |
> |
} |
439 |
> |
} |
440 |
> |
closedir(dh); |
441 |
> |
|
442 |
> |
if (diskio_stats_ptr->disk_name == NULL) { |
443 |
> |
if (sg_update_string(&diskio_stats_ptr->disk_name, di->psd_hw_path.psh_name) < 0) { |
444 |
|
return NULL; |
445 |
|
} |
433 |
– |
break; |
446 |
|
} |
447 |
|
} |
436 |
– |
closedir(dh); |
437 |
– |
|
438 |
– |
if (diskio_stats_ptr->disk_name == NULL) { |
439 |
– |
if (sg_update_string(&diskio_stats_ptr->disk_name, pstat_diskinfo.psd_hw_path.psh_name) < 0) { |
440 |
– |
return NULL; |
441 |
– |
} |
442 |
– |
} |
448 |
|
} |
449 |
+ |
diskidx = pstat_diskinfo[num - 1].psd_idx + 1; |
450 |
|
} |
451 |
|
#endif |
452 |
|
#ifdef OPENBSD |