1 |
|
/* |
2 |
< |
* i-scream central monitoring system |
2 |
> |
* i-scream libstatgrab |
3 |
|
* http://www.i-scream.org |
4 |
|
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
31 |
|
#include <time.h> |
32 |
|
#include "statgrab.h" |
33 |
|
#include "vector.h" |
34 |
+ |
#include "tools.h" |
35 |
|
|
36 |
|
#ifdef SOLARIS |
37 |
|
#include <sys/mnttab.h> |
43 |
|
#if defined(LINUX) || defined(CYGWIN) |
44 |
|
#include <mntent.h> |
45 |
|
#include <sys/vfs.h> |
45 |
– |
#include "tools.h" |
46 |
|
#endif |
47 |
|
|
48 |
|
#ifdef LINUX |
49 |
|
#define VALID_FS_TYPES {"adfs", "affs", "befs", "bfs", "efs", "ext2", \ |
50 |
< |
"ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \ |
51 |
< |
"jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \ |
52 |
< |
"rootfs", "reiserfs", "sysv", "v7", "udf", "ufs", \ |
53 |
< |
"umsdos", "vfat", "xfs", "jfs"} |
50 |
> |
"ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \ |
51 |
> |
"jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \ |
52 |
> |
"rootfs", "reiserfs", "sysv", "v7", "udf", "ufs", \ |
53 |
> |
"umsdos", "vfat", "xfs", "jfs"} |
54 |
|
#endif |
55 |
|
|
56 |
|
#ifdef CYGWIN |
66 |
|
#include <sys/dkstat.h> |
67 |
|
#include <devstat.h> |
68 |
|
#define VALID_FS_TYPES {"hpfs", "msdosfs", "ntfs", "udf", "ext2fs", \ |
69 |
< |
"ufs", "mfs"} |
69 |
> |
"ufs", "mfs"} |
70 |
|
#endif |
71 |
|
#if defined(NETBSD) || defined(OPENBSD) |
72 |
|
#include <sys/param.h> |
73 |
|
#include <sys/sysctl.h> |
74 |
|
#include <sys/disk.h> |
75 |
|
#define VALID_FS_TYPES {"ffs", "mfs", "msdos", "lfs", "adosfs", "ext2fs", \ |
76 |
< |
"ntfs"} |
76 |
> |
"ntfs"} |
77 |
|
#endif |
78 |
|
|
79 |
< |
static char *copy_string(char **dest, const char *src) { |
80 |
< |
char *new; |
81 |
< |
|
82 |
< |
new = realloc(*dest, strlen(src) + 1); |
83 |
< |
if (new == NULL) { |
84 |
< |
return NULL; |
85 |
< |
} |
86 |
< |
|
87 |
< |
strcpy(new, src); |
88 |
< |
*dest = new; |
89 |
< |
return new; |
90 |
< |
} |
91 |
< |
|
92 |
< |
static void disk_stat_init(disk_stat_t *d) { |
79 |
> |
static void disk_stat_init(sg_fs_stats *d) { |
80 |
|
d->device_name = NULL; |
81 |
|
d->fs_type = NULL; |
82 |
|
d->mnt_point = NULL; |
83 |
|
} |
84 |
|
|
85 |
< |
static void disk_stat_destroy(disk_stat_t *d) { |
85 |
> |
static void disk_stat_destroy(sg_fs_stats *d) { |
86 |
|
free(d->device_name); |
87 |
|
free(d->fs_type); |
88 |
|
free(d->mnt_point); |
89 |
|
} |
90 |
|
|
91 |
< |
int is_valid_fs_type(const char *type) { |
91 |
> |
static int is_valid_fs_type(const char *type) { |
92 |
|
const char *types[] = VALID_FS_TYPES; |
93 |
|
int i; |
94 |
|
|
100 |
|
return 0; |
101 |
|
} |
102 |
|
|
103 |
< |
disk_stat_t *get_disk_stats(int *entries){ |
104 |
< |
VECTOR_DECLARE_STATIC(disk_stats, disk_stat_t, 10, |
105 |
< |
disk_stat_init, disk_stat_destroy); |
103 |
> |
sg_fs_stats *sg_get_fs_stats(int *entries){ |
104 |
> |
VECTOR_DECLARE_STATIC(disk_stats, sg_fs_stats, 10, |
105 |
> |
disk_stat_init, disk_stat_destroy); |
106 |
|
|
107 |
|
int valid_type; |
108 |
|
int num_disks=0; |
110 |
|
FILE *f; |
111 |
|
#endif |
112 |
|
|
113 |
< |
disk_stat_t *disk_ptr; |
113 |
> |
sg_fs_stats *disk_ptr; |
114 |
|
|
115 |
|
#ifdef SOLARIS |
116 |
|
struct mnttab mp; |
128 |
|
#ifdef ALLBSD |
129 |
|
nummnt=getmntinfo(&mp , MNT_LOCAL); |
130 |
|
if (nummnt<=0){ |
131 |
+ |
sg_set_error(SG_ERROR_GETMNTINFO, NULL); |
132 |
|
return NULL; |
133 |
|
} |
134 |
|
for(;nummnt--; mp++){ |
137 |
|
|
138 |
|
#if defined(LINUX) || defined(CYGWIN) |
139 |
|
if ((f=setmntent("/etc/mtab", "r" ))==NULL){ |
140 |
+ |
sg_set_error(SG_ERROR_SETMNTENT, NULL); |
141 |
|
return NULL; |
142 |
|
} |
143 |
|
|
151 |
|
|
152 |
|
#ifdef SOLARIS |
153 |
|
if ((f=fopen("/etc/mnttab", "r" ))==NULL){ |
154 |
+ |
sg_set_error(SG_ERROR_OPEN, "/etc/mnttab"); |
155 |
|
return NULL; |
156 |
|
} |
157 |
|
while((getmntent(f, &mp)) == 0){ |
168 |
|
disk_ptr=disk_stats+num_disks; |
169 |
|
|
170 |
|
#ifdef ALLBSD |
171 |
< |
if (copy_string(&disk_ptr->device_name, mp->f_mntfromname) == NULL) { |
171 |
> |
if (sg_update_string(&disk_ptr->device_name, mp->f_mntfromname) < 0) { |
172 |
|
return NULL; |
173 |
|
} |
174 |
< |
if (copy_string(&disk_ptr->fs_type, mp->f_fstypename) == NULL) { |
174 |
> |
if (sg_update_string(&disk_ptr->fs_type, mp->f_fstypename) < 0) { |
175 |
|
return NULL; |
176 |
|
} |
177 |
< |
if (copy_string(&disk_ptr->mnt_point, mp->f_mntonname) == NULL) { |
177 |
> |
if (sg_update_string(&disk_ptr->mnt_point, mp->f_mntonname) < 0) { |
178 |
|
return NULL; |
179 |
|
} |
180 |
|
|
188 |
|
disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes; |
189 |
|
#endif |
190 |
|
#if defined(LINUX) || defined(CYGWIN) |
191 |
< |
if (copy_string(&disk_ptr->device_name, mp->mnt_fsname) == NULL) { |
191 |
> |
if (sg_update_string(&disk_ptr->device_name, mp->mnt_fsname) < 0) { |
192 |
|
return NULL; |
193 |
|
} |
194 |
|
|
195 |
< |
if (copy_string(&disk_ptr->fs_type, mp->mnt_type) == NULL) { |
195 |
> |
if (sg_update_string(&disk_ptr->fs_type, mp->mnt_type) < 0) { |
196 |
|
return NULL; |
197 |
|
} |
198 |
|
|
199 |
< |
if (copy_string(&disk_ptr->mnt_point, mp->mnt_dir) == NULL) { |
199 |
> |
if (sg_update_string(&disk_ptr->mnt_point, mp->mnt_dir) < 0) { |
200 |
|
return NULL; |
201 |
|
} |
202 |
|
disk_ptr->size = (long long)fs.f_bsize * (long long)fs.f_blocks; |
214 |
|
* Downside is its a bit hungry for a lot of mounts, as MNT_MAX_SIZE would prob |
215 |
|
* be upwards of a k each |
216 |
|
*/ |
217 |
< |
if (copy_string(&disk_ptr->device_name, mp.mnt_special) == NULL) { |
217 |
> |
if (sg_update_string(&disk_ptr->device_name, mp.mnt_special) < 0) { |
218 |
|
return NULL; |
219 |
|
} |
220 |
|
|
221 |
< |
if (copy_string(&disk_ptr->fs_type, mp.mnt_fstype) == NULL) { |
222 |
< |
return NULL; |
223 |
< |
} |
221 |
> |
if (sg_update_string(&disk_ptr->fs_type, mp.mnt_fstype) < 0) { |
222 |
> |
return NULL; |
223 |
> |
} |
224 |
|
|
225 |
< |
if (copy_string(&disk_ptr->mnt_point, mp.mnt_mountp) == NULL) { |
226 |
< |
return NULL; |
227 |
< |
} |
225 |
> |
if (sg_update_string(&disk_ptr->mnt_point, mp.mnt_mountp) < 0) { |
226 |
> |
return NULL; |
227 |
> |
} |
228 |
|
|
229 |
|
disk_ptr->size = (long long)fs.f_frsize * (long long)fs.f_blocks; |
230 |
|
disk_ptr->avail = (long long)fs.f_frsize * (long long)fs.f_bavail; |
241 |
|
*entries=num_disks; |
242 |
|
|
243 |
|
/* If this fails, there is very little i can do about it, so |
244 |
< |
I'll ignore it :) */ |
244 |
> |
I'll ignore it :) */ |
245 |
|
#if defined(LINUX) || defined(CYGWIN) |
246 |
|
endmntent(f); |
247 |
|
#endif |
253 |
|
|
254 |
|
} |
255 |
|
|
256 |
< |
static void diskio_stat_init(diskio_stat_t *d) { |
256 |
> |
int sg_fs_compare_device_name(const void *va, const void *vb) { |
257 |
> |
const sg_fs_stats *a = (const sg_fs_stats *)va; |
258 |
> |
const sg_fs_stats *b = (const sg_fs_stats *)vb; |
259 |
> |
|
260 |
> |
return strcmp(a->device_name, b->device_name); |
261 |
> |
} |
262 |
> |
|
263 |
> |
int sg_fs_compare_mnt_point(const void *va, const void *vb) { |
264 |
> |
const sg_fs_stats *a = (const sg_fs_stats *)va; |
265 |
> |
const sg_fs_stats *b = (const sg_fs_stats *)vb; |
266 |
> |
|
267 |
> |
return strcmp(a->mnt_point, b->mnt_point); |
268 |
> |
} |
269 |
> |
|
270 |
> |
static void diskio_stat_init(sg_disk_io_stats *d) { |
271 |
|
d->disk_name = NULL; |
272 |
|
} |
273 |
|
|
274 |
< |
static void diskio_stat_destroy(diskio_stat_t *d) { |
274 |
> |
static void diskio_stat_destroy(sg_disk_io_stats *d) { |
275 |
|
free(d->disk_name); |
276 |
|
} |
277 |
|
|
278 |
< |
VECTOR_DECLARE_STATIC(diskio_stats, diskio_stat_t, 10, |
279 |
< |
diskio_stat_init, diskio_stat_destroy); |
278 |
> |
VECTOR_DECLARE_STATIC(diskio_stats, sg_disk_io_stats, 10, |
279 |
> |
diskio_stat_init, diskio_stat_destroy); |
280 |
|
|
281 |
|
#ifdef LINUX |
282 |
|
typedef struct { |
285 |
|
} partition; |
286 |
|
#endif |
287 |
|
|
288 |
< |
diskio_stat_t *get_diskio_stats(int *entries){ |
288 |
> |
sg_disk_io_stats *sg_get_disk_io_stats(int *entries){ |
289 |
|
int num_diskio; |
290 |
|
#ifndef LINUX |
291 |
< |
diskio_stat_t *diskio_stats_ptr; |
291 |
> |
sg_disk_io_stats *diskio_stats_ptr; |
292 |
|
#endif |
293 |
|
|
294 |
|
#ifdef SOLARIS |
295 |
< |
kstat_ctl_t *kc; |
296 |
< |
kstat_t *ksp; |
295 |
> |
kstat_ctl_t *kc; |
296 |
> |
kstat_t *ksp; |
297 |
|
kstat_io_t kios; |
298 |
|
#endif |
299 |
|
#ifdef LINUX |
344 |
|
|
345 |
|
size = sizeof(diskcount); |
346 |
|
if (sysctl(mib, MIBSIZE, &diskcount, &size, NULL, 0) < 0) { |
347 |
+ |
sg_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKCOUNT"); |
348 |
|
return NULL; |
349 |
|
} |
350 |
|
|
352 |
|
mib[1] = HW_DISKNAMES; |
353 |
|
|
354 |
|
if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) { |
355 |
+ |
sg_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES"); |
356 |
|
return NULL; |
357 |
|
} |
358 |
|
|
359 |
< |
disknames = malloc(size); |
359 |
> |
disknames = sg_malloc(size); |
360 |
|
if (disknames == NULL) { |
361 |
|
return NULL; |
362 |
|
} |
363 |
|
|
364 |
|
if (sysctl(mib, MIBSIZE, disknames, &size, NULL, 0) < 0) { |
365 |
+ |
sg_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES"); |
366 |
|
return NULL; |
367 |
|
} |
368 |
|
|
369 |
< |
dk_name = calloc(diskcount, sizeof(char *)); |
369 |
> |
dk_name = sg_malloc(diskcount * sizeof(char *)); |
370 |
|
bufpp = disknames; |
371 |
|
for (i = 0; i < diskcount && (name = strsep(&bufpp, ",")) != NULL; i++) { |
372 |
|
dk_name[i] = name; |
381 |
|
#endif |
382 |
|
|
383 |
|
if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) { |
384 |
+ |
sg_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS"); |
385 |
|
return NULL; |
386 |
|
} |
387 |
|
|
391 |
|
num_disks = size / sizeof(struct diskstats); |
392 |
|
#endif |
393 |
|
|
394 |
< |
stats = malloc(size); |
394 |
> |
stats = sg_malloc(size); |
395 |
|
if (stats == NULL) { |
396 |
|
return NULL; |
397 |
|
} |
398 |
|
|
399 |
|
if (sysctl(mib, MIBSIZE, stats, &size, NULL, 0) < 0) { |
400 |
+ |
sg_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS"); |
401 |
|
return NULL; |
402 |
|
} |
403 |
|
|
404 |
|
for (i = 0; i < num_disks; i++) { |
405 |
+ |
const char *name; |
406 |
|
u_int64_t rbytes, wbytes; |
407 |
|
|
408 |
|
#ifdef NETBSD |
429 |
|
|
430 |
|
diskio_stats_ptr->read_bytes = rbytes; |
431 |
|
diskio_stats_ptr->write_bytes = wbytes; |
422 |
– |
if (diskio_stats_ptr->disk_name != NULL) { |
423 |
– |
free(diskio_stats_ptr->disk_name); |
424 |
– |
} |
432 |
|
#ifdef NETBSD |
433 |
< |
diskio_stats_ptr->disk_name = strdup(stats[i].dk_name); |
433 |
> |
name = stats[i].dk_name; |
434 |
|
#else |
435 |
< |
diskio_stats_ptr->disk_name = strdup(dk_name[i]); |
435 |
> |
name = dk_name[i]; |
436 |
|
#endif |
437 |
+ |
if (sg_update_string(&diskio_stats_ptr->disk_name, name) < 0) { |
438 |
+ |
return NULL; |
439 |
+ |
} |
440 |
|
diskio_stats_ptr->systime = time(NULL); |
441 |
|
|
442 |
|
num_diskio++; |
451 |
|
|
452 |
|
#if defined(FREEBSD) || defined(DFBSD) |
453 |
|
if (!stats_init) { |
454 |
< |
stats.dinfo=malloc(sizeof(struct devinfo)); |
454 |
> |
stats.dinfo=sg_malloc(sizeof(struct devinfo)); |
455 |
|
if(stats.dinfo==NULL) return NULL; |
456 |
|
bzero(stats.dinfo, sizeof(struct devinfo)); |
457 |
|
stats_init = 1; |
458 |
|
} |
459 |
|
#ifdef FREEBSD5 |
460 |
< |
if ((devstat_getdevs(NULL, &stats)) < 0) return NULL; |
460 |
> |
if ((devstat_getdevs(NULL, &stats)) < 0) { |
461 |
> |
sg_set_error(SG_ERROR_DEVSTAT_GETDEVS, NULL); |
462 |
> |
return NULL; |
463 |
> |
} |
464 |
|
/* Not aware of a get all devices, so i said 999. If we ever |
465 |
|
* find a machine with more than 999 disks, then i'll change |
466 |
|
* this number :) |
467 |
|
*/ |
468 |
< |
if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL; |
468 |
> |
if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) { |
469 |
> |
sg_set_error(SG_ERROR_DEVSTAT_SELECTDEVS, NULL); |
470 |
> |
return NULL; |
471 |
> |
} |
472 |
|
#else |
473 |
< |
if ((getdevs(&stats)) < 0) return NULL; |
473 |
> |
if ((getdevs(&stats)) < 0) { |
474 |
> |
sg_set_error(SG_ERROR_DEVSTAT_GETDEVS, NULL); |
475 |
> |
return NULL; |
476 |
> |
} |
477 |
|
/* Not aware of a get all devices, so i said 999. If we ever |
478 |
|
* find a machine with more than 999 disks, then i'll change |
479 |
|
* this number :) |
480 |
|
*/ |
481 |
< |
if (selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL; |
481 |
> |
if (selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) { |
482 |
> |
sg_set_error(SG_ERROR_DEVSTAT_SELECTDEVS, NULL); |
483 |
> |
return NULL; |
484 |
> |
} |
485 |
|
#endif |
486 |
|
|
487 |
|
for(counter=0;counter<stats.dinfo->numdevs;counter++){ |
510 |
|
diskio_stats_ptr->write_bytes=dev_ptr->bytes_written; |
511 |
|
#endif |
512 |
|
if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name); |
513 |
< |
asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number); |
513 |
> |
if (asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number) == -1) { |
514 |
> |
sg_set_error(SG_ERROR_ASPRINTF, NULL); |
515 |
> |
return NULL; |
516 |
> |
} |
517 |
|
diskio_stats_ptr->systime=time(NULL); |
518 |
|
|
519 |
|
num_diskio++; |
523 |
|
#endif |
524 |
|
#ifdef SOLARIS |
525 |
|
if ((kc = kstat_open()) == NULL) { |
526 |
< |
return NULL; |
527 |
< |
} |
526 |
> |
sg_set_error(SG_ERROR_KSTAT_OPEN, NULL); |
527 |
> |
return NULL; |
528 |
> |
} |
529 |
|
|
530 |
|
for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { |
531 |
< |
if (!strcmp(ksp->ks_class, "disk")) { |
531 |
> |
if (!strcmp(ksp->ks_class, "disk")) { |
532 |
|
|
533 |
|
if(ksp->ks_type != KSTAT_TYPE_IO) continue; |
534 |
|
/* We dont want metadevices appearins as num_diskio */ |
535 |
|
if(strcmp(ksp->ks_module, "md")==0) continue; |
536 |
< |
if((kstat_read(kc, ksp, &kios))==-1){ |
536 |
> |
if((kstat_read(kc, ksp, &kios))==-1){ |
537 |
|
} |
538 |
|
|
539 |
|
if (VECTOR_RESIZE(diskio_stats, num_diskio + 1) < 0) { |
543 |
|
diskio_stats_ptr=diskio_stats+num_diskio; |
544 |
|
|
545 |
|
diskio_stats_ptr->read_bytes=kios.nread; |
520 |
– |
|
546 |
|
diskio_stats_ptr->write_bytes=kios.nwritten; |
547 |
< |
|
548 |
< |
if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name); |
549 |
< |
|
550 |
< |
diskio_stats_ptr->disk_name=strdup((char *) get_svr_from_bsd(ksp->ks_name)); |
547 |
> |
if (sg_update_string(&diskio_stats_ptr->disk_name, |
548 |
> |
sg_get_svr_from_bsd(ksp->ks_name)) < 0) { |
549 |
> |
return NULL; |
550 |
> |
} |
551 |
|
diskio_stats_ptr->systime=time(NULL); |
552 |
+ |
|
553 |
|
num_diskio++; |
554 |
|
} |
555 |
|
} |
575 |
|
if (f == NULL) goto out; |
576 |
|
now = time(NULL); |
577 |
|
|
578 |
< |
while ((line_ptr = f_read_line(f, "")) != NULL) { |
578 |
> |
while ((line_ptr = sg_f_read_line(f, "")) != NULL) { |
579 |
|
char name[100]; |
580 |
|
char *s; |
581 |
|
long long rsect, wsect; |
604 |
|
goto out; |
605 |
|
} |
606 |
|
|
607 |
< |
if (diskio_stats[n].disk_name != NULL) |
608 |
< |
free(diskio_stats[n].disk_name); |
609 |
< |
diskio_stats[n].disk_name = strdup(name); |
607 |
> |
if (sg_update_string(&diskio_stats[n].disk_name, name) < 0) { |
608 |
> |
goto out; |
609 |
> |
} |
610 |
|
diskio_stats[n].read_bytes = rsect * 512; |
611 |
|
diskio_stats[n].write_bytes = wsect * 512; |
612 |
|
diskio_stats[n].systime = now; |
628 |
|
if (f == NULL) goto out; |
629 |
|
now = time(NULL); |
630 |
|
|
631 |
< |
line_ptr = f_read_line(f, "disk_io:"); |
631 |
> |
line_ptr = sg_f_read_line(f, "disk_io:"); |
632 |
|
if (line_ptr == NULL) goto out; |
633 |
|
|
634 |
|
while((line_ptr=strchr(line_ptr, ' '))!=NULL){ |
692 |
|
#endif |
693 |
|
|
694 |
|
#ifdef CYGWIN |
695 |
+ |
sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin"); |
696 |
|
return NULL; |
697 |
|
#endif |
698 |
|
|
701 |
|
return diskio_stats; |
702 |
|
} |
703 |
|
|
704 |
< |
diskio_stat_t *get_diskio_stats_diff(int *entries){ |
705 |
< |
VECTOR_DECLARE_STATIC(diff, diskio_stat_t, 1, |
706 |
< |
diskio_stat_init, diskio_stat_destroy); |
707 |
< |
diskio_stat_t *src = NULL, *dest; |
704 |
> |
sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries){ |
705 |
> |
VECTOR_DECLARE_STATIC(diff, sg_disk_io_stats, 1, |
706 |
> |
diskio_stat_init, diskio_stat_destroy); |
707 |
> |
sg_disk_io_stats *src = NULL, *dest; |
708 |
|
int i, j, diff_count, new_count; |
709 |
|
|
710 |
|
if (diskio_stats == NULL) { |
711 |
|
/* No previous stats, so we can't calculate a difference. */ |
712 |
< |
return get_diskio_stats(entries); |
712 |
> |
return sg_get_disk_io_stats(entries); |
713 |
|
} |
714 |
|
|
715 |
|
/* Resize the results array to match the previous stats. */ |
723 |
|
src = &diskio_stats[i]; |
724 |
|
dest = &diff[i]; |
725 |
|
|
726 |
< |
if (dest->disk_name != NULL) { |
727 |
< |
free(dest->disk_name); |
726 |
> |
if (sg_update_string(&dest->disk_name, src->disk_name) < 0) { |
727 |
> |
return NULL; |
728 |
|
} |
702 |
– |
dest->disk_name = strdup(src->disk_name); |
729 |
|
dest->read_bytes = src->read_bytes; |
730 |
|
dest->write_bytes = src->write_bytes; |
731 |
|
dest->systime = src->systime; |
732 |
|
} |
733 |
|
|
734 |
|
/* Get a new set of stats. */ |
735 |
< |
if (get_diskio_stats(&new_count) == NULL) { |
735 |
> |
if (sg_get_disk_io_stats(&new_count) == NULL) { |
736 |
|
return NULL; |
737 |
|
} |
738 |
|
|
763 |
|
|
764 |
|
*entries = diff_count; |
765 |
|
return diff; |
766 |
+ |
} |
767 |
+ |
|
768 |
+ |
int sg_disk_io_compare_name(const void *va, const void *vb) { |
769 |
+ |
const sg_disk_io_stats *a = (const sg_disk_io_stats *)va; |
770 |
+ |
const sg_disk_io_stats *b = (const sg_disk_io_stats *)vb; |
771 |
+ |
|
772 |
+ |
return strcmp(a->disk_name, b->disk_name); |
773 |
|
} |
774 |
|
|