[Cluster-devel] [PATCH] libgfs2: Remove 'die' from mp2fsname and find_debugfs_mount
Steven Whitehouse
swhiteho at redhat.com
Fri Mar 20 14:33:32 UTC 2009
Hi,
Looks good to me,
Steve.
On Fri, 2009-03-20 at 13:03 +0000, Andrew Price wrote:
> Removes the call to 'die' from mp2fsname and updates its callers to
> handle the error. Also removes the die calls from find_debugfs_mount
> which only has one caller that already handles the error cases.
>
> Signed-off-by: Andrew Price <andy at andrewprice.me.uk>
> ---
> gfs2/libgfs2/misc.c | 10 ++++++----
> gfs2/quota/check.c | 8 +++++++-
> gfs2/quota/main.c | 10 ++++++++++
> gfs2/tool/df.c | 5 +++++
> gfs2/tool/misc.c | 15 +++++++++++++++
> gfs2/tool/tune.c | 10 ++++++++++
> 6 files changed, 53 insertions(+), 5 deletions(-)
>
> diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
> index 7666ded..8441137 100644
> --- a/gfs2/libgfs2/misc.c
> +++ b/gfs2/libgfs2/misc.c
> @@ -291,11 +291,13 @@ char *find_debugfs_mount(void)
>
> file = fopen("/proc/mounts", "rt");
> if (!file)
> - die("can't open /proc/mounts: %s\n", strerror(errno));
> + return NULL;
>
> path = malloc(PATH_MAX);
> - if (!path)
> - die("Can't allocate memory for debugfs.\n");
> + if (!path) {
> + fclose(file);
> + return NULL;
> + }
> while (fgets(line, PATH_MAX, file)) {
>
> if (sscanf(line, "%s %s %s", device, path, type) != 3)
> @@ -432,7 +434,7 @@ char *mp2fsname(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] == '.')
> diff --git a/gfs2/quota/check.c b/gfs2/quota/check.c
> index 0352fa9..9223971 100644
> --- a/gfs2/quota/check.c
> +++ b/gfs2/quota/check.c
> @@ -507,8 +507,14 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user,
> goto out;
> }
>
> - /* Write the id to sysfs quota refresh file to refresh gfs quotas */
> fs = mp2fsname(comline->filesystem);
> + if (!fs) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + comline->filesystem);
> + exit(-1);
> + }
> +
> + /* Write the id to sysfs quota refresh file to refresh gfs quotas */
> sprintf(id_str, "%d", comline->id);
> if (set_sysfs(fs, (user) ? "quota_refresh_user" : "quota_refresh_group",
> id_str)) {
> diff --git a/gfs2/quota/main.c b/gfs2/quota/main.c
> index 374b5ea..7b6ad78 100644
> --- a/gfs2/quota/main.c
> +++ b/gfs2/quota/main.c
> @@ -783,6 +783,11 @@ do_sync_one(struct gfs2_sbd *sdp, char *filesystem)
> char *fsname;
>
> fsname = mp2fsname(filesystem);
> + if (!fsname) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + filesystem);
> + exit(-1);
> + }
> if (set_sysfs(fsname, "quota_sync", "1")) {
> fprintf(stderr, "Error writing to sysfs quota sync file: %s\n",
> strerror(errno));
> @@ -992,6 +997,11 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline)
> }
>
> fs = mp2fsname(comline->filesystem);
> + if (!fs) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + comline->filesystem);
> + exit(-1);
> + }
> sprintf(id_str, "%d", comline->id);
> if (set_sysfs(fs, comline->id_type == GQ_ID_USER ?
> "quota_refresh_user" : "quota_refresh_group", id_str)) {
> diff --git a/gfs2/tool/df.c b/gfs2/tool/df.c
> index c817813..8b6d9b4 100644
> --- a/gfs2/tool/df.c
> +++ b/gfs2/tool/df.c
> @@ -95,6 +95,11 @@ do_df_one(char *path)
> exit(-1);
> }
> fs = mp2fsname(sbd.path_name);
> + if (!fs) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + sbd.path_name);
> + exit(-1);
> + }
>
> sbd.device_fd = open(sbd.device_name, O_RDONLY);
> if (sbd.device_fd < 0)
> diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
> index 694acb8..3315e6e 100644
> --- a/gfs2/tool/misc.c
> +++ b/gfs2/tool/misc.c
> @@ -272,6 +272,11 @@ print_args(int argc, char **argv)
> exit(-1);
> }
> fs = mp2fsname(argv[optind]);
> + if (!fs) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + argv[optind]);
> + exit(-1);
> + }
>
> memset(path, 0, PATH_MAX);
> snprintf(path, PATH_MAX - 1, "%s/%s/args/", SYS_BASE, fs);
> @@ -457,6 +462,11 @@ do_shrink(int argc, char **argv)
> exit(-1);
> }
> fs = mp2fsname(argv[optind]);
> + if (!fs) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + argv[optind]);
> + exit(-1);
> + }
>
> if (set_sysfs(fs, "shrink", "1")) {
> fprintf(stderr, "Error writing to sysfs shrink file: %s\n",
> @@ -491,6 +501,11 @@ do_withdraw(int argc, char **argv)
> exit(-1);
> }
> name = mp2fsname(argv[optind]);
> + if (!name) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + argv[optind]);
> + exit(-1);
> + }
>
> if (set_sysfs(name, "withdraw", "1")) {
> fprintf(stderr, "Error writing to sysfs withdraw file: %s\n",
> diff --git a/gfs2/tool/tune.c b/gfs2/tool/tune.c
> index 29c529b..277d2dd 100644
> --- a/gfs2/tool/tune.c
> +++ b/gfs2/tool/tune.c
> @@ -54,6 +54,11 @@ get_tune(int argc, char **argv)
> exit(-1);
> }
> fs = mp2fsname(argv[optind]);
> + if (!fs) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + argv[optind]);
> + exit(-1);
> + }
> memset(path, 0, PATH_MAX);
> snprintf(path, PATH_MAX - 1, "%s/%s/tune", SYS_BASE, fs);
>
> @@ -117,6 +122,11 @@ set_tune(int argc, char **argv)
> exit(-1);
> }
> fs = mp2fsname(sbd.path_name);
> + if (!fs) {
> + fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
> + sbd.path_name);
> + exit(-1);
> + }
>
> if (strcmp(param, "quota_scale") == 0) {
> float s;
More information about the Cluster-devel
mailing list