]> err.no Git - util-linux/commitdiff
mount: and libblkid: covert /dev/dm-N to /dev/mapper/<name>
authorKarel Zak <kzak@redhat.com>
Mon, 26 Oct 2009 12:33:03 +0000 (13:33 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 26 Oct 2009 12:33:03 +0000 (13:33 +0100)
 * mount(8) uses private device-mapper names in mtab

 * libblkid returns private device-mapper names when evaluate udev
   /dev/disk-by symlinks.

 * on systems where DM is fully integrated with udev the /dev/mapper/<name>
   files are symlinks to /dev/dm-N. It means we need a special care to hide
   private device-mapper names.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/canonicalize.h
lib/canonicalize.c
shlibs/blkid/src/devname.c

index b04510c79ea2fd1448f002750ee4138abe7a5675..f26df18c2b116599528e1c23b811b015c4f0a117 100644 (file)
@@ -4,5 +4,6 @@
 #include "c.h" /* for PATH_MAX */
 
 extern char *canonicalize_path(const char *path);
+extern char *canonicalize_dm_name(const char *ptname);
 
 #endif /* CANONICALIZE_H */
index b888fbb8e9be629d56fa4726ea081b4dce9c1053..e54cf0c06aebc96dafb1b9b67a8414dbba93a639 100644 (file)
@@ -20,6 +20,9 @@
  *
  * TODO: use canonicalize_file_name() when exist in glibc
  */
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
@@ -136,17 +139,54 @@ myrealpath(const char *path, char *resolved_path, int maxreslth) {
        return NULL;
 }
 
+/*
+ * Converts private "dm-N" names to "/dev/mapper/<name>"
+ *
+ * Since 2.6.29 (patch 784aae735d9b0bba3f8b9faef4c8b30df3bf0128) kernel sysfs
+ * provides the real DM device names in /sys/block/<ptname>/dm/name
+ */
 char *
-canonicalize_path(const char *path) {
+canonicalize_dm_name(const char *ptname)
+{
+       FILE    *f;
+       size_t  sz;
+       char    path[256], name[256], *res = NULL;
+
+       snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptname);
+       if (!(f = fopen(path, "r")))
+               return NULL;
+
+       /* read "<name>\n" from sysfs */
+       if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) {
+               name[sz - 1] = '\0';
+               snprintf(path, sizeof(path), "/dev/mapper/%s", name);
+               res = strdup(path);
+       }
+       fclose(f);
+       return res;
+}
+
+char *
+canonicalize_path(const char *path)
+{
        char canonical[PATH_MAX+2];
+       char *p;
 
        if (path == NULL)
                return NULL;
 
-       if (myrealpath (path, canonical, PATH_MAX+1))
-               return strdup(canonical);
+       if (!myrealpath(path, canonical, PATH_MAX+1))
+               return strdup(path);
+
+
+       p = strrchr(canonical, '/');
+       if (p && strncmp(p, "/dm-", 4) == 0 && isdigit(*(p + 4))) {
+               p = canonicalize_dm_name(p+1);
+               if (p)
+                       return p;
+       }
 
-       return strdup(path);
+       return strdup(canonical);
 }
 
 
index fe0d1b332d2b563f557ae6b65a3b528651e8ed0f..d048c722259782adfec9a18bea9ee8d138d86220 100644 (file)
@@ -38,6 +38,7 @@
 #include <time.h>
 
 #include "blkidP.h"
+#include "canonicalize.h"              /* $(top_srcdir)/include */
 
 /*
  * Find a dev struct in the cache by device name, if available.
@@ -152,30 +153,6 @@ static int is_dm_leaf(const char *devname)
        return ret;
 }
 
-/*
- * Since 2.6.29 (patch 784aae735d9b0bba3f8b9faef4c8b30df3bf0128) kernel sysfs
- * provides the real DM device names in /sys/block/<ptname>/dm/name
- */
-static char *get_dm_name(const char *ptname)
-{
-       FILE    *f;
-       size_t  sz;
-       char    path[256], name[256], *res = NULL;
-
-       snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptname);
-       if ((f = fopen(path, "r")) == NULL)
-               return NULL;
-
-       /* read "<name>\n" from sysfs */
-       if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) {
-               name[sz - 1] = '\0';
-               snprintf(path, sizeof(path), "/dev/mapper/%s", name);
-               res = blkid_strdup(path);
-       }
-       fclose(f);
-       return res;
-}
-
 /*
  * Probe a single block device to add to the device cache.
  */
@@ -207,7 +184,7 @@ static void probe_one(blkid_cache cache, const char *ptname,
         * to standard /dev/mapper/<name>.
         */
        if (!strncmp(ptname, "dm-", 3) && isdigit(ptname[3])) {
-               devname = get_dm_name(ptname);
+               devname = canonicalize_dm_name(ptname);
                if (!devname)
                        blkid__scan_dir("/dev/mapper", devno, 0, &devname);
                if (devname)