From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5132 invoked by alias); 19 Feb 2009 10:12:53 -0000 Received: (qmail 5126 invoked by alias); 19 Feb 2009 10:12:52 -0000 X-SWARE-Spam-Status: No, hits=-0.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_44,J_CHICKENPOX_52,J_CHICKENPOX_64,J_CHICKENPOX_73,J_CHICKENPOX_84,SPF_HELO_PASS X-Spam-Status: No, hits=-0.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_44,J_CHICKENPOX_52,J_CHICKENPOX_64,J_CHICKENPOX_73,J_CHICKENPOX_84,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: cluster: STABLE3 - gfs2-utils: Remove 'die' calls from set_sysfs To: cluster-cvs-relay@redhat.com X-Project: Cluster Project X-Git-Module: cluster.git X-Git-Refname: refs/heads/STABLE3 X-Git-Reftype: branch X-Git-Oldrev: cb7c47857fce808e17b09abba7db8a2312835795 X-Git-Newrev: 7e5b2eea8826e79f4be10a2dc41887564e4a503e From: "Fabio M. Di Nitto" Message-Id: <20090219100934.5A91E12030E@lists.fedorahosted.org> Date: Thu, 19 Feb 2009 10:12: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/msg00513.txt.bz2 Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=7e5b2eea8826e79f4be10a2dc41887564e4a503e Commit: 7e5b2eea8826e79f4be10a2dc41887564e4a503e Parent: cb7c47857fce808e17b09abba7db8a2312835795 Author: Andrew Price AuthorDate: Fri Feb 13 13:29:54 2009 +0000 Committer: Fabio M. Di Nitto CommitterDate: Thu Feb 19 10:59:58 2009 +0100 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); + } }