public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: STABLE3 - libgfs2: Clean up mp2fsname2
@ 2009-03-20 12:42 Andrew Price
  0 siblings, 0 replies; only message in thread
From: Andrew Price @ 2009-03-20 12:42 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=28a79acd2f499555253290db03f9bb5f8b132bec
Commit:        28a79acd2f499555253290db03f9bb5f8b132bec
Parent:        64b4ae12b61e66ce1720d7bdda0cc4adf6353bc5
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:57:38 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")) {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-03-20 12:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-20 12:42 cluster: STABLE3 - libgfs2: Clean up mp2fsname2 Andrew Price

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).