From: rpeterso@sourceware.org <rpeterso@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/gfs2/tool util.c
Date: 6 Nov 2007 20:22:55 -0000 [thread overview]
Message-ID: <20071106202255.31062.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: rpeterso at sourceware.org 2007-11-06 20:22:55
Modified files:
gfs2/tool : util.c
Log message:
Resolves: bz 354201: GFS2: gfs2_tool: unknown mountpoint on some
mount points
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/util.c.diff?cvsroot=cluster&r1=1.6&r2=1.7
--- cluster/gfs2/tool/util.c 2007/10/25 14:14:33 1.6
+++ cluster/gfs2/tool/util.c 2007/11/06 20:22:55 1.7
@@ -27,6 +27,7 @@
#include <libgen.h>
#include <dirent.h>
#include <string.h>
+#include <linux/kdev_t.h>
#define __user
#include <linux/gfs2_ondisk.h>
@@ -282,42 +283,6 @@
return name;
}
-/* Iterate through gfs2 dirs looking for one where the "id"
- attribute matches devname and return the associated fsname:
- /sys/kernel/gfs2/<fsname>/fsname
- /sys/kernel/gfs2/<fsname>/id
-
- The "id" attribute is the superblock id (s_id) from the kernel.
- It often matches the device node the fs was mounted from (as
- displayed in /proc/mounts), but not always.
-*/
-
-char *
-devname2fsname(char *devname)
-{
- char *fsname = NULL;
- DIR *d;
- struct dirent *de;
-
- d = opendir(SYS_BASE);
- if (!d)
- die("can't open %s: %s\n", SYS_BASE, strerror(errno));
-
- while ((de = readdir(d))) {
- if (de->d_name[0] == '.')
- continue;
-
- if (strcmp(get_sysfs(de->d_name, "id"), devname) == 0) {
- fsname = strdup(de->d_name);
- break;
- }
- }
-
- closedir(d);
-
- return fsname;
-}
-
/* The fsname can be substituted for the mountpoint on the command line.
This is necessary when we can't resolve a devname from /proc/mounts
to a fsname. */
@@ -349,7 +314,20 @@
/**
* mp2fsname - Find the name for a filesystem given its mountpoint
- * @mp:
+ *
+ * We do this by iterating through gfs2 dirs in /sys/fs/gfs2/ looking for
+ * one where the "id" attribute matches the device id returned by stat for
+ * the mount point. The reason we go through all this is simple: the
+ * kernel's sysfs is named after the VFS s_id, not the device name.
+ * So it's perfectly legal to do something like this to simulate user
+ * conditions without the proper hardware:
+ * # rm /dev/sdb1
+ * # mkdir /dev/cciss
+ * # mknod /dev/cciss/c0d0p1 b 8 17
+ * # mount -tgfs2 /dev/cciss/c0d0p1 /mnt/gfs2
+ * # gfs2_tool gettune /mnt/gfs2
+ * In this example the tuning variables are in a directory named after the
+ * VFS s_id, which in this case would be /sys/fs/gfs2/sdb1/
*
* Returns: the fsname
*/
@@ -357,22 +335,35 @@
char *
mp2fsname(char *mp)
{
- char *devname = NULL, *fsname = NULL;
+ char device_id[PATH_MAX], *fsname = NULL;
+ struct stat statbuf;
+ DIR *d;
+ struct dirent *de;
- devname = mp2devname(mp);
+ if (stat(mp, &statbuf))
+ return NULL;
+
+ memset(device_id, 0, sizeof(device_id));
+ sprintf(device_id, "%u:%u", (uint32_t)MAJOR(statbuf.st_dev),
+ (uint32_t)MINOR(statbuf.st_dev));
+
+ d = opendir(SYS_BASE);
+ if (!d)
+ die("can't open %s: %s\n", SYS_BASE, strerror(errno));
- if (devname) {
- fsname = devname2fsname(devname);
- if (fsname)
- return fsname;
- die("unknown mountpoint %s, no fsname for %s\n", mp, devname);
- } else {
- if (is_fsname(mp))
- return mp;
- die("unknown mountpoint %s, no device found\n", mp);
+ while ((de = readdir(d))) {
+ if (de->d_name[0] == '.')
+ continue;
+
+ if (strcmp(get_sysfs(de->d_name, "id"), device_id) == 0) {
+ fsname = strdup(de->d_name);
+ break;
+ }
}
- return NULL;
+ closedir(d);
+
+ return fsname;
}
/**
next reply other threads:[~2007-11-06 20:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-06 20:22 rpeterso [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-11-06 20:23 [Cluster-devel] cluster/gfs2/tool util.c rpeterso
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=20071106202255.31062.qmail@sourceware.org \
--to=rpeterso@sourceware.org \
/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.