ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/disk_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/disk_stats.c (file contents):
Revision 1.69 by tdb, Sun Jun 20 17:00:25 2004 UTC vs.
Revision 1.73 by tdb, Mon Nov 1 18:30:17 2004 UTC

# Line 37 | Line 37
37   #include <sys/mnttab.h>
38   #include <sys/statvfs.h>
39   #include <kstat.h>
40 < #define VALID_FS_TYPES {"ufs", "tmpfs"}
40 > #define VALID_FS_TYPES {"ufs", "tmpfs", "vxfs"}
41   #endif
42  
43   #if defined(LINUX) || defined(CYGWIN)
# Line 76 | Line 76
76                          "ntfs"}
77   #endif
78  
79 + #ifdef HPUX
80 + #include <sys/param.h>
81 + #include <sys/pstat.h>
82 + #include <sys/types.h>
83 + #include <sys/stat.h>
84 + #include <sys/vfs.h>
85 + #include <mntent.h>
86 + #include <dirent.h>
87 + #include <stdio.h>
88 + #include <time.h>
89 + #define VALID_FS_TYPES {"vxfs", "hfs"}
90 + #endif
91 +
92   static void disk_stat_init(sg_fs_stats *d) {
93          d->device_name = NULL;
94          d->fs_type = NULL;
# Line 106 | Line 119 | sg_fs_stats *sg_get_fs_stats(int *entries){
119  
120          int valid_type;
121          int num_disks=0;
122 < #if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN)
122 > #if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN) || defined(HPUX)
123          FILE *f;
124   #endif
125  
# Line 116 | Line 129 | sg_fs_stats *sg_get_fs_stats(int *entries){
129          struct mnttab mp;
130          struct statvfs fs;
131   #endif
132 < #if defined(LINUX) || defined(CYGWIN)
132 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
133          struct mntent *mp;
134          struct statfs fs;
135   #endif
136   #ifdef ALLBSD
137          int nummnt;
138 + #ifdef HAVE_STATVFS
139 +        struct statvfs *mp;
140 + #else
141          struct statfs *mp;
142   #endif
143 + #endif
144  
145   #ifdef ALLBSD
146          nummnt=getmntinfo(&mp , MNT_LOCAL);
147          if (nummnt<=0){
148 <                sg_set_error(SG_ERROR_GETMNTINFO, NULL);
148 >                sg_set_error_with_errno(SG_ERROR_GETMNTINFO, NULL);
149                  return NULL;
150          }
151          for(;nummnt--; mp++){
152                  valid_type = is_valid_fs_type(mp->f_fstypename);
153   #endif
154  
155 < #if defined(LINUX) || defined(CYGWIN)
155 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
156 > #ifdef MNT_MNTTAB
157 >        if ((f=setmntent(MNT_MNTTAB, "r" ))==NULL){
158 > #else
159          if ((f=setmntent("/etc/mtab", "r" ))==NULL){
160 + #endif
161                  sg_set_error(SG_ERROR_SETMNTENT, NULL);
162                  return NULL;
163          }
# Line 151 | Line 172 | sg_fs_stats *sg_get_fs_stats(int *entries){
172  
173   #ifdef SOLARIS
174          if ((f=fopen("/etc/mnttab", "r" ))==NULL){
175 <                sg_set_error(SG_ERROR_OPEN, "/etc/mnttab");
175 >                sg_set_error_with_errno(SG_ERROR_OPEN, "/etc/mnttab");
176                  return NULL;
177          }
178          while((getmntent(f, &mp)) == 0){
# Line 187 | Line 208 | sg_fs_stats *sg_get_fs_stats(int *entries){
208                          /* Freebsd doesn't have a "available" inodes */
209                          disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes;
210   #endif
211 < #if defined(LINUX) || defined(CYGWIN)
211 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
212                          if (sg_update_string(&disk_ptr->device_name, mp->mnt_fsname) < 0) {
213                                  return NULL;
214                          }
# Line 242 | Line 263 | sg_fs_stats *sg_get_fs_stats(int *entries){
263  
264          /* If this fails, there is very little i can do about it, so
265             I'll ignore it :) */
266 < #if defined(LINUX) || defined(CYGWIN)
266 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
267          endmntent(f);
268   #endif
269   #if defined(SOLARIS)
# Line 291 | Line 312 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
312          sg_disk_io_stats *diskio_stats_ptr;
313   #endif
314  
315 + #ifdef HPUX
316 +        long long rbytes = 0, wbytes = 0;
317 +        struct dirent *dinfo = NULL;
318 +        struct stat lstatinfo;
319 +        struct pst_diskinfo pstat_diskinfo;
320 +        char fullpathbuf[1024] = {0};
321 +        dev_t diskid;
322 +        DIR *dh = NULL;
323 +        int disknum = 0;
324 + #endif
325   #ifdef SOLARIS
326          kstat_ctl_t *kc;
327          kstat_t *ksp;
# Line 338 | Line 369 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
369  
370          num_diskio=0;
371  
372 + #ifdef HPUX
373 +
374 +        /* The "128" here is arbitrary, it can be increased to any number
375 +           at the expense of only more system calls to pstat(). */
376 +        for (disknum = 0; disknum < 128; disknum++) {
377 +                if (pstat_getdisk(&pstat_diskinfo, sizeof(pstat_diskinfo), 1, disknum) == -1) {
378 +                        break;
379 +                }
380 +
381 +                if (pstat_diskinfo.psd_idx != disknum) {
382 +                        continue;
383 +                }
384 +
385 +                /* Skip "disabled" disks.. */
386 +                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) {
415 +                                continue;
416 +                        }
417 +
418 +                        diskid = (pstat_diskinfo.psd_dev.psd_major << 24) | pstat_diskinfo.psd_dev.psd_minor;
419 +                        while (1) {
420 +                                dinfo = readdir(dh);
421 +                                if (dinfo == NULL) {
422 +                                        break;
423 +                                }
424 +                                snprintf(fullpathbuf, sizeof(fullpathbuf), "/dev/dsk/%s", dinfo->d_name);
425 +                                if (lstat(fullpathbuf, &lstatinfo) < 0) {
426 +                                        continue;
427 +                                }
428 +
429 +                                if (lstatinfo.st_rdev == diskid) {
430 +                                        if (sg_update_string(&diskio_stats_ptr->disk_name, dinfo->d_name) < 0) {
431 +                                                return NULL;
432 +                                        }
433 +                                        break;
434 +                                }
435 +                        }
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 +                        }
443 +                }
444 +        }
445 + #endif
446   #ifdef OPENBSD
447          mib[0] = CTL_HW;
448          mib[1] = HW_DISKCOUNT;
449  
450          size = sizeof(diskcount);
451          if (sysctl(mib, MIBSIZE, &diskcount, &size, NULL, 0) < 0) {
452 <                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKCOUNT");
452 >                sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKCOUNT");
453                  return NULL;
454          }
455  
# Line 352 | Line 457 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
457          mib[1] = HW_DISKNAMES;
458  
459          if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) {
460 <                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES");
460 >                sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES");
461                  return NULL;
462          }
463  
# Line 362 | Line 467 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
467          }
468  
469          if (sysctl(mib, MIBSIZE, disknames, &size, NULL, 0) < 0) {
470 <                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES");
470 >                sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES");
471                  return NULL;
472          }
473  
# Line 381 | Line 486 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
486   #endif
487  
488          if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) {
489 <                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS");
489 >                sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS");
490                  return NULL;
491          }
492  
# Line 397 | Line 502 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
502          }
503  
504          if (sysctl(mib, MIBSIZE, stats, &size, NULL, 0) < 0) {
505 <                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS");
505 >                sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS");
506                  return NULL;
507          }
508  
# Line 464 | Line 569 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
569          }
570   #ifdef FREEBSD5
571          if ((devstat_getdevs(NULL, &stats)) < 0) {
572 +                /* FIXME devstat functions return a string error in
573 +                   devstat_errbuf */
574                  sg_set_error(SG_ERROR_DEVSTAT_GETDEVS, NULL);
575                  return NULL;
576          }
# Line 517 | Line 624 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
624   #endif
625                  if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name);
626                  if (asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number) == -1) {
627 <                        sg_set_error(SG_ERROR_ASPRINTF, NULL);
627 >                        sg_set_error_with_errno(SG_ERROR_ASPRINTF, NULL);
628                          return NULL;
629                  }
630                  diskio_stats_ptr->systime=time(NULL);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines