summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
authorRajesh Amaravathi <rajesh@redhat.com>2012-01-31 17:04:37 +0530
committerVijay Bellur <vijay@gluster.com>2012-02-18 00:03:00 -0800
commitdf12073c4cc8340eb85b5d25c2da84fc21ec1f38 (patch)
treebea7be987249a13120faeefd61f92362a0ab61bc /xlators/mgmt
parentacb691f8908049e651fc12ff1cf01e9cf4ddde65 (diff)
cli/glusterd: volume status modification
* Method of getting mount details of brick has been changed from direct reading of /etc/mtab to using libc's <mntent.h>, providing a fairly portable version independent of different linux distributions. It is only supported on Linux though. * Wrong fs type (rootfs for /) in fedora-based distributions has been fixed. * Allows options (detail, mem, fd, et al) to "all" volumes. * Use of the fnmatch's GNU extension flag, FNM_LEADING_DIR is restricted to Linux hosts only. In case of non-Linux hosts, partial match functionality is absent. Change-Id: I102ce808c192ef635c2536a2167101be0aa0fc50 BUG: 786367 Signed-off-by: Rajesh Amaravathi <rajesh@redhat.com> Reviewed-on: http://review.gluster.com/2705 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/mgmt')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c71
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h3
2 files changed, 32 insertions, 42 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 864467fd3..42924a5f6 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -60,6 +60,9 @@
#include <fnmatch.h>
#include <sys/statvfs.h>
+#ifdef GF_LINUX_HOST_OS
+#include <mntent.h>
+#endif
#ifdef GF_SOLARIS_HOST_OS
#include <sys/sockio.h>
@@ -744,9 +747,11 @@ glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
*brickinfo = brickiter;
break;
}
+
if (path_match != GF_PATH_PARTIAL)
continue;
+#ifdef GF_LINUX_HOST_OS
if (!fnmatch (path, brickiter->path, FNM_LEADING_DIR) ||
!fnmatch (brickiter->path, path, FNM_LEADING_DIR)) {
gf_log (THIS->name, GF_LOG_ERROR,
@@ -756,6 +761,7 @@ glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
ret = 0;
break;
}
+#endif
}
out:
@@ -3109,7 +3115,8 @@ out:
return -1;
}
-int
+#ifdef GF_LINUX_HOST_OS
+static int
glusterd_get_brick_root (char *path, char **mount_point)
{
char *ptr = NULL;
@@ -3257,16 +3264,14 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
dict_t *dict, int count)
{
int ret = -1;
- int fd = -1;
char key[1024] = {0};
char base_key[1024] = {0};
- char buffer[4096] = {0};
- char cmd_str[1024] = {0};
char *mnt_pt = NULL;
char *fs_name = NULL;
char *mnt_options = NULL;
char *device = NULL;
- runner_t runner = {0};
+ FILE *mtab = NULL;
+ struct mntent *entry = NULL;
snprintf (base_key, sizeof (base_key), "brick%d", count);
@@ -3274,33 +3279,25 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
if (ret)
goto out;
- /* get mount details of brick in back-end */
- snprintf (cmd_str, sizeof (cmd_str), " %s ", mnt_pt);
-
- runinit (&runner);
- runner_add_args (&runner, "grep", cmd_str, "/etc/mtab", NULL);
- runner_redir (&runner, STDOUT_FILENO, RUN_PIPE);
+ mtab = setmntent (_PATH_MNTTAB, "r");
+ entry = getmntent (mtab);
- ret = runner_start (&runner);
- if (ret)
- goto out;
-
- if (!fgets (buffer, sizeof(buffer),
- runner_chio (&runner, STDOUT_FILENO))) {
- ret = -1;
- goto out;
+ while (1) {
+ if (!entry) {
+ ret = -1;
+ goto out;
+ }
+ if (!strcmp (entry->mnt_dir, mnt_pt) &&
+ strcmp (entry->mnt_type, "rootfs"))
+ break;
+ entry = getmntent (mtab);
}
- runner_end (&runner);
-
/* get device file */
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "%s.device", base_key);
- device = get_nth_word (buffer, 1);
- if (!device)
- goto out;
-
+ device = gf_strdup (entry->mnt_fsname);
ret = dict_set_dynstr (dict, key, device);
if (ret)
goto out;
@@ -3309,10 +3306,7 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "%s.fs_name", base_key);
- fs_name = get_nth_word (buffer, 3);
- if (!fs_name)
- goto out;
-
+ fs_name = gf_strdup (entry->mnt_type);
ret = dict_set_dynstr (dict, key, fs_name);
if (ret)
goto out;
@@ -3321,18 +3315,15 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "%s.mnt_options", base_key);
- mnt_options = get_nth_word (buffer, 4);
- if (!mnt_options)
- goto out;
+ mnt_options = gf_strdup (entry->mnt_opts);
ret = dict_set_dynstr (dict, key, mnt_options);
out:
if (mnt_pt)
GF_FREE (mnt_pt);
- if (fd >= 0)
- close (fd);
return ret;
}
+#endif
int
glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo,
@@ -3348,7 +3339,9 @@ glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo,
char key[1024] = {0};
char base_key[1024] = {0};
struct statvfs brickstat = {0};
+ xlator_t *this = NULL;
+ this = THIS;
GF_ASSERT (volinfo);
GF_ASSERT (brickinfo);
GF_ASSERT (dict);
@@ -3357,7 +3350,7 @@ glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo,
ret = statvfs (brickinfo->path, &brickstat);
if (ret) {
- gf_log (THIS->name, GF_LOG_ERROR, "statfs error: %s ",
+ gf_log (this->name, GF_LOG_ERROR, "statfs error: %s ",
strerror (errno));
goto out;
}
@@ -3404,16 +3397,16 @@ glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo,
if (ret)
goto out;
}
-
+#ifdef GF_LINUX_HOST_OS
ret = glusterd_add_brick_mount_details (brickinfo, dict, count);
if (ret)
goto out;
ret = glusterd_add_inode_size_to_dict (dict, count);
-
+#endif
out:
if (ret)
- gf_log (THIS->name, GF_LOG_DEBUG, "Error adding brick"
+ gf_log (this->name, GF_LOG_DEBUG, "Error adding brick"
" detail to dict: %s", strerror (errno));
return ret;
}
@@ -3481,7 +3474,7 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo,
out:
if (ret)
- gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index b8c65cbb0..6f9a5e14d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -349,9 +349,6 @@ int32_t
glusterd_handle_upgrade_downgrade (dict_t *options, glusterd_conf_t *conf);
int
-glusterd_get_brick_root (char *path, char **mount_point);
-
-int
glusterd_add_brick_detail_to_dict (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo,
dict_t *dict, int32_t count);