From: Karel Zak <kzak@redhat.com>
To: linux-ext4@vger.kernel.org
Cc: Eric Sandeen <sandeen@redhat.com>, Theodore Tso <tytso@mit.edu>,
Karel Zak <kzak@redhat.com>, Milan Broz <mbroz@redhat.com>
Subject: [PATCH] blkid: use /sys/block/dm-<N>/dm/name
Date: Mon, 27 Apr 2009 15:00:58 +0200 [thread overview]
Message-ID: <1240837258-5440-2-git-send-email-kzak@redhat.com> (raw)
In-Reply-To: <1240837258-5440-1-git-send-email-kzak@redhat.com>
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
next prev parent reply other threads:[~2009-04-27 13:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2009-05-03 2:41 ` [PATCH] blkid: use /sys/block/dm-<N>/dm/name 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
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=1240837258-5440-2-git-send-email-kzak@redhat.com \
--to=kzak@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=mbroz@redhat.com \
--cc=sandeen@redhat.com \
--cc=tytso@mit.edu \
/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 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).