diff options
-rw-r--r-- | glusterfsd/src/glusterfsd.c | 25 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd.h | 1 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 2 | ||||
-rw-r--r-- | libglusterfs/src/mem-pool.c | 27 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 61 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rebalance.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 3 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 2 |
10 files changed, 89 insertions, 40 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 57b3f0160bd..68c51162101 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -185,6 +185,8 @@ static struct argp_option gf_options[] = { "Dump fuse traffic to PATH"}, {"volfile-check", ARGP_VOLFILE_CHECK_KEY, 0, 0, "Enable strict volume file checking"}, + {"mem-accounting", ARGP_MEM_ACCOUNTING_KEY, 0, OPTION_HIDDEN, + "Enable internal memory accounting"}, {0, 0, 0, 0, "Miscellaneous Options:"}, {0, } }; @@ -501,6 +503,7 @@ out: static error_t parse_opts (int key, char *arg, struct argp_state *state) { + glusterfs_ctx_t *ctx = NULL; cmd_args_t *cmd_args = NULL; uint32_t n = 0; double d = 0.0; @@ -763,6 +766,12 @@ parse_opts (int key, char *arg, struct argp_state *state) argp_failure (state, -1, 0, "unknown brick (listen) port %s", arg); break; + + case ARGP_MEM_ACCOUNTING_KEY: + /* TODO: it should have got handled much earlier */ + ctx = glusterfs_ctx_get (); + ctx->mem_accounting = 1; + break; } return 0; @@ -1102,6 +1111,17 @@ logging_init (glusterfs_ctx_t *ctx) return 0; } +void +gf_check_and_set_mem_acct (int argc, char *argv[], glusterfs_ctx_t *ctx) +{ + int i = 0; + for (i = 0; i < argc; i++) { + if (strcmp (argv[i], "--mem-accounting") == 0) { + ctx->mem_accounting = 1; + break; + } + } +} int parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx) @@ -1582,7 +1602,10 @@ main (int argc, char *argv[]) "ERROR: glusterfs context not initialized"); return ENOMEM; } - +#ifndef DEBUG + /* Enable memory accounting on the fly based on argument */ + gf_check_and_set_mem_acct (argc, argv, ctx); +#endif ret = glusterfs_ctx_defaults_init (ctx); if (ret) goto out; diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h index 3c38fbef065..06c23a34233 100644 --- a/glusterfsd/src/glusterfsd.h +++ b/glusterfsd/src/glusterfsd.h @@ -80,6 +80,7 @@ enum argp_option_keys { ARGP_ACL_KEY = 154, ARGP_WORM_KEY = 155, ARGP_USER_MAP_ROOT_KEY = 156, + ARGP_MEM_ACCOUNTING_KEY = 157, }; struct _gfd_vol_top_priv_t { diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 0d4240a2a6e..a3adf151b19 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -376,6 +376,8 @@ struct _glusterfs_ctx { struct mem_pool *dict_pair_pool; struct mem_pool *dict_data_pool; + int mem_accounting; /* if value is other than 0, it + will be set */ }; typedef struct _glusterfs_ctx glusterfs_ctx_t; diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 0cfd8bd712a..7f20d6d4b36 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -50,26 +50,31 @@ gf_mem_acct_is_enabled () void gf_mem_acct_enable_set () { - char *opt = NULL; - long val = -1; - #ifdef DEBUG gf_mem_acct_enable = 1; return; #endif + glusterfs_ctx_t *ctx = NULL; + char *opt = NULL; + long val = -1; - opt = getenv (GLUSTERFS_ENV_MEM_ACCT_STR); - - if (!opt) - return; + gf_mem_acct_enable = 0; - val = strtol (opt, NULL, 0); + ctx = glusterfs_ctx_get (); - if (val) - gf_mem_acct_enable = 0; - else + if (ctx->mem_accounting) { gf_mem_acct_enable = 1; + return; + } + opt = getenv (GLUSTERFS_ENV_MEM_ACCT_STR); + if (opt) { + val = strtol (opt, NULL, 0); + if (val) + gf_mem_acct_enable = 1; + } + + return; } void diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index f9813db12f5..d96d6717eeb 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -391,11 +391,25 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) global_opt = _gf_false; sprintf (str, "key%d", count); ret = dict_get_str (dict, str, &key); - - if (ret) break; + sprintf (str, "value%d", count); + ret = dict_get_str (dict, str, &value); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "invalid key,value pair in 'volume set'"); + ret = -1; + goto out; + } + + if (strcmp (key, "memory-accounting") == 0) { + gf_log (this->name, GF_LOG_INFO, + "enabling memory accounting for volume %s", + volname); + ret = 0; + goto out; + } exists = glusterd_check_option_exists (key, &key_fixed); if (exists == -1) { ret = -1; @@ -416,16 +430,6 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) goto out; } - sprintf (str, "value%d", count); - ret = dict_get_str (dict, str, &value); - - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "invalid key,value pair in 'volume set'"); - ret = -1; - goto out; - } - if (key_fixed) key = key_fixed; @@ -1008,24 +1012,9 @@ glusterd_op_set_volume (dict_t *dict) global_opt = _gf_false; sprintf (str, "key%d", count); ret = dict_get_str (dict, str, &key); - if (ret) break; - if (!ret) { - ret = glusterd_check_option_exists (key, &key_fixed); - GF_ASSERT (ret); - if (ret == -1) { - key_fixed = NULL; - goto out; - } - ret = 0; - } - - ret = glusterd_check_globaloption (key); - if (ret) - global_opt = _gf_true; - sprintf (str, "value%d", count); ret = dict_get_str (dict, str, &value); if (ret) { @@ -1035,6 +1024,22 @@ glusterd_op_set_volume (dict_t *dict) goto out; } + if (strcmp (key, "memory-accounting") == 0) { + ret = gf_string2boolean (value, + &volinfo->memory_accounting); + goto out; + } + ret = glusterd_check_option_exists (key, &key_fixed); + GF_ASSERT (ret); + if (ret == -1) { + key_fixed = NULL; + goto out; + } + + ret = glusterd_check_globaloption (key); + if (ret) + global_opt = _gf_true; + if (!global_opt) value = gf_strdup (value); @@ -1067,7 +1072,7 @@ glusterd_op_set_volume (dict_t *dict) } } - if ( count == 1 ) { + if (count == 1) { gf_log (this->name, GF_LOG_ERROR, "No options received "); ret = -1; goto out; diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c index 5d567e37a8a..36435868602 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c +++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c @@ -327,6 +327,8 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr, runner_argprintf (&runner, "%s",pidfile); runner_add_arg (&runner, "-l"); runner_argprintf (&runner, logfile); + if (volinfo->memory_accounting) + runner_add_arg (&runner, "--mem-accounting"); ret = runner_run_reuse (&runner); if (ret) { diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c index 01bc974b75f..ca127f7a8ea 100644 --- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c @@ -635,6 +635,8 @@ rb_spawn_dst_brick (glusterd_volinfo_t *volinfo, priv->workdir, volinfo->volname); runner_add_arg (&runner, "--xlator-option"); runner_argprintf (&runner, "src-server.listen-port=%d", port); + if (volinfo->memory_accounting) + runner_add_arg (&runner, "--mem-accounting"); ret = runner_run (&runner); if (ret) { @@ -671,6 +673,8 @@ rb_spawn_glusterfs_client (glusterd_volinfo_t *volinfo, priv->workdir, volinfo->volname); runner_argprintf (&runner, "%s/vols/%s/"RB_CLIENT_MOUNTPOINT, priv->workdir, volinfo->volname); + if (volinfo->memory_accounting) + runner_add_arg (&runner, "--mem-accounting"); ret = runner_run (&runner); if (ret) { diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 64b7ba9ad1b..3c084635166 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -1236,6 +1236,9 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo, runner_argprintf (&runner, "%s-server.listen-port=%d", volinfo->volname, port); + if (volinfo->memory_accounting) + runner_add_arg (&runner, "--mem-accounting"); + runner_log (&runner, "", GF_LOG_DEBUG, "Starting GlusterFS"); ret = runner_run (&runner); diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index ef338658b97..d6e58c1b844 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -1665,6 +1665,8 @@ glusterd_clearlocks_mount (glusterd_volinfo_t *volinfo, char **xl_opts, runner_add_arg (&runner, "-l"); runner_argprintf (&runner, DEFAULT_LOG_FILE_DIRECTORY "/%s-clearlocks-mnt.log", volinfo->volname); + if (volinfo->memory_accounting) + runner_add_arg (&runner, "--mem-accounting"); for (i = 0; i < volinfo->brick_count && xl_opts[i]; i++) { runner_add_arg (&runner, "--xlator-option"); diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 7a6ee653f0f..44934b2fc80 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -244,6 +244,8 @@ struct glusterd_volinfo_ { int decommission_in_progress; xlator_t *xl; + + gf_boolean_t memory_accounting; }; typedef enum gd_node_type_ { |