xlator: make 'xlator_api' mandatory

* Remove the options to load old symbol.
* keep only 'xlator_api' symbol from being exported using xlator.sym
* add xlator_api to all the xlators where its missing

NOTE: This covers all the xlators which has at least a test case
to validate its loading. If there is a translator, which doesn't
have any test, then we should probably remove that from codebase.

fixes: #164
Change-Id: Ibcdc8c9844cda6b4463d907a15813745d14c1ebb
Signed-off-by: Amar Tumballi <amarts@redhat.com>
This commit is contained in:
Amar Tumballi 2018-12-06 16:24:52 +05:30
parent 088e2cbb5e
commit af7e957b49
28 changed files with 286 additions and 238 deletions

View File

@ -169,6 +169,21 @@ struct xlator_dumpops dumpops;
struct xlator_fops fops;
struct xlator_cbks cbks = {.forget = glfs_forget,
.release = glfs_release,
.releasedir = glfs_releasedir};
struct xlator_cbks cbks = {
.forget = glfs_forget,
.release = glfs_release,
.releasedir = glfs_releasedir,
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.dumpops = &dumpops,
.fops = &fops,
.cbks = &cbks,
.identifier = "glfs-api",
.category = GF_MAINTAINED,
};

View File

@ -866,13 +866,6 @@ struct _xlator {
uint32_t notify_down;
};
typedef struct {
int32_t (*init)(xlator_t *this);
void (*fini)(xlator_t *this);
int32_t (*reconfigure)(xlator_t *this, dict_t *options);
event_notify_fn_t notify;
} class_methods_t;
/* This would be the only structure which needs to be exported by
the translators. For the backward compatibility, in 4.x series
even the old exported fields will be supported */

View File

