]> granicus.if.org Git - sysstat/commitdiff
sar: Use /sys/dev/block/major:minor links to determine devices real name.
authorSebastien <seb@kluane.home>
Sun, 1 Jul 2012 19:29:44 +0000 (21:29 +0200)
committerSebastien <seb@kluane.home>
Sun, 1 Jul 2012 19:29:44 +0000 (21:29 +0200)
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?

CHANGES
common.h
sa_common.c

diff --git a/CHANGES b/CHANGES
index 685ed7df6332758a7e6138d81feb3e8a188c0d59..2d10aeecd13d3d33eb04a2774263cdcb6b5218f1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@ Changes:
 
 xxxx/xx/xx: Version 10.1.1 - Sebastien Godard (sysstat <at> 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 <at> orange.fr)
        * [Alain Chereau]: Options -g and -T added to iostat. These
index 283cd3fb619028169287a5ea04a15b858aa21b56..b70ea6628cfd62a2c0e0f500ade362905dfcd6b2 100644 (file)
--- 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"
index 925b93ebd071ab0b93c1eab3ee58bfda83bc969f..18a08f9fd563c59bff6c0a1b1feb74e7311cad25 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * sar and sadf common routines.
- * (C) 1999-2011 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1999-2012 by Sebastien GODARD (sysstat <at> orange.fr)
  *
  ***************************************************************************
  * This program is free software; you can redistribute it and/or modify it *
@@ -27,6 +27,7 @@
 #include <unistd.h>    /* For STDOUT_FILENO, among others */
 #include <dirent.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
 
@@ -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);
 }
 
 /*