[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH] gfs2-utils: Remove 'die' calls from mount_gfs2_meta



This patch removes the calls to 'die' from mount_gfs2_meta and adds
error reporting: It now returns -1 with errno set. All callers of this
function are updated to check for errors.

The static function lock_for_admin gets similar treatment as
mount_gfs2_meta is its only caller.

Signed-off-by: Andrew Price <andy andrewprice me uk>
---
 gfs2/libgfs2/libgfs2.h |    2 +-
 gfs2/libgfs2/misc.c    |   20 ++++++++++----------
 gfs2/mkfs/main_grow.c  |    6 +++++-
 gfs2/mkfs/main_jadd.c  |    6 +++++-
 gfs2/quota/check.c     |   12 ++++++++++--
 gfs2/quota/main.c      |   24 ++++++++++++++++++++----
 gfs2/tool/df.c         |    6 +++++-
 gfs2/tool/misc.c       |    7 ++++++-
 8 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index a25cf7b..a4ccf60 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -628,7 +628,7 @@ extern void compute_constants(struct gfs2_sbd *sdp);
 extern int find_gfs2_meta(struct gfs2_sbd *sdp);
 extern int dir_exists(const char *dir);
 extern int check_for_gfs2(struct gfs2_sbd *sdp);
-extern void mount_gfs2_meta(struct gfs2_sbd *sdp);
+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);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 21329f3..7a1c157 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -148,7 +148,7 @@ int check_for_gfs2(struct gfs2_sbd *sdp)
 	return -1;
 }
 
-static void lock_for_admin(struct gfs2_sbd *sdp)
+static int lock_for_admin(struct gfs2_sbd *sdp)
 {
 	int error;
 
@@ -157,18 +157,18 @@ static void lock_for_admin(struct gfs2_sbd *sdp)
 
 	sdp->metafs_fd = open(sdp->metafs_path, O_RDONLY | O_NOFOLLOW);
 	if (sdp->metafs_fd < 0)
-		die("can't open %s: %s\n",
-		    sdp->metafs_path, strerror(errno));
+		return -1;
 	
 	error = flock(sdp->metafs_fd, LOCK_EX);
 	if (error)
-		die("can't flock %s: %s\n", sdp->metafs_path, strerror(errno));
+		return -1;
 	if (sdp->debug)
 		printf("Got it.\n");
+	return 0;
 }
 
 
-void mount_gfs2_meta(struct gfs2_sbd *sdp)
+int mount_gfs2_meta(struct gfs2_sbd *sdp)
 {
 	int ret;
 
@@ -176,16 +176,16 @@ void mount_gfs2_meta(struct gfs2_sbd *sdp)
 	snprintf(sdp->metafs_path, PATH_MAX - 1, "/tmp/.gfs2meta.XXXXXX");
 
 	if(!mkdtemp(sdp->metafs_path))
-		die("Couldn't create %s : %s\n", sdp->metafs_path,
-		    strerror(errno));
+		return -1;
 
 	ret = mount(sdp->path_name, sdp->metafs_path, "gfs2meta", 0, NULL);
 	if (ret) {
 		rmdir(sdp->metafs_path);
-		die("Couldn't mount %s : %s\n", sdp->metafs_path,
-		    strerror(errno));
+		return -1;
 	}
-	lock_for_admin(sdp);
+	if (lock_for_admin(sdp))
+		return -1;
+	return 0;
 }
 
 void cleanup_metafs(struct gfs2_sbd *sdp)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index bb2a587..0e18d1a 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -295,7 +295,11 @@ main_grow(int argc, char *argv[])
 			die("gfs: Error reading superblock.\n");
 
 		fix_device_geometry(sdp);
-		mount_gfs2_meta(sdp);
+		if (mount_gfs2_meta(sdp)) {
+			fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+					strerror(errno));
+			exit(-1);
+		}
 
 		sprintf(rindex_name, "%s/rindex", sdp->metafs_path);
 		rindex_fd = open(rindex_name, (test ? O_RDONLY : O_RDWR));
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 8d96886..3f574de 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -507,7 +507,11 @@ main_jadd(int argc, char *argv[])
 
 	gather_info(sdp);
 
-	mount_gfs2_meta(sdp);
+	if (mount_gfs2_meta(sdp)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+				strerror(errno));
+		exit(-1);
+	}
 
 	compute_constants(sdp);
 	find_current_journals(sdp);
