]> granicus.if.org Git - sysstat/commitdiff
No longer assume that device-mapper major number is 253.
authorSebastien Godard <sysstat@orange.fr>
Sat, 11 Dec 2010 20:49:22 +0000 (21:49 +0100)
committerSebastien Godard <sysstat@orange.fr>
Sat, 11 Dec 2010 20:49:22 +0000 (21:49 +0100)
Get the real number from /proc/devices file.

The sar, sadf and iostat commands used to assume that device-mapper
major number was 253. This happened to be false sometimes. So get
the real number from the /proc/devices file.

From Mike Coleman <tutufan@gmail.com> 04/10/2010:

The iostat program seems to assume that the major device number for
devmap will always be 253.  This doesn't seem to be an official
number, though, and I have a box where it actually ends up being 252,
which breaks 'iostat -N'.

It looks like this can be determined dynamically by looking at /proc/devices.

CHANGES
common.c
common.h
iostat.c
pr_stats.c
rndr_stats.c
sadf.c
sar.c
xml_stats.c

diff --git a/CHANGES b/CHANGES
index 04153df9476951bbdacfb1b95f3d97dc398c000b..c3aadac1ac59c2ab116317702bac6512e81379f0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,8 @@ xxxx/xx/xx: Version 9.1.7 - Sebastien Godard (sysstat <at> orange.fr)
          variable. nfsiostat default output is expressed in kB/s,
          unless this variable is set (in which case the output is
          expressed in blocks/s).
+       * No longer assume that device-mapper major number is 253.
+         Get the real number from /proc/devices file.
        * [Kenichi Okuyama]: Small change to sar manual page.
        * sar manual page updated.
        * Code cleaned.
index 48c8368642280202b0a23779fa70f54ef936ecc5..8b1bdbab51aa1b6fe329b59cfbe04df1afca65e8 100644 (file)
--- a/common.c
+++ b/common.c
@@ -262,6 +262,38 @@ int get_sysfs_dev_nr(int display_partitions)
        return dev;
 }
 
+/*
+ ***************************************************************************
+ * Read /proc/devices file and get device-mapper major number.
+ * If device-mapper entry is not found in file, use DEFAULT_DEMAP_MAJOR
+ * number.
+ *
+ * RETURNS:
+ * Device-mapper major number.
+ ***************************************************************************
+ */
+unsigned int get_devmap_major(void)
+{
+       FILE *fp;
+       char line[128];
+       unsigned int dm_major = DEFAULT_DEVMAP_MAJOR;
+
+       if ((fp = fopen(DEVICES, "r")) == NULL)
+               return dm_major;
+
+       while (fgets(line, 128, fp) != NULL) {
+
+               if (strstr(line, "device-mapper")) {
+                       /* Read device-mapper major number */
+                       sscanf(line, "%u", &dm_major);
+               }
+       }
+
+       fclose(fp);
+
+       return dm_major;
+}
+
 /*
  ***************************************************************************
  * Print banner.
index 4d2651e1bf22b1d0acf241ed85ea2cdd4cd6994c..cf067a392ddcb3c2487a786af8d4f7c57698c921 100644 (file)
--- a/common.h
+++ b/common.h
 #define SYSFS_TIME_IN_STATE    "cpufreq/stats/time_in_state"
 #define S_STAT                 "stat"
 #define DEVMAP_DIR             "/dev/mapper"
+#define DEVICES                        "/proc/devices"
 
-#define MAX_FILE_LEN   256
-#define MAX_PF_NAME    1024
-#define DEVMAP_MAJOR   253
-#define MAX_NAME_LEN   72
+#define MAX_FILE_LEN           256
+#define MAX_PF_NAME            1024
+#define DEFAULT_DEVMAP_MAJOR   253
+#define MAX_NAME_LEN           72
 
-#define NR_DISKS       4
+#define NR_DISKS               4
 
 /* Environment variables */
-#define ENV_TIME_FMT   "S_TIME_FORMAT"
-#define ENV_TIME_DEFTM "S_TIME_DEF_TIME"
+#define ENV_TIME_FMT           "S_TIME_FORMAT"
+#define ENV_TIME_DEFTM         "S_TIME_DEF_TIME"
 
-#define DIGITS         "0123456789"
+#define DIGITS                 "0123456789"
 
 
 /*
@@ -163,6 +164,8 @@ extern char *
        device_name(char *);
 extern void
        get_HZ(void);
+extern unsigned int
+       get_devmap_major(void);
 extern unsigned long long
        get_interval(unsigned long long, unsigned long long);
 extern void
index e2f98c73ab4c6209ff6d314d0b1886d550d3f3f0..745a53068f4e82e519e96441951b8cbd62cd4dfd 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -61,6 +61,7 @@ int iodev_nr = 0;     /* Nb of devices and partitions found */
 int cpu_nr = 0;                /* Nb of processors on the machine */
 int dlist_idx = 0;     /* Nb of devices entered on the command line */
 int flags = 0;         /* Flag for common options and system state */