@ -214,26 +214,16 @@ xlator_volopt_dynload(char *xlator_type, void **dl_handle,
/* check new struct first, and then check this */
xlapi = dlsym(handle, "xlator_api");
if (!xlapi) {
gf_msg("xlator", GF_LOG_DEBUG, 0, LG_MSG_DLSYM_ERROR,
"dlsym(xlator_api) on %s. "
"Fall back to old symbols",
dlerror());
/* This case is not an error for now, so allow it
to fall back to old methods. */
opt_list->given_opt = dlsym(handle, "options");
if (!opt_list->given_opt) {
dlerror();
gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED,
"Failed to load xlator opt table");
goto out;
}
} else {
opt_list->given_opt = xlapi->options;
if (!opt_list->given_opt) {
gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED,
"Failed to load xlator options table");
goto out;
}
gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_DLSYM_ERROR,
"dlsym(xlator_api) missing: %s", dlerror());
goto out;
}
opt_list->given_opt = xlapi->options;
if (!opt_list->given_opt) {
gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED,
"Failed to load xlator options table");
goto out;
}
*dl_handle = handle;
@ -249,110 +239,8 @@ out:
return ret;
}
int
xlator_dynload_oldway(xlator_t *xl)
{
int i = 0;
int ret = -1;
void *handle = NULL;
volume_opt_list_t *vol_opt = NULL;
class_methods_t *vtbl = NULL;
handle = xl->dlhandle;
xl->fops = dlsym(handle, "fops");
if (!xl->fops) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(fops) on %s", dlerror());
goto out;
}
xl->cbks = dlsym(handle, "cbks");
if (!xl->cbks) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(cbks) 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_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(init) on %s", dlerror());
goto out;
}
if (!(*VOID(&(xl->fini)) = dlsym(handle, "fini"))) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(fini) on %s", dlerror());
goto out;
}
if (!(*VOID(&(xl->reconfigure)) = dlsym(handle, "reconfigure"))) {
gf_msg_trace("xlator", 0,
"dlsym(reconfigure) on %s "
"-- neglecting",
dlerror());
}
if (!(*VOID(&(xl->notify)) = dlsym(handle, "notify"))) {
gf_msg_trace("xlator", 0,
"dlsym(notify) on %s -- "
"neglecting",
dlerror());
}
}
if (!(xl->dumpops = dlsym(handle, "dumpops"))) {
gf_msg_trace("xlator", 0,
"dlsym(dumpops) on %s -- "
"neglecting",
dlerror());
}
if (!(*VOID(&(xl->mem_acct_init)) = dlsym(handle, "mem_acct_init"))) {
gf_msg_trace(xl->name, 0,
"dlsym(mem_acct_init) on %s -- "
"neglecting",
dlerror());
}
vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t),
gf_common_mt_volume_opt_list_t);
if (!vol_opt) {
goto out;
}
INIT_LIST_HEAD(&vol_opt->list);
vol_opt->given_opt = dlsym(handle, "options");
if (!vol_opt->given_opt) {
vol_opt->given_opt = default_options;
}
list_add_tail(&vol_opt->list, &xl->volume_options);
/* make sure 'min' is set to high value, so it would be
properly set later */
for (i = 0; i < GF_FOP_MAXVALUE; i++) {
xl->stats.interval.latencies[i].min = 0xffffffff;
}
ret = 0;
out:
return ret;
}
int
xlator_dynload_newway(xlator_t *xl)
static int
xlator_dynload_apis(xlator_t *xl)
{
int ret = -1;
void *handle = NULL;
@ -363,13 +251,9 @@ xlator_dynload_newway(xlator_t *xl)
xlapi = dlsym(handle, "xlator_api");
if (!xlapi) {
gf_msg("xlator", GF_LOG_INFO, 0, LG_MSG_DLSYM_ERROR,
"dlsym(xlator_api) on %s. "
"Fall back to old symbols",
dlerror());
/* This case is not an error for now, so allow it
to fall back to old methods. */
ret = 1;
gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_DLSYM_ERROR,
"dlsym(xlator_api) missing: %s", dlerror());
ret = -1;
goto out;
}
@ -492,15 +376,9 @@ xlator_dynload(xlator_t *xl)
}
xl->dlhandle = handle;
ret = xlator_dynload_newway(xl);
ret = xlator_dynload_apis(xl);
if (-1 == ret)
goto out;
if (1 == ret) {
/* it means we don't find the new symbol in xlator code */
ret = xlator_dynload_oldway(xl);
if (-1 == ret)
goto out;
}
fill_defaults(xl);

View File

@ -14,19 +14,13 @@ dht_la_SOURCES = $(dht_common_source) dht.c
nufa_la_SOURCES = $(dht_common_source) nufa.c
switch_la_SOURCES = $(dht_common_source) switch.c
dht_la_LDFLAGS = -module \
-export-symbols $(top_srcdir)/xlators/cluster/dht/src/dht.sym \
$(GF_XLATOR_LDFLAGS)
dht_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
dht_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
nufa_la_LDFLAGS = -module \
-export-symbols $(top_srcdir)/xlators/cluster/dht/src/nufa.sym \
$(GF_XLATOR_LDFLAGS)
nufa_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
nufa_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
switch_la_LDFLAGS = -module \
-export-symbols $(top_srcdir)/xlators/cluster/dht/src/switch.sym \
$(GF_XLATOR_LDFLAGS)
switch_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
switch_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
noinst_HEADERS = dht-common.h dht-mem-types.h dht-messages.h \
@ -41,8 +35,6 @@ AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \
CLEANFILES =
EXTRA_DIST = dht.sym nufa.sym switch.sym
uninstall-local:
rm -f $(DESTDIR)$(xlatordir)/distribute.so

View File

@ -1,9 +0,0 @@
xlator_api
fops
cbks
class_methods
dht_methods
options
mem_acct_init
reconfigure
dumpops

View File

