diff options
author | Atin Mukherjee <amukherj@redhat.com> | 2016-03-10 10:19:44 +0530 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2016-03-11 09:00:05 -0800 |
commit | 173eb1a056daef79cd593290250211d86de2cb82 (patch) | |
tree | 7d5f79bd0ec2fc5a29b74f463f7b2a826dcc10e6 | |
parent | 2492bbc3bb8a115be0b0a6fe85fd42f906df8395 (diff) |
glusterd: fix glusterd_add_inode_size_to_dict to avoid glusterd to crash
Backport of
http://review.gluster.org/#/c/8134/
http://review.gluster.org/#/c/8492/
There were couple of backports from mainline got missed and due to which
glusterd crashes if the underlying file system doesn't fail under list of
supported file systems. This patch takes care of handling this negative
scenario.
Reported-by: Michael Martel <michael.martel@vsc.edu>
Change-Id: I6f601a4421869bbd7fc26e31f4ca4ffe075c0924
BUG: 1316116
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-on: http://review.gluster.org/13661
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.com>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index f261a8db43e..9b4429007a8 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -5081,32 +5081,37 @@ glusterd_add_inode_size_to_dict (dict_t *dict, int count) runinit (&runner); runner_redir (&runner, STDOUT_FILENO, RUN_PIPE); - for (fs = glusterd_fs ; glusterd_fs->fs_type_name; fs++) { + for (fs = glusterd_fs ; fs->fs_type_name; fs++) { if (strcmp (fs_name, fs->fs_type_name) == 0) { - snprintf (fs_tool_name, sizeof fs_tool_name, + snprintf (fs_tool_name, sizeof (fs_tool_name), "/usr/sbin/%s", fs->fs_tool_name); - if (access (fs_tool_name, R_OK|X_OK) == 0) + if (sys_access (fs_tool_name, R_OK|X_OK) == 0) runner_add_arg (&runner, fs_tool_name); else { - snprintf (fs_tool_name, sizeof fs_tool_name, + snprintf (fs_tool_name, sizeof (fs_tool_name), "/sbin/%s", fs->fs_tool_name); - if (access (fs_tool_name, R_OK|X_OK) == 0) + if (sys_access (fs_tool_name, R_OK|X_OK) == 0) runner_add_arg (&runner, fs_tool_name); } - if (runner.argv[0]) { - if (fs->fs_tool_arg) - runner_add_arg (&runner, fs->fs_tool_arg); - } break; } } + if (runner.argv[0]) { + if (fs->fs_tool_arg) + runner_add_arg (&runner, fs->fs_tool_arg); + runner_add_arg (&runner, device); + } else { + gf_log (THIS->name, GF_LOG_ERROR, "could not find %s to get" + "inode size for %s (%s): %s package missing?", + fs->fs_tool_name, device, fs_name, fs->fs_tool_pkg); + goto out; + } + ret = runner_start (&runner); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "could not get inode " - "size for %s : %s package missing", fs_name, - ((strcmp (fs_name, "xfs")) ? - "e2fsprogs" : "xfsprogs")); + gf_log (THIS->name, GF_LOG_ERROR, "failed to execute \"%s\"", + fs->fs_tool_name); /* * Runner_start might return an error after the child has * been forked, e.g. if the program isn't there. In that @@ -5114,7 +5119,7 @@ glusterd_add_inode_size_to_dict (dict_t *dict, int count) * child and free resources. Fortunately, that seems to * be harmless for other kinds of failures. */ - (void) runner_end(&runner); + (void) runner_end (&runner); goto out; } @@ -5135,24 +5140,22 @@ glusterd_add_inode_size_to_dict (dict_t *dict, int count) ret = runner_end (&runner); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "%s exited with non-zero exit status", - fs->fs_tool_name); + gf_log (THIS->name, GF_LOG_ERROR, "%s exited with non-zero exit" + " status", fs->fs_tool_name); goto out; } if (!cur_word) { ret = -1; - gf_log (THIS->name, GF_LOG_ERROR, - "Unable to retrieve inode size using %s", - fs->fs_tool_name); + gf_log (THIS->name, GF_LOG_ERROR, "Unable to retrieve inode " + "size using %s", fs->fs_tool_name); goto out; } if (dict_set_dynstr_with_alloc (cached_fs, device, cur_word)) { /* not fatal if not entered into the cache */ - gf_log (THIS->name, GF_LOG_DEBUG, - "failed to cache fs inode size for %s", device); + gf_log (THIS->name, GF_LOG_DEBUG, "failed to cache fs inode " + "size for %s", device); } cached: @@ -5161,7 +5164,7 @@ cached: ret = dict_set_dynstr_with_alloc (dict, key, cur_word); - out: +out: if (ret) gf_log (THIS->name, GF_LOG_ERROR, "failed to get inode size"); return ret; |