From: Sebastien Godard Date: Sun, 29 Jan 2012 13:43:53 +0000 (+0100) Subject: [Andrey Borzenkov]: Don't take virtual devices into account in sar -b results. X-Git-Tag: v10.0.4~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b5adcc71e0e8ef744d2910e0c0f99fe87df0726;p=sysstat [Andrey Borzenkov]: Don't take virtual devices into account in sar -b results. Add only physical devices stats to sar -b results. This avoids multiplying totals when layered devices (device mapper, Linux MD, etc) are present. The device is assumed to be virtual if no /sys/block//device link exists. Only sar -b stats are modified, other statistics (e.g. sar -d) as well as iostat continue to process virtual devices as before. Problem noticed by Diedrich Ehlerding. --- diff --git a/CHANGES b/CHANGES index 001b6e2..da3891a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Changes: xxxx/xx/xx: Version 10.0.4 - Sebastien Godard (sysstat orange.fr) + * [Andrey Borzenkov]: Don't take virtual devices into account in + sar -b results. * configure script updated: Added --disable-stripping option. Using this option tells configure to NOT strip object files. * NLS updated. Serbian translation added. diff --git a/CREDITS b/CREDITS index 6287931..918a943 100644 --- a/CREDITS +++ b/CREDITS @@ -138,6 +138,7 @@ I would also thank the following people for their hints or bug reports Michael Blakeley Pascal Bleser Lodewijk Bonebakker + Andrey Borzenkov Jesse Brandeburg Xavier Bru Jason Burnett diff --git a/common.c b/common.c index 1bf459a..dad20c6 100644 --- a/common.c +++ b/common.c @@ -403,13 +403,16 @@ char *device_name(char *name) * ioconf.c which should be used only with kernels that don't have sysfs. * * IN: - * @name Device or partition name. + * @name Device or partition name. + * @allow_virtual TRUE if virtual devices are also accepted. + * The device is assumed to be virtual if no + * /sys/block//device link exists. * * RETURNS: - * TRUE if @name is a (whole) device. + * TRUE if @name is not a partition. *************************************************************************** */ -int is_device(char *name) +int is_device(char *name, int allow_virtual) { char syspath[PATH_MAX]; char *slash; @@ -418,7 +421,8 @@ int is_device(char *name) while ((slash = strchr(name, '/'))) { *slash = '!'; } - snprintf(syspath, sizeof(syspath), "%s/%s", SYSFS_BLOCK, name); + snprintf(syspath, sizeof(syspath), "%s/%s%s", SYSFS_BLOCK, name, + allow_virtual ? "" : "/device"); return !(access(syspath, F_OK)); } diff --git a/common.h b/common.h index 3eff7ed..3ad5544 100644 --- a/common.h +++ b/common.h @@ -70,6 +70,9 @@ #define NR_DISKS 4 +#define IGNORE_VIRTUAL_DEVICES FALSE +#define ACCEPT_VIRTUAL_DEVICES TRUE + /* Environment variables */ #define ENV_TIME_FMT "S_TIME_FORMAT" #define ENV_TIME_DEFTM "S_TIME_DEF_TIME" @@ -192,7 +195,7 @@ extern int extern void init_nls(void); extern int - is_device(char *); + is_device(char *, int); extern double ll_s_value(unsigned long long, unsigned long long, unsigned long long); extern double diff --git a/iostat.c b/iostat.c index 95d5b4d..2892afb 100644 --- a/iostat.c +++ b/iostat.c @@ -639,7 +639,8 @@ void read_diskstats_stat(int curr) if (i == 14) { /* Device or partition */ - if (!dlist_idx && !DISPLAY_PARTITIONS(flags) && !is_device(dev_name)) + if (!dlist_idx && !DISPLAY_PARTITIONS(flags) && + !is_device(dev_name, ACCEPT_VIRTUAL_DEVICES)) continue; sdev.rd_ios = rd_ios; sdev.rd_merges = rd_merges_or_rd_sec; diff --git a/rd_stats.c b/rd_stats.c index 13ad0c1..7da6b70 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -484,9 +484,9 @@ void read_diskstats_io(struct stats_io *st_io) &major, &minor, dev_name, &rd_ios, &rd_sec, &wr_ios, &wr_sec) == 7) { - if (is_device(dev_name)) { + if (is_device(dev_name, IGNORE_VIRTUAL_DEVICES)) { /* - * OK: It's a device and not a partition. + * OK: It's a (real) device and not a partition. * Note: Structure should have been initialized first! */ st_io->dk_drive += rd_ios + wr_ios; @@ -541,7 +541,7 @@ void read_diskstats_disk(struct stats_disk *st_disk, int nbr, int read_part) if (!rd_ios && !wr_ios) /* Unused device: Ignore it */ continue; - if (read_part || is_device(dev_name)) { + if (read_part || is_device(dev_name, ACCEPT_VIRTUAL_DEVICES)) { st_disk_i = st_disk + dsk++; st_disk_i->major = major; st_disk_i->minor = minor; @@ -2017,7 +2017,7 @@ int get_diskstats_dev_nr(int count_part, int only_used_dev) if (!count_part) { i = sscanf(line, "%*d %*d %s %lu %*u %*u %*u %lu", dev_name, &rd_ios, &wr_ios); - if ((i == 2) || !is_device(dev_name)) + if ((i == 2) || !is_device(dev_name, ACCEPT_VIRTUAL_DEVICES)) /* It was a partition and not a device */ continue; if (only_used_dev && !rd_ios && !wr_ios)