linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N>
@ 2009-04-27 13:00 Karel Zak
  2009-04-27 13:00 ` [PATCH] blkid: use /sys/block/dm-<N>/dm/name Karel Zak
  2009-05-03  2:05 ` [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N> Theodore Tso
  0 siblings, 2 replies; 5+ messages in thread
From: Karel Zak @ 2009-04-27 13:00 UTC (permalink / raw)
  To: linux-ext4; +Cc: Eric Sandeen, Theodore Tso, Karel Zak

The libblkid (since v1.41.1) returns private device-mapper names (e.g.
/dev/dm-0). It's because the probe_one() function scans /dev before
/dev/mapper.

brw-rw---- 1 root disk 253, 0 2009-04-27 13:41 /dev/dm-0
brw-rw---- 1 root disk 253, 0 2009-04-27 13:41 /dev/mapper/TestVolGroup-TestLogVolume

Old version:
  # blkid -t LABEL="TEST-LABEL" -o device
  /dev/dm-0

Fixed version:
  # blkid -t LABEL="TEST-LABEL" -o device
  /dev/mapper/TestVolGroup-TestLogVolume

Addresses-Red-Hat-Bug: #497259
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 lib/blkid/devname.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c
index 8553e9f..59c0919 100644
--- a/lib/blkid/devname.c
+++ b/lib/blkid/devname.c
@@ -179,6 +179,15 @@ static void probe_one(blkid_cache cache, const char *ptname,
 	if (dev && dev->bid_devno == devno)
 		goto set_pri;
 
+	/* Try to translate private device-mapper dm-<N> names
+	 * to standard /dev/mapper/<name>.
+	 */
+	if (!strncmp(ptname, "dm-", 3) && isdigit(ptname[3])) {
+		blkid__scan_dir("/dev/mapper", devno, 0, &devname);
+		if (devname)
+			goto get_dev;
+	}
+
 	/*
 	 * Take a quick look at /dev/ptname for the device number.  We check
 	 * all of the likely device directories.  If we don't find it, or if
@@ -197,17 +206,16 @@ static void probe_one(blkid_cache cache, const char *ptname,
 		if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
 		    st.st_rdev == devno) {
 			devname = blkid_strdup(device);
-			break;
+			goto get_dev;
 		}
 	}
-	/* Do a short-cut scan of /dev/mapper first */
-	if (!devname)
-		blkid__scan_dir("/dev/mapper", devno, 0, &devname);
 	if (!devname) {
 		devname = blkid_devno_to_devname(devno);
 		if (!devname)
 			return;
 	}
+
+get_dev:
 	dev = blkid_get_dev(cache, devname, BLKID_DEV_NORMAL);
 	free(devname);
 
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] blkid: use /sys/block/dm-<N>/dm/name
  2009-04-27 13:00 [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N> Karel Zak
@ 2009-04-27 13:00 ` Karel Zak
  2009-05-03  2:41   ` Theodore Tso
  2009-05-03  2:05 ` [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N> Theodore Tso
  1 sibling, 1 reply; 5+ messages in thread
From: Karel Zak @ 2009-04-27 13:00 UTC (permalink / raw)
  To: linux-ext4; +Cc: Eric Sandeen, Theodore Tso, Karel Zak, Milan Broz

The Linux kernel (since 2.6.29, patch 784aae735d9b0bba3f8b9faef4c8b30df3bf0128)
exports the real DM device names in /sys/block/<ptname>/dm/name.

The sysfs based solution is nicer and faster than scan for devno in
/dev/mapper/.

CC: Milan Broz <mbroz@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 lib/blkid/devname.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c
index 59c0919..4dde766 100644
--- a/lib/blkid/devname.c
+++ b/lib/blkid/devname.c
@@ -153,6 +153,30 @@ static int is_dm_leaf(const char *devname)
 }
 
 /*
+ * 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.
  */
 static void probe_one(blkid_cache cache, const char *ptname,
@@ -183,7 +207,9 @@ static void probe_one(blkid_cache cache, const char *ptname,
 	 * to standard /dev/mapper/<name>.
 	 */
 	if (!strncmp(ptname, "dm-", 3) && isdigit(ptname[3])) {
-		blkid__scan_dir("/dev/mapper", devno, 0, &devname);
+		devname = get_dm_name(ptname);
+		if (!devname)
+			blkid__scan_dir("/dev/mapper", devno, 0, &devname);
 		if (devname)
 			goto get_dev;
 	}
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N>
  2009-04-27 13:00 [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N> Karel Zak
  2009-04-27 13:00 ` [PATCH] blkid: use /sys/block/dm-<N>/dm/name Karel Zak
@ 2009-05-03  2:05 ` Theodore Tso
  2009-05-05 19:54   ` Karel Zak
  1 sibling, 1 reply; 5+ messages in thread
From: Theodore Tso @ 2009-05-03  2:05 UTC (permalink / raw)
  To: Karel Zak; +Cc: linux-ext4, Eric Sandeen

On Mon, Apr 27, 2009 at 03:00:57PM +0200, Karel Zak wrote:
> The libblkid (since v1.41.1) returns private device-mapper names (e.g.
> /dev/dm-0). It's because the probe_one() function scans /dev before
> /dev/mapper.

Checked in, thanks.  Debian-derived distributions don't create
/dev/dm-X names, which is why I didn't notice this issue.  However,
because of this, I modified your patch to keep this chunk which you removed:

> -	/* Do a short-cut scan of /dev/mapper first */
> -	if (!devname)
> -		blkid__scan_dir("/dev/mapper", devno, 0, &devname);

For distributions that don't create /dev/dm-X devices, your check
above won't find the device name, so after searching /dev, we need to
do a short-cut scan of /dev/mapper before we do a full brute force
search via blkid_devno_to_devname.

							- Ted

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blkid: use /sys/block/dm-<N>/dm/name
  2009-04-27 13:00 ` [PATCH] blkid: use /sys/block/dm-<N>/dm/name Karel Zak
@ 2009-05-03  2:41   ` Theodore Tso
  0 siblings, 0 replies; 5+ messages in thread
From: Theodore Tso @ 2009-05-03  2:41 UTC (permalink / raw)
  To: Karel Zak; +Cc: linux-ext4, Eric Sandeen, Milan Broz

On Mon, Apr 27, 2009 at 03:00:58PM +0200, Karel Zak wrote:
> The Linux kernel (since 2.6.29, patch 784aae735d9b0bba3f8b9faef4c8b30df3bf0128)
> exports the real DM device names in /sys/block/<ptname>/dm/name.

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N>
  2009-05-03  2:05 ` [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N> Theodore Tso
@ 2009-05-05 19:54   ` Karel Zak
  0 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2009-05-05 19:54 UTC (permalink / raw)
  To: Theodore Tso; +Cc: linux-ext4, Eric Sandeen

On Sat, May 02, 2009 at 10:05:28PM -0400, Theodore Tso wrote:
> On Mon, Apr 27, 2009 at 03:00:57PM +0200, Karel Zak wrote:
> > The libblkid (since v1.41.1) returns private device-mapper names (e.g.
> > /dev/dm-0). It's because the probe_one() function scans /dev before
> > /dev/mapper.
> 
> Checked in, thanks.  Debian-derived distributions don't create
> /dev/dm-X names, which is why I didn't notice this issue.  However,
> because of this, I modified your patch to keep this chunk which you removed:

 You needn't this chunk.

> > -	/* Do a short-cut scan of /dev/mapper first */
> > -	if (!devname)
> > -		blkid__scan_dir("/dev/mapper", devno, 0, &devname);
> 
> For distributions that don't create /dev/dm-X devices, your check

 I guess that all distributions have "dm-X" names in /proc/partitions, it
 means my check

   if (!strncmp(ptname, "dm-", 3) && isdigit(ptname[3]))
       blkid__scan_dir("/dev/mapper", devno, 0, &devname);

 works everywhere and you needn't to check /dev before /dev/mapper for 
 dm-X ptnames.

> above won't find the device name, so after searching /dev, we need to
> do a short-cut scan of /dev/mapper before we do a full brute force
> search via blkid_devno_to_devname.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-05-05 19:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-27 13:00 [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N> Karel Zak
2009-04-27 13:00 ` [PATCH] blkid: use /sys/block/dm-<N>/dm/name Karel Zak
2009-05-03  2:41   ` Theodore Tso
2009-05-03  2:05 ` [PATCH] blkid: use /dev/mapper/<name> rather than /dev/dm-<N> Theodore Tso
2009-05-05 19:54   ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).