summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-volgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c362
1 files changed, 335 insertions, 27 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 3eceb5f44ea..2551d5f222e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -25,6 +25,11 @@
#include <fnmatch.h>
+#if (HAVE_LIB_XML)
+#include <libxml/encoding.h>
+#include <libxml/xmlwriter.h>
+#endif
+
#include "xlator.h"
#include "glusterd.h"
#include "defaults.h"
@@ -121,8 +126,8 @@ static struct volopt_map_entry glusterd_volopt_map[] = {
{VKEY_DIAG_LAT_MEASUREMENT, "debug/io-stats", "latency-measurement", "off", NO_DOC, 0 },
{"diagnostics.dump-fd-stats", "debug/io-stats", NULL, NULL, NO_DOC, 0 },
{VKEY_DIAG_CNT_FOP_HITS, "debug/io-stats", "count-fop-hits", "off", NO_DOC, 0 },
- {"diagnostics.brick-log-level", "debug/io-stats", "!log-level", NULL, DOC, 0},
- {"diagnostics.client-log-level", "debug/io-stats", "!log-level", NULL, DOC, 0},
+ {"diagnostics.brick-log-level", "debug/io-stats", "!brick-log-level", NULL, DOC, 0},
+ {"diagnostics.client-log-level", "debug/io-stats", "!client-log-level", NULL, DOC, 0},
{"performance.cache-max-file-size", "performance/io-cache", "max-file-size", NULL, DOC, 0},
{"performance.cache-min-file-size", "performance/io-cache", "min-file-size", NULL, DOC, 0},
@@ -143,8 +148,8 @@ static struct volopt_map_entry glusterd_volopt_map[] = {
{"network.ping-timeout", "protocol/client", NULL, NULL, NO_DOC, 0 },
{"network.inode-lru-limit", "protocol/server", NULL, NULL, NO_DOC, 0 },
- {"auth.allow", "protocol/server", "!server-auth", "*", DOC, 0},
- {"auth.reject", "protocol/server", "!server-auth", NULL, DOC, 0},
+ {"auth.allow", "protocol/server", "!auth.addr.*.allow", "*", DOC},
+ {"auth.reject", "protocol/server", "!auth.addr.*.reject", NULL, DOC},
{"transport.keepalive", "protocol/server", "transport.socket.keepalive", NULL, NO_DOC, 0},
{"server.allow-insecure", "protocol/server", "rpc-auth-allow-insecure", NULL, NO_DOC, 0},
@@ -163,26 +168,26 @@ static struct volopt_map_entry glusterd_volopt_map[] = {
{"nfs.export-dirs", "nfs/server", "nfs3.export-dirs", NULL, GLOBAL_DOC, 0},
{"nfs.export-volumes", "nfs/server", "nfs3.export-volumes", NULL, GLOBAL_DOC, 0},
{"nfs.addr-namelookup", "nfs/server", "rpc-auth.addr.namelookup", NULL, GLOBAL_DOC, 0},
- {"nfs.dynamic-volumes", "nfs/server", "nfs.dynamic-volumes", NULL, GLOBAL_DOC, 0},
+ {"nfs.dynamic-volumes", "nfs/server", "nfs.dynamic-volumes", NULL, GLOBAL_NO_DOC, 0},
{"nfs.register-with-portmap", "nfs/server", "rpc.register-with-portmap", NULL, GLOBAL_DOC, 0},
{"nfs.port", "nfs/server", "nfs.port", NULL, GLOBAL_DOC, 0},
- {"nfs.rpc-auth-unix", "nfs/server", "!nfs.rpc-auth-auth-unix", NULL, DOC, 0},
- {"nfs.rpc-auth-null", "nfs/server", "!nfs.rpc-auth-auth-null", NULL, DOC, 0},
- {"nfs.rpc-auth-allow", "nfs/server", "!nfs.rpc-auth.addr.allow", NULL, DOC, 0},
- {"nfs.rpc-auth-reject", "nfs/server", "!nfs.rpc-auth.addr.reject", NULL, DOC, 0},
- {"nfs.ports-insecure", "nfs/server", "!nfs.auth.ports.insecure", NULL, DOC, 0},
+ {"nfs.rpc-auth-unix", "nfs/server", "!rpc-auth.auth-unix.*", NULL, DOC, 0},
+ {"nfs.rpc-auth-null", "nfs/server", "!rpc-auth.auth-null.*", NULL, DOC},
+ {"nfs.rpc-auth-allow", "nfs/server", "!rpc-auth.addr.*.allow", NULL, DOC, 0},
+ {"nfs.rpc-auth-reject", "nfs/server", "!rpc-auth.addr.*.reject", NULL, DOC, 0},
+ {"nfs.ports-insecure", "nfs/server", "!rpc-auth.ports.*.insecure", NULL, DOC, 0},
{"nfs.transport-type", "nfs/server", "!nfs.transport-type", NULL, DOC, 0},
- {"nfs.trusted-sync", "nfs/server", "!nfs-trusted-sync", NULL, DOC, 0},
- {"nfs.trusted-write", "nfs/server", "!nfs-trusted-write", NULL, DOC, 0},
- {"nfs.volume-access", "nfs/server", "!nfs-volume-access", NULL, DOC, 0},
- {"nfs.export-dir", "nfs/server", "!nfs-export-dir", NULL, DOC, 0},
+ {"nfs.trusted-sync", "nfs/server", "!nfs3.*.trusted-sync", NULL, DOC, 0},
+ {"nfs.trusted-write", "nfs/server", "!nfs3.*.trusted-write", NULL, DOC, 0},
+ {"nfs.volume-access", "nfs/server", "!nfs3.*.volume-access", NULL, DOC, 0},
+ {"nfs.export-dir", "nfs/server", "!nfs3.*.export-dir", NULL, DOC, 0},
{"nfs.disable", "nfs/server", "!nfs-disable", NULL, DOC, 0},
{VKEY_FEATURES_QUOTA, "features/marker", "quota", "off", NO_DOC, OPT_FLAG_FORCE},
{VKEY_FEATURES_LIMIT_USAGE, "features/quota", "limit-set", NULL, NO_DOC, 0},
- {"features.quota-timeout", "features/quota", "timeout", "0", NO_DOC, 0},
+ {"features.quota-timeout", "features/quota", "timeout", "0", DOC, 0},
{NULL, }
};
@@ -1214,7 +1219,8 @@ server_auth_option_handler (volgen_graph_t *graph,
int ret = 0;
char *key = NULL;
- if (strcmp (vme->option, "!server-auth") != 0)
+ if ( (strcmp (vme->option, "!auth.addr.*.allow") != 0) &&
+ (strcmp (vme->option, "!auth.addr.*.reject") != 0))
return 0;
xl = first_of (graph);
@@ -1243,8 +1249,9 @@ loglevel_option_handler (volgen_graph_t *graph,
char *role = param;
struct volopt_map_entry vme2 = {0,};
- if (strcmp (vme->option, "!log-level") != 0 ||
- !strstr (vme->key, role))
+ if ( (strcmp (vme->option, "!client-log-level") != 0 &&
+ strcmp (vme->option, "!brick-log-level") != 0)
+ || !strstr (vme->key, role))
return 0;
memcpy (&vme2, vme, sizeof (vme2));
@@ -1462,6 +1469,307 @@ perfxl_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme,
return -1;
}
+#if (HAVE_LIB_XML)
+static int
+end_sethelp_xml_doc (xmlTextWriterPtr writer)
+{
+ int ret = -1;
+
+ ret = xmlTextWriterEndElement(writer);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not end an "
+ "xmlElemetnt");
+ ret = -1;
+ goto out;
+ }
+ ret = xmlTextWriterEndDocument (writer);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not end an "
+ "xmlDocument");
+ ret = -1;
+ goto out;
+ }
+
+ ret = xmlTextWriterFlush (writer);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not flush an "
+ "xmlDocument");
+ ret = -1;
+ goto out;
+ }
+
+
+ ret = 0;
+ out:
+ gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+
+}
+
+static int
+init_sethelp_xml_doc (xmlTextWriterPtr *writer, xmlBufferPtr *buf)
+{
+ int ret;
+
+ *buf = xmlBufferCreateSize (16 * GF_UNIT_KB);
+ if (buf == NULL) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Error creating the xml "
+ "buffer");
+ ret = -1;
+ goto out;
+ }
+
+ xmlBufferSetAllocationScheme (*buf,XML_BUFFER_ALLOC_DOUBLEIT);
+
+ *writer = xmlNewTextWriterMemory(*buf, 0);
+ if (writer == NULL) {
+ gf_log ("glusterd", GF_LOG_ERROR, " Error creating the xml "
+ "writer");
+ ret = -1;
+ goto out;
+ }
+
+ ret = xmlTextWriterStartDocument(*writer, "1.0", "UTF-8", "yes");
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Error While starting the "
+ "xmlDoc");
+ goto out;
+ }
+
+ ret = xmlTextWriterStartElement(*writer,
+ (xmlChar *)"options");
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not create an "
+ "xmlElemetnt");
+ ret = -1;
+ goto out;
+ }
+
+
+ ret = 0;
+
+ out:
+ gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+
+}
+
+static int
+xml_add_volset_element (xmlTextWriterPtr writer, const char *name,
+ const char *def_val, const char *dscrpt)
+{
+
+ int ret = -1;
+
+ GF_ASSERT (name);
+
+ ret = xmlTextWriterStartElement(writer, (xmlChar *) "option");
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not create an "
+ "xmlElemetnt");
+ ret = -1;
+ goto out;
+ }
+
+ ret = xmlTextWriterWriteFormatElement(writer, (xmlChar*)"defaultValue",
+ "%s", def_val);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not create an "
+ "xmlElemetnt");
+ ret = -1;
+ goto out;
+ }
+
+ ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"description",
+ "%s", dscrpt );
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not create an "
+ "xmlElemetnt");
+ ret = -1;
+ goto out;
+ }
+
+ ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *) "name", "%s",
+ name);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not create an "
+ "xmlElemetnt");
+ ret = -1;
+ goto out;
+ }
+
+ ret = xmlTextWriterEndElement(writer);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Could not end an "
+ "xmlElemetnt");
+ ret = -1;
+ goto out;
+ }
+
+ ret = 0;
+ out:
+ gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+
+}
+
+#endif
+
+static int
+get_key_from_volopt ( struct volopt_map_entry *vme, char **key)
+{
+ int ret = 0;
+
+ GF_ASSERT (vme);
+ GF_ASSERT (key);
+
+
+ if (vme->option) {
+ if (vme->option[0] == '!') {
+ *key = vme->option + 1;
+ if (!*key[0])
+ ret = -1;
+ } else {
+ *key = vme->option;
+ }
+ } else {
+ *key = strchr (vme->key, '.');
+ if (*key) {
+ (*key) ++;
+ if (!*key[0])
+ ret = -1;
+ } else {
+ ret = -1;
+ }
+ }
+
+ if (ret)
+ gf_log ("glusterd", GF_LOG_ERROR, "Wrong entry found in "
+ "glusterd_volopt_map entry %s", vme->key);
+ else
+ gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+
+int
+glusterd_get_volopt_content (gf_boolean_t xml_out)
+{
+
+ char *xlator_type = NULL;
+ void *dl_handle = NULL;
+ volume_opt_list_t vol_opt_handle;
+ volume_opt_list_t *vol_opt = NULL;
+ volume_opt_list_t *tmp = NULL;
+ char *key = NULL;
+ struct volopt_map_entry *vme = NULL;
+ int ret = -1;
+ char *def_val = NULL;
+ char *descr = NULL;
+ char output_string[8192] = {0, };
+ char *output = NULL;
+ char tmp_str[1024] = {0, };
+ dict_t *ctx = NULL;
+#if (HAVE_LIB_XML)
+ xmlTextWriterPtr writer = NULL;
+ xmlBufferPtr buf = NULL;
+#endif
+
+ INIT_LIST_HEAD (&vol_opt_handle.list);
+
+#if (HAVE_LIB_XML)
+ if (xml_out) {
+ ret = init_sethelp_xml_doc (&writer, &buf);
+ if (ret) /*logging done in init_xml_lib*/
+ goto out;
+ }
+#endif
+
+ ctx = glusterd_op_get_ctx (GD_OP_SET_VOLUME);
+
+ if (!ctx) {
+ /*extract the vol-set-help output only in host glusterd*/
+ ret = 0;
+ goto out;
+ }
+
+
+ for (vme = &glusterd_volopt_map[0]; vme->key; vme++) {
+
+ if ( ( vme->type == NO_DOC) || (vme->type == GLOBAL_NO_DOC) )
+ continue;
+
+ if (get_key_from_volopt (vme, &key))
+ goto out; /*Some error while getin key*/
+
+ if (!xlator_type || strcmp (vme->voltype, xlator_type)){
+ ret = xlator_volopt_dynload (vme->voltype,
+ &dl_handle,
+ &vol_opt_handle);
+ if (ret)
+ continue;
+ }
+
+ ret = xlator_get_volopt_info (&vol_opt_handle.list, key,
+ &def_val, &descr);
+ if (ret) /*Swallow Error i.e if option not found*/
+ continue;
+
+ if (xml_out) {
+#if (HAVE_LIB_XML)
+ if (xml_add_volset_element (writer,vme->key,
+ def_val, descr))
+ goto out;
+#else
+ gf_log ("glusterd", GF_LOG_ERROR, "Libxml not present");
+#endif
+ } else {
+ snprintf (tmp_str, 1024, "Option: %s\nDefault "
+ "Value: %s\nDescription: %s\n\n",
+ vme->key, def_val, descr);
+ strcat (output_string, tmp_str);
+ }
+ }
+
+#if (HAVE_LIB_XML)
+ if ((xml_out) &&
+ (ret = end_sethelp_xml_doc (writer)))
+ goto out;
+#else
+ if (xml_out)
+ gf_log ("glusterd", GF_LOG_ERROR, "Libxml not present");
+#endif
+
+ if (!xml_out)
+ output = gf_strdup (output_string);
+ else
+#if (HAVE_LIB_XML)
+ output = gf_strdup ((char *)buf->content);
+ xmlFreeTextWriter (writer);
+ xmlBufferFree (buf);
+
+#else
+ gf_log ("glusterd", GF_LOG_ERROR, "Libxml not present");
+#endif
+
+ if (NULL == output) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_set_dynstr (ctx, "help-str", output);
+ out:
+ list_for_each_entry_safe (vol_opt, tmp, &vol_opt_handle.list, list) {
+ list_del_init (&vol_opt->list);
+ GF_FREE (vol_opt);
+ }
+
+ gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+
+}
+
static int
client_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
dict_t *set_dict, void *param)
@@ -1650,7 +1958,7 @@ nfs_option_handler (volgen_graph_t *graph,
if ( !volinfo || !volinfo->volname)
return 0;
- if (! strcmp (vme->option, "!nfs.rpc-auth-addr-allow")) {
+ if (! strcmp (vme->option, "!rpc-auth.addr.*.allow")) {
ret = gf_asprintf (&aa, "rpc-auth.addr.%s.allow",
volinfo->volname);
@@ -1663,7 +1971,7 @@ nfs_option_handler (volgen_graph_t *graph,
return -1;
}
- if (! strcmp (vme->option, "!nfs.rpc-auth-addr-reject")) {
+ if (! strcmp (vme->option, "!rpc-auth.addr.%s.reject")) {
ret = gf_asprintf (&aa, "rpc-auth.addr.%s.reject",
volinfo->volname);
@@ -1676,7 +1984,7 @@ nfs_option_handler (volgen_graph_t *graph,
return -1;
}
- if (! strcmp (vme->option, "!nfs.rpc-auth-auth-unix")) {
+ if (! strcmp (vme->option, "!rpc-auth.auth-unix.*")) {
ret = gf_asprintf (&aa, "rpc-auth.auth.unix.%s",
volinfo->volname);
@@ -1688,7 +1996,7 @@ nfs_option_handler (volgen_graph_t *graph,
if (ret)
return -1;
}
- if (! strcmp (vme->option, "!nfs.rpc-auth-auth-null")) {
+ if (! strcmp (vme->option, "!rpc-auth.auth.null.*")) {
ret = gf_asprintf (&aa, "rpc-auth.auth.null.%s",
volinfo->volname);
@@ -1701,7 +2009,7 @@ nfs_option_handler (volgen_graph_t *graph,
return -1;
}
- if (! strcmp (vme->option, "!nfs-trusted-sync")) {
+ if (! strcmp (vme->option, "!nfs3.%s.trusted-sync")) {
ret = gf_asprintf (&aa, "nfs3.%s.trusted-sync",
volinfo->volname);
@@ -1714,7 +2022,7 @@ nfs_option_handler (volgen_graph_t *graph,
return -1;
}
- if (! strcmp (vme->option, "!nfs-trusted-write")) {
+ if (! strcmp (vme->option, "!nfs3.*.trusted-write")) {
ret = gf_asprintf (&aa, "nfs3.%s.trusted-write",
volinfo->volname);
@@ -1727,7 +2035,7 @@ nfs_option_handler (volgen_graph_t *graph,
return -1;
}
- if (! strcmp (vme->option, "!nfs-volume-access")) {
+ if (! strcmp (vme->option, "!nfs3.*.volume-access")) {
ret = gf_asprintf (&aa, "nfs3.%s.volume-access",
volinfo->volname);
@@ -1740,7 +2048,7 @@ nfs_option_handler (volgen_graph_t *graph,
return -1;
}
- if (! strcmp (vme->option, "!nfs-export-dir")) {
+ if (! strcmp (vme->option, "!nfs3.*.export-dir")) {
ret = gf_asprintf (&aa, "nfs3.%s.export-dir",
volinfo->volname);
@@ -1755,7 +2063,7 @@ nfs_option_handler (volgen_graph_t *graph,
- if (! strcmp (vme->option, "!nfs.ports-insecure")) {
+ if (! strcmp (vme->option, "!rpc-auth.ports.*.insecure")) {
ret = gf_asprintf (&aa, "rpc-auth.ports.%s.insecure",
volinfo->volname);