From: Sebastien Godard Date: Sat, 11 Dec 2010 20:49:22 +0000 (+0100) Subject: No longer assume that device-mapper major number is 253. X-Git-Tag: v9.1.7~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4accbb2d37dc04dad87cdc4ffbf9021d10eadbf1;p=sysstat No longer assume that device-mapper major number is 253. 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 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. --- diff --git a/CHANGES b/CHANGES index 04153df..c3aadac 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,8 @@ xxxx/xx/xx: Version 9.1.7 - Sebastien Godard (sysstat 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. diff --git a/common.c b/common.c index 48c8368..8b1bdba 100644 --- 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. diff --git a/common.h b/common.h index 4d2651e..cf067a3 100644 --- a/common.h +++ b/common.h @@ -55,19 +55,20 @@ #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 diff --git a/iostat.c b/iostat.c index e2f98c7..745a530 100644 --- 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(); diff --git a/pr_stats.c b/pr_stats.c index 86d9a8c..6fc7fad 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -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); } diff --git a/rndr_stats.c b/rndr_stats.c index de0b840..58172fa 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -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 77379e7..0d7b836 100644 --- 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 69b9709..6a2f84c 100644 --- 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 diff --git a/xml_stats.c b/xml_stats.c index df9fe14..096a997 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -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); }