diff options
author | Amar Tumballi <amarts@redhat.com> | 2018-06-29 23:40:53 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-22 15:47:38 +0000 |
commit | a2112bd6fa2e4851cd982a691165f76f0c90d977 (patch) | |
tree | 51dd84fbaaa75a3a94167337dc8de920a2111f57 | |
parent | bfba1d3602b20895956767c668e86390f16cb782 (diff) |
xlators/playground: fix the template files with latest requirements
* Make use of xlator_api
* Make use of gf_msg()
* Make use of mem-pool
* Add a sample metrics dump function
* Provide an dummy option, which can be initialized, and reconfigured
* Add a test case to make sure template xlator is built and used
with default fops
* Make a change in rpc-coverage to run without lock tests.
Updates: bz#1193929
Change-Id: I377dd67b656f440f9bc7c0098e21c0c1934e9096
Signed-off-by: Amar Tumballi <amarts@redhat.com>
-rw-r--r-- | glusterfs.spec.in | 4 | ||||
-rw-r--r-- | libglusterfs/src/glfs-message-id.h | 1 | ||||
-rwxr-xr-x | tests/basic/playground/template-xlator-sanity.t | 27 | ||||
-rwxr-xr-x | tests/basic/rpc-coverage.sh | 13 | ||||
-rw-r--r-- | xlators/playground/template/src/Makefile.am | 2 | ||||
-rw-r--r-- | xlators/playground/template/src/template.c | 169 | ||||
-rw-r--r-- | xlators/playground/template/src/template.h | 29 |
7 files changed, 225 insertions, 20 deletions
diff --git a/glusterfs.spec.in b/glusterfs.spec.in index 9d4d62fdf38..8acc387b6b4 100644 --- a/glusterfs.spec.in +++ b/glusterfs.spec.in @@ -1187,8 +1187,8 @@ exit 0 %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/glupy.so %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/quiesce.so %dir %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/testing -%dir %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/testing/features - %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/testing/features/template.so +%dir %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/playground + %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/playground/template.so %dir %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/testing/performance %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/testing/performance/symlink-cache.so # Glupy Python files diff --git a/libglusterfs/src/glfs-message-id.h b/libglusterfs/src/glfs-message-id.h index f991ce142d4..9702a18ffe4 100644 --- a/libglusterfs/src/glfs-message-id.h +++ b/libglusterfs/src/glfs-message-id.h @@ -88,6 +88,7 @@ enum _msgid_comp { GLFS_MSGID_COMP(SDFS, 1), GLFS_MSGID_COMP(QUIESCE, 1), GLFS_MSGID_COMP(TA, 1), + GLFS_MSGID_COMP(TEMPLATE, 1), /* --- new segments for messages goes above this line --- */ diff --git a/tests/basic/playground/template-xlator-sanity.t b/tests/basic/playground/template-xlator-sanity.t new file mode 100755 index 00000000000..c3090dae5a8 --- /dev/null +++ b/tests/basic/playground/template-xlator-sanity.t @@ -0,0 +1,27 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +cleanup; + +TEST mkdir -p $B0/single-brick +cat > $B0/template.vol <<EOF +volume posix + type storage/posix + option directory $B0/single-brick +end-volume + +volume template + type playground/template + subvolumes posix +end-volume +EOF + +TEST glusterfs -f $B0/template.vol $M0 + +TEST $(dirname $0)/../rpc-coverage.sh --no-locks $M0 + +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0 + +cleanup; diff --git a/tests/basic/rpc-coverage.sh b/tests/basic/rpc-coverage.sh index 11d3be66dcb..b7aaef0bcb5 100755 --- a/tests/basic/rpc-coverage.sh +++ b/tests/basic/rpc-coverage.sh @@ -437,7 +437,9 @@ function run_tests() test_chmod; test_chown; test_utimes; - test_locks; + if $run_lock_tests; then + test_locks; + fi test_readdir; test_setxattr; test_listxattr; @@ -453,14 +455,19 @@ function _init() DIR=$(pwd); } - +run_lock_tests=1 function parse_cmdline() { if [ "x$1" == "x" ] ; then - echo "Usage: $0 /path/mount" + echo "Usage: $0 [--no-locks] /path/mount" exit 1 fi + if [ "$1" == "--no-locks" ] ; then + run_lock_tests=0 + shift + fi + DIR=$1; if [ ! -d "$DIR" ] ; then diff --git a/xlators/playground/template/src/Makefile.am b/xlators/playground/template/src/Makefile.am index 92cbe974093..e76a717a550 100644 --- a/xlators/playground/template/src/Makefile.am +++ b/xlators/playground/template/src/Makefile.am @@ -1,5 +1,5 @@ xlator_LTLIBRARIES = template.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/testing/features +xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/playground template_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS) diff --git a/xlators/playground/template/src/template.c b/xlators/playground/template/src/template.c index c4db42debd0..45d310a8c6e 100644 --- a/xlators/playground/template/src/template.c +++ b/xlators/playground/template/src/template.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2012 Red Hat, Inc. <http://www.redhat.com> + Copyright (c) 2006-2018 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. This file is licensed to you under your choice of the GNU Lesser @@ -8,37 +8,180 @@ cases as published by the Free Software Foundation. */ #include "template.h" +#include "statedump.h" -int32_t -init (xlator_t *this) +static int32_t +template_mem_acct_init (xlator_t *this) { + int ret = -1; + + GF_VALIDATE_OR_GOTO ("template", this, out); + + ret = xlator_mem_acct_init (this, gf_template_mt_end + 1); + + if (ret != 0) { + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, TEMPLATE_MSG_NO_MEMORY, + "Memory accounting init failed"); + goto out; + } + + ret = 0; +out: + return ret; +} + +static int32_t +template_priv_to_dict (xlator_t *this, dict_t *dict, char *brickname) +{ + int ret = 0; + template_private_t *priv = NULL; + + priv = this->private; + ret = dict_set_uint64 (dict, "template.dummy", priv->dummy); + if (ret) + gf_msg_debug (this->name, ENOMEM, + "dict_set of dummy key failed"); + + return 0; +} + + +static int32_t +template_priv (xlator_t *this) +{ + template_private_t *priv = NULL; + + priv = this->private; + gf_proc_dump_write ("template.dummy", "%lu", priv->dummy); + + return 0; +} + +static int32_t +template_dump_metrics (xlator_t *this, int fd) +{ + template_private_t *priv = NULL; + + priv = this->private; + /* NOTE: currently this is adding private variable, which can + be constant here. But in reality, things which are changing + can be added here, so we get to plot them on graph. */ + dprintf (fd, "%s.private.dummy %d\n", this->name, priv->dummy); + + return 0; +} + +static int32_t +template_init (xlator_t *this) +{ + int ret = -1; + template_private_t *priv = NULL; if (!this->children || this->children->next) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, EINVAL, TEMPLATE_MSG_NO_GRAPH, "not configured with exactly one child. exiting"); - return -1; + goto out; } if (!this->parents) { - gf_log (this->name, GF_LOG_WARNING, + gf_msg (this->name, GF_LOG_ERROR, EINVAL, TEMPLATE_MSG_NO_GRAPH, "dangling volume. check volfile "); + goto out; } - return 0; + priv = GF_CALLOC (1, sizeof (template_private_t), + gf_template_mt_private_t); + if (!priv) { + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, TEMPLATE_MSG_NO_MEMORY, + "priv allocation failed"); + goto out; + } + + GF_OPTION_INIT ("dummy", priv->dummy, int32, out); + + this->private = priv; + ret = 0; + +out: + return ret; } -void -fini (xlator_t *this) +static int +template_reconfigure (xlator_t *this, dict_t *options) { - return; + int ret = -1; + template_private_t *priv = NULL; + + priv = this->private; + + GF_OPTION_RECONF ("dummy", priv->dummy, options, int32, out); + + ret = 0; + out: + return ret; } -struct xlator_fops fops = { +static void +template_fini (xlator_t *this) +{ + template_private_t *priv = NULL; + + priv = this->private; + this->private = NULL; + + GF_FREE (priv); +} + +static int +template_notify (xlator_t *this, int32_t event, void *data, ...) +{ + switch (event) { + default: + default_notify (this, event, data); + gf_msg_debug (this->name, 0, "event %d received", event); + } + + return 0; +} + +struct xlator_fops template_fops = { +}; + +struct xlator_cbks template_cbks = { }; -struct xlator_cbks cbks = { +struct xlator_dumpops template_dumpops = { + .priv = template_priv, + .priv_to_dict = template_priv_to_dict, }; -struct volume_options options[] = { +struct volume_options template_options[] = { + { .key = {"dummy"}, + .type = GF_OPTION_TYPE_INT, + .min = 1, + .max = 1024, + .default_value = "1", + .description = "a dummy option to show how to set the option", + .op_version = {GD_OP_VERSION_4_2_0}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC, + .level = OPT_STATUS_EXPERIMENTAL, + .tags = { "development", "experimental", "template" }, + }, { .key = {NULL} }, }; + + +xlator_api_t xlator_api = { + .init = template_init, + .fini = template_fini, + .notify = template_notify, + .reconfigure = template_reconfigure, + .mem_acct_init = template_mem_acct_init, + .dump_metrics = template_dump_metrics, + .op_version = {GD_OP_VERSION_4_2_0}, + .dumpops = &template_dumpops, + .fops = &template_fops, + .cbks = &template_cbks, + .options = template_options, + .identifier = "template", +}; diff --git a/xlators/playground/template/src/template.h b/xlators/playground/template/src/template.h index 2e9752cac09..e384c0181f7 100644 --- a/xlators/playground/template/src/template.h +++ b/xlators/playground/template/src/template.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> + Copyright (c) 2013-2018 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. This file is licensed to you under your choice of the GNU Lesser @@ -16,4 +16,31 @@ #include "xlator.h" #include "defaults.h" +struct template_private { + /* Add all the relevant fields you need here */ + int32_t dummy; +}; + +typedef struct template_private template_private_t; + +/* Below section goes to template-mem-types.h */ +#include "mem-types.h" + +enum gf_template_mem_types_ { + gf_template_mt_private_t = gf_common_mt_end + 1, + gf_template_mt_end, +}; + +/* This normally goes to another file 'template-messages.h", + required for 'gf_msg()'. + NOTE: make sure you have added your component (in this case, + TEMPLATE) in `libglusterfs/src/glfs-message-id.h`. + */ +#include "glfs-message-id.h" + +GLFS_MSGID(TEMPLATE, + TEMPLATE_MSG_NO_MEMORY, + TEMPLATE_MSG_NO_GRAPH + ); + #endif /* __TEMPLATE_H__ */ |