From: Sebastien Date: Sun, 1 Jul 2012 19:29:44 +0000 (+0200) Subject: sar: Use /sys/dev/block/major:minor links to determine devices real name. X-Git-Tag: v10.1.1~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c39b9ca0deac7799d4e6b5074905e280c5752b80;p=sysstat sar: Use /sys/dev/block/major:minor links to determine devices real name. Now use /sys/dev/block/major:minor links to determine devices real name. This is used as the first option now, before using sysstat.ioconf configuration file. Mail from Peter Schiffer (pschiffe@redhat.com) 20/06/2012: I am sending you a patch which is looking into /sys/dev/block/major:minor link to determine the device name. This should work for any device, but I let it as the last option when determining devname. What do you think? --- diff --git a/CHANGES b/CHANGES index 685ed7d..2d10aee 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ Changes: xxxx/xx/xx: Version 10.1.1 - Sebastien Godard (sysstat orange.fr) * Added option -[0-9]* to sar to show data of that days ago. + * [Peter Schiffer]: sar: Use /sys/dev/block/major:minor links + to determine devices real name. 2012/05/16: Version 10.0.5 - Sebastien Godard (sysstat orange.fr) * [Alain Chereau]: Options -g and -T added to iostat. These diff --git a/common.h b/common.h index 283cd3f..b70ea66 100644 --- a/common.h +++ b/common.h @@ -54,6 +54,7 @@ #define INTERRUPTS "/proc/interrupts" #define MEMINFO "/proc/meminfo" #define SYSFS_BLOCK "/sys/block" +#define SYSFS_DEV_BLOCK "/sys/dev/block" #define SYSFS_DEVCPU "/sys/devices/system/cpu" #define SYSFS_TIME_IN_STATE "cpufreq/stats/time_in_state" #define S_STAT "stat" diff --git a/sa_common.c b/sa_common.c index 925b93e..18a08f9 100644 --- a/sa_common.c +++ b/sa_common.c @@ -1,6 +1,6 @@ /* * sar and sadf common routines. - * (C) 1999-2011 by Sebastien GODARD (sysstat orange.fr) + * (C) 1999-2012 by Sebastien GODARD (sysstat orange.fr) * *************************************************************************** * This program is free software; you can redistribute it and/or modify it * @@ -27,6 +27,7 @@ #include /* For STDOUT_FILENO, among others */ #include #include +#include #include #include @@ -111,6 +112,44 @@ void free_structures(struct activity *act[]) } } +/* + *************************************************************************** + * 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[32], target[PATH_MAX]; + char *devname; + ssize_t r; + + snprintf(link, 32, "%s/%d:%d", 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. @@ -138,11 +177,15 @@ char *get_devname(unsigned int major, unsigned int minor, int pretty) if (!pretty) return (buf); + 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 (buf); + if ((name != NULL) && strcmp(name, K_NODEV)) + return (name); - return (name); + return (buf); } /*