diff options
Diffstat (limited to 'libglusterfs/src/xlator.c')
| -rw-r--r-- | libglusterfs/src/xlator.c | 219 |
1 files changed, 136 insertions, 83 deletions
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 16a931716..a277c58a8 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _CONFIG_H @@ -88,6 +79,9 @@ fill_defaults (xlator_t *xl) SET_DEFAULT_FOP (fxattrop); SET_DEFAULT_FOP (setattr); SET_DEFAULT_FOP (fsetattr); + SET_DEFAULT_FOP (fallocate); + SET_DEFAULT_FOP (discard); + SET_DEFAULT_FOP (zerofill); SET_DEFAULT_FOP (getspec); @@ -128,18 +122,9 @@ xlator_volopt_dynload (char *xlator_type, void **dl_handle, int ret = -1; char *name = NULL; void *handle = NULL; - volume_opt_list_t *vol_opt = NULL; GF_VALIDATE_OR_GOTO ("xlator", xlator_type, out); - GF_ASSERT (dl_handle); - - if (*dl_handle) - if (dlclose (*dl_handle)) - gf_log ("xlator", GF_LOG_WARNING, "Unable to close " - "previously opened handle( may be stale)." - "Ignoring the invalid handle"); - ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xlator_type); if (-1 == ret) { gf_log ("xlator", GF_LOG_ERROR, "asprintf failed"); @@ -155,28 +140,20 @@ xlator_volopt_dynload (char *xlator_type, void **dl_handle, gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ()); goto out; } - *dl_handle = handle; - - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - - if (!vol_opt) { - goto out; - } - - if (!(vol_opt->given_opt = dlsym (handle, "options"))) { + if (!(opt_list->given_opt = dlsym (handle, "options"))) { dlerror (); - gf_log ("xlator", GF_LOG_DEBUG, - "Strict option validation not enforced -- neglecting"); + gf_log ("xlator", GF_LOG_ERROR, + "Failed to load xlator opt table"); + goto out; } - opt_list->given_opt = vol_opt->given_opt; - INIT_LIST_HEAD (&vol_opt->list); - list_add_tail (&vol_opt->list, &opt_list->list); + *dl_handle = handle; ret = 0; out: + GF_FREE (name); + gf_log ("xlator", GF_LOG_DEBUG, "Returning %d", ret); return ret; @@ -190,7 +167,7 @@ xlator_dynload (xlator_t *xl) char *name = NULL; void *handle = NULL; volume_opt_list_t *vol_opt = NULL; - + class_methods_t *vtbl = NULL; GF_VALIDATE_OR_GOTO ("xlator", xl, out); @@ -225,21 +202,42 @@ xlator_dynload (xlator_t *xl) goto out; } - if (!(xl->init = dlsym (handle, "init"))) { - gf_log ("xlator", GF_LOG_WARNING, "dlsym(init) on %s", - dlerror ()); - goto out; - } + /* + * If class_methods exists, its contents override any definitions of + * init or fini for that translator. Otherwise, we fall back to the + * older method of looking for init and fini directly. + */ + vtbl = dlsym(handle,"class_methods"); + if (vtbl) { + xl->init = vtbl->init; + xl->fini = vtbl->fini; + xl->reconfigure = vtbl->reconfigure; + xl->notify = vtbl->notify; + } + else { + if (!(*VOID(&xl->init) = dlsym (handle, "init"))) { + gf_log ("xlator", GF_LOG_WARNING, "dlsym(init) on %s", + dlerror ()); + goto out; + } - if (!(xl->fini = dlsym (handle, "fini"))) { - gf_log ("xlator", GF_LOG_WARNING, "dlsym(fini) on %s", - dlerror ()); - goto out; - } + if (!(*VOID(&(xl->fini)) = dlsym (handle, "fini"))) { + gf_log ("xlator", GF_LOG_WARNING, "dlsym(fini) on %s", + dlerror ()); + goto out; + } + if (!(*VOID(&(xl->reconfigure)) = dlsym (handle, + "reconfigure"))) { + gf_log ("xlator", GF_LOG_TRACE, + "dlsym(reconfigure) on %s -- neglecting", + dlerror()); + } + if (!(*VOID(&(xl->notify)) = dlsym (handle, "notify"))) { + gf_log ("xlator", GF_LOG_TRACE, + "dlsym(notify) on %s -- neglecting", + dlerror ()); + } - if (!(xl->notify = dlsym (handle, "notify"))) { - gf_log ("xlator", GF_LOG_TRACE, - "dlsym(notify) on %s -- neglecting", dlerror ()); } if (!(xl->dumpops = dlsym (handle, "dumpops"))) { @@ -247,18 +245,12 @@ xlator_dynload (xlator_t *xl) "dlsym(dumpops) on %s -- neglecting", dlerror ()); } - if (!(xl->mem_acct_init = dlsym (handle, "mem_acct_init"))) { + if (!(*VOID(&(xl->mem_acct_init)) = dlsym (handle, "mem_acct_init"))) { gf_log (xl->name, GF_LOG_TRACE, "dlsym(mem_acct_init) on %s -- neglecting", dlerror ()); } - if (!(xl->reconfigure = dlsym (handle, "reconfigure"))) { - gf_log ("xlator", GF_LOG_TRACE, - "dlsym(reconfigure) on %s -- neglecting", - dlerror()); - } - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t); @@ -271,6 +263,7 @@ xlator_dynload (xlator_t *xl) gf_log (xl->name, GF_LOG_TRACE, "Strict option validation not enforced -- neglecting"); } + INIT_LIST_HEAD (&vol_opt->list); list_add_tail (&vol_opt->list, &xl->volume_options); fill_defaults (xl); @@ -278,8 +271,7 @@ xlator_dynload (xlator_t *xl) ret = 0; out: - if (name) - GF_FREE (name); + GF_FREE (name); return ret; } @@ -329,6 +321,24 @@ out: } +void +xlator_foreach_depth_first (xlator_t *this, + void (*fn)(xlator_t *each, void *data), + void *data) +{ + xlator_list_t *subv = NULL; + + subv = this->children; + + while (subv) { + xlator_foreach_depth_first (subv->xlator, fn, data); + subv = subv->next; + } + + fn (this, data); +} + + xlator_t * xlator_search_by_name (xlator_t *any, const char *name) { @@ -352,7 +362,6 @@ out: return search; } - static int __xlator_init(xlator_t *xl) { @@ -468,12 +477,12 @@ xlator_mem_acct_init (xlator_t *xl, int num_types) int i = 0; int ret = 0; - if (!gf_mem_acct_is_enabled()) - return 0; - if (!xl) return -1; + if (!xl->ctx->mem_acct_enable) + return 0; + xl->mem_acct.num_types = num_types; xl->mem_acct.rec = CALLOC(num_types, sizeof(struct mem_acct_rec)); @@ -507,10 +516,26 @@ out: return; } +int +xlator_list_destroy (xlator_list_t *list) +{ + xlator_list_t *next = NULL; + + while (list) { + next = list->next; + GF_FREE (list); + list = next; + } + + return 0; +} + int xlator_tree_free (xlator_t *tree) { + volume_opt_list_t *vol_opt = NULL; + volume_opt_list_t *tmp = NULL; xlator_t *trav = tree; xlator_t *prev = tree; @@ -521,9 +546,19 @@ xlator_tree_free (xlator_t *tree) while (prev) { trav = prev->next; - dict_destroy (prev->options); + if (prev->dlhandle) + dlclose (prev->dlhandle); + dict_unref (prev->options); GF_FREE (prev->name); GF_FREE (prev->type); + xlator_list_destroy (prev->children); + xlator_list_destroy (prev->parents); + + list_for_each_entry_safe (vol_opt, tmp, &prev->volume_options, + list) { + list_del_init (&vol_opt->list); + GF_FREE (vol_opt); + } GF_FREE (prev); prev = trav; } @@ -589,6 +624,31 @@ out: return ret; } +void +loc_gfid (loc_t *loc, uuid_t gfid) +{ + if (!gfid) + goto out; + uuid_clear (gfid); + + if (!loc) + goto out; + else if (!uuid_is_null (loc->gfid)) + uuid_copy (gfid, loc->gfid); + else if (loc->inode && (!uuid_is_null (loc->inode->gfid))) + uuid_copy (gfid, loc->inode->gfid); +out: + return; +} + +char* +loc_gfid_utoa (loc_t *loc) +{ + uuid_t gfid; + loc_gfid (loc, gfid); + return uuid_utoa (gfid); +} + int loc_copy (loc_t *dst, loc_t *src) { @@ -628,22 +688,17 @@ err: return ret; } - -int -xlator_list_destroy (xlator_list_t *list) +gf_boolean_t +loc_is_root (loc_t *loc) { - xlator_list_t *next = NULL; - - while (list) { - next = list->next; - GF_FREE (list); - list = next; + if (loc && __is_root_gfid (loc->gfid)) { + return _gf_true; + } else if (loc && loc->inode && __is_root_gfid (loc->inode->gfid)) { + return _gf_true; } - - return 0; + return _gf_false; } - int xlator_destroy (xlator_t *xl) { @@ -653,10 +708,8 @@ xlator_destroy (xlator_t *xl) if (!xl) return 0; - if (xl->name) - GF_FREE (xl->name); - if (xl->type) - GF_FREE (xl->type); + GF_FREE (xl->name); + GF_FREE (xl->type); if (xl->dlhandle) dlclose (xl->dlhandle); if (xl->options) @@ -731,7 +784,7 @@ is_gf_log_command (xlator_t *this, const char *name, char *value) goto out; } - ctx = glusterfs_ctx_get(); + ctx = this->ctx; if (!ctx) goto out; if (!ctx->active) |
