public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
From: Abhijith Das <adas@fedoraproject.org>
To: cluster-cvs-relay@redhat.com
Subject: gfs2-utils: master - gfs2_tool, libgfs2: bz487608 - GFS2: gfs2_tool unfreeze hangs
Date: Fri, 13 Mar 2009 14:53:00 -0000	[thread overview]
Message-ID: <20090313145228.1160E12015A@lists.fedorahosted.org> (raw)

Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=1d2727647dda5479cc780577682d83f6ca57133c
Commit:        1d2727647dda5479cc780577682d83f6ca57133c
Parent:        231ae2bce3351b0e9cf29a128f8f61326a767754
Author:        Abhijith Das <adas@redhat.com>
AuthorDate:    Fri Mar 13 08:51:00 2009 -0500
Committer:     Abhijith Das <adas@redhat.com>
CommitterDate: Fri Mar 13 09:51:18 2009 -0500

gfs2_tool, libgfs2: bz487608 - GFS2: gfs2_tool unfreeze hangs

gfs2_tool tries to stat() the mountpoint in order to get to the
device number and ultimately get to the sysfs freeze tunable.

When the filesystem is frozen, followed by another process holding
an exclusive lock on the mountpoint (eg. touch creating a new file
in root dir), gfs2_tool hangs behind this lock at the stat() call.

This patch makes freeze/unfreeze stat the block device instead of
the mountpoint.

Signed-off-by: Abhijith Das <adas@redhat.com>
---
 gfs2/libgfs2/libgfs2.h |    1 +
 gfs2/libgfs2/misc.c    |   77 ++++++++++++++++++++++++++++++++++++++++++++++++
 gfs2/tool/misc.c       |    2 +-
 3 files changed, 79 insertions(+), 1 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index a4ccf60..2e79ad4 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -632,6 +632,7 @@ extern int mount_gfs2_meta(struct gfs2_sbd *sdp);
 extern void cleanup_metafs(struct gfs2_sbd *sdp);
 extern char *find_debugfs_mount(void);
 extern char *mp2fsname(char *mp);
+extern char *mp2fsname2(char *devname);
 extern char *get_sysfs(char *fsname, char *filename);
 extern unsigned int get_sysfs_uint(char *fsname, char *filename);
 extern int set_sysfs(char *fsname, char *filename, char *val);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 7a1c157..320ce84 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -296,6 +296,83 @@ char *find_debugfs_mount(void)
 	return NULL;
 }
 
+/*
+ * Same as mp2fsname, except that this function doesn't stat() the mountpoint
+ * to get the device no. Used by gfs2_tool freeze/unfreeze where we don't want
+ * to touch the potetially frozen filesytem and hang gfs2_tool itself.
+ */
+char *
+mp2fsname2(char *mp)
+{
+	char device_id[PATH_MAX], *fsname = NULL;
+	struct stat statbuf;
+	DIR *d;
+	struct dirent *de;
+	struct gfs2_sbd sb;
+	FILE *fp = fopen("/proc/mounts", "r");
+	char buffer[PATH_MAX], device_name[PATH_MAX];
+	int fsdump, fspass, ret, found = 0;
+	char fspath[PATH_MAX], fsoptions[PATH_MAX], fstype[80];
+
+	/* Take care of trailing '/' */
+	if (mp[strlen(mp) - 1] == '/')
+		mp[strlen(mp) - 1] = 0;
+
+	if (fp == NULL) {
+		perror("open: /proc/mounts");
+		exit(EXIT_FAILURE);
+	}
+
+	while ((fgets(buffer, PATH_MAX - 1, fp)) != NULL) {
+		buffer[PATH_MAX - 1] = 0;
+		if (strstr(buffer, "0") == 0)
+			continue;
+
+		if ((ret = sscanf(buffer, "%s %s %s %s %d %d",
+				  device_name, fspath,
+				  fstype, fsoptions, &fsdump, &fspass)) != 6)
+			continue;
+
+		if (strcmp(fstype, "gfs2") != 0)
+			continue;
+
+		if (strcmp(fspath, mp) != 0)
+			continue;
+
+		found = 1;
+		break;
+	}
+
+	if (!found)
+		die("can't find gfs2 filesystem mounted at %s\n", mp);
+
+	if (stat(device_name, &statbuf))
+		return NULL;
+
+	memset(device_id, 0, sizeof(device_id));
+	sprintf(device_id, "%u:%u", (uint32_t)MAJOR(statbuf.st_rdev),
+		(uint32_t)MINOR(statbuf.st_rdev));
+
+	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"), device_id) == 0) {
+			fsname = strdup(de->d_name);
+			break;
+		}
+	}
+
+	fclose(fp);
+	closedir(d);
+
+	return fsname;
+}
+
 /**
  * mp2fsname - Find the name for a filesystem given its mountpoint
  *
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index 7d3a510..6b054c6 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -39,7 +39,7 @@ do_freeze(int argc, char **argv)
 	if (optind == argc)
 		die("Usage: gfs2_tool %s <mountpoint>\n", command);
 
-	name = mp2fsname(argv[optind]);
+	name = mp2fsname2(argv[optind]);
 
 	if (strcmp(command, "freeze") == 0) {
 		if (set_sysfs(name, "freeze", "1")) {


                 reply	other threads:[~2009-03-13 14:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20090313145228.1160E12015A@lists.fedorahosted.org \
    --to=adas@fedoraproject.org \
    --cc=cluster-cvs-relay@redhat.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).