public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* gfs2-utils: master - gfs2-utils: Remove 'die' calls from set_sysfs
@ 2009-02-17 13:09 Andrew Price
  0 siblings, 0 replies; only message in thread
From: Andrew Price @ 2009-02-17 13:09 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=ce665cb330b3a1d7df9401463c6af2d974fe05d3
Commit:        ce665cb330b3a1d7df9401463c6af2d974fe05d3
Parent:        8398a4e351a3b4966afa06d241ab15ec376fa58e
Author:        Andrew Price <andy@andrewprice.me.uk>
AuthorDate:    Fri Feb 13 13:29:54 2009 +0000
Committer:     Andrew Price <andy@andrewprice.me.uk>
CommitterDate: Mon Feb 16 12:31:05 2009 +0000

gfs2-utils: Remove 'die' calls from set_sysfs

This patch removes the calls to 'die' from set_sysfs and adds error
reporting: It now returns -1 with errno set. All callers of this
function are also updated to check for errors.
---
 gfs2/libgfs2/libgfs2.h |    2 +-
 gfs2/libgfs2/misc.c    |   20 ++++++++++----------
 gfs2/quota/check.c     |    8 ++++++--
 gfs2/quota/main.c      |   14 +++++++++++---
 gfs2/tool/misc.c       |   29 +++++++++++++++++++++++------
 gfs2/tool/tune.c       |    6 +++++-
 6 files changed, 56 insertions(+), 23 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 8ea23f5..a89c25c 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -635,7 +635,7 @@ extern char *find_debugfs_mount(void);
 extern char *mp2fsname(char *mp);
 extern char *get_sysfs(char *fsname, char *filename);
 extern unsigned int get_sysfs_uint(char *fsname, char *filename);
-extern void set_sysfs(char *fsname, char *filename, char *val);
+extern int set_sysfs(char *fsname, char *filename, char *val);
 extern int is_fsname(char *name);
 
 /* recovery.c */
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6cd9335..d5ce490 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -240,31 +240,31 @@ unsigned int get_sysfs_uint(char *fsname, char *filename)
 	return x;
 }
 
-void set_sysfs(char *fsname, char *filename, char *val)
+int set_sysfs(char *fsname, char *filename, char *val)
 {
 	char path[PATH_MAX];
 	int fd, rv, len;
 
 	len = strlen(val) + 1;
-	if (len > PAGE_SIZE)
-		die("value for %s is too larger for sysfs\n", path);
+	if (len > PAGE_SIZE) {
+		errno = EINVAL;
+		return -1;
+	}
 
 	memset(path, 0, PATH_MAX);
 	snprintf(path, PATH_MAX - 1, "%s/%s/%s", SYS_BASE, fsname, filename);
 
 	fd = open(path, O_WRONLY);
 	if (fd < 0)
-		die("can't open %s: %s\n", path, strerror(errno));
+		return -1;
 
 	rv = write(fd, val, len);
-	if (rv != len){
-		if (rv < 0)
-			die("can't write to %s: %s", path, strerror(errno));
-		else
-			die("tried to write %d bytes to path, wrote %d\n",
-			    len, rv);
+	if (rv != len) {
+		close(fd);
+		return -1;
 	}
 	close(fd);
+	return 0;
 }
 
 /**
diff --git a/gfs2/quota/check.c b/gfs2/quota/check.c
index fdb3b42..1c577b1 100644
--- a/gfs2/quota/check.c
+++ b/gfs2/quota/check.c
@@ -502,8 +502,12 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user,
 		/* Write the id to sysfs quota refresh file to refresh gfs quotas */
 		fs = mp2fsname(comline->filesystem);
 		sprintf(id_str, "%d", comline->id);
-		set_sysfs(fs, (user) ? "quota_refresh_user" :
-			  "quota_refresh_group", id_str);
+		if (set_sysfs(fs, (user) ? "quota_refresh_user" : "quota_refresh_group",
+					id_str)) {
+			fprintf(stderr, "Error writing id to sysfs quota refresh file: %s\n",
+					strerror(errno));
+			exit(-1);
+		}
 	}
 
 out:
