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]

gfs2-utils: master - libgfs2: Clean up mp2fsname2


Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=7e0eb7013b43289473e4dc7c934d1ea8aa6fac5b
Commit:        7e0eb7013b43289473e4dc7c934d1ea8aa6fac5b
Parent:        f4a9ca2a74fae23456293dd2577526513b014215
Author:        Andrew Price <andy@andrewprice.me.uk>
AuthorDate:    Fri Mar 20 00:05:34 2009 +0000
Committer:     Andrew Price <andy@andrewprice.me.uk>
CommitterDate: Fri Mar 20 11:48:43 2009 +0000

libgfs2: Clean up mp2fsname2

This patch removes the calls to 'die' and 'exit' from mp2fsname2 and
cleans up the function a bit. Namely, it removes an unused variable
(sb), adds error checking and fixes a typo.

Signed-off-by: Andrew Price <andy@andrewprice.me.uk>
---
 gfs2/libgfs2/libgfs2.h |    2 +-
 gfs2/libgfs2/misc.c    |   21 ++++++++++++---------
 gfs2/tool/misc.c       |    5 +++++
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d8faf45..1742da9 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -632,7 +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 *mp2fsname2(char *mp);
 extern char *get_sysfs(char *fsname, char *filename);
 extern int get_sysfs_uint(char *fsname, char *filename, unsigned int *val);
 extern int set_sysfs(char *fsname, char *filename, char *val);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 60b2d4f..7666ded 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -314,7 +314,7 @@ char *find_debugfs_mount(void)
 /*
  * 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.
+ * to touch the potentially frozen filesytem and hang gfs2_tool itself.
  */
 char *
 mp2fsname2(char *mp)
@@ -323,8 +323,7 @@ mp2fsname2(char *mp)
 	struct stat statbuf;
 	DIR *d;
 	struct dirent *de;
-	struct gfs2_sbd sb;
-	FILE *fp = fopen("/proc/mounts", "r");
+	FILE *fp;
 	char buffer[PATH_MAX], device_name[PATH_MAX];
 	int fsdump, fspass, ret, found = 0;
 	char fspath[PATH_MAX], fsoptions[PATH_MAX], fstype[80];
@@ -334,9 +333,9 @@ mp2fsname2(char *mp)
 	if (mp[strlen(mp) - 1] == '/')
 		mp[strlen(mp) - 1] = 0;
 
+	fp = fopen("/proc/mounts", "r");
 	if (fp == NULL) {
-		perror("open: /proc/mounts");
-		exit(EXIT_FAILURE);
+		return NULL;
 	}
 
 	while ((fgets(buffer, PATH_MAX - 1, fp)) != NULL) {
@@ -358,9 +357,12 @@ mp2fsname2(char *mp)
 		found = 1;
 		break;
 	}
+	fclose(fp);
 
-	if (!found)
-		die("can't find gfs2 filesystem mounted at %s\n", mp);
+	if (!found) {
+		errno = ENOENT;
+		return NULL;
+	}
 
 	if (stat(device_name, &statbuf))
 		return NULL;
@@ -371,7 +373,7 @@ mp2fsname2(char *mp)
 
 	d = opendir(SYS_BASE);
 	if (!d)
-		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
+		return NULL;
 
 	while ((de = readdir(d))) {
 		if (de->d_name[0] == '.')
@@ -386,9 +388,10 @@ mp2fsname2(char *mp)
 		}
 	}
 
-	fclose(fp);
 	closedir(d);
 
+	if (!fsname)
+		errno = ENOENT;
 	return fsname;
 }
 
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index 6b054c6..694acb8 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -40,6 +40,11 @@ do_freeze(int argc, char **argv)
 		die("Usage: gfs2_tool %s <mountpoint>\n", command);
 
 	name = mp2fsname2(argv[optind]);
+	if (!name) {
+		fprintf(stderr, "Couldn't find a GFS2 filesystem mounted at %s\n",
+				argv[optind]);
+		exit(-1);
+	}
 
 	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]