diff options
Diffstat (limited to 'xlators/cluster/dht/src/switch.c')
| -rw-r--r-- | xlators/cluster/dht/src/switch.c | 163 | 
1 files changed, 19 insertions, 144 deletions
diff --git a/xlators/cluster/dht/src/switch.c b/xlators/cluster/dht/src/switch.c index 8e0b69887cf..861012247c9 100644 --- a/xlators/cluster/dht/src/switch.c +++ b/xlators/cluster/dht/src/switch.c @@ -22,6 +22,8 @@  #include <fnmatch.h>  #include <string.h> +extern struct volume_options options[]; +  struct switch_sched_array {          xlator_t *xl;          int32_t   eligible; @@ -569,20 +571,9 @@ err:  } -int -notify (xlator_t *this, int event, void *data, ...) -{ -        int ret = -1; - -        ret = dht_notify (this, event, data); - -        return ret; -} -  void -fini (xlator_t *this) +switch_fini (xlator_t *this)  { -        int                   i = 0;          dht_conf_t           *conf = NULL;          struct switch_struct *trav = NULL;          struct switch_struct *prev = NULL; @@ -598,22 +589,9 @@ fini (xlator_t *this)                          trav = trav->next;                          GF_FREE (prev);                  } - -                if (conf->file_layouts) { -                        for (i = 0; i < conf->subvolume_cnt; i++) { -                                GF_FREE (conf->file_layouts[i]); -                        } -                        GF_FREE (conf->file_layouts); -                } - -                GF_FREE (conf->subvolumes); - -                GF_FREE (conf->subvolume_status); - -                GF_FREE (conf);          } -        return; +        dht_fini(this);  }  int @@ -839,68 +817,18 @@ err:  } -int -init (xlator_t *this) +int32_t +switch_init (xlator_t *this)  {          dht_conf_t            *conf = NULL;          data_t                *data = NULL; -        char                  *temp_str = NULL;          int                    ret = -1; -        int                    i = 0; -        double                 temp_free_disk = 0; -        uint64_t               size = 0; - -        if (!this->children) { -                gf_log (this->name, GF_LOG_CRITICAL, -                        "SWITCH needs more than one subvolume"); -                return -1; -        } - -        if (!this->parents) { -                gf_log (this->name, GF_LOG_WARNING, -                        "dangling volume. check volfile"); -        } - -        conf = GF_CALLOC (1, sizeof (*conf), gf_switch_mt_dht_conf_t); -        if (!conf) { -                goto err; -        } - -        conf->search_unhashed = GF_DHT_LOOKUP_UNHASHED_ON; -        if (dict_get_str (this->options, "lookup-unhashed", &temp_str) == 0) { -                /* If option is not "auto", other options _should_ be boolean */ -                if (strcasecmp (temp_str, "auto")) -                        gf_string2boolean (temp_str, &conf->search_unhashed); -                else -                        conf->search_unhashed = GF_DHT_LOOKUP_UNHASHED_AUTO; -        } -        conf->unhashed_sticky_bit = 0; -        if (dict_get_str (this->options, "unhashed-sticky-bit", -                          &temp_str) == 0) { -                gf_string2boolean (temp_str, &conf->unhashed_sticky_bit); -        } - -        conf->min_free_disk = 10.0; -        conf->disk_unit = 'p'; - -        if (dict_get_str (this->options, "min-free-disk", -                          &temp_str) == 0) { -                if (gf_string2percent (temp_str, &temp_free_disk) == 0) { -                        if (temp_free_disk > 100) { -                                gf_string2bytesize (temp_str, &size); -                                conf->min_free_disk = size; -                                conf->disk_unit = 'b'; -                        } else { -                                conf->min_free_disk = temp_free_disk; -                                conf->disk_unit = 'p'; -                        } -                } else { -                        gf_string2bytesize (temp_str, &size); -                        conf->min_free_disk = size; -                        conf->disk_unit = 'b'; -                } +        ret = dht_init(this); +        if (ret) { +                return ret;          } +        conf = this->private;          data = dict_get (this->options, "pattern.switch.case");          if (data) { @@ -911,60 +839,23 @@ init (xlator_t *this)                  }          } -        ret = dht_init_subvolumes (this, conf); -        if (ret == -1) { -                goto err; -        } - -        ret = dht_layouts_init (this, conf); -        if (ret == -1) { -                goto err; -        } - -        LOCK_INIT (&conf->subvolume_lock); -        LOCK_INIT (&conf->layout_lock); - -        conf->gen = 1; - -        conf->du_stats = GF_CALLOC (conf->subvolume_cnt, sizeof (dht_du_t), -                                    gf_switch_mt_dht_du_t); -        if (!conf->du_stats) { -                goto err; -        } - -        this->local_pool = mem_pool_new (dht_local_t, 128); -        if (!this->local_pool) { -                gf_log (this->name, GF_LOG_ERROR, -                        "failed to create local_t's memory pool"); -                goto err; -        } -          this->private = conf; -          return 0;  err: -        if (conf) { -                if (conf->file_layouts) { -                        for (i = 0; i < conf->subvolume_cnt; i++) { -                                GF_FREE (conf->file_layouts[i]); -                        } -                        GF_FREE (conf->file_layouts); -                } - -                GF_FREE (conf->subvolumes); - -                GF_FREE (conf->subvolume_status); - -                GF_FREE (conf->du_stats); - -                GF_FREE (conf); -        } - +        dht_fini(this);          return -1;  } +class_methods_t class_methods = { +        .init           = switch_init, +        .fini           = switch_fini, +        .reconfigure    = dht_reconfigure, +        .notify         = dht_notify +}; + +  struct xlator_fops fops = {          .lookup      = switch_lookup,          .create      = switch_create, @@ -1009,19 +900,3 @@ struct xlator_fops fops = {  struct xlator_cbks cbks = {          .forget     = dht_forget  }; - - -struct volume_options options[] = { -        { .key  = {"lookup-unhashed"}, -          .value = {"auto", "yes", "no", "enable", "disable", "1", "0", -                    "on", "off"}, -          .type = GF_OPTION_TYPE_STR -        }, -        { .key  = {"pattern.switch.case"}, -          .type = GF_OPTION_TYPE_ANY -        }, -        { .key  = {"min-free-disk"}, -          .type = GF_OPTION_TYPE_PERCENT_OR_SIZET, -        }, -        { .key  = {NULL} }, -};  | 
