From: Jeff Mahoney <jeffm@suse.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH] ocfs2console: Allow ocfs2console to enumerate device mapper devices
Date: Tue, 12 Aug 2008 11:18:31 -0400 [thread overview]
Message-ID: <48A1A9C7.1080906@suse.com> (raw)
ocfs2console will currently display device mapper devices as dm-#, where
the number can be dynamic across reboots making it non-obvious which
device the user is using. While LVM volumes aren't safe to use across
physical nodes, they are often used with virtual machines. Many ocfs2
users also use dm-multipath.
This patch refactors partition_info_fill to separate hashing from
enumeration so that it is trivial to add a device-mapper enumerator.
The device mapper enumerator is automatically enabled if libdevmapper
is present at build time. When enabled, it suppresses the dm-# devices
from enumeration. If disabled, the dm-# devices are used instead.
I have a bug report for this (Novell Bugzilla 414756) and it was easy
enough to bang out quickly.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
Config.make.in | 2
configure.in | 5 +
ocfs2console/ocfs2interface/Makefile | 7 +
ocfs2console/ocfs2interface/ocfsplist.c | 148 ++++++++++++++++++++++----------
4 files changed, 118 insertions(+), 44 deletions(-)
--- a/Config.make.in
+++ b/Config.make.in
@@ -72,6 +72,8 @@ HAVE_BLKID = @HAVE_BLKID@
LIBDLM_FOUND = @LIBDLM_FOUND@
+LIBDEVMAPPER_FOUND = @LIBDEVMAPPER_FOUND@
+
BUILD_OCFS2CONSOLE = @BUILD_OCFS2CONSOLE@
BUILD_DEBUGOCFS2 = @BUILD_DEBUGOCFS2@
--- a/configure.in
+++ b/configure.in
@@ -289,6 +289,11 @@ if test "x$cman_found" = "xyes" -a "x$cp
fi
AC_SUBST(BUILD_CMAN_SUPPORT)
+LIBDEVMAPPER_FOUND=
+AC_CHECK_HEADER(libdevmapper.h, LIBDEVMAPPER_FOUND=yes,
+ [AC_MSG_WARN([libdevmapper.h not found, device-mapper support will not be built])])
+AC_SUBST(LIBDEVMAPPER_FOUND)
+
BUILD_OCFS2CONSOLE=
AC_ARG_ENABLE(ocfs2console, [ --enable-ocfs2console=[yes/no] Build GUI frontend [default=yes]],,enable_ocfs2console=yes)
--- a/ocfs2console/ocfs2interface/Makefile
+++ b/ocfs2console/ocfs2interface/Makefile
@@ -48,6 +48,11 @@ OCFS2_CFILES = ocfs2module.c
ocfs2module_CPPFLAGS = $(OCFS2_CPPFLAGS)
ocfs2module_CFLAGS = $(PYMOD_CFLAGS)
+ifneq ($(LIBDEVMAPPER_FOUND),)
+ocfsplist_CPPFLAGS += -DHAVE_DEVICE_MAPPER
+LIBDEVMAPPER_LIBS = -ldevmapper
+endif
+
PLIST_OBJS = $(subst .c,.o,$(PLIST_CFILES))
GIDLE_OBJS = $(subst .c,.o,$(GIDLE_CFILES))
OCFS2_OBJS = $(subst .c,.o,$(OCFS2_CFILES))
@@ -90,7 +95,7 @@ INSTALL_RULES = install-pylib
DIST_FILES = $(PLIST_CFILES) $(PLIST_HFILES) $(GIDLE_CFILES) $(OCFS2_CFILES) $(O2CB_CFILES) $(PYSRC) $(addsuffix .in,$(BUILT_PYSRC))
plistmodule.so: $(PLIST_OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS) $(BLKID_DEPS)
- $(LINK) -shared $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(BLKID_LIBS) $(COM_ERR_LIBS) $(GLIB_LIBS)
+ $(LINK) -shared $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(BLKID_LIBS) $(COM_ERR_LIBS) $(GLIB_LIBS) $(LIBDEVMAPPER_LIBS)
gidlemodule.so: $(GIDLE_OBJS)
$(LINK) -shared $(GLIB_LIBS)
--- a/ocfs2console/ocfs2interface/ocfsplist.c
+++ b/ocfs2console/ocfs2interface/ocfsplist.c
@@ -37,6 +37,11 @@
#include <blkid/blkid.h>
+#ifdef HAVE_DEVICE_MAPPER
+#include <libdevmapper.h>
+#include <limits.h>
+#endif
+
#include "ocfsplist.h"
@@ -214,15 +219,91 @@ get_device_fstype (const gchar *device,
}
static void
-partition_info_fill (GHashTable *info,
- gboolean async)
+partition_add_one(GHashTable *info, gboolean async, const char *name,
+ guint *count)
+{
+ GSList *list = NULL;
+ gchar *device = g_strconcat ("/dev/", name, NULL);
+ gint i = strlen (device) - 1;
+
+ if (g_ascii_isdigit (device[i]))
+ {
+ gchar *p;
+ while (i > 0 && g_ascii_isdigit (device[i]))
+ i--;
+
+ p = g_strndup (device, i + 1);
+ list = g_hash_table_lookup (info, p);
+
+ if (list == NULL)
+ {
+ list = g_slist_prepend (NULL, device);
+ g_hash_table_insert (info, p, list);
+ }
+ else
+ {
+ if (strcmp (p, list->data) == 0)
+ {
+ g_free (list->data);
+ list->data = device;
+ }
+ else
+ g_slist_append (list, device);
+
+ g_free (p);
+ }
+ }
+ else if (!g_hash_table_lookup (info, device))
+ {
+ list = g_slist_prepend (NULL, g_strdup (device));
+ g_hash_table_insert (info, device, list);
+ }
+ else
+ g_free (device);
+
+ async_loop_run (async, count, FILL_ASYNC_ITERATIONS);
+}
+
+#ifdef HAVE_DEVICE_MAPPER
+static void
+partition_add_dm(GHashTable *info, gboolean async, guint *count)
+{
+ struct dm_names *names;
+ struct dm_task *dmt;
+ unsigned int next = 0;
+
+ if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
+ return;
+
+ if (!dm_task_run(dmt))
+ goto out;
+
+ if (!(names = dm_task_get_names(dmt)))
+ goto out;
+
+ if (!names->dev)
+ goto out;
+
+ do
+ {
+ char name[PATH_MAX];
+ names = (void *) names + next;
+ snprintf(name, PATH_MAX, "mapper/%s", names->name);
+ partition_add_one(info, async, name, count);
+ next = names->next;
+ }
+ while (next);
+
+out:
+ dm_task_destroy(dmt);
+}
+#endif
+
+static void
+partition_add_partitions(GHashTable *info, gboolean async, guint *count)
{
FILE *proc;
- gchar line[100], name[100], *device;
- GSList *list;
- gint i;
- gchar *p;
- guint count = 0;
+ gchar line[100], name[100];
proc = fopen ("/proc/partitions", "r");
if (proc == NULL)
@@ -233,47 +314,28 @@ partition_info_fill (GHashTable *info,
if (sscanf(line, "%*d %*d %*d %99[^ \t\n]", name) != 1)
continue;
- device = g_strconcat ("/dev/", name, NULL);
-
- i = strlen (device) - 1;
- if (g_ascii_isdigit (device[i]))
- {
- while (i > 0 && g_ascii_isdigit (device[i]))
- i--;
+#ifdef HAVE_DEVICE_MAPPER
+ if (strstr(name, "dm-") == name)
+ continue;
+#endif
- p = g_strndup (device, i + 1);
- list = g_hash_table_lookup (info, p);
+ partition_add_one(info, async, name, count);
- if (list == NULL)
- {
- list = g_slist_prepend (NULL, device);
- g_hash_table_insert (info, p, list);
- }
- else
- {
- if (strcmp (p, list->data) == 0)
- {
- g_free (list->data);
- list->data = device;
- }
- else
- g_slist_append (list, device);
+ }
+ fclose (proc);
+}
- g_free (p);
- }
- }
- else if (!g_hash_table_lookup (info, device))
- {
- list = g_slist_prepend (NULL, g_strdup (device));
- g_hash_table_insert (info, device, list);
- }
- else
- g_free (device);
+static void
+partition_info_fill (GHashTable *info,
+ gboolean async)
+{
+ guint count = 0;
- async_loop_run (async, &count, FILL_ASYNC_ITERATIONS);
- }
+ partition_add_partitions(info, async, &count);
- fclose (proc);
+#ifdef HAVE_DEVICE_MAPPER
+ partition_add_dm(info, async, &count);
+#endif
}
static gboolean
--
Jeff Mahoney
SUSE Labs
next reply other threads:[~2008-08-12 15:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-12 15:18 Jeff Mahoney [this message]
2008-08-12 19:25 ` [Ocfs2-devel] [PATCH] ocfs2console: Allow ocfs2console to enumerate device mapper devices Joel Becker
2008-08-12 19:37 ` Jeff Mahoney
2008-08-12 19:48 ` Joel Becker
2008-08-12 19:38 ` [Ocfs2-devel] [PATCH V2] " Jeff Mahoney
2008-08-13 23:37 ` Sunil Mushran
-- strict thread matches above, loose matches on Subject: below --
2008-09-22 14:16 [Ocfs2-devel] [PATCH] " Andrew Beekhof
2008-09-22 20:53 ` Sunil Mushran
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48A1A9C7.1080906@suse.com \
--to=jeffm@suse.com \
--cc=ocfs2-devel@oss.oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.