@ -599,11 +599,6 @@ dht_methods_t dht_methods = {
.layout_search = dht_layout_search,
};
class_methods_t class_methods = {.init = nufa_init,
.fini = dht_fini,
.reconfigure = dht_reconfigure,
.notify = dht_notify};
struct xlator_fops fops = {
.lookup = nufa_lookup,
.create = nufa_create,
@ -645,3 +640,19 @@ struct xlator_fops fops = {
};
struct xlator_cbks cbks = {.forget = dht_forget};
extern int32_t
mem_acct_init(xlator_t *this);
xlator_api_t xlator_api = {
.init = nufa_init,
.fini = dht_fini,
.notify = dht_notify,
.reconfigure = dht_reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {1}, /* Present from the initial version */
.fops = &fops,
.cbks = &cbks,
.options = dht_options,
.identifier = "nufa",
.category = GF_TECH_PREVIEW,
};

View File

@ -1,8 +0,0 @@
fops
cbks
class_methods
dht_methods
options
mem_acct_init
reconfigure
dumpops

View File

@ -823,11 +823,6 @@ err:
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,
@ -869,3 +864,19 @@ struct xlator_fops fops = {
};
struct xlator_cbks cbks = {.forget = dht_forget};
extern int32_t
mem_acct_init(xlator_t *this);
xlator_api_t xlator_api = {
.init = switch_init,
.fini = switch_fini,
.notify = dht_notify,
.reconfigure = dht_reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {1}, /* Present from the initial version */
.fops = &fops,
.cbks = &cbks,
.options = dht_options,
.identifier = "switch",
.category = GF_TECH_PREVIEW,
};

View File

@ -1,8 +0,0 @@
fops
cbks
class_methods
dht_methods
options
mem_acct_init
reconfigure
dumpops

View File

@ -1666,4 +1666,22 @@ struct volume_options options[] = {
"specially for sequential writes. However, this will also"
"lead to extra memory consumption, maximum "
"(cache size * stripe size) Bytes per open file."},
{.key = {NULL}}};
{
.key = {NULL},
},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.reconfigure = reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.dumpops = &dumpops,
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "disperse",
.category = GF_MAINTAINED,
};

View File

@ -679,4 +679,19 @@ struct volume_options options[] = {
.default_value = "",
},
{.key = {NULL}}};
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.reconfigure = reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {GD_OP_VERSION_3_12_0},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "delay-gen",
.category = GF_TECH_PREVIEW,
};

View File

@ -1644,4 +1644,19 @@ struct volume_options options[] = {
.flags = OPT_FLAG_SETTABLE,
},
{.key = {NULL}}};
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.reconfigure = reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.dumpops = &dumpops,
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "error-gen",
.category = GF_TECH_PREVIEW,
};

View File

@ -80,3 +80,15 @@ struct xlator_cbks cbks = {};
struct volume_options options[] = {
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.op_version = {GD_OP_VERSION_3_12_0},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "sink",
.category = GF_TECH_PREVIEW,
};

View File

@ -3520,3 +3520,17 @@ struct volume_options options[] = {
};
struct xlator_dumpops dumpops = {.history = trace_dump_history};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.reconfigure = reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.dumpops = &dumpops,
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "trace",
.category = GF_TECH_PREVIEW,
};

View File

@ -334,3 +334,15 @@ struct volume_options options[] = {
"to disk as a gzip file."},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.mem_acct_init = mem_acct_init,
.op_version = {GD_OP_VERSION_3_9_0},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "cdc",
.category = GF_TECH_PREVIEW,
};

View File

@ -1408,3 +1408,15 @@ struct volume_options options[] = {
/* This translator doesn't take any options, or provide any options */
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "gfid-access",
.category = GF_MAINTAINED,
};

View File

@ -1330,3 +1330,16 @@ struct volume_options options[] = {
},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.reconfigure = reconfigure,
.op_version = {GD_OP_VERSION_3_12_0},
.dumpops = &dumpops,
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "namespace",
.category = GF_TECH_PREVIEW,
};

View File

@ -2664,3 +2664,18 @@ struct volume_options options[] = {
"the thin clients can failover to."},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.reconfigure = reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {GD_OP_VERSION_3_12_0},
.dumpops = &dumpops,
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "quiesce",
.category = GF_TECH_PREVIEW,
};