+unsigned int dm_major; /* Device-mapper major number */
 
 long interval = 0;
 char timestamp[64];
@@ -678,7 +679,7 @@ void read_diskstats_stat(int curr)
                        }
                }
 
-               if ((DISPLAY_DEVMAP_NAME(flags)) && (major == DEVMAP_MAJOR)) {
+               if ((DISPLAY_DEVMAP_NAME(flags)) && (major == dm_major)) {
                        /*
                         * If the device is a device mapper device, try to get its
                         * assigned name of its logical device.
@@ -1298,6 +1299,10 @@ int main(int argc, char **argv)
                dlist_idx = 0;
        }
 
+       if (DISPLAY_DEVMAP_NAME(flags)) {
+               dm_major = get_devmap_major();
+       }
+
        /* Init structures according to machine architecture */
        io_sys_init();
 
index 86d9a8c7a8dac9340956b8ea50fb85b38a3a465d..6fc7fad5ad794676410e83044a1b3a6db525c473 100644 (file)
@@ -37,6 +37,7 @@
 #endif
 
 extern unsigned int flags;
+extern unsigned int dm_major;
 extern int  dis;
 extern char timestamp[][TIMESTAMP_LEN];
 extern unsigned long avg_count;
@@ -823,7 +824,7 @@ __print_funct_t print_disk_stats(struct activity *a, int prev, int curr,
                
                dev_name = NULL;
 
-               if ((USE_PRETTY_OPTION(flags)) && (sdc->major == DEVMAP_MAJOR)) {
+               if ((USE_PRETTY_OPTION(flags)) && (sdc->major == dm_major)) {
                        dev_name = transform_devmapname(sdc->major, sdc->minor);
                }
 
index de0b840898665b264e1f9907ae515b51a177310f..58172faf9d7dcc9250388e8995d0eac6527bf639 100644 (file)
@@ -38,6 +38,7 @@
 static char *seps[] =  {"\t", ";"};
 
 extern unsigned int flags;
+extern unsigned int dm_major;
 
 /*
  ***************************************************************************
@@ -909,7 +910,7 @@ __print_funct_t render_disk_stats(struct activity *a, int isdb, char *pre,
 
                dev_name = NULL;
 
-               if ((USE_PRETTY_OPTION(flags)) && (sdc->major == DEVMAP_MAJOR)) {
+               if ((USE_PRETTY_OPTION(flags)) && (sdc->major == dm_major)) {
                        dev_name = transform_devmapname(sdc->major, sdc->minor);
                }
 
diff --git a/sadf.c b/sadf.c
index 77379e714db621f031d37487bb06ae6e372b6d28..0d7b83655515ec41f0eb11df96f8ac81d26b4e5c 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -49,6 +49,7 @@ char *sccsid(void) { return (SCCSID); }
 long interval = -1, count = 0;
 
 unsigned int flags = 0;
+unsigned int dm_major;         /* Device-mapper major number */
 unsigned int format = 0;       /* Output format */
 
 /* File header */
@@ -1364,6 +1365,10 @@ int main(int argc, char **argv)
                tm_end.tm_hour += 24;
        }
 
+       if (USE_PRETTY_OPTION(flags)) {
+               dm_major = get_devmap_major();
+       }
+
        /*
         * Display all the contents of the daily data file if the count parameter
         * was not set on the command line.
diff --git a/sar.c b/sar.c
index 69b970926e5db6cf790596b2bdce9be3d51ad39c..6a2f84c6c83496acf69937c05af91a93f9fdf452 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -50,6 +50,8 @@ long interval = -1, count = 0;
 int dis = TRUE;
 
 unsigned int flags = 0;
+unsigned int dm_major; /* Device-mapper major number */
+
 char timestamp[2][TIMESTAMP_LEN];
 
 unsigned long avg_count = 0;
@@ -1273,6 +1275,10 @@ int main(int argc, char **argv)
                usage(argv[0]);
        }
 
+       if (USE_PRETTY_OPTION(flags)) {
+               dm_major = get_devmap_major();
+       }
+       
        if (!count) {
                /*
                 * count parameter not set: Display all the contents of the file
index df9fe1467ea4664c2d9f207e78c7aa4dff89d535..096a9973584f5f82148f648118db0c8bd95549a0 100644 (file)
@@ -36,6 +36,7 @@
 #endif
 
 extern unsigned int flags;
+extern unsigned int dm_major;
 
 /*
  ***************************************************************************
@@ -697,7 +698,7 @@ __print_funct_t xml_print_disk_stats(struct activity *a, int curr, int tab,
                
                dev_name = NULL;
 
-               if ((USE_PRETTY_OPTION(flags)) && (sdc->major == DEVMAP_MAJOR)) {
+               if ((USE_PRETTY_OPTION(flags)) && (sdc->major == dm_major)) {
                        dev_name = transform_devmapname(sdc->major, sdc->minor);
                }