1. use option is a good idea
2. we could also traverse the this->children to see whether there is a xlator with type == protocol/client (depth first!)
and save cache value in conf->use_with_client
gf_boolean_t
could_use_xlator(xlator_t *this)
{
struct ios_conf *conf = NULL;
gf_boolean_t ret_value = _gf_false;
conf = this->private;
if(!conf) {
gf_log(this->name, GF_LOG_INFO, "configuration should not be null when check whether on client xlator");
return ret_value;
}
LOCK(&conf->lock);
{
if (conf->check_use_client == _gf_true) {
gf_log(this->name, GF_LOG_INFO, "use the cached value");
ret_value = conf->use_with_client;
} else {
conf->use_with_client = ret_value = trav_children(this);
conf->check_use_client = _gf_true;
}
}
UNLOCK(&conf->lock);
return ret_value;
}
gf_boolean_t
trav_children(xlator_t *this)
{
xlator_list_t * children = this->children;
while(children)
{
gf_log(this->name, GF_LOG_INFO, "children - name %s type %s ", children->xlator->name, children->xlator->type);
if (children->xlator->init_succeeded && strcmp(children->xlator->type, "protocol/client") == 0) {
return _gf_true;
}
if(trav_children(children -> xlator) == _gf_true) {
return _gf_true;
}
children = children->next;
}
return _gf_false;
}
and then,