diff options
author | Ravishankar N <ravishankar@redhat.com> | 2018-11-28 15:19:24 +0530 |
---|---|---|
committer | Shyamsundar Ranganathan <srangana@redhat.com> | 2018-11-29 15:30:11 +0000 |
commit | 70ae565c759cb019b73c7b4d6ac3650293984bc2 (patch) | |
tree | 6030abec5c2f39c05f795867da0aa1fcf101754a /heal | |
parent | 4c3cfd0f85c1044c804b2c31d99a4bc3b1c1fe49 (diff) | |
download | glusterfs-70ae565c759cb019b73c7b4d6ac3650293984bc2.tar.gz glusterfs-70ae565c759cb019b73c7b4d6ac3650293984bc2.tar.xz glusterfs-70ae565c759cb019b73c7b4d6ac3650293984bc2.zip |
glfsheal: add a '--nolog' flag
....and if set, change the log level to GF_LOG_NONE. This is useful for
monitoring applications which invoke the heal info set of commands once
every minute, leading to un-necessary glfsheal* logs in
/var/log/glusterfs/. For example, we can now run
`gluster volume heal <VOLNAME> info --nolog`
`gluster volume heal <VOLNAME> info split-brain --nolog` etc.
The default log level is still retained at GF_LOG_INFO.
The patch also changes glfsheal internally to accept '--xml' instead of 'xml'.
Note: The --nolog flag is *not* displayed in the help anywhere, for the
sake of consistency in how the other flags are not displayed anywhere in
the help.
fixes: bz#1654229
Change-Id: Ia08b6aa6e4a0548379db7e313dd4411ebc66f206
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
Diffstat (limited to 'heal')
-rw-r--r-- | heal/src/glfs-heal.c | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/heal/src/glfs-heal.c b/heal/src/glfs-heal.c index 930b08f830..eb7689ec88 100644 --- a/heal/src/glfs-heal.c +++ b/heal/src/glfs-heal.c @@ -40,6 +40,9 @@ xmlDocPtr glfsh_doc = NULL; ret = 0; \ } while (0) \ +#define MODE_XML (1 << 0) +#define MODE_NO_LOG (1 << 1) + typedef struct num_entries { uint64_t num_entries; uint64_t pending_entries; @@ -1479,6 +1482,28 @@ out: return ret; } +static void +parse_flags(int *argc, char **argv, int *flags) +{ + int i = 0; + char *opt = NULL; + int count = 0; + + for (i = 0; i < *argc; i++) { + opt = strtail(argv[i], "--"); + if (!opt) + continue; + if (strcmp(opt, "nolog") == 0) { + *flags |= MODE_NO_LOG; + count++; + } else if (strcmp(opt, "xml") == 0) { + *flags |= MODE_XML; + count++; + } + } + *argc = *argc - count; +} + int glfsh_heal_from_bigger_file_or_mtime (glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc, char *file, @@ -1564,6 +1589,8 @@ main (int argc, char **argv) char *op_errstr = NULL; char *socket_filepath = NULL; gf_xl_afr_op_t heal_op = -1; + gf_loglevel_t log_level = GF_LOG_INFO; + int flags = 0; if (argc < 2) { printf (USAGE_STR, argv[0]); @@ -1576,6 +1603,13 @@ main (int argc, char **argv) } } volname = argv[1]; + + parse_flags(&argc, argv, &flags); + if (flags & MODE_NO_LOG) + log_level = GF_LOG_NONE; + if (flags & MODE_XML) + is_xml = 1; + switch (argc) { case 2: heal_op = GF_SHD_OP_INDEX_SUMMARY; @@ -1583,9 +1617,6 @@ main (int argc, char **argv) case 3: if (!strcmp (argv[2], "split-brain-info")) { heal_op = GF_SHD_OP_SPLIT_BRAIN_FILES; - } else if (!strcmp (argv[2], "xml")) { - heal_op = GF_SHD_OP_INDEX_SUMMARY; - is_xml = 1; } else if (!strcmp (argv[2], "granular-entry-heal-op")) { heal_op = GF_SHD_OP_GRANULAR_ENTRY_HEAL_ENABLE; } else if (!strcmp (argv[2], "info-summary")) { @@ -1597,15 +1628,7 @@ main (int argc, char **argv) } break; case 4: - if ((!strcmp (argv[2], "split-brain-info")) && - (!strcmp (argv[3], "xml"))) { - heal_op = GF_SHD_OP_SPLIT_BRAIN_FILES; - is_xml = 1; - } else if ((!strcmp (argv[2], "info-summary")) && - (!strcmp (argv[3], "xml"))) { - heal_op = GF_SHD_OP_HEAL_SUMMARY; - is_xml = 1; - } else if (!strcmp (argv[2], "bigger-file")) { + if (!strcmp (argv[2], "bigger-file")) { heal_op = GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE; file = argv[3]; } else if (!strcmp (argv[2], "latest-mtime")) { @@ -1642,7 +1665,15 @@ main (int argc, char **argv) glfsh_output = &glfsh_human_readable; if (is_xml) { #if (HAVE_LIB_XML) - glfsh_output = &glfsh_xml_output; + if ((heal_op == GF_SHD_OP_INDEX_SUMMARY) || + (heal_op == GF_SHD_OP_SPLIT_BRAIN_FILES) || + (heal_op == GF_SHD_OP_HEAL_SUMMARY)) { + glfsh_output = &glfsh_xml_output; + } else { + printf(USAGE_STR, argv[0]); + ret = -1; + goto out; + } #else /*No point doing anything, just fail the command*/ exit (EXIT_FAILURE); @@ -1690,7 +1721,7 @@ main (int argc, char **argv) } snprintf (logfilepath, sizeof (logfilepath), DEFAULT_HEAL_LOG_FILE_DIRECTORY"/glfsheal-%s.log", volname); - ret = glfs_set_logging(fs, logfilepath, GF_LOG_INFO); + ret = glfs_set_logging(fs, logfilepath, log_level); if (ret < 0) { ret = -errno; gf_asprintf (&op_errstr, "Failed to set the log file path, " |