diff --git a/gfs2/quota/check.c b/gfs2/quota/check.c
index 1c577b1..0352fa9 100644
--- a/gfs2/quota/check.c
+++ b/gfs2/quota/check.c
@@ -188,7 +188,11 @@ read_quota_file(struct gfs2_sbd *sdp, commandline_t *comline,
 		exit(-1);
 	}
 	read_superblock(&sdp->sd_sb, sdp);
-	mount_gfs2_meta(sdp);
+	if (mount_gfs2_meta(sdp)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+				strerror(errno));
+		exit(-1);
+	}
 
 	strcpy(quota_file, sdp->metafs_path);
 	strcat(quota_file, "/quota");
@@ -467,7 +471,11 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user,
 		exit(-1);
 	}
 	read_superblock(&sdp->sd_sb, sdp);
-	mount_gfs2_meta(sdp);
+	if (mount_gfs2_meta(sdp)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+			strerror(errno));
+		exit(-1);
+	}
 
 	strcpy(quota_file, sdp->metafs_path);
 	strcat(quota_file, "/quota");
diff --git a/gfs2/quota/main.c b/gfs2/quota/main.c
index 5cdf118..374b5ea 100644
--- a/gfs2/quota/main.c
+++ b/gfs2/quota/main.c
@@ -515,7 +515,11 @@ do_reset(struct gfs2_sbd *sdp, commandline_t *comline)
 		exit(-1);
 	}
 	read_superblock(&sdp->sd_sb, sdp);
-	mount_gfs2_meta(sdp);
+	if (mount_gfs2_meta(sdp)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+			strerror(errno));
+		exit(-1);
+	}
 
 	strcpy(quota_file, sdp->metafs_path);
 	strcat(quota_file, "/quota");
@@ -579,7 +583,11 @@ do_list(struct gfs2_sbd *sdp, commandline_t *comline)
 		exit(-1);
 	}
 	read_superblock(&sdp->sd_sb, sdp);
-	mount_gfs2_meta(sdp);
+	if (mount_gfs2_meta(sdp)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+			strerror(errno));
+		exit(-1);
+	}
 
 	strcpy(quota_file, sdp->metafs_path);
 	strcat(quota_file, "/quota");
@@ -673,7 +681,11 @@ do_get_one(struct gfs2_sbd *sdp, commandline_t *comline, char *filesystem)
 		exit(-1);
 	}
 	read_superblock(&sdp->sd_sb, sdp);
-	mount_gfs2_meta(sdp);
+	if (mount_gfs2_meta(sdp)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+			strerror(errno));
+		exit(-1);
+	}
 
 	strcpy(quota_file, sdp->metafs_path);
 	strcat(quota_file, "/quota");
@@ -845,7 +857,11 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline)
 		exit(-1);
 	}
 	read_superblock(&sdp->sd_sb, sdp);
-	mount_gfs2_meta(sdp);
+	if (mount_gfs2_meta(sdp)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+			strerror(errno));
+		exit(-1);
+	}
 
 	strcpy(quota_file, sdp->metafs_path);
 	strcat(quota_file, "/quota");
diff --git a/gfs2/tool/df.c b/gfs2/tool/df.c
index 207fac7..7d2875d 100644
--- a/gfs2/tool/df.c
+++ b/gfs2/tool/df.c
@@ -165,7 +165,11 @@ do_df_one(char *path)
 		(get_sysfs_uint(fs, "args/localcaching")) ? "TRUE" : "FALSE");
 
 	/* Read the master statfs file */
-	mount_gfs2_meta(&sbd);
+	if (mount_gfs2_meta(&sbd)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+			strerror(errno));
+		exit(-1);
+	}
 
 	sprintf(statfs_fn, "%s/statfs", sbd.metafs_path);
 	statfs_fd = open(statfs_fn, O_RDONLY);
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index f23ec82..7d3a510 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -328,7 +328,12 @@ print_journals(int argc, char **argv)
 	if (sbd.device_fd < 0)
 		die("can't open device %s: %s\n",
 		    sbd.device_name, strerror(errno));
-	mount_gfs2_meta(&sbd);
+
+	if (mount_gfs2_meta(&sbd)) {
+		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+			strerror(errno));
+		exit(-1);
+	}
 
 	sprintf(jindex_name, "%s/jindex", sbd.metafs_path);
 	jindex = opendir(jindex_name);
-- 
1.6.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]