diff options
Diffstat (limited to 'heal/src/glfs-heal.c')
| -rw-r--r-- | heal/src/glfs-heal.c | 97 |
1 files changed, 71 insertions, 26 deletions
diff --git a/heal/src/glfs-heal.c b/heal/src/glfs-heal.c index f0576f9d76e..bf4b47f8760 100644 --- a/heal/src/glfs-heal.c +++ b/heal/src/glfs-heal.c @@ -12,15 +12,13 @@ #include <stdlib.h> #include <errno.h> #include "glfs.h" -#include "glfs-handles.h" #include "glfs-internal.h" #include "protocol-common.h" -#include "syscall.h" -#include "syncop.h" -#include "syncop-utils.h" +#include <glusterfs/syscall.h> +#include <glusterfs/syncop.h> +#include <glusterfs/syncop-utils.h> #include <string.h> -#include <time.h> -#include "glusterfs.h" +#include <glusterfs/glusterfs.h> #include <libgen.h> #if (HAVE_LIB_XML) @@ -40,6 +38,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; @@ -1054,6 +1055,10 @@ glfsh_set_heal_options(glfs_t *fs, gf_xl_afr_op_t heal_op) if (ret) goto out; + ret = glfs_set_xlator_option(fs, "*-replicate-*", "halo-enabled", "off"); + if (ret) + goto out; + if ((heal_op != GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE) && (heal_op != GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK) && (heal_op != GF_SHD_OP_SBRAIN_HEAL_FROM_LATEST_MTIME)) @@ -1143,7 +1148,8 @@ glfsh_gather_heal_info(glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc, while (xl->next) xl = xl->next; while (xl) { - if (strcmp(xl->type, "protocol/client") == 0) { + if (strcmp(xl->type, "protocol/client") == 0 && + !strstr(xl->name, "-ta-")) { heal_xl = _get_ancestor(xl, heal_op); if (heal_xl) { old_THIS = THIS; @@ -1508,6 +1514,28 @@ glfsh_info_t glfsh_xml_output = { .end = glfsh_xml_end}; #endif +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 main(int argc, char **argv) { @@ -1523,6 +1551,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]); @@ -1535,6 +1565,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; @@ -1542,9 +1579,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")) { @@ -1556,15 +1590,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")) { @@ -1601,7 +1627,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); @@ -1647,7 +1681,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, @@ -1657,6 +1691,12 @@ main(int argc, char **argv) goto out; } + ret = glfs_setfspid(fs, GF_CLIENT_PID_GLFS_HEAL); + if (ret) { + printf("Setting client pid failed, %s\n", strerror(errno)); + goto out; + } + ret = glfs_init(fs); if (ret < 0) { ret = -errno; @@ -1689,14 +1729,19 @@ main(int argc, char **argv) goto out; } + char *var_str = (heal_op == GF_SHD_OP_INDEX_SUMMARY || + heal_op == GF_SHD_OP_HEAL_SUMMARY) + ? "replicate/disperse" + : "replicate"; + ret = glfsh_validate_volume(top_subvol, heal_op); if (ret < 0) { ret = -EINVAL; - gf_asprintf(&op_errstr, "Volume %s is not of type %s", volname, - (heal_op == GF_SHD_OP_INDEX_SUMMARY || - heal_op == GF_SHD_OP_HEAL_SUMMARY) - ? "replicate/disperse" - : "replicate"); + gf_asprintf(&op_errstr, + "This command is supported " + "for only volumes of %s type. Volume %s " + "is not of type %s", + var_str, volname, var_str); goto out; } rootloc.inode = inode_ref(top_subvol->itable->root); |
