diff options
| author | Pranith Kumar K <pranithk@gluster.com> | 2011-04-12 07:17:44 +0000 | 
|---|---|---|
| committer | Anand Avati <avati@gluster.com> | 2011-04-13 00:39:03 -0700 | 
| commit | bc16a1e999648ba58f863d26281c152fb477174a (patch) | |
| tree | 339e72925c06d56355b338b01f72618892a1667a | |
| parent | fb3e469e29578393a0d5f964991d26b5449bffb0 (diff) | |
mgmt/glusterd: volume reset force implementation
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Anand Avati <avati@gluster.com>
BUG: 2729 (Implement force option for volume reset)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2729
| -rw-r--r-- | cli/src/cli-cmd-parser.c | 20 | ||||
| -rw-r--r-- | cli/src/cli-cmd-volume.c | 2 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 34 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.h | 2 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 190 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.h | 7 | 
6 files changed, 161 insertions, 94 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index c476638ba..a0219a04a 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -342,6 +342,9 @@ cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options)          if (wordcount < 3)                  goto out; +        if (wordcount > 4) +                goto out; +          volname = (char *)words[2];          if (!volname) { @@ -350,17 +353,26 @@ cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options)          }          ret = dict_set_str (dict, "volname", volname); -          if (ret)                  goto out; +        if (wordcount == 4) { +                if (strcmp ("force", (char*)words[3])) { +                        ret = -1; +                        goto out; +                } else { +                        ret = dict_set_int32 (dict, "force", 1); +                        if (ret) +                                goto out; +                } +        } +          *options = dict;  out: -                if (ret) { -        if (dict) +        if (ret && dict) {                  dict_destroy (dict); -                } +        }                  return ret;  } diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index f2e323638..1735c3873 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1160,7 +1160,7 @@ struct cli_cmd volume_cmds[] = {            cli_cmd_sync_volume_cbk,           "sync the volume information from a peer"}, -         { "volume reset <VOLNAME> ", +         { "volume reset <VOLNAME> [force]",           cli_cmd_volume_reset_cbk,           "reset all the reconfigured options"}, diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 8d1cd639f..b9d63605a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -3519,21 +3519,30 @@ out:  void  _delete_reconfig_opt (dict_t *this, char *key, data_t *value, void *data)  { +        int             exists = 0; +        int32_t         is_force = 0; -        int            exists = 0; - +        GF_ASSERT (data); +        is_force = *((int32_t*)data);          exists = glusterd_check_option_exists(key, NULL); -        if (exists == 1) { -                gf_log ("", GF_LOG_DEBUG, "deleting dict with key=%s,value=%s", -                        key, value->data); -                dict_del (this, key); -        } +        if (exists != 1) +                goto out; + +        if ((!is_force) && +            (_gf_true == glusterd_check_voloption_flags (key, +                                                         OPT_FLAG_FORCE))) +                goto out; +        gf_log ("", GF_LOG_DEBUG, "deleting dict with key=%s,value=%s", +                key, value->data); +        dict_del (this, key); +out: +        return;  }  int -glusterd_options_reset (glusterd_volinfo_t *volinfo) +glusterd_options_reset (glusterd_volinfo_t *volinfo, int32_t is_force)  {          int                      ret = 0; @@ -3541,7 +3550,7 @@ glusterd_options_reset (glusterd_volinfo_t *volinfo)          GF_ASSERT (volinfo->dict); -        dict_foreach (volinfo->dict, _delete_reconfig_opt, volinfo->dict); +        dict_foreach (volinfo->dict, _delete_reconfig_opt, &is_force);          ret = glusterd_create_volfiles_and_notify_services (volinfo); @@ -3575,6 +3584,7 @@ glusterd_op_reset_volume (dict_t *dict)          glusterd_volinfo_t     *volinfo    = NULL;          int                     ret        = -1;          char                   *volname    = NULL; +        int32_t                is_force    = 0;          ret = dict_get_str (dict, "volname", &volname);          if (ret) { @@ -3582,13 +3592,17 @@ glusterd_op_reset_volume (dict_t *dict)                  goto out;          } +        ret = dict_get_int32 (dict, "force", &is_force); +        if (ret) +                is_force = 0; +          ret = glusterd_volinfo_find (volname, &volinfo);          if (ret) {                  gf_log ("", GF_LOG_ERROR, "Unable to allocate memory");                  goto out;          } -        ret = glusterd_options_reset (volinfo); +        ret = glusterd_options_reset (volinfo, is_force);  out:          gf_log ("", GF_LOG_DEBUG, "'volume reset' returning %d", ret); diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 5e1106bc1..9c322b0bf 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -251,7 +251,7 @@ glusterd_check_brick_rb_part (char *bricks, int count, glusterd_volinfo_t *volin  void  glusterd_do_replace_brick (void *data);  int -glusterd_options_reset (glusterd_volinfo_t *volinfo); +glusterd_options_reset (glusterd_volinfo_t *volinfo, int32_t is_force);  char*  glusterd_op_sm_state_name_get (int state); diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 0d05ec5b5..816e9e68b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -84,91 +84,92 @@ struct volopt_map_entry {          char *option;          char *value;          option_type_t type; +        uint32_t flags;  };  static struct volopt_map_entry glusterd_volopt_map[] = { -        {"cluster.lookup-unhashed",              "cluster/distribute", NULL, NULL, NO_DOC       }, /* NODOC */ -        {"cluster.min-free-disk",                "cluster/distribute", NULL, NULL, NO_DOC       }, /* NODOC */ - -        {"cluster.entry-change-log",             "cluster/replicate",  NULL, NULL, NO_DOC        }, /* NODOC */ -        {"cluster.read-subvolume",               "cluster/replicate",  NULL, NULL, NO_DOC       }, /* NODOC */ -        {"cluster.background-self-heal-count",   "cluster/replicate",  NULL, NULL, NO_DOC       }, /* NODOC */ -        {"cluster.metadata-self-heal",           "cluster/replicate",  NULL, NULL, NO_DOC        }, /* NODOC */ -        {"cluster.data-self-heal",               "cluster/replicate",  NULL, NULL, NO_DOC        }, /* NODOC */ -        {"cluster.entry-self-heal",              "cluster/replicate",  NULL, NULL, NO_DOC        }, /* NODOC */ -        {"cluster.strict-readdir",               "cluster/replicate",  NULL, NULL, NO_DOC        }, /* NODOC */ -        {"cluster.self-heal-window-size",        "cluster/replicate",         "data-self-heal-window-size", NULL, DOC}, -        {"cluster.data-change-log",              "cluster/replicate",  NULL, NULL, NO_DOC        }, /* NODOC */ -        {"cluster.metadata-change-log",          "cluster/replicate",  NULL, NULL, NO_DOC        }, /* NODOC */ -        {"cluster.data-self-heal-algorithm",     "cluster/replicate",         "data-self-heal-algorithm", NULL,DOC}, - -        {"cluster.stripe-block-size",            "cluster/stripe",            "block-size", NULL, DOC}, - -        {"diagnostics.latency-measurement",      "debug/io-stats",     NULL, NULL, NO_DOC         }, -        {"diagnostics.dump-fd-stats",            "debug/io-stats",     NULL, NULL, NO_DOC        }, -        {"diagnostics.count-fop-hits",            "debug/io-stats",     NULL, NULL, NO_DOC        }, -        {"diagnostics.brick-log-level",          "debug/io-stats",            "!log-level", NULL, DOC}, -        {"diagnostics.client-log-level",         "debug/io-stats",            "!log-level", NULL, DOC}, - -        {"performance.cache-max-file-size",      "performance/io-cache",      "max-file-size", NULL, DOC}, -        {"performance.cache-min-file-size",      "performance/io-cache",      "min-file-size", NULL, DOC}, -        {"performance.cache-refresh-timeout",    "performance/io-cache",      "cache-timeout", NULL, DOC}, -        {"performance.cache-priority",           "performance/io-cache",      "priority", NULL, DOC}, /* NODOC */ -        {"performance.cache-size",               "performance/io-cache",   NULL, NULL, NO_DOC    }, -        {"performance.cache-size",               "performance/quick-read", NULL, NULL, NO_DOC    }, -        {"performance.flush-behind",             "performance/write-behind",      "flush-behind", NULL, DOC}, - -        {"performance.io-thread-count",          "performance/io-threads",    "thread-count", DOC}, - -        {"performance.disk-usage-limit",         "performance/quota",   NULL, NULL, NO_DOC       }, /* NODOC */ -        {"performance.min-free-disk-limit",      "performance/quota",   NULL, NULL, NO_DOC       }, /* NODOC */ +        {"cluster.lookup-unhashed",              "cluster/distribute", NULL, NULL, NO_DOC, 0    }, +        {"cluster.min-free-disk",                "cluster/distribute", NULL, NULL, NO_DOC, 0    }, + +        {"cluster.entry-change-log",             "cluster/replicate",  NULL, NULL, NO_DOC, 0     }, +        {"cluster.read-subvolume",               "cluster/replicate",  NULL, NULL, NO_DOC, 0    }, +        {"cluster.background-self-heal-count",   "cluster/replicate",  NULL, NULL, NO_DOC, 0    }, +        {"cluster.metadata-self-heal",           "cluster/replicate",  NULL, NULL, NO_DOC, 0     }, +        {"cluster.data-self-heal",               "cluster/replicate",  NULL, NULL, NO_DOC, 0     }, +        {"cluster.entry-self-heal",              "cluster/replicate",  NULL, NULL, NO_DOC, 0     }, +        {"cluster.strict-readdir",               "cluster/replicate",  NULL, NULL, NO_DOC, 0     }, +        {"cluster.self-heal-window-size",        "cluster/replicate",         "data-self-heal-window-size", NULL, DOC, 0}, +        {"cluster.data-change-log",              "cluster/replicate",  NULL, NULL, NO_DOC, 0     }, +        {"cluster.metadata-change-log",          "cluster/replicate",  NULL, NULL, NO_DOC, 0     }, +        {"cluster.data-self-heal-algorithm",     "cluster/replicate",         "data-self-heal-algorithm", NULL,DOC, 0}, + +        {"cluster.stripe-block-size",            "cluster/stripe",            "block-size", NULL, DOC, 0}, + +        {"diagnostics.latency-measurement",      "debug/io-stats",     NULL, NULL, NO_DOC, 0      }, +        {"diagnostics.dump-fd-stats",            "debug/io-stats",     NULL, NULL, NO_DOC, 0     }, +        {"diagnostics.count-fop-hits",           "debug/io-stats",     NULL, NULL, NO_DOC, 0     }, +        {"diagnostics.brick-log-level",          "debug/io-stats",            "!log-level", NULL, DOC, 0}, +        {"diagnostics.client-log-level",         "debug/io-stats",            "!log-level", NULL, DOC, 0}, + +        {"performance.cache-max-file-size",      "performance/io-cache",      "max-file-size", NULL, DOC, 0}, +        {"performance.cache-min-file-size",      "performance/io-cache",      "min-file-size", NULL, DOC, 0}, +        {"performance.cache-refresh-timeout",    "performance/io-cache",      "cache-timeout", NULL, DOC, 0}, +        {"performance.cache-priority",           "performance/io-cache",      "priority", NULL, DOC, 0}, +        {"performance.cache-size",               "performance/io-cache",   NULL, NULL, NO_DOC, 0 }, +        {"performance.cache-size",               "performance/quick-read", NULL, NULL, NO_DOC, 0 }, +        {"performance.flush-behind",             "performance/write-behind",      "flush-behind", NULL, DOC, 0}, + +        {"performance.io-thread-count",          "performance/io-threads",    "thread-count", DOC, 0}, + +        {"performance.disk-usage-limit",         "performance/quota",   NULL, NULL, NO_DOC, 0    }, +        {"performance.min-free-disk-limit",      "performance/quota",   NULL, NULL, NO_DOC, 0    },          {"performance.write-behind-window-size", "performance/write-behind",  "cache-size", NULL, DOC}, -        {"network.frame-timeout",                "protocol/client",    NULL, NULL, NO_DOC        }, -        {"network.ping-timeout",                 "protocol/client",    NULL, NULL, NO_DOC        }, -        {"network.inode-lru-limit",              "protocol/server",    NULL, NULL, NO_DOC        }, /* NODOC */ - -        {"auth.allow",                           "protocol/server",           "!server-auth", "*", DOC}, -        {"auth.reject",                          "protocol/server",           "!server-auth", NULL, DOC}, - -        {"transport.keepalive",                   "protocol/server",           "transport.socket.keepalive", NULL, NO_DOC}, -        {"server.allow-insecure",                 "protocol/server",          "rpc-auth-allow-insecure", NULL, NO_DOC}, - -        {"performance.write-behind",             "performance/write-behind",  "!perf", "on", NO_DOC}, /* NODOC */ -        {"performance.read-ahead",               "performance/read-ahead",    "!perf", "on", NO_DOC}, /* NODOC */ -        {"performance.io-cache",                 "performance/io-cache",      "!perf", "on", NO_DOC}, /* NODOC */ -        {"performance.quick-read",               "performance/quick-read",    "!perf", "on", NO_DOC}, /* NODOC */ -        {"performance.stat-prefetch",            "performance/stat-prefetch", "!perf", "on", NO_DOC},      /* NODOC */ - -        {"features.marker-gsync",                "features/marker",           "gsync", "off", NO_DOC}, - -        {"nfs.enable-ino32",                     "nfs/server",                "nfs.enable-ino32", NULL, GLOBAL_DOC}, -        {"nfs.mem-factor",                       "nfs/server",                "nfs.mem-factor", NULL, GLOBAL_DOC}, -        {"nfs.export-dirs",                      "nfs/server",                "nfs3.export-dirs", NULL, GLOBAL_DOC}, -        {"nfs.export-volumes",                   "nfs/server",                "nfs3.export-volumes", NULL, GLOBAL_DOC}, -        {"nfs.addr-namelookup",                  "nfs/server",                "rpc-auth.addr.namelookup", NULL, GLOBAL_DOC}, -        {"nfs.dynamic-volumes",                  "nfs/server",                "nfs.dynamic-volumes", NULL, GLOBAL_DOC}, -        {"nfs.register-with-portmap",            "nfs/server",                "rpc.register-with-portmap", NULL, GLOBAL_DOC}, -        {"nfs.port",                             "nfs/server",                "nfs.port", NULL, GLOBAL_DOC}, - -        {"nfs.rpc-auth-unix",                    "nfs/server",                "!nfs.rpc-auth-auth-unix", NULL, DOC}, -        {"nfs.rpc-auth-null",                    "nfs/server",                "!nfs.rpc-auth-auth-null", NULL, DOC}, -        {"nfs.rpc-auth-allow",                   "nfs/server",                "!nfs.rpc-auth.addr.allow", NULL, DOC}, -        {"nfs.rpc-auth-reject",                  "nfs/server",                "!nfs.rpc-auth.addr.reject", NULL, DOC}, -        {"nfs.ports-insecure",                   "nfs/server",                "!nfs.auth.ports.insecure", NULL, DOC}, - -        {"nfs.trusted-sync",                     "nfs/server",                "!nfs-trusted-sync", NULL, DOC}, -        {"nfs.trusted-write",                    "nfs/server",                "!nfs-trusted-write", NULL, DOC}, -        {"nfs.volume-access",                    "nfs/server",                "!nfs-volume-access", NULL, DOC}, -        {"nfs.export-dir",                       "nfs/server",                "!nfs-export-dir", NULL, DOC}, -        {"nfs.disable",                          "nfs/server",                "!nfs-disable", NULL, DOC}, - -        {"features.quota",                       "features/quota",            "quota", "off", NO_DOC}, -        {"features.quota",                       "features/marker",           "quota", "off", NO_DOC}, -        {"features.limit-usage",                 "features/quota",            "limit-set", NULL, NO_DOC}, -        {"features.quota-timeout",               "features/quota",            "timeout", "0", NO_DOC}, +        {"network.frame-timeout",                "protocol/client",    NULL, NULL, NO_DOC, 0     }, +        {"network.ping-timeout",                 "protocol/client",    NULL, NULL, NO_DOC, 0     }, +        {"network.inode-lru-limit",              "protocol/server",    NULL, NULL, NO_DOC, 0     }, + +        {"auth.allow",                           "protocol/server",           "!server-auth", "*", DOC, 0}, +        {"auth.reject",                          "protocol/server",           "!server-auth", NULL, DOC, 0}, + +        {"transport.keepalive",                   "protocol/server",           "transport.socket.keepalive", NULL, NO_DOC, 0}, +        {"server.allow-insecure",                 "protocol/server",          "rpc-auth-allow-insecure", NULL, NO_DOC, 0}, + +        {"performance.write-behind",             "performance/write-behind",  "!perf", "on", NO_DOC, 0}, +        {"performance.read-ahead",               "performance/read-ahead",    "!perf", "on", NO_DOC, 0}, +        {"performance.io-cache",                 "performance/io-cache",      "!perf", "on", NO_DOC, 0}, +        {"performance.quick-read",               "performance/quick-read",    "!perf", "on", NO_DOC, 0}, +        {"performance.stat-prefetch",            "performance/stat-prefetch", "!perf", "on", NO_DOC, 0}, + +        {"features.marker-gsync",                "features/marker",           "gsync", "off", NO_DOC, OPT_FLAG_FORCE}, + +        {"nfs.enable-ino32",                     "nfs/server",                "nfs.enable-ino32", NULL, GLOBAL_DOC, 0}, +        {"nfs.mem-factor",                       "nfs/server",                "nfs.mem-factor", NULL, GLOBAL_DOC, 0}, +        {"nfs.export-dirs",                      "nfs/server",                "nfs3.export-dirs", NULL, GLOBAL_DOC, 0}, +        {"nfs.export-volumes",                   "nfs/server",                "nfs3.export-volumes", NULL, GLOBAL_DOC, 0}, +        {"nfs.addr-namelookup",                  "nfs/server",                "rpc-auth.addr.namelookup", NULL, GLOBAL_DOC, 0}, +        {"nfs.dynamic-volumes",                  "nfs/server",                "nfs.dynamic-volumes", NULL, GLOBAL_DOC, 0}, +        {"nfs.register-with-portmap",            "nfs/server",                "rpc.register-with-portmap", NULL, GLOBAL_DOC, 0}, +        {"nfs.port",                             "nfs/server",                "nfs.port", NULL, GLOBAL_DOC, 0}, + +        {"nfs.rpc-auth-unix",                    "nfs/server",                "!nfs.rpc-auth-auth-unix", NULL, DOC, 0}, +        {"nfs.rpc-auth-null",                    "nfs/server",                "!nfs.rpc-auth-auth-null", NULL, DOC, 0}, +        {"nfs.rpc-auth-allow",                   "nfs/server",                "!nfs.rpc-auth.addr.allow", NULL, DOC, 0}, +        {"nfs.rpc-auth-reject",                  "nfs/server",                "!nfs.rpc-auth.addr.reject", NULL, DOC, 0}, +        {"nfs.ports-insecure",                   "nfs/server",                "!nfs.auth.ports.insecure", NULL, DOC, 0}, + +        {"nfs.trusted-sync",                     "nfs/server",                "!nfs-trusted-sync", NULL, DOC, 0}, +        {"nfs.trusted-write",                    "nfs/server",                "!nfs-trusted-write", NULL, DOC, 0}, +        {"nfs.volume-access",                    "nfs/server",                "!nfs-volume-access", NULL, DOC, 0}, +        {"nfs.export-dir",                       "nfs/server",                "!nfs-export-dir", NULL, DOC, 0}, +        {"nfs.disable",                          "nfs/server",                "!nfs-disable", NULL, DOC, 0}, + +        {"features.quota",                       "features/quota",            "quota", "off", NO_DOC, OPT_FLAG_FORCE}, +        {"features.quota",                       "features/marker",           "quota", "off", NO_DOC, OPT_FLAG_FORCE}, +        {"features.limit-usage",                 "features/quota",            "limit-set", NULL, NO_DOC, 0}, +        {"features.quota-timeout",               "features/quota",            "timeout", "0", NO_DOC, 0},          {NULL,                                                                }  }; @@ -749,6 +750,39 @@ glusterd_volinfo_get (glusterd_volinfo_t *volinfo, char *key, char **value)  }  gf_boolean_t +glusterd_check_voloption_flags (char *key, int32_t flags) +{ +        char *completion = NULL; +        struct volopt_map_entry *vmep = NULL; +        int   ret = 0; + +        if (!strchr (key, '.')) { +                ret = option_complete (key, &completion); +                if (ret) { +                        gf_log ("", GF_LOG_ERROR, "Out of memory"); +                        return _gf_false; +                } + +                if (!completion) { +                        gf_log ("", GF_LOG_ERROR, "option %s does not exist", +                                        key); +                        return _gf_false; +                } +        } + +        for (vmep = glusterd_volopt_map; vmep->key; vmep++) { +                if (strcmp (vmep->key, key) == 0) { +                        if (vmep->flags & flags) +                                return _gf_true; +                        else +                                return _gf_false; +                } +        } + +        return _gf_false; +} + +gf_boolean_t  glusterd_check_globaloption (char *key)  {          char *completion = NULL; diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h index 268611501..7028ea7b6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.h +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h @@ -27,6 +27,10 @@  #include "glusterd.h" +typedef enum gd_volopt_flags_ { +        OPT_FLAG_NONE, +        OPT_FLAG_FORCE = 1, +} gd_volopt_flags_t;  int glusterd_create_rb_volfiles (glusterd_volinfo_t *volinfo,                                   glusterd_brickinfo_t *brickinfo); @@ -45,5 +49,8 @@ int glusterd_validate_globalopts (glusterd_volinfo_t *volinfo, dict_t *val_dict,  int glusterd_validate_localopts (dict_t *val_dict, char **op_errstr);  gf_boolean_t glusterd_check_globaloption (char *key); +gf_boolean_t +glusterd_check_voloption_flags (char *key, int32_t flags); +  #endif  | 
