This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cluster: STABLE3 - gfs2_tool,libgfs2: bz487608 - GFS2: gfs2_tool unfreeze hangs


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=ad1736b57771e744e9c61389a90176fe40b7b0fd
Commit:        ad1736b57771e744e9c61389a90176fe40b7b0fd
Parent:        777d9acb4a06cbd687d9819ab19b95314c48c0e3
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 08:51:00 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")) {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]