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.
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.
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.
#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"
/*
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
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];
}
}
- 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.
dlist_idx = 0;
}
+ if (DISPLAY_DEVMAP_NAME(flags)) {
+ dm_major = get_devmap_major();
+ }
+
/* Init structures according to machine architecture */
io_sys_init();
#endif
extern unsigned int flags;
+extern unsigned int dm_major;
extern int dis;
extern char timestamp[][TIMESTAMP_LEN];
extern unsigned long avg_count;
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);
}
static char *seps[] = {"\t", ";"};
extern unsigned int flags;
+extern unsigned int dm_major;
/*
***************************************************************************
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);
}
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 */
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.
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;
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
#endif
extern unsigned int flags;
+extern unsigned int dm_major;
/*
***************************************************************************
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);
}