[PATCH] disk plugin: make linux device mapper disk names persistent using the map name provided by the device mapper.

Simone Gotti simone.gotti at gmail.com
Fri Feb 4 11:10:48 CET 2011


Signed-off-by: Simone Gotti <simone.gotti at gmail.com>
---
 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


--------------010608050500000908090900--



More information about the collectd mailing list