diff options
Diffstat (limited to 'xlators/performance/io-cache')
| -rw-r--r-- | xlators/performance/io-cache/src/io-cache.c | 59 | 
1 files changed, 54 insertions, 5 deletions
diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 90c14ea7d6c..375004c9346 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -1514,13 +1514,50 @@ mem_acct_init (xlator_t *this)  } +gf_boolean_t +check_cache_size_ok (xlator_t *this, uint64_t cache_size) +{ +        gf_boolean_t            ret = _gf_true; +        uint64_t                total_mem = 0; +        uint64_t                max_cache_size = 0; +        volume_option_t         *opt = NULL; + +        GF_ASSERT (this); +        opt = xlator_volume_option_get (this, "cache-size"); +        if (!opt) { +                ret = _gf_false; +                gf_log (this->name, GF_LOG_ERROR, +                        "could not get cache-size option"); +                goto out; +        } + +        total_mem = get_mem_size (); +        if (-1 == total_mem) +                max_cache_size = opt->max; +        else +                max_cache_size = total_mem; + +        gf_log (this->name, GF_LOG_INFO, "Max cache size is %"PRIu64, +                max_cache_size); + +        if (cache_size > max_cache_size) { +                ret = _gf_false; +                gf_log (this->name, GF_LOG_ERROR, "Cache size %"PRIu64 +                        " is greater than the max size of %"PRIu64, +                        cache_size, max_cache_size); +                goto out; +        } +out: +        return ret; +} +  int  reconfigure (xlator_t *this, dict_t *options)  {          data_t      *data              = NULL;          ioc_table_t *table             = NULL;          int          ret               = -1; - +        uint64_t      cache_size_new    = 0;          if (!this || !this->private)                  goto out; @@ -1531,9 +1568,6 @@ reconfigure (xlator_t *this, dict_t *options)                  GF_OPTION_RECONF ("cache-timeout", table->cache_timeout,                                    options, int32, unlock); -                GF_OPTION_RECONF ("cache-size", table->cache_size, -                                  options, size, unlock); -                  data = dict_get (options, "priority");                  if (data) {                          char *option_list = data_to_str (data); @@ -1566,6 +1600,16 @@ reconfigure (xlator_t *this, dict_t *options)                          goto unlock;                  } +                GF_OPTION_RECONF ("cache-size", cache_size_new, +                                  options, size, unlock); +                if (!check_cache_size_ok (this, cache_size_new)) { +                        ret = -1; +                        gf_log (this->name, GF_LOG_ERROR, +                                "Not reconfiguring cache-size"); +                        goto unlock; +                } +                table->cache_size = cache_size_new; +                  ret = 0;          }  unlock: @@ -1621,6 +1665,11 @@ init (xlator_t *this)          GF_OPTION_INIT ("max-file-size", table->max_file_size, size, out); +        if  (!check_cache_size_ok (this, table->cache_size)) { +                ret = -1; +                goto out; +        } +          INIT_LIST_HEAD (&table->priority_list);          table->max_pri = 1;          data = dict_get (xl_options, "priority"); @@ -1921,7 +1970,7 @@ struct volume_options options[] = {          { .key  = {"cache-size"},            .type = GF_OPTION_TYPE_SIZET,            .min  = 4 * GF_UNIT_MB, -          .max  = 6 * GF_UNIT_GB, +          .max  = 32 * GF_UNIT_GB,            .default_value = "32MB",            .description = "Size of the read cache."          },  | 
