Hi all,

as on linux all in kernel names for devices (scsi devices: sd, device
mapper devices: dm-X) are not persistent but will change during
operations on devices (remove/add disks, activate/deactivate logical
volumes, multipathed devices and so on), reboot etc... you'll get inside
the same rrdfile values from different scsi/devicemapper devices and
will be very difficult to understand the relation between the kernel
name and the real device.

For scsi devices (sdX) it's difficult to get a persistent name. If it's
a partition with a filesystem then you can use the filesystem label/uuid
(you can get it from /dev/disk/by-*/). If it's a path of a multipath
device than this will be not possibile. The rules can be a lot and the
way to get a persistent name will be different between linux
distributions and releases (changes to udev rules or other)

One thing that can be done and will be quite useful are persistent and
meaningful names for device mapper devices. The kernel names them as
dm-X where X is dynamic. But the device mapper table has a name that is
usually persistent (lvm has its convention, dm multipathed devices can
be named in the configuration file).

The attached patch (based on the master branch) uses libdevmapper to
retrieve the name of a dm-X device and uses this name as the
plugin_instance value.
Perhabs, to avoid this different behavior after a possibile patch
inclusion (and the presence of the libdevmapper development files on the
build system) that will led to new files created with the new name, a
config option to the disk plugin should be added to activate it. I'll
add it if you like this patch.

What do you think about it?


P.S
A more generic solution will be to call from the disk plugin an external
script (call it a "PersistentNameProvider") that given the kernel name
will provide the persistent name to use. But I think that this will
create a great overhead with system with a lot of disks...


Thanks.

Bye!

--
Simone Gotti
>From e07fcb9975969d6ae99adfd6955fbdf94133411a Mon Sep 17 00:00:00 2001
From: Simone Gotti <[email protected]>
Date: Fri, 4 Feb 2011 11:10:48 +0100
Subject: [PATCH] disk plugin: make linux device mapper disk names persistent 
using the map name provided by the device mapper.

Signed-off-by: Simone Gotti <[email protected]>
---
 configure.in    |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am |    4 ++
 src/disk.c      |   30 +++++++++++++++++
 3 files changed, 132 insertions(+), 0 deletions(-)

diff --git a/configure.in b/configure.in
index 8db24ca..c4de33a 100644
--- a/configure.in
+++ b/configure.in
@@ -4189,6 +4189,103 @@ PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
                         with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)"
                 fi])
 