View File

@ -4,7 +4,7 @@ endif
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/features
quota_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
quotad_la_LDFLAGS = -module -export-symbols $(top_srcdir)/xlators/features/quota/src/quotad.sym $(GF_XLATOR_LDFLAGS)
quotad_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
quota_la_SOURCES = quota.c quota-enforcer-client.c
quota_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \
@ -27,6 +27,3 @@ AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \
AM_CFLAGS = -Wall $(GF_CFLAGS)
CLEANFILES =
EXTRA_DIST = quotad.sym

View File

@ -220,11 +220,6 @@ err:
return ret;
}
class_methods_t class_methods = {.init = qd_init,
.fini = qd_fini,
.reconfigure = qd_reconfigure,
.notify = qd_notify};
struct xlator_fops fops = {};
struct xlator_cbks cbks = {};
@ -240,4 +235,19 @@ struct volume_options options[] = {
.key = {"transport.*"},
.type = GF_OPTION_TYPE_ANY,
},
{.key = {NULL}}};
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = qd_init,
.fini = qd_fini,
.reconfigure = qd_reconfigure,
.notify = qd_notify,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "quotad",
.category = GF_MAINTAINED,
};

View File

@ -1,7 +0,0 @@
fops
cbks
class_methods
options
mem_acct_init
reconfigure
dumpops

View File

@ -1425,12 +1425,11 @@ out:
return ret;
}
int
void
fini(xlator_t *this)
{
mem_pool_destroy(this->local_pool);
return 0;
return;
}
struct xlator_fops fops = {
@ -1458,3 +1457,15 @@ struct volume_options options[] = {
.description = "Enable/Disable dentry serialize functionality"},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.reconfigure = reconfigure,
.op_version = {GD_OP_VERSION_4_0_0},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "sdfs",
.category = GF_TECH_PREVIEW,
};

View File

@ -2559,3 +2559,17 @@ struct volume_options options[] = {
},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.reconfigure = reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "snapview-client",
.category = GF_MAINTAINED,
};

View File

@ -2691,3 +2691,16 @@ struct volume_options options[] = {
},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "snapview-server",
.category = GF_MAINTAINED,
};

View File

@ -2225,3 +2225,15 @@ struct volume_options options[] = {
" power. Range 1-32 threads."},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.mem_acct_init = mem_acct_init,
.op_version = {1}, /* Present from the initial version */
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "glusterd",
.category = GF_MAINTAINED,
};

View File

@ -1529,7 +1529,7 @@ notify(xlator_t *this, int32_t event, void *data, ...)
return 0;
}
int
void
fini(xlator_t *this)
{
struct nfs_state *nfs = NULL;
@ -1539,7 +1539,7 @@ fini(xlator_t *this)
gf_msg_debug(GF_NFS, 0, "NFS service going down");
nfs_deinit_versions(&nfs->versions, this);
GF_FREE(this->instance_name);
return 0;
return;
}
int32_t
@ -2040,3 +2040,18 @@ struct volume_options options[] = {
},
{.key = {NULL}},
};
xlator_api_t xlator_api = {
.init = init,
.fini = fini,
.notify = notify,
.reconfigure = reconfigure,
.mem_acct_init = mem_acct_init,
.op_version = {1},
.dumpops = &dumpops,
.fops = &fops,
.cbks = &cbks,
.options = options,
.identifier = "gnfs",
.category = GF_MAINTAINED,
};

View File

@ -1,12 +1,3 @@
init
fini
fops
cbks
options
notify
mem_acct_init
reconfigure
dumpops
exp_file_parse
exp_file_print
exp_file_get_dir
@ -18,3 +9,4 @@ ng_file_parse
ng_file_get_netgroup
ng_file_print
ng_file_deinit
xlator_api

View File

@ -1,11 +1 @@
class_methods
xlator_api
init
fini
fops
cbks
options
notify
mem_acct_init
reconfigure
dumpops