]> granicus.if.org Git - sysstat/commitdiff
[Andrey Borzenkov]: Don't take virtual devices into account in sar -b results.
authorSebastien Godard <sysstat@orange.fr>
Sun, 29 Jan 2012 13:43:53 +0000 (14:43 +0100)
committerSebastien Godard <sysstat@orange.fr>
Sun, 29 Jan 2012 13:43:53 +0000 (14:43 +0100)
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>/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.

CHANGES
CREDITS
common.c
common.h
iostat.c
rd_stats.c

diff --git a/CHANGES b/CHANGES
index 001b6e2f0a3e228c2319a82a125f40704ce9c0f4..da3891af7d987a414e070d76941833c2f46551ab 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
 Changes:
 
 xxxx/xx/xx: Version 10.0.4 - Sebastien Godard (sysstat <at> 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 6287931f9beccd132d1f901aca0252f927073858..918a943a1848effb565e5f42d3bebe980d32e60c 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -138,6 +138,7 @@ I would also thank the following people for their hints or bug reports
        Michael Blakeley <mike@bla[...].com>
        Pascal Bleser <pbleser@ato[...].com>
        Lodewijk Bonebakker <jlbonebakker@gma[...].com>
+       Andrey Borzenkov <arvidjaar@gma[...].com>
        Jesse Brandeburg <jesse.brandeburg@int[...].com>
        Xavier Bru <xavier.bru@bul[...].net>
        Jason Burnett <jason@jnj[...].org>
index 1bf459a5daf8cbf449cca8cef55e1aa56521fcf5..dad20c6a85c2fbd4ec4a916a2fd3748456511939 100644 (file)
--- 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>/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));
 }
index 3eff7ed8bae24ec5ae517c410e811be7b04cc1e2..3ad5544fa66f3a5875bee73c7ba196ff0e265607 100644 (file)
--- 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
index 95d5b4d7d2e5cc74c0e5e397d359ce29e8833f0a..2892afb83371931e1fa33d682da78647565d5efd 100644 (file)
--- 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;
index 13ad0c1cef92187f9e53e797cca6b0da90d8d8f7..7da6b7064185fe8bb0c85c0872198e6f73b49774 100644 (file)
@@ -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)