+
+# --with-libdevmapper {{{
+with_libdevmapper_config=""
+with_libdevmapper_cflags=""
+with_libdevmapper_libs=""
+AC_ARG_WITH(libdevmapper, 
[AS_HELP_STRING([--with-libdevmapper@<:@=PREFIX@:>@], [Path to the devmapper 
library.])],
+[
+       if test "x$withval" = "xno"
+       then
+               with_libdevmapper="no"
+       else if test "x$withval" = "xyes"
+       then
+               with_libdevmapper="use_pkgconfig"
+       else if test -d "$with_libdevmapper/lib"
+       then
+               AC_MSG_NOTICE([Not checking for libdevmapper: Manually 
configured])
+               with_libdevmapper_cflags="-I$withval/include"
+               with_libdevmapper_libs="-L$withval/lib -ldevmapper"
+               with_libdevmapper="yes"
+       fi; fi; fi
+],
+[with_libdevmapper="use_pkgconfig"])
+
+# configure using pkg-config
+if test "x$with_libdevmapper" = "xuse_pkgconfig"
+then
+       if test "x$PKG_CONFIG" = "x"
+       then
+               with_libdevmapper="no (Don't have pkg-config)"
+       fi
+fi
+if test "x$with_libdevmapper" = "xuse_pkgconfig"
+then
+       AC_MSG_NOTICE([Checking for devmapper using $PKG_CONFIG])
+       $PKG_CONFIG --exists 'devmapper' 2>/dev/null
+       if test $? -ne 0
+       then
+               with_libdevmapper="no (pkg-config doesn't know library)"
+       fi
+fi
+if test "x$with_libdevmapper" = "xuse_pkgconfig"
+then
+       with_libdevmapper_cflags="`$PKG_CONFIG --cflags 'devmapper'`"
+       if test $? -ne 0
+       then
+               with_libdevmapper="no ($PKG_CONFIG failed)"
+       fi
+       with_libdevmapper_libs="`$PKG_CONFIG --libs 'devmapper'`"
+       if test $? -ne 0
+       then
+               with_libdevmapper="no ($PKG_CONFIG failed)"
+       fi
+fi
+if test "x$with_libdevmapper" = "xuse_pkgconfig"
+then
+       with_libdevmapper="yes"
+fi
+
+# with_libdevmapper_cflags and with_libdevmapper_libs are set up now, let's do
+# the actual checks.
+if test "x$with_libdevmapper" = "xyes"
+then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_libdevmapper_cflags"
+
+       AC_CHECK_HEADERS(libdevmapper.h, [], [with_libdevmapper="no 
(libdevmapper.h not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libdevmapper" = "xyes"
+then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       SAVE_LDFLAGS="$LDFLAGS"
+
+       CPPFLAGS="$CPPFLAGS $with_libdevmapper_cflags"
+       LDFLAGS="$LDFLAGS $with_libdevmapper_libs"
+
+       AC_CHECK_LIB(devmapper, dm_task_create,
+                    [with_libdevmapper="yes"],
+                    [with_libdevmapper="no (symbol dm_task_create not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+       LDFLAGS="$SAVE_LDFLAGS"
+fi
+
+if test "x$with_libdevmapper" = "xyes"
+then
+       AC_DEFINE(HAVE_LIBDEVMAPPER, 1, [Define to 1 if you have the devmapper 
library (-ldevmapper).])
+       BUILD_WITH_LIBDEVMAPPER_CFLAGS="$with_libdevmapper_cflags"
+       BUILD_WITH_LIBDEVMAPPER_LIBS="$with_libdevmapper_libs"
+       AC_SUBST(BUILD_WITH_LIBDEVMAPPER_CFLAGS)
+       AC_SUBST(BUILD_WITH_LIBDEVMAPPER_LIBS)
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBDEVMAPPER, test "x$with_libdevmapper" = "xyes")
+# }}}
+
+
 # Check for enabled/disabled features
 #
 
@@ -4889,6 +4986,7 @@ Configuration:
     libcurl . . . . . . . $with_libcurl
     libdbi  . . . . . . . $with_libdbi
     libcredis . . . . . . $with_libcredis
+    libdevmapper  . . . . $with_libdevmapper
     libesmtp  . . . . . . $with_libesmtp
     libganglia  . . . . . $with_libganglia
     libgcrypt . . . . . . $with_libgcrypt
diff --git a/src/Makefile.am b/src/Makefile.am
index 5728144..9e03ca4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -340,6 +340,10 @@ endif
 if BUILD_WITH_PERFSTAT
 disk_la_LIBADD += -lperfstat
 endif
+if BUILD_WITH_LIBDEVMAPPER
+disk_la_LIBADD += -ldevmapper
+endif
+
 collectd_LDADD += "-dlopen" disk.la
 collectd_DEPENDENCIES += disk.la
 endif
diff --git a/src/disk.c b/src/disk.c
index 697d850..663d1c6 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -73,6 +73,10 @@
 # include <libperfstat.h>
 #endif
 
+#if HAVE_LIBDEVMAPPER
+# include "libdevmapper.h"
+#endif
+
 #if HAVE_IOKIT_IOKITLIB_H
 static mach_port_t io_master_port = MACH_PORT_NULL;
 /* #endif HAVE_IOKIT_IOKITLIB_H */
@@ -458,6 +462,9 @@ static int disk_read (void)
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
                char *disk_name;
+#if HAVE_LIBDEVMAPPER
+               char dm_disk_name[256];
+#endif
 
                numfields = strsplit (buffer, fields, 32);
 
@@ -469,6 +476,29 @@ static int disk_read (void)
 
                disk_name = fields[2 + fieldshift];
 
+#if HAVE_LIBDEVMAPPER
+               if(!strncmp(disk_name, "dm-", 3)) {
+                       struct dm_task *dmt = NULL;
+
+                       if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
+                               goto dmout;
+
+                       if (!dm_task_set_major(dmt, major) ||
+                           !dm_task_set_minor(dmt, minor))
+                               goto dmout;
+
+                       if (!dm_task_run(dmt))
+                               goto dmout;
+
+                       snprintf(dm_disk_name, sizeof(dm_disk_name), "%s", 
dm_task_get_name(dmt));
+                       disk_name = dm_disk_name;
+
+                   dmout:
+                       if(dmt != NULL)
+                               dm_task_destroy(dmt);
+               }
+#endif
+
                for (ds = disklist, pre_ds = disklist; ds != NULL; pre_ds = ds, 
ds = ds->next)
                        if (strcmp (disk_name, ds->name) == 0)
                                break;
-- 
1.7.3.5

_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd

Reply via email to