From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8475 invoked by alias); 13 Mar 2009 14:53:15 -0000 Received: (qmail 8469 invoked by alias); 13 Mar 2009 14:53:15 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_66,SPF_HELO_PASS X-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_66,SPF_HELO_PASS X-Spam-Check-By: sourceware.org X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bastion.fedora.phx.redhat.com Subject: gfs2-utils: master - gfs2_tool, libgfs2: bz487608 - GFS2: gfs2_tool unfreeze hangs To: cluster-cvs-relay@redhat.com X-Project: Cluster Project X-Git-Module: gfs2-utils.git X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 231ae2bce3351b0e9cf29a128f8f61326a767754 X-Git-Newrev: 1d2727647dda5479cc780577682d83f6ca57133c From: Abhijith Das Message-Id: <20090313145228.1160E12015A@lists.fedorahosted.org> Date: Fri, 13 Mar 2009 14:53:00 -0000 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 Mailing-List: contact cluster-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cluster-cvs-owner@sourceware.org X-SW-Source: 2009-q1/txt/msg00781.txt.bz2 Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=1d2727647dda5479cc780577682d83f6ca57133c Commit: 1d2727647dda5479cc780577682d83f6ca57133c Parent: 231ae2bce3351b0e9cf29a128f8f61326a767754 Author: Abhijith Das AuthorDate: Fri Mar 13 08:51:00 2009 -0500 Committer: Abhijith Das 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 --- 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 \n", command); - name = mp2fsname(argv[optind]); + name = mp2fsname2(argv[optind]); if (strcmp(command, "freeze") == 0) { if (set_sysfs(name, "freeze", "1")) {