#include "version.h"
#include "common.h"
+#include "ioconf.h"
#ifdef USE_NLS
#include <locale.h>
return pretty;
}
+/*
+ * **************************************************************************
+ * Try to get device real name from sysfs tree.
+ *
+ * IN:
+ * @major Major number of the device.
+ * @minor Minor number of the device.
+ *
+ * RETURNS:
+ * The name of the device, which may be the real name (as it appears in /dev)
+ * or NULL.
+ ***************************************************************************
+ */
+char *get_devname_from_sysfs(unsigned int major, unsigned int minor)
+{
+ static char link[256], target[PATH_MAX];
+ char *devname;
+ ssize_t r;
+
+ snprintf(link, 256, "%s/%u:%u", SYSFS_DEV_BLOCK, major, minor);
+
+ /* Get full path to device knowing its major and minor numbers */
+ r = readlink(link, target, PATH_MAX);
+ if (r <= 0 || r >= PATH_MAX) {
+ return (NULL);
+ }
+
+ target[r] = '\0';
+
+ /* Get device name */
+ devname = basename(target);
+ if (!devname || strnlen(devname, FILENAME_MAX) == 0) {
+ return (NULL);
+ }
+
+ return (devname);
+}
+
+/*
+ * **************************************************************************
+ * Get device real name if possible.
+ *
+ * IN:
+ * @major Major number of the device.
+ * @minor Minor number of the device.
+ *
+ * RETURNS:
+ * The name of the device, which may be the real name (as it appears in /dev)
+ * or a string with the following format devM-n.
+ ***************************************************************************
+ */
+char *get_devname(unsigned int major, unsigned int minor)
+{
+ static char buf[32];
+ char *name;
+
+ name = get_devname_from_sysfs(major, minor);
+ if (name != NULL)
+ return (name);
+
+ name = ioc_name(major, minor);
+ if ((name != NULL) && strcmp(name, K_NODEV))
+ return (name);
+
+ snprintf(buf, 32, "dev%u-%u", major, minor);
+ return (buf);
+}
+
+/*
+ * **************************************************************************
+ * Get device name (whether pretty-printed, persistent or not).
+ *
+ * IN:
+ * @major Major number of the device.
+ * @minor Minor number of the device.
+ * @wwn WWN identifier of the device (0 if unknown).
+ * @part_nr Partition number (0 if unknown).
+ * @disp_devmap_name Display device mapper name.
+ * @disp_persist_name Display persistent name of the device.
+ * @use_stable_id Display stable-across-reboots name.
+ * @dflt_name Device name to use by default (if existent).
+ *
+ * RETURNS:
+ * The name of the device.
+ ***************************************************************************
+ */
+char *get_device_name(unsigned int major, unsigned int minor, unsigned long long wwn[],
+ unsigned int part_nr, unsigned int disp_devmap_name,
+ unsigned int disp_persist_name, unsigned int use_stable_id,
+ char *dflt_name)
+{
+ static unsigned int dm_major = 0;
+ char *dev_name = NULL, *persist_dev_name = NULL, *bang;
+ static char sid[64], dname[MAX_NAME_LEN];
+ char xsid[32] = "", pn[16] = "";
+
+ if (disp_persist_name) {
+ persist_dev_name = get_persistent_name_from_pretty(get_devname(major, minor));
+ }
+
+ if (persist_dev_name) {
+ dev_name = persist_dev_name;
+ }
+ else {
+ if (use_stable_id && (wwn[0] != 0)) {
+ if (wwn[1] != 0) {
+ sprintf(xsid, "%016llx", wwn[1]);
+ }
+ if (part_nr) {
+ sprintf(pn, "-%d", part_nr);
+ }
+ snprintf(sid, sizeof(sid), "%#016llx%s%s", wwn[0], xsid, pn);
+ dev_name = sid;
+ }
+ else if (disp_devmap_name) {
+ if (!dm_major) {
+ dm_major = get_devmap_major();
+ }
+ if (major == dm_major) {
+ dev_name = transform_devmapname(major, minor);
+ }
+ }
+
+ if (!dev_name) {
+ if (dflt_name) {
+ dev_name = dflt_name;
+ }
+ else {
+ dev_name = get_devname(major, minor);
+ }
+ }
+ }
+
+ strncpy(dname, dev_name, sizeof(dname));
+ dname[sizeof(dname) - 1] = '\0';
+
+ while ((bang = strchr(dname, '!'))) {
+ /*
+ * Some devices may have had a slash replaced with
+ * a bang character (eg. cciss!c0d0...)
+ * Restore their original names.
+ */
+ *bang = '/';
+ }
+
+ return dname;
+}
+
/*
***************************************************************************
* Init color strings.
(int, int, ...);
char *device_name
(char *);
+char *get_device_name
+ (unsigned int, unsigned int, unsigned long long [],
+ unsigned int, unsigned int, unsigned int, unsigned int, char *);
unsigned int get_devmap_major
(void);
unsigned long long get_interval
int group_nr = 0; /* Nb of device groups */
int cpu_nr = 0; /* Nb of processors on the machine */
int flags = 0; /* Flag for common options and system state */
-unsigned int dm_major; /* Device-mapper major number */
long interval = 0;
char timestamp[TIMESTAMP_LEN];
int h, hl = 0, hh = 0, fctr = 1, tab = 4, next = FALSE;
unsigned long long itv;
struct io_device *d, *dtmp, *g = NULL, *dnext = NULL;
- char *dev_name, *pdname, *bang, dname[MAX_NAME_LEN];
+ char *dev_name, *pdname;
/* Test stdout */
TEST_STDOUT(STDOUT_FILENO);
ioj = &iozero;
}
- /* Get device name to print */
- dev_name = NULL;
-
- if ((DISPLAY_DEVMAP_NAME(flags)) && (d->major == dm_major)) {
- /*
- * If the device is a device mapper device, try to get its
- * assigned name of its logical device.
- */
- dev_name = transform_devmapname(d->major, d->minor);
- }
-
- if (DISPLAY_PERSIST_NAME_I(flags)) {
- pdname = get_persistent_name_from_pretty(dev_name ? dev_name : d->name);
- if (pdname) {
- dev_name = pdname;
- }
- }
-
- if (!dev_name) {
- dev_name = d->name;
- }
- strncpy(dname, dev_name, sizeof(dname));
- dname[sizeof(dname) - 1] = '\0';
-
- while ((bang = strchr(dname, '!'))) {
- /*
- * Some devices may have had a slash replaced with
- * a bang character (eg. cciss!c0d0...)
- * Restore their original names.
- */
- *bang = '/';
- }
-
+ dev_name = get_device_name(d->major, d->minor, NULL, 0,
+ DISPLAY_DEVMAP_NAME(flags),
+ DISPLAY_PERSIST_NAME_I(flags),
+ FALSE, d->name);
#ifdef DEBUG
if (DISPLAY_DEBUG(flags)) {
/* Debug output */
"fl_ios=%lu fl_ticks=%u "
"ios_pgr=%u tot_ticks=%u "
"rq_ticks=%u }\n",
- dname,
+ dev_name,
itv,
fctr,
ioi->rd_sectors,
next = TRUE;
if (DISPLAY_EXTENDED(flags)) {
- write_ext_stat(itv, fctr, h, d, ioi, ioj, tab, dname);
+ write_ext_stat(itv, fctr, h, d, ioi, ioj, tab, dev_name);
}
else {
- write_basic_stat(itv, fctr, d, ioi, ioj, tab, dname);
+ write_basic_stat(itv, fctr, d, ioi, ioj, tab, dev_name);
}
}
}
/* Select disk output unit (kB/s or blocks/s) */
set_disk_output_unit();
- if (DISPLAY_DEVMAP_NAME(flags)) {
- dm_major = get_devmap_major();
- }
-
if (DISPLAY_JSON_OUTPUT(flags)) {
/* Use a decimal point to make JSON code compliant with RFC7159 */
setlocale(LC_NUMERIC, "C");
}
/* Get device name */
- dev_name = get_sa_devname(sdc->major, sdc->minor,
- sdc->wwn, sdc->part_nr, flags);
+ dev_name = get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL);
if (a->item_list != NULL) {
/* A list of devices has been entered on the command line */
}
/* Get device name */
- dev_name = get_sa_devname(sdc->major, sdc->minor,
- sdc->wwn, sdc->part_nr, flags);
+ dev_name = get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL);
if (a->item_list != NULL) {
/* A list of devices has been entered on the command line */
continue;
/* Get device name */
- dev_name = get_sa_devname(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr, flags);
+ dev_name = get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL);
if (a->item_list != NULL) {
/* A list of devices has been entered on the command line */
sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize);
/* Get device name */
- dev_name = get_sa_devname(sdc->major, sdc->minor,
- sdc->wwn, sdc->part_nr, flags);
+ dev_name = get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL);
if (a->item_list != NULL) {
/* A list of devices has been entered on the command line */
}
/* Get device name */
- dev_name = get_sa_devname(sdc->major, sdc->minor,
- sdc->wwn, sdc->part_nr, flags);
+ dev_name = get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL);
if (a->item_list != NULL) {
/* A list of devices has been entered on the command line */
a->nr_allocated = nr_realloc;
}
-/*
- ***************************************************************************
- * Try to get device real name from sysfs tree.
- *
- * IN:
- * @major Major number of the device.
- * @minor Minor number of the device.
- *
- * RETURNS:
- * The name of the device, which may be the real name (as it appears in /dev)
- * or NULL.
- ***************************************************************************
- */
-char *get_devname_from_sysfs(unsigned int major, unsigned int minor)
-{
- static char link[256], target[PATH_MAX];
- char *devname;
- ssize_t r;
-
- snprintf(link, 256, "%s/%u:%u", SYSFS_DEV_BLOCK, major, minor);
-
- /* Get full path to device knowing its major and minor numbers */
- r = readlink(link, target, PATH_MAX);
- if (r <= 0 || r >= PATH_MAX) {
- return (NULL);
- }
-
- target[r] = '\0';
-
- /* Get device name */
- devname = basename(target);
- if (!devname || strnlen(devname, FILENAME_MAX) == 0) {
- return (NULL);
- }
-
- return (devname);
-}
-
-/*
- ***************************************************************************
- * Get device real name if possible.
- *
- * IN:
- * @major Major number of the device.
- * @minor Minor number of the device.
- *
- * RETURNS:
- * The name of the device, which may be the real name (as it appears in /dev)
- * or a string with the following format devM-n.
- ***************************************************************************
- */
-char *get_devname(unsigned int major, unsigned int minor)
-{
- static char buf[32];
- char *name;
-
- snprintf(buf, 32, "dev%u-%u", major, minor);
-
- name = get_devname_from_sysfs(major, minor);
- if (name != NULL)
- return (name);
-
- name = ioc_name(major, minor);
- if ((name != NULL) && strcmp(name, K_NODEV))
- return (name);
-
- return (buf);
-}
-
/*
***************************************************************************
* Check if we are close enough to desired interval.
ssnp_all->flow_limit += ssnp->flow_limit;
}
}
-
-/*
- ***************************************************************************
- * Get device name (whether pretty-printed, persistent or not).
- *
- * IN:
- * @major Major number of the device.
- * @minor Minor number of the device.
- * @wwn WWN identifier of the device (0 if unknown).
- * @part_nr Partition number (0 if unknown).
- * @flags Flags for common options and system state.
- *
- * RETURNS:
- * The name of the device.
- ***************************************************************************
- */
-char *get_sa_devname(unsigned int major, unsigned int minor, unsigned long long wwn[],
- unsigned int part_nr, uint64_t flags)
-{
- char *dev_name = NULL, *persist_dev_name = NULL;
- static char sid[64];
- char xsid[32] = "", pn[16] = "";
-
- if (DISPLAY_PERSIST_NAME_S(flags)) {
- persist_dev_name = get_persistent_name_from_pretty(get_devname(major, minor));
- }
-
- if (persist_dev_name) {
- dev_name = persist_dev_name;
- }
- else {
- if ((USE_STABLE_ID(flags)) && (wwn[0] != 0)) {
- if (wwn[1] != 0) {
- sprintf(xsid, "%016llx", wwn[1]);
- }
- if (part_nr) {
- sprintf(pn, "-%d", part_nr);
- }
- snprintf(sid, sizeof(sid), "%#016llx%s%s", wwn[0], xsid, pn);
- dev_name = sid;
- }
- else if ((DISPLAY_PRETTY(flags)) && (major == dm_major)) {
- dev_name = transform_devmapname(major, minor);
- }
-
- if (!dev_name) {
- dev_name = get_devname(major, minor);
- }
- }
-
- return dev_name;
-}
-
#endif /* SOURCE_SADC undefined */
sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize);
nr += add_list_item(&(a->item_list),
- get_sa_devname(sdc->major, sdc->minor, sdc->wwn,
- sdc->part_nr, flags),
+ get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL),
MAX_DEV_LEN);
}
int dplaces_nr = -1;
uint64_t flags = 0;
-unsigned int dm_major; /* Device-mapper major number */
char timestamp[2][TIMESTAMP_LEN];
extern unsigned int rec_types_nr[];
usage(argv[0]);
}
- if (DISPLAY_PRETTY(flags)) {
- dm_major = get_devmap_major();
- }
-
if (!count) {
/*
* count parameter not set: Display all the contents of the file
sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize);
/* Get device name */
- dev_name = get_sa_devname(sdc->major, sdc->minor,
- sdc->wwn, sdc->part_nr, flags);
+ dev_name = get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL);
if (a->item_list != NULL) {
/* A list of devices has been entered on the command line */
}
/* Get device name */
- dev_name = get_sa_devname(sdc->major, sdc->minor,
- sdc->wwn, sdc->part_nr, flags);
+ dev_name = get_device_name(sdc->major, sdc->minor, sdc->wwn, sdc->part_nr,
+ DISPLAY_PRETTY(flags), DISPLAY_PERSIST_NAME_S(flags),
+ USE_STABLE_ID(flags), NULL);
if (a->item_list != NULL) {
/* A list of devices has been entered on the command line */