diff options
author | Amar Tumballi <amarts@redhat.com> | 2012-09-06 00:13:04 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-09-06 00:34:15 -0700 |
commit | d6c99b6134f1eb90b3a8020c3538101df266e9b5 (patch) | |
tree | a5ec27bcf3136ddfda5ce5f21917bea50ad3be58 /xlators/protocol/server/src | |
parent | 54b71368ef290bc579f113e683a82b09893fb50a (diff) |
libglusterfs/dict: make 'dict_t' a opaque object
* ie, don't dereference dict_t pointer, instead use APIs everywhere
* other than dict_t only 'data_t' should be the valid export from dict.h
* added 'dict_foreach_fnmatch()' API
* changed dict_lookup() to use data_t, instead of data_pair_t
Change-Id: I400bb0dd55519a7c5d2a107e67c8e7a7207228dc
Signed-off-by: Amar Tumballi <amarts@redhat.com>
BUG: 850917
Reviewed-on: http://review.gluster.org/3829
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators/protocol/server/src')
-rw-r--r-- | xlators/protocol/server/src/authenticate.c | 46 | ||||
-rw-r--r-- | xlators/protocol/server/src/server-helpers.c | 29 | ||||
-rw-r--r-- | xlators/protocol/server/src/server-rpc-fops.c | 44 | ||||
-rw-r--r-- | xlators/protocol/server/src/server.c | 75 |
4 files changed, 102 insertions, 92 deletions
diff --git a/xlators/protocol/server/src/authenticate.c b/xlators/protocol/server/src/authenticate.c index d1cdebdee..9c843d0bb 100644 --- a/xlators/protocol/server/src/authenticate.c +++ b/xlators/protocol/server/src/authenticate.c @@ -31,7 +31,7 @@ #include <errno.h> #include "authenticate.h" -static void +static int init (dict_t *this, char *key, data_t *value, void *data) { void *handle = NULL; @@ -59,7 +59,7 @@ init (dict_t *this, char *key, data_t *value, void *data) if (-1 == ret) { dict_set (this, key, data_from_dynptr (NULL, 0)); *error = -1; - return; + return -1; } handle = dlopen (auth_file, RTLD_LAZY); @@ -69,7 +69,7 @@ init (dict_t *this, char *key, data_t *value, void *data) dict_set (this, key, data_from_dynptr (NULL, 0)); GF_FREE (auth_file); *error = -1; - return; + return -1; } GF_FREE (auth_file); @@ -80,7 +80,7 @@ init (dict_t *this, char *key, data_t *value, void *data) dict_set (this, key, data_from_dynptr (NULL, 0)); dlclose (handle); *error = -1; - return; + return -1; } auth_handle = GF_CALLOC (1, sizeof (*auth_handle), @@ -89,7 +89,7 @@ init (dict_t *this, char *key, data_t *value, void *data) dict_set (this, key, data_from_dynptr (NULL, 0)); *error = -1; dlclose (handle); - return; + return -1; } auth_handle->vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t); @@ -98,7 +98,7 @@ init (dict_t *this, char *key, data_t *value, void *data) *error = -1; GF_FREE (auth_handle); dlclose (handle); - return; + return -1; } auth_handle->vol_opt->given_opt = dlsym (handle, "options"); if (auth_handle->vol_opt->given_opt == NULL) { @@ -111,15 +111,17 @@ init (dict_t *this, char *key, data_t *value, void *data) dict_set (this, key, data_from_dynptr (auth_handle, sizeof (*auth_handle))); + return 0; } -static void +static int fini (dict_t *this, char *key, data_t *value, void *data) { auth_handle_t *handle = data_to_ptr (value); if (handle) { dlclose (handle->handle); } + return 0; } int32_t @@ -127,31 +129,29 @@ gf_auth_init (xlator_t *xl, dict_t *auth_modules) { int ret = 0; auth_handle_t *handle = NULL; - data_pair_t *pair = NULL; dict_foreach (auth_modules, init, &ret); if (ret) goto out; - pair = auth_modules->members_list; - while (pair) { - handle = data_to_ptr (pair->value); - if (!handle) { - pair = pair->next; - continue; - } + int _auth_option_validate (dict_t *d, char *k, data_t *v, void *tmp) + { + handle = data_to_ptr (v); + if (!handle) + return 0; list_add_tail (&(handle->vol_opt->list), &(xl->volume_options)); ret = xlator_options_validate_list (xl, xl->options, handle->vol_opt, NULL); - - if (ret) + if (ret) { gf_log ("authenticate", GF_LOG_ERROR, "volume option validation failed"); - - pair = pair->next; + return -1; + } + return 0; } + ret = dict_foreach (auth_modules, _auth_option_validate, NULL); out: if (ret) { @@ -165,7 +165,7 @@ out: static dict_t *__input_params; static dict_t *__config_params; -void +int map (dict_t *this, char *key, data_t *value, void *data) { dict_t *res = data; @@ -180,15 +180,16 @@ map (dict_t *this, char *key, data_t *value, void *data) } else { dict_set (res, key, int_to_data (AUTH_DONT_CARE)); } + return 0; } -void +int reduce (dict_t *this, char *key, data_t *value, void *data) { int64_t val = 0; int64_t *res = data; if (!data) - return; + return 0; val = data_to_int64 (value); switch (val) @@ -205,6 +206,7 @@ reduce (dict_t *this, char *key, data_t *value, void *data) case AUTH_DONT_CARE: break; } + return 0; } diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index eec1684ca..0adcd1cf1 100644 --- a/xlators/protocol/server/src/server-helpers.c +++ b/xlators/protocol/server/src/server-helpers.c @@ -1388,7 +1388,6 @@ int gf_server_check_setxattr_cmd (call_frame_t *frame, dict_t *dict) { - data_pair_t *pair = NULL; server_conf_t *conf = NULL; rpc_transport_t *xprt = NULL; uint64_t total_read = 0; @@ -1398,19 +1397,23 @@ gf_server_check_setxattr_cmd (call_frame_t *frame, dict_t *dict) if (!conf || !dict) return 0; - for (pair = dict->members_list; pair; pair = pair->next) { - /* this exact key is used in 'io-stats' too. - * But this is better place for this information dump. - */ - if (fnmatch ("*io*stat*dump", pair->key, 0) == 0) { - list_for_each_entry (xprt, &conf->xprt_list, list) { - total_read += xprt->total_bytes_read; - total_write += xprt->total_bytes_write; - } - gf_log ("stats", GF_LOG_INFO, - "total-read %"PRIu64", total-write %"PRIu64, - total_read, total_write); + /* this exact key is used in 'io-stats' too. + * But this is better place for this information dump. + */ + int _handle_keyvalue_pair (dict_t *d, char *k, + data_t *v, void *tmp) + { + return 0; + } + if (dict_foreach_fnmatch (dict, "*io*stat*dump", + _handle_keyvalue_pair, NULL ) > 0) { + list_for_each_entry (xprt, &conf->xprt_list, list) { + total_read += xprt->total_bytes_read; + total_write += xprt->total_bytes_write; } + gf_log ("stats", GF_LOG_INFO, + "total-read %"PRIu64", total-write %"PRIu64, + total_read, total_write); } return 0; diff --git a/xlators/protocol/server/src/server-rpc-fops.c b/xlators/protocol/server/src/server-rpc-fops.c index a8f79ea76..db02aaf92 100644 --- a/xlators/protocol/server/src/server-rpc-fops.c +++ b/xlators/protocol/server/src/server-rpc-fops.c @@ -904,15 +904,19 @@ server_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, rsp.xdata.xdata_len, op_errno, out); if (op_ret == -1) { - gf_log (this->name, ((op_errno == ENOTSUP) ? - GF_LOG_DEBUG : GF_LOG_INFO), - "%"PRId64": SETXATTR %s (%s) ==> %s (%s)", - frame->root->unique, state->loc.path, - uuid_utoa (state->resolve.gfid), - ((state->dict) ? ((state->dict->members_list) ? - state->dict->members_list->key : - "(null)") : ("null")), - strerror (op_errno)); + /* print every key */ + int _log_setxattr_failure (dict_t *d, char *k, data_t *v, + void *tmp) + { + gf_log (this->name, ((op_errno == ENOTSUP) ? + GF_LOG_DEBUG : GF_LOG_INFO), + "%"PRId64": SETXATTR %s (%s) ==> %s (%s)", + frame->root->unique, state->loc.path, + uuid_utoa (state->resolve.gfid), k, + strerror (op_errno)); + return 0; + } + dict_foreach (state->dict, _log_setxattr_failure, NULL); goto out; } @@ -944,15 +948,19 @@ server_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, rsp.xdata.xdata_len, op_errno, out); if (op_ret == -1) { - gf_log (this->name, ((op_errno == ENOTSUP) ? - GF_LOG_DEBUG : GF_LOG_INFO), - "%"PRId64": FSETXATTR %"PRId64" (%s) ==> %s (%s)", - frame->root->unique, state->resolve.fd_no, - uuid_utoa (state->resolve.gfid), - ((state->dict) ? ((state->dict->members_list) ? - state->dict->members_list->key : - "(null)") : "null"), - strerror (op_errno)); + /* print every key here */ + int _log_setxattr_failure (dict_t *d, char *k, data_t *v, + void *tmp) + { + gf_log (this->name, ((op_errno == ENOTSUP) ? + GF_LOG_DEBUG : GF_LOG_INFO), + "%"PRId64": FSETXATTR %"PRId64" (%s) ==> %s (%s)", + frame->root->unique, state->resolve.fd_no, + uuid_utoa (state->resolve.gfid), k, + strerror (op_errno)); + return 0; + } + dict_foreach (state->dict, _log_setxattr_failure, NULL); goto out; } diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c index b6519e595..9b1bd7cf5 100644 --- a/xlators/protocol/server/src/server.c +++ b/xlators/protocol/server/src/server.c @@ -509,7 +509,7 @@ out: } -static void +static int get_auth_types (dict_t *this, char *key, data_t *value, void *data) { dict_t *auth_dict = NULL; @@ -546,7 +546,7 @@ get_auth_types (dict_t *this, char *key, data_t *value, void *data) GF_FREE (key_cpy); out: - return; + return 0; } @@ -555,7 +555,6 @@ validate_auth_options (xlator_t *this, dict_t *dict) { int error = -1; xlator_list_t *trav = NULL; - data_pair_t *pair = NULL; char *tail = NULL; char *tmp_addr_list = NULL; char *addr = NULL; @@ -566,51 +565,52 @@ validate_auth_options (xlator_t *this, dict_t *dict) trav = this->children; while (trav) { - error = -1; - for (pair = dict->members_list; pair; pair = pair->next) { - tail = strtail (pair->key, "auth."); + int _check_for_auth_option (dict_t *d, char *k, data_t *v, + void *tmp) + { + int ret = 0; + tail = strtail (k, "auth."); if (!tail) - continue; + goto internal_out; + /* fast fwd thru module type */ tail = strchr (tail, '.'); if (!tail) - continue; + goto internal_out; tail++; tail = strtail (tail, trav->xlator->name); if (!tail) - continue; + goto internal_out; if (*tail == '.') { - error = 0; /* when we are here, the key is checked for * valid auth.allow.<xlator> * Now we verify the ip address */ - if (!strcmp (pair->value->data, "*")) { - error = 0; - goto out; + if (!strcmp (v->data, "*")) { + ret = 0; + goto internal_out; } - tmp_addr_list = gf_strdup (pair->value->data); - addr = strtok_r (tmp_addr_list, ",", - &tmp_str); + tmp_addr_list = gf_strdup (v->data); + addr = strtok_r (tmp_addr_list, ",", &tmp_str); if (!addr) - addr = pair->value->data; + addr = v->data; while (addr) { - if (valid_internet_address - (addr, _gf_true)) { - error = 0; + if (valid_internet_address (addr, + _gf_true)) { + ret = 0; } else { - error = -1; + ret = -1; gf_log (this->name, GF_LOG_ERROR, "internet address '%s'" " does not conform to" " standards.", addr); - goto out; + goto internal_out; } if (tmp_str) @@ -623,8 +623,10 @@ validate_auth_options (xlator_t *this, dict_t *dict) GF_FREE (tmp_addr_list); tmp_addr_list = NULL; } - + internal_out: + return ret; } + error = dict_foreach (dict, _check_for_auth_option, NULL); if (-1 == error) { gf_log (this->name, GF_LOG_ERROR, @@ -766,31 +768,24 @@ out: } -static void -_delete_auth_opt (dict_t *this, - char *key, - data_t *value, - void *data) +static int +_delete_auth_opt (dict_t *this, char *key, data_t *value, void *data) { char *auth_option_pattern[] = { "auth.addr.*.allow", "auth.addr.*.reject"}; - if (fnmatch ( auth_option_pattern[0], key, 0) != 0) { + + if (fnmatch ( auth_option_pattern[0], key, 0) != 0) dict_del (this, key); - return; - } - if (fnmatch ( auth_option_pattern[1], key, 0) != 0) { + if (fnmatch ( auth_option_pattern[1], key, 0) != 0) dict_del (this, key); - return; - } + + return 0; } -static void -_copy_auth_opt (dict_t *unused, - char *key, - data_t *value, - void *xl_dict) +static int +_copy_auth_opt (dict_t *unused, char *key, data_t *value, void *xl_dict) { char *auth_option_pattern[] = { "auth.addr.*.allow", "auth.addr.*.reject"}; @@ -799,6 +794,8 @@ _copy_auth_opt (dict_t *unused, if (fnmatch ( auth_option_pattern[1], key, 0) != 0) dict_set ((dict_t *)xl_dict, key, (value)); + + return 0; } |