diff options
| -rw-r--r-- | cli/src/cli-cmd-parser.c | 7 | ||||
| -rw-r--r-- | cli/src/cli-rpc-ops.c | 19 | ||||
| -rw-r--r-- | configure.ac | 10 | ||||
| -rw-r--r-- | libglusterfs/src/xlator.c | 107 | ||||
| -rw-r--r-- | libglusterfs/src/xlator.h | 6 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/Makefile.am | 4 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 98 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 16 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 332 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.h | 2 | 
10 files changed, 541 insertions, 60 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 8cfdc808a14..1d5bf40d8f5 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -370,7 +370,7 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options)          if (!dict)                  goto out; -        if (wordcount < 4) +        if (wordcount < 3)                  goto out;          volname = (char *)words[2]; @@ -382,6 +382,11 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options)          if (ret)                  goto out; +        if (!strcmp (volname, "help") && !words[3] && !words[4]) +                ret = dict_set_str (dict, "help", volname); + +        if (!strcmp (volname, "help-xml") && !words[3] && !words[4]) +                ret = dict_set_str (dict, "help-xml", volname);          for (i = 3; i < wordcount; i+=2) { diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 1082a908fb0..ce154f58d6c 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -956,6 +956,8 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,  {          gf1_cli_set_vol_rsp  rsp   = {0,};          int                  ret   = 0; +        dict_t               *dict = NULL; +        char                 *help_str = NULL;          if (-1 == req->rpc_status) {                  goto out; @@ -971,9 +973,24 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,          if (rsp.op_ret &&  strcmp (rsp.op_errstr, ""))                  cli_out ("%s", rsp.op_errstr); -        else + +        dict = dict_new (); + +        if (!dict) { +                ret = -1; +                goto out; +        } + +        ret = dict_unserialize (rsp.dict.dict_val, rsp.dict.dict_len, &dict); + +        if (ret) +                goto out; + +        if (dict_get_str (dict, "help-str", &help_str))                  cli_out ("Set volume %s", (rsp.op_ret) ? "unsuccessful":                                                           "successful"); +        else +                cli_out ("%s", help_str);          ret = rsp.op_ret; diff --git a/configure.ac b/configure.ac index fcf03782e9c..3d326315d4d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,5 @@  dnl Copyright (c) 2006-2010 Gluster, Inc. <http://www.gluster.com> +  dnl This file is part of GlusterFS.  dnl  dnl GlusterFS is free software; you can redistribute it and/or modify @@ -318,6 +319,15 @@ AC_SUBST(SYNCDAEMON_COMPILE)  AC_SUBST(SYNCDAEMON_SUBDIR)  # end SYNCDAEMON section +#check if libxml is present if so enable HAVE_LIB_XML +echo -n "checking if libxml2 is present... " + +PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.19], +                  [echo "yes (features requiring libxml2 enabled)"  AC_DEFINE(HAVE_LIB_XML, 1, [define if libxml2 is present])], +                  [echo "no"] ) + +AC_SUBST(LIBXML2_CFLAGS) +AC_SUBST(LIBXML2_LIBS)  dnl FreeBSD > 5 has execinfo as a Ported library for giving a workaround  dnl solution to GCC backtrace functionality diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index d38754ecdd4..3674bddd97e 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -569,6 +569,65 @@ xlator_set_type_virtual (xlator_t *xl, const char *type)                  return -1;  } +int32_t +xlator_volopt_dynload (char *xlator_type, void **dl_handle, +                    volume_opt_list_t *opt_list) +{ +        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"); +                goto out; +        } + +        ret = -1; + +        gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name); + +        handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); +        if (!handle) { +                gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ()); +                goto out; +        } +        *dl_handle = handle; + +        INIT_LIST_HEAD (&opt_list->list); + +        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"))) { +                dlerror (); +                gf_log ("xlator", GF_LOG_DEBUG, +                         "Strict option validation not enforced -- neglecting"); +        } +        list_add_tail (&vol_opt->list, &opt_list->list); + +        ret = 0; + out: +        gf_log ("xlator", GF_LOG_DEBUG, "Returning %d", ret); +        return ret; + +} +  int32_t  xlator_dynload (xlator_t *xl) @@ -1226,3 +1285,51 @@ glusterd_check_log_level (const char *value)          return log_level;  } + +int +xlator_get_volopt_info (struct list_head *opt_list, char *key, char **def_val, +                         char **descr) +{ + +        int                     index = 0; +        int                     ret = -1; +        volume_opt_list_t       *vol_list = NULL; +        volume_option_t         *opt = NULL; + +        if (!opt_list || !key || !def_val ) { +                gf_log ("", GF_LOG_WARNING, " Parameters to the function not " +                         "valid"); +                ret = -1; +                goto out; +        } + +        if (list_empty (opt_list)) { +                gf_log ("xlator", GF_LOG_WARNING, "No elements in Volume option" +                         " list"); +                ret = -1; +                goto out; +        } + + +        vol_list = list_entry (opt_list->next, volume_opt_list_t, list); + +        opt = vol_list->given_opt; + +        for (index = 0; opt[index].key && opt[index].key[0] ; index++) { +                if (strncmp (key, opt[index].key[0], strlen (key))) +                        continue; + +                *def_val = opt[index].default_value; +                if (descr) +                        *descr = opt[index].description; +                ret = 0; +                goto out; +        } + +        ret = -1; + +out: +        gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); +        return ret; + +} diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 0a2dcbafd76..2af1012ab2d 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -787,6 +787,7 @@ typedef struct volume_options {          char                *value[ZR_OPTION_MAX_ARRAY_SIZE];                                     /* If specified, will check for one of  				      the value from this array */ +        char                *default_value;  	char                *description; /* about the key */  } volume_option_t; @@ -876,6 +877,11 @@ int is_gf_log_command (xlator_t *trans, const char *name, char *value);  int xlator_validate_rec (xlator_t *xlator, char **op_errstr);  int graph_reconf_validateopt (glusterfs_graph_t *graph, char **op_errstr);  int glusterd_check_log_level (const char *value); +int32_t xlator_volopt_dynload (char *xlator_type, void **dl_handle, +                    volume_opt_list_t *vol_opt_handle); +int xlator_get_volopt_info (struct list_head *opt_list, char *key, +                            char **def_val, char **descr); +  #define GF_STAT_PRINT_FMT_STR "%"PRIx64",%"PRIx64",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx64",%"PRIx64",%"PRIx32",%"PRIx64",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32"\n" diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am index 84209b6f8cf..76aa4550fe6 100644 --- a/xlators/mgmt/glusterd/src/Makefile.am +++ b/xlators/mgmt/glusterd/src/Makefile.am @@ -1,6 +1,6 @@  xlator_LTLIBRARIES = glusterd.la  xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/mgmt -glusterd_la_LDFLAGS = -module -avoidversion +glusterd_la_LDFLAGS = -module -avoidversion $(LIBXML2_LIBS)  glusterd_la_SOURCES = glusterd.c glusterd-handler.c glusterd-sm.c glusterd-op-sm.c \  	glusterd-utils.c glusterd-rpc-ops.c glusterd-store.c glusterd-handshake.c \  	glusterd-pmap.c glusterd-volgen.c glusterd-rebalance.c @@ -16,7 +16,7 @@ AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\  	-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)\  	-I$(rpclibdir) -L$(xlatordir)/ -I$(CONTRIBDIR)/rbtree -I$(top_srcdir)/rpc/xdr/src\  	-I$(top_srcdir)/rpc/rpc-lib/src -I$(CONTRIBDIR)/uuid -DGFS_PREFIX=\"$(prefix)\" \ -	-DDATADIR=\"$(localstatedir)\" -DGSYNCD_PREFIX=\"$(libexecdir)\" +	-DDATADIR=\"$(localstatedir)\" -DGSYNCD_PREFIX=\"$(libexecdir)\" $(LIBXML2_CFLAGS)  CLEANFILES = diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 771c95bef4a..6ef1723bd72 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -1113,6 +1113,39 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)          if (!val_dict)                  goto out; +        ret = dict_get_int32 (dict, "count", &dict_count); + +        if (ret) { +                gf_log ("", GF_LOG_ERROR, "Count(dict),not set in Volume-Set"); +                goto out; +        } + +        if ( dict_count == 0 ) { +                /*No options would be specified of volume set help */ +                if (dict_get (dict, "help" ))  { +                        ret = 0; +                        goto out; +                } + +                if (dict_get (dict, "help-xml" )) { + +#if (HAVE_LIB_XML) +                        ret = 0; +                        goto out; +#else +                        ret  = -1; +                        gf_log ("", GF_LOG_ERROR, "libxml not present in the" +                                   "system"); +                        *op_errstr = gf_strdup ("Error: xml libraries not " +                                                "present to produce xml-output"); +                        goto out; +#endif +                } +                gf_log ("", GF_LOG_ERROR, "No options received "); +                *op_errstr = gf_strdup ("Options not specified"); +                ret = -1; +                goto out; +        }          ret = dict_get_str (dict, "volname", &volname);          if (ret) { @@ -1121,7 +1154,6 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)          }          exists = glusterd_check_volume_exists (volname); -          if (!exists) {                  snprintf (errstr, sizeof (errstr), "Volume %s does not exist",                            volname); @@ -1137,27 +1169,6 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)                  goto out;          } -        ret = dict_get_int32 (dict, "count", &dict_count); - -        if (ret) { -                gf_log ("", GF_LOG_ERROR, "Count(dict),not set in Volume-Set"); -                goto out; -        } - -        if ( dict_count == 1 ) { -                if (dict_get (dict, "history" )) { -                        ret = 0; -                        goto out; -                } - -                gf_log ("", GF_LOG_ERROR, "No options received "); -                *op_errstr = gf_strdup ("Options not specified"); -                ret = -1; -                goto out; -        } - - -  	for ( count = 1; ret != 1 ; count++ ) {                  global_opt = _gf_false;  		sprintf (str, "key%d", count); @@ -3874,6 +3885,25 @@ glusterd_restart_brick_servers (glusterd_volinfo_t *volinfo)  }  static int +glusterd_volset_help (dict_t *dict) +{ +        int                     ret = -1; +        gf_boolean_t            xml_out = _gf_false; + +        if (dict_get (dict, "help" )) +                xml_out = _gf_false; +        else if (dict_get (dict, "help-xml" )) +                xml_out = _gf_true; +        else +                goto out; + +        ret = glusterd_get_volopt_content (xml_out); + out: +        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); +        return ret; +} + +static int  glusterd_op_set_volume (dict_t *dict)  {          int                                      ret = 0; @@ -3888,7 +3918,8 @@ glusterd_op_set_volume (dict_t *dict)  	char					*value = NULL;  	char					 str[50] = {0, };          gf_boolean_t                             global_opt    = _gf_false; -        glusterd_volinfo_t                       *voliter = NULL; +        glusterd_volinfo_t                      *voliter = NULL; +        int32_t                                  dict_count = 0;          this = THIS;          GF_ASSERT (this); @@ -3896,8 +3927,21 @@ glusterd_op_set_volume (dict_t *dict)          priv = this->private;          GF_ASSERT (priv); -        ret = dict_get_str (dict, "volname", &volname); +        ret = dict_get_int32 (dict, "count", &dict_count); +        if (ret) { +                gf_log ("", GF_LOG_ERROR, "Count(dict),not set in Volume-Set"); +                goto out; +        } +        if ( dict_count == 0 ) { +                ret = glusterd_volset_help (dict); +                if (ret) +                        gf_log ("glusterd", GF_LOG_ERROR, "Volume set help" +                                                        "internal error"); +                goto out; +        } + +        ret = dict_get_str (dict, "volname", &volname);          if (ret) {                  gf_log ("", GF_LOG_ERROR, "Unable to get volume name");                  goto out; @@ -3983,7 +4027,6 @@ glusterd_op_set_volume (dict_t *dict)                  }          } -          if ( count == 1 ) {                  gf_log ("", GF_LOG_ERROR, "No options received ");                  ret = -1; @@ -4061,11 +4104,8 @@ glusterd_op_set_volume (dict_t *dict)                  }          } - -          ret = 0; - -out: + out:          if (key_fixed)                  GF_FREE (key_fixed);          gf_log ("", GF_LOG_DEBUG, "returning %d", ret); diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index e7134c990b7..7be5fdb0510 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -53,6 +53,7 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,          gd_serialize_t  sfunc = NULL;          void            *cli_rsp = NULL;          dict_t          *ctx = NULL; +        char            *free_ptr = NULL;          switch (op) {          case GD_OP_CREATE_VOLUME: @@ -181,10 +182,20 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,                  rsp.op_ret = op_ret;                  rsp.op_errno = op_errno;                  rsp.volname = ""; +                ctx = op_ctx; +                  if (op_errstr)                          rsp.op_errstr = op_errstr;                  else                          rsp.op_errstr = ""; +                if (ctx) { +                        ret = dict_allocate_and_serialize (ctx, +                                                           &rsp.dict.dict_val, +                                                           (size_t*)&rsp.dict.dict_len); +                        if (ret == 0) +                                free_ptr = rsp.dict.dict_val; +                } +                  cli_rsp = &rsp;                  sfunc = gf_xdr_serialize_cli_set_vol_rsp;                  break; @@ -316,10 +327,9 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,          ret = glusterd_submit_reply (req, cli_rsp, NULL, 0, NULL,                                       sfunc); -        if (ret) -                goto out; +        if (free_ptr) +                GF_FREE (free_ptr); -out:          gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);          return ret;  } diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 23bd8929d88..d76cf2864c9 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" @@ -35,7 +40,7 @@  #include "glusterd-mem-types.h"  #include "cli1.h"  #include "glusterd-volgen.h" - +#include "glusterd-op-sm.h"  /* dispatch table for VOLUME SET   * ----------------------------- @@ -107,8 +112,9 @@ static struct volopt_map_entry glusterd_volopt_map[] = {          {"diagnostics.latency-measurement",      "debug/io-stats",     NULL, NULL, NO_DOC         },          {"diagnostics.dump-fd-stats",            "debug/io-stats",     NULL, NULL, NO_DOC        }, -        {"diagnostics.brick-log-level",          "debug/io-stats",            "!log-level", NULL, DOC}, -        {"diagnostics.client-log-level",         "debug/io-stats",            "!log-level", NULL, DOC}, +        {"diagnostics.brick-log-level",          "debug/io-stats",     "!brick-log-level", NULL, DOC}, +        {"diagnostics.client-log-level",         "debug/io-stats",     "!client-log-level", NULL, DOC}, +          {"performance.cache-max-file-size",      "performance/io-cache",      "max-file-size", NULL, DOC},          {"performance.cache-min-file-size",      "performance/io-cache",      "min-file-size", NULL, DOC}, @@ -148,20 +154,21 @@ static struct volopt_map_entry glusterd_volopt_map[] = {          {"nfs.export-dirs",                      "nfs/server",                "nfs3.export-dirs", NULL, GLOBAL_DOC},          {"nfs.export-volumes",                   "nfs/server",                "nfs3.export-volumes", NULL, GLOBAL_DOC},          {"nfs.addr-namelookup",                  "nfs/server",                "rpc-auth.addr.namelookup", NULL, GLOBAL_DOC}, -        {"nfs.dynamic-volumes",                  "nfs/server",                "nfs.dynamic-volumes", NULL, GLOBAL_DOC}, +        {"nfs.dynamic-volumes",                  "nfs/server",                "nfs.dynamic-volumes", NULL, GLOBAL_NO_DOC},          {"nfs.register-with-portmap",            "nfs/server",                "rpc.register-with-portmap", NULL, GLOBAL_DOC},          {"nfs.port",                             "nfs/server",                "nfs.port", NULL, GLOBAL_DOC}, -        {"nfs.rpc-auth-unix",                    "nfs/server",                "!nfs.rpc-auth-auth-unix", NULL, DOC}, -        {"nfs.rpc-auth-null",                    "nfs/server",                "!nfs.rpc-auth-auth-null", NULL, DOC}, -        {"nfs.rpc-auth-allow",                   "nfs/server",                "!nfs.rpc-auth.addr.allow", NULL, DOC}, -        {"nfs.rpc-auth-reject",                  "nfs/server",                "!nfs.rpc-auth.addr.reject", NULL, DOC}, -        {"nfs.ports-insecure",                   "nfs/server",                "!nfs.auth.ports.insecure", NULL, DOC}, +        {"nfs.rpc-auth-unix",                    "nfs/server",                "!rpc-auth.auth-unix.*", NULL, DOC}, +        {"nfs.rpc-auth-null",                    "nfs/server",                "!rpc-auth.auth.null.*", NULL, DOC}, +        {"nfs.rpc-auth-allow",                   "nfs/server",                "!rpc-auth.addr.*.allow", NULL, DOC}, +        {"nfs.rpc-auth-reject",                  "nfs/server",                "!rpc-auth.addr.*.reject", NULL, DOC}, +        {"nfs.ports-insecure",                   "nfs/server",                "!rpc-auth.ports.*.insecure", NULL, DOC}, + +        {"nfs.trusted-sync",                     "nfs/server",                "!nfs3.*.trusted-sync", NULL, DOC}, +        {"nfs.trusted-write",                    "nfs/server",                "!nfs3.*.trusted-write", NULL, DOC}, +        {"nfs.volume-access",                    "nfs/server",                "!nfs3.*.volume-access", NULL, DOC}, +        {"nfs.export-dir",                       "nfs/server",                "!nfs3.*.export-dir", NULL, DOC}, -        {"nfs.trusted-sync",                     "nfs/server",                "!nfs-trusted-sync", NULL, DOC}, -        {"nfs.trusted-write",                    "nfs/server",                "!nfs-trusted-write", NULL, DOC}, -        {"nfs.volume-access",                    "nfs/server",                "!nfs-volume-access", NULL, DOC}, -        {"nfs.export-dir",                       "nfs/server",                "!nfs-export-dir", NULL, DOC},          {"nfs.disable",                          "nfs/server",                "!nfs-disable", NULL, DOC},          {"nfs.transport-type",                   "nfs/server",                "!nfs.transport-type", NULL, DOC}, @@ -1088,8 +1095,9 @@ loglevel_option_handler (glusterfs_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)); @@ -1303,6 +1311,282 @@ perfxl_option_handler (glusterfs_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 = 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 (8192); +        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 *)"volumeOptionsDefaults"); +        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 *) "volumeOption"); +        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; +        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; + +        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); +#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: +        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); +        return ret; + +} +  static int  client_graph_builder (glusterfs_graph_t *graph, glusterd_volinfo_t *volinfo,                        dict_t *set_dict, void *param) @@ -1481,7 +1765,7 @@ nfs_option_handler (glusterfs_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); @@ -1494,7 +1778,7 @@ nfs_option_handler (glusterfs_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); @@ -1507,7 +1791,7 @@ nfs_option_handler (glusterfs_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); @@ -1519,7 +1803,7 @@ nfs_option_handler (glusterfs_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); @@ -1532,7 +1816,7 @@ nfs_option_handler (glusterfs_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); @@ -1545,7 +1829,7 @@ nfs_option_handler (glusterfs_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); @@ -1558,7 +1842,7 @@ nfs_option_handler (glusterfs_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); @@ -1571,7 +1855,7 @@ nfs_option_handler (glusterfs_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); @@ -1586,7 +1870,7 @@ nfs_option_handler (glusterfs_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); diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h index e34937cefe1..8d981332c31 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.h +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h @@ -49,4 +49,6 @@ int glusterd_validate_localopts (dict_t *val_dict, char **op_errstr);  gf_boolean_t glusterd_check_globaloption (char *key);  int generate_brick_volfiles (glusterd_volinfo_t *volinfo); + +int glusterd_get_volopt_content (gf_boolean_t xml_out);  #endif  | 
