summaryrefslogtreecommitdiffstats
path: root/xlators/playground
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/playground')
-rw-r--r--xlators/playground/Makefile.am2
-rw-r--r--xlators/playground/rot-13/Makefile.am3
-rw-r--r--xlators/playground/rot-13/src/Makefile.am16
-rw-r--r--xlators/playground/rot-13/src/rot-13.c166
-rw-r--r--xlators/playground/rot-13/src/rot-13.h18
-rw-r--r--xlators/playground/template/Makefile.am2
-rw-r--r--xlators/playground/template/src/Makefile.am17
-rw-r--r--xlators/playground/template/src/template.c186
-rw-r--r--xlators/playground/template/src/template.h43
9 files changed, 453 insertions, 0 deletions
diff --git a/xlators/playground/Makefile.am b/xlators/playground/Makefile.am
new file mode 100644
index 00000000000..e7de6b31aff
--- /dev/null
+++ b/xlators/playground/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = template
+CLEANFILES =
diff --git a/xlators/playground/rot-13/Makefile.am b/xlators/playground/rot-13/Makefile.am
new file mode 100644
index 00000000000..d471a3f9243
--- /dev/null
+++ b/xlators/playground/rot-13/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = src
+
+CLEANFILES =
diff --git a/xlators/playground/rot-13/src/Makefile.am b/xlators/playground/rot-13/src/Makefile.am
new file mode 100644
index 00000000000..9978661509d
--- /dev/null
+++ b/xlators/playground/rot-13/src/Makefile.am
@@ -0,0 +1,16 @@
+xlator_LTLIBRARIES = rot-13.la
+xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/encryption
+
+rot_13_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
+
+rot_13_la_SOURCES = rot-13.c
+rot_13_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
+
+noinst_HEADERS = rot-13.h
+
+AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \
+ -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src
+
+AM_CFLAGS = -Wall $(GF_CFLAGS)
+
+CLEANFILES =
diff --git a/xlators/playground/rot-13/src/rot-13.c b/xlators/playground/rot-13/src/rot-13.c
new file mode 100644
index 00000000000..0f45ee31964
--- /dev/null
+++ b/xlators/playground/rot-13/src/rot-13.c
@@ -0,0 +1,166 @@
+/*
+ Copyright (c) 2006-2012 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
+ 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.
+*/
+#include <ctype.h>
+#include <sys/uio.h>
+
+#include <glusterfs/glusterfs.h>
+#include <glusterfs/xlator.h>
+#include <glusterfs/logging.h>
+
+#include "rot-13.h"
+
+/*
+ * This is a rot13 ``encryption'' xlator. It rot13's data when
+ * writing to disk and rot13's it back when reading it.
+ * This xlator is meant as an example, NOT FOR PRODUCTION
+ * USE ;) (hence no error-checking)
+ */
+
+void
+rot13(char *buf, int len)
+{
+ int i;
+ for (i = 0; i < len; i++) {
+ if (buf[i] >= 'a' && buf[i] <= 'z')
+ buf[i] = 'a' + ((buf[i] - 'a' + 13) % 26);
+ else if (buf[i] >= 'A' && buf[i] <= 'Z')
+ buf[i] = 'A' + ((buf[i] - 'A' + 13) % 26);
+ }
+}
+
+void
+rot13_iovec(struct iovec *vector, int count)
+{
+ int i;
+ for (i = 0; i < count; i++) {
+ rot13(vector[i].iov_base, vector[i].iov_len);
+ }
+}
+
+int32_t
+rot13_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iovec *vector,
+ int32_t count, struct iatt *stbuf, struct iobref *iobref,
+ dict_t *xdata)
+{
+ rot_13_private_t *priv = (rot_13_private_t *)this->private;
+
+ if (priv->decrypt_read)
+ rot13_iovec(vector, count);
+
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, vector, count, stbuf,
+ iobref, xdata);
+ return 0;
+}
+
+int32_t
+rot13_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
+{
+ STACK_WIND(frame, rot13_readv_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readv, fd, size, offset, flags, xdata);
+ return 0;
+}
+
+int32_t
+rot13_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
+{
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
+}
+
+int32_t
+rot13_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t offset, uint32_t flags,
+ struct iobref *iobref, dict_t *xdata)
+{
+ rot_13_private_t *priv = (rot_13_private_t *)this->private;
+ if (priv->encrypt_write)
+ rot13_iovec(vector, count);
+
+ STACK_WIND(frame, rot13_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,
+ flags, iobref, xdata);
+ return 0;
+}
+
+int32_t
+init(xlator_t *this)
+{
+ data_t *data = NULL;
+ rot_13_private_t *priv = NULL;
+
+ if (!this->children || this->children->next) {
+ gf_log("rot13", GF_LOG_ERROR,
+ "FATAL: rot13 should have exactly one child");
+ return -1;
+ }
+
+ if (!this->parents) {
+ gf_log(this->name, GF_LOG_WARNING, "dangling volume. check volfile ");
+ }
+
+ priv = GF_CALLOC(sizeof(rot_13_private_t), 1, 0);
+ if (!priv)
+ return -1;
+
+ priv->decrypt_read = 1;
+ priv->encrypt_write = 1;
+
+ data = dict_get(this->options, "encrypt-write");
+ if (data) {
+ if (gf_string2boolean(data->data, &priv->encrypt_write) == -1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "encrypt-write takes only boolean options");
+ GF_FREE(priv);
+ return -1;
+ }
+ }
+
+ data = dict_get(this->options, "decrypt-read");
+ if (data) {
+ if (gf_string2boolean(data->data, &priv->decrypt_read) == -1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "decrypt-read takes only boolean options");
+ GF_FREE(priv);
+ return -1;
+ }
+ }
+
+ this->private = priv;
+ gf_log("rot13", GF_LOG_DEBUG, "rot13 xlator loaded");
+ return 0;
+}
+
+void
+fini(xlator_t *this)
+{
+ rot_13_private_t *priv = this->private;
+
+ if (!priv)
+ return;
+ this->private = NULL;
+ GF_FREE(priv);
+
+ return;
+}
+
+struct xlator_fops fops = {.readv = rot13_readv, .writev = rot13_writev};
+
+struct xlator_cbks cbks;
+
+struct volume_options options[] = {
+ {.key = {"encrypt-write"}, .type = GF_OPTION_TYPE_BOOL},
+ {.key = {"decrypt-read"}, .type = GF_OPTION_TYPE_BOOL},
+ {.key = {NULL}},
+};
diff --git a/xlators/playground/rot-13/src/rot-13.h b/xlators/playground/rot-13/src/rot-13.h
new file mode 100644
index 00000000000..edbc99798b4
--- /dev/null
+++ b/xlators/playground/rot-13/src/rot-13.h
@@ -0,0 +1,18 @@
+/*
+ Copyright (c) 2006-2012 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
+ 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 __ROT_13_H__
+#define __ROT_13_H__
+
+typedef struct {
+ gf_boolean_t encrypt_write;
+ gf_boolean_t decrypt_read;
+} rot_13_private_t;
+
+#endif /* __ROT_13_H__ */
diff --git a/xlators/playground/template/Makefile.am b/xlators/playground/template/Makefile.am
new file mode 100644
index 00000000000..f2689244371
--- /dev/null
+++ b/xlators/playground/template/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = src
+
diff --git a/xlators/playground/template/src/Makefile.am b/xlators/playground/template/src/Makefile.am
new file mode 100644
index 00000000000..e76a717a550
--- /dev/null
+++ b/xlators/playground/template/src/Makefile.am
@@ -0,0 +1,17 @@
+xlator_LTLIBRARIES = template.la
+xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/playground
+
+template_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS)
+
+template_la_SOURCES = template.c
+template_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
+
+noinst_HEADERS = template.h
+
+AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \
+ -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src
+
+AM_CFLAGS = -Wall $(GF_CFLAGS)
+
+CLEANFILES =
+
diff --git a/xlators/playground/template/src/template.c b/xlators/playground/template/src/template.c
new file mode 100644
index 00000000000..2f25d2363a6
--- /dev/null
+++ b/xlators/playground/template/src/template.c
@@ -0,0 +1,186 @@
+/*
+ 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
+ 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.
+*/
+#include "template.h"
+#include <glusterfs/statedump.h>
+
+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", "%" PRId32, 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_msg(this->name, GF_LOG_ERROR, EINVAL, TEMPLATE_MSG_NO_GRAPH,
+ "not configured with exactly one child. exiting");
+ goto out;
+ }
+
+ if (!this->parents) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, TEMPLATE_MSG_NO_GRAPH,
+ "dangling volume. check volfile ");
+ goto out;
+ }
+
+ 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;
+ priv = NULL;
+ ret = 0;
+
+out:
+ if (priv)
+ GF_FREE(priv);
+
+ return ret;
+}
+
+static int
+template_reconfigure(xlator_t *this, dict_t *options)
+{
+ 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;
+}
+
+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_dumpops template_dumpops = {
+ .priv = template_priv,
+ .priv_to_dict = template_priv_to_dict,
+};
+
+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_5_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_5_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
new file mode 100644
index 00000000000..c53dc1c7010
--- /dev/null
+++ b/xlators/playground/template/src/template.h
@@ -0,0 +1,43 @@
+/*
+ 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
+ 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 __TEMPLATE_H__
+#define __TEMPLATE_H__
+
+#include <glusterfs/glusterfs.h>
+#include <glusterfs/logging.h>
+#include <glusterfs/dict.h>
+#include <glusterfs/xlator.h>
+#include <glusterfs/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 <glusterfs/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 <glusterfs/glfs-message-id.h>
+
+GLFS_MSGID(TEMPLATE, TEMPLATE_MSG_NO_MEMORY, TEMPLATE_MSG_NO_GRAPH);
+
+#endif /* __TEMPLATE_H__ */