diff --git a/gfs2/quota/main.c b/gfs2/quota/main.c
index 544c793..5cdf118 100644
--- a/gfs2/quota/main.c
+++ b/gfs2/quota/main.c
@@ -771,7 +771,11 @@ do_sync_one(struct gfs2_sbd *sdp, char *filesystem)
 	char *fsname;
 
 	fsname = mp2fsname(filesystem);
-	set_sysfs(fsname, "quota_sync", "1");
+	if (set_sysfs(fsname, "quota_sync", "1")) {
+		fprintf(stderr, "Error writing to sysfs quota sync file: %s\n",
+				strerror(errno));
+		exit(-1);
+	}
 }
 
 /**
@@ -973,8 +977,12 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline)
 
 	fs = mp2fsname(comline->filesystem);
 	sprintf(id_str, "%d", comline->id);
-	set_sysfs(fs, comline->id_type == GQ_ID_USER ?
-		  "quota_refresh_user" : "quota_refresh_group", id_str);
+	if (set_sysfs(fs, comline->id_type == GQ_ID_USER ?
+		  "quota_refresh_user" : "quota_refresh_group", id_str)) {
+		fprintf(stderr, "Error writing to sysfs quota refresh file: %s\n",
+				strerror(errno));
+		exit(-1);
+	}
 	
 	if (adj_flag)
 		adjust_quota_list(fd, comline);
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index 44e5126..2e57cd1 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -41,10 +41,19 @@ do_freeze(int argc, char **argv)
 
 	name = mp2fsname(argv[optind]);
 
-	if (strcmp(command, "freeze") == 0)
-		set_sysfs(name, "freeze", "1");
-	else if (strcmp(command, "unfreeze") == 0)
-		set_sysfs(name, "freeze", "0");
+	if (strcmp(command, "freeze") == 0) {
+		if (set_sysfs(name, "freeze", "1")) {
+			fprintf(stderr, "Error writing to sysfs freeze file: %s\n",
+					strerror(errno));
+			exit(-1);
+		}
+	} else if (strcmp(command, "unfreeze") == 0) {
+		if (set_sysfs(name, "freeze", "0")) {
+			fprintf(stderr, "Error writing to sysfs freeze file: %s\n",
+					strerror(errno));
+			exit(-1);
+		}
+	}
 
 	sync();
 }
@@ -387,7 +396,11 @@ do_shrink(int argc, char **argv)
 	}
 	fs = mp2fsname(argv[optind]);
 	
-	set_sysfs(fs, "shrink", "1");
+	if (set_sysfs(fs, "shrink", "1")) {
+		fprintf(stderr, "Error writing to sysfs shrink file: %s\n",
+				strerror(errno));
+		exit(-1);
+	}
 }
 
 /**
@@ -417,6 +430,10 @@ do_withdraw(int argc, char **argv)
 	}
 	name = mp2fsname(argv[optind]);
 
-	set_sysfs(name, "withdraw", "1");
+	if (set_sysfs(name, "withdraw", "1")) {
+		fprintf(stderr, "Error writing to sysfs withdraw file: %s\n",
+				strerror(errno));
+		exit(-1);
+	}
 }
 
diff --git a/gfs2/tool/tune.c b/gfs2/tool/tune.c
index 6a8dcda..b4b24d8 100644
--- a/gfs2/tool/tune.c
+++ b/gfs2/tool/tune.c
@@ -118,5 +118,9 @@ set_tune(int argc, char **argv)
 		sprintf(buf, "%u %u", (unsigned int)(s * 10000.0 + 0.5), 10000);
 		value = buf;
 	}
-	set_sysfs(fs, strcat(tune_base, param), value);
+	if (set_sysfs(fs, strcat(tune_base, param), value)) {
+		fprintf(stderr, "Error writing to sysfs %s tune file: %s\n",
+				param, strerror(errno));
+		exit(-1);
+	}
 }


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

only message in thread, other threads:[~2009-02-17 13:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-17 13:09 gfs2-utils: master - gfs2-utils: Remove 'die' calls from set_sysfs 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).