summaryrefslogtreecommitdiffstats
path: root/xlators/nfs/server/src/exports.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/nfs/server/src/exports.c')
-rw-r--r--xlators/nfs/server/src/exports.c1609
1 files changed, 806 insertions, 803 deletions
diff --git a/xlators/nfs/server/src/exports.c b/xlators/nfs/server/src/exports.c
index 671aa04ffcb..342ad503a6a 100644
--- a/xlators/nfs/server/src/exports.c
+++ b/xlators/nfs/server/src/exports.c
@@ -17,10 +17,14 @@
#include "parse-utils.h"
#include "nfs-messages.h"
-static void _exp_dict_destroy (dict_t *ng_dict);
-static void _export_options_print (const struct export_options *opts);
-static void _export_options_deinit (struct export_options *opts);
-static void _export_dir_deinit (struct export_dir *dir);
+static void
+_exp_dict_destroy(dict_t *ng_dict);
+static void
+_export_options_print(const struct export_options *opts);
+static void
+_export_options_deinit(struct export_options *opts);
+static void
+_export_dir_deinit(struct export_dir *dir);
static struct parser *netgroup_parser;
static struct parser *hostname_parser;
@@ -33,36 +37,36 @@ static struct parser *options_parser;
* failure: -1
*/
static int
-_exp_init_parsers ()
+_exp_init_parsers()
{
- int ret = -1;
+ int ret = -1;
- netgroup_parser = parser_init (NETGROUP_REGEX_PATTERN);
- if (!netgroup_parser)
- goto out;
+ netgroup_parser = parser_init(NETGROUP_REGEX_PATTERN);
+ if (!netgroup_parser)
+ goto out;
- hostname_parser = parser_init (HOSTNAME_REGEX_PATTERN);
- if (!hostname_parser)
- goto out;
+ hostname_parser = parser_init(HOSTNAME_REGEX_PATTERN);
+ if (!hostname_parser)
+ goto out;
- options_parser = parser_init (OPTIONS_REGEX_PATTERN);
- if (!options_parser)
- goto out;
+ options_parser = parser_init(OPTIONS_REGEX_PATTERN);
+ if (!options_parser)
+ goto out;
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
/**
* _exp_deinit_parsers -- Free parsers used in this file
*/
static void
-_exp_deinit_parsers ()
+_exp_deinit_parsers()
{
- parser_deinit (netgroup_parser);
- parser_deinit (hostname_parser);
- parser_deinit (options_parser);
+ parser_deinit(netgroup_parser);
+ parser_deinit(hostname_parser);
+ parser_deinit(options_parser);
}
/**
@@ -74,35 +78,35 @@ _exp_deinit_parsers ()
* Not for external use.
*/
struct exports_file *
-_exports_file_init ()
+_exports_file_init()
{
- struct exports_file *file = NULL;
+ struct exports_file *file = NULL;
- file = GF_CALLOC (1, sizeof (*file), gf_common_mt_nfs_exports);
- if (!file) {
- gf_msg (GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
- "Failed to allocate file struct!");
- goto out;
- }
+ file = GF_CALLOC(1, sizeof(*file), gf_common_mt_nfs_exports);
+ if (!file) {
+ gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
+ "Failed to allocate file struct!");
+ goto out;
+ }
- file->exports_dict = dict_new ();
- file->exports_map = dict_new ();
- if (!file->exports_dict || !file->exports_map) {
- gf_msg (GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
- "Failed to allocate dict!");
- goto free_and_out;
- }
+ file->exports_dict = dict_new();
+ file->exports_map = dict_new();
+ if (!file->exports_dict || !file->exports_map) {
+ gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
+ "Failed to allocate dict!");
+ goto free_and_out;
+ }
- goto out;
+ goto out;
free_and_out:
- if (file->exports_dict)
- dict_unref (file->exports_dict);
+ if (file->exports_dict)
+ dict_unref(file->exports_dict);
- GF_FREE (file);
- file = NULL;
+ GF_FREE(file);
+ file = NULL;
out:
- return file;
+ return file;
}
/**
@@ -116,24 +120,24 @@ out:
* Not for external use.
*/
static int
-_exp_file_dict_destroy (dict_t *dict, char *key, data_t *val, void *tmp)
+_exp_file_dict_destroy(dict_t *dict, char *key, data_t *val, void *tmp)
{
- struct export_dir *dir = NULL;
+ struct export_dir *dir = NULL;
- GF_VALIDATE_OR_GOTO (GF_EXP, dict, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, dict, out);
- if (val) {
- dir = (struct export_dir *)val->data;
+ if (val) {
+ dir = (struct export_dir *)val->data;
- if (dir) {
- _export_dir_deinit (dir);
- val->data = NULL;
- }
- dict_del (dict, key);
+ if (dir) {
+ _export_dir_deinit(dir);
+ val->data = NULL;
}
+ dict_del(dict, key);
+ }
out:
- return 0;
+ return 0;
}
/**
@@ -144,27 +148,25 @@ out:
* Externally usable.
*/
void
-exp_file_deinit (struct exports_file *expfile)
+exp_file_deinit(struct exports_file *expfile)
{
- if (!expfile)
- goto out;
+ if (!expfile)
+ goto out;
- if (expfile->exports_dict) {
- dict_foreach (expfile->exports_dict, _exp_file_dict_destroy,
- NULL);
- dict_unref (expfile->exports_dict);
- }
+ if (expfile->exports_dict) {
+ dict_foreach(expfile->exports_dict, _exp_file_dict_destroy, NULL);
+ dict_unref(expfile->exports_dict);
+ }
- if (expfile->exports_map) {
- dict_foreach (expfile->exports_map, _exp_file_dict_destroy,
- NULL);
- dict_unref (expfile->exports_map);
- }
+ if (expfile->exports_map) {
+ dict_foreach(expfile->exports_map, _exp_file_dict_destroy, NULL);
+ dict_unref(expfile->exports_map);
+ }
- GF_FREE (expfile->filename);
- GF_FREE (expfile);
+ GF_FREE(expfile->filename);
+ GF_FREE(expfile);
out:
- return;
+ return;
}
/**
@@ -176,16 +178,16 @@ out:
* Not for external use.
*/
static struct export_dir *
-_export_dir_init ()
+_export_dir_init()
{
- struct export_dir *expdir = GF_CALLOC (1, sizeof (*expdir),
- gf_common_mt_nfs_exports);
+ struct export_dir *expdir = GF_CALLOC(1, sizeof(*expdir),
+ gf_common_mt_nfs_exports);
- if (!expdir)
- gf_msg (GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
- "Failed to allocate export dir structure!");
+ if (!expdir)
+ gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
+ "Failed to allocate export dir structure!");
- return expdir;
+ return expdir;
}
/**
@@ -196,19 +198,18 @@ _export_dir_init ()
* Not for external use.
*/
static void
-_export_dir_deinit (struct export_dir *dir)
+_export_dir_deinit(struct export_dir *dir)
{
- GF_VALIDATE_OR_GOTO (GF_EXP, dir, out);
- GF_FREE (dir->dir_name);
- _exp_dict_destroy (dir->netgroups);
- _exp_dict_destroy (dir->hosts);
- GF_FREE (dir);
+ GF_VALIDATE_OR_GOTO(GF_EXP, dir, out);
+ GF_FREE(dir->dir_name);
+ _exp_dict_destroy(dir->netgroups);
+ _exp_dict_destroy(dir->hosts);
+ GF_FREE(dir);
out:
- return;
+ return;
}
-
/**
* _export_item_print -- Print the elements in the export item.
*
@@ -217,13 +218,13 @@ out:
* Not for external use.
*/
static void
-_export_item_print (const struct export_item *item)
+_export_item_print(const struct export_item *item)
{
- GF_VALIDATE_OR_GOTO (GF_EXP, item, out);
- printf ("%s", item->name);
- _export_options_print (item->opts);
+ GF_VALIDATE_OR_GOTO(GF_EXP, item, out);
+ printf("%s", item->name);
+ _export_options_print(item->opts);
out:
- return;
+ return;
}
/**
@@ -234,14 +235,14 @@ out:
* Not for external use.
*/
static void
-_export_item_deinit (struct export_item *item)
+_export_item_deinit(struct export_item *item)
{
- if (!item)
- return;
+ if (!item)
+ return;
- _export_options_deinit (item->opts);
- GF_FREE (item->name);
- GF_FREE (item);
+ _export_options_deinit(item->opts);
+ GF_FREE(item->name);
+ GF_FREE(item);
}
/**
@@ -253,19 +254,19 @@ _export_item_deinit (struct export_item *item)
* Not for external use.
*/
static struct export_item *
-_export_item_init ()
+_export_item_init()
{
- struct export_item *item = GF_CALLOC (1, sizeof (*item),
- gf_common_mt_nfs_exports);
-
- if (item) {
- GF_REF_INIT(item, _export_item_deinit);
- } else {
- gf_msg (GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
- "Failed to allocate export item!");
- }
+ struct export_item *item = GF_CALLOC(1, sizeof(*item),
+ gf_common_mt_nfs_exports);
- return item;
+ if (item) {
+ GF_REF_INIT(item, _export_item_deinit);
+ } else {
+ gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
+ "Failed to allocate export item!");
+ }
+
+ return item;
}
/**
@@ -277,16 +278,16 @@ _export_item_init ()
* Not for external use.
*/
static struct export_options *
-_export_options_init ()
+_export_options_init()
{
- struct export_options *opts = GF_CALLOC (1, sizeof (*opts),
- gf_common_mt_nfs_exports);
+ struct export_options *opts = GF_CALLOC(1, sizeof(*opts),
+ gf_common_mt_nfs_exports);
- if (!opts)
- gf_msg (GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
- "Failed to allocate options structure!");
+ if (!opts)
+ gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
+ "Failed to allocate options structure!");
- return opts;
+ return opts;
}
/**
@@ -297,14 +298,14 @@ _export_options_init ()
* Not for external use.
*/
static void
-_export_options_deinit (struct export_options *opts)
+_export_options_deinit(struct export_options *opts)
{
- if (!opts)
- return;
+ if (!opts)
+ return;
- GF_FREE (opts->anon_uid);
- GF_FREE (opts->sec_type);
- GF_FREE (opts);
+ GF_FREE(opts->anon_uid);
+ GF_FREE(opts->sec_type);
+ GF_FREE(opts);
}
/**
@@ -315,31 +316,31 @@ _export_options_deinit (struct export_options *opts)
* Not for external use.
*/
static void
-_export_options_print (const struct export_options *opts)
+_export_options_print(const struct export_options *opts)
{
- GF_VALIDATE_OR_GOTO (GF_EXP, opts, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, opts, out);
- printf ("(");
- if (opts->rw)
- printf ("rw,");
- else
- printf ("ro,");
+ printf("(");
+ if (opts->rw)
+ printf("rw,");
+ else
+ printf("ro,");
- if (opts->nosuid)
- printf ("nosuid,");
+ if (opts->nosuid)
+ printf("nosuid,");
- if (opts->root)
- printf ("root,");
+ if (opts->root)
+ printf("root,");
- if (opts->anon_uid)
- printf ("anonuid=%s,", opts->anon_uid);
+ if (opts->anon_uid)
+ printf("anonuid=%s,", opts->anon_uid);
- if (opts->sec_type)
- printf ("sec=%s,", opts->sec_type);
+ if (opts->sec_type)
+ printf("sec=%s,", opts->sec_type);
- printf (") ");
+ printf(") ");
out:
- return;
+ return;
}
/**
@@ -355,14 +356,14 @@ out:
* Not for external use.
*/
static int
-__exp_dict_free_walk (dict_t *dict, char *key, data_t *val, void *tmp)
+__exp_dict_free_walk(dict_t *dict, char *key, data_t *val, void *tmp)
{
- if (val) {
- GF_REF_PUT ((struct export_item *)val->data);
- val->data = NULL;
- dict_del (dict, key);
- }
- return 0;
+ if (val) {
+ GF_REF_PUT((struct export_item *)val->data);
+ val->data = NULL;
+ dict_del(dict, key);
+ }
+ return 0;
}
/**
@@ -374,14 +375,14 @@ __exp_dict_free_walk (dict_t *dict, char *key, data_t *val, void *tmp)
* Not for external use.
*/
static void
-_exp_dict_destroy (dict_t *ng_dict)
+_exp_dict_destroy(dict_t *ng_dict)
{
- if (!ng_dict)
- goto out;
+ if (!ng_dict)
+ goto out;
- dict_foreach (ng_dict, __exp_dict_free_walk, NULL);
+ dict_foreach(ng_dict, __exp_dict_free_walk, NULL);
out:
- return;
+ return;
}
/**
@@ -395,20 +396,22 @@ out:
* failure: NULL
*/
struct export_dir *
-exp_file_dir_from_uuid (const struct exports_file *file,
- const uuid_t export_uuid)
+exp_file_dir_from_uuid(const struct exports_file *file,
+ const uuid_t export_uuid)
{
- char export_uuid_str[512] = {0, };
- data_t *dirdata = NULL;
- struct export_dir *dir = NULL;
+ char export_uuid_str[512] = {
+ 0,
+ };
+ data_t *dirdata = NULL;
+ struct export_dir *dir = NULL;
- gf_uuid_unparse (export_uuid, export_uuid_str);
+ gf_uuid_unparse(export_uuid, export_uuid_str);
- dirdata = dict_get (file->exports_map, export_uuid_str);
- if (dirdata)
- dir = (struct export_dir *)dirdata->data;
+ dirdata = dict_get(file->exports_map, export_uuid_str);
+ if (dirdata)
+ dir = (struct export_dir *)dirdata->data;
- return dir;
+ return dir;
}
/**
@@ -425,32 +428,36 @@ exp_file_dir_from_uuid (const struct exports_file *file,
* Not for external use.
*/
static void
-_exp_file_insert (struct exports_file *file, struct export_dir *dir)
+_exp_file_insert(struct exports_file *file, struct export_dir *dir)
{
- data_t *dirdata = NULL;
- uint32_t hashedval = 0;
- uuid_t export_uuid = {0, };
- char export_uuid_str[512] = {0, };
- char *dirdup = NULL;
-
- GF_VALIDATE_OR_GOTO (GF_EXP, file, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, dir, out);
-
- dirdata = bin_to_data (dir, sizeof (*dir));
- dict_set (file->exports_dict, dir->dir_name, dirdata);
-
- dirdup = strdupa (dir->dir_name);
- while (strlen (dirdup) > 0 && dirdup[0] == '/')
- dirdup++;
-
- hashedval = SuperFastHash (dirdup, strlen (dirdup));
- memset (export_uuid, 0, sizeof (export_uuid));
- memcpy (export_uuid, &hashedval, sizeof (hashedval));
- gf_uuid_unparse (export_uuid, export_uuid_str);
-
- dict_set (file->exports_map, export_uuid_str, dirdata);
+ data_t *dirdata = NULL;
+ uint32_t hashedval = 0;
+ uuid_t export_uuid = {
+ 0,
+ };
+ char export_uuid_str[512] = {
+ 0,
+ };
+ char *dirdup = NULL;
+
+ GF_VALIDATE_OR_GOTO(GF_EXP, file, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, dir, out);
+
+ dirdata = bin_to_data(dir, sizeof(*dir));
+ dict_set(file->exports_dict, dir->dir_name, dirdata);
+
+ dirdup = strdupa(dir->dir_name);
+ while (strlen(dirdup) > 0 && dirdup[0] == '/')
+ dirdup++;
+
+ hashedval = SuperFastHash(dirdup, strlen(dirdup));
+ memset(export_uuid, 0, sizeof(export_uuid));
+ memcpy(export_uuid, &hashedval, sizeof(hashedval));
+ gf_uuid_unparse(export_uuid, export_uuid_str);
+
+ dict_set(file->exports_map, export_uuid_str, dirdata);
out:
- return;
+ return;
}
/**
@@ -466,12 +473,12 @@ out:
* Not for external use.
*/
static int
-__exp_item_print_walk (dict_t *dict, char *key, data_t *val, void *tmp)
+__exp_item_print_walk(dict_t *dict, char *key, data_t *val, void *tmp)
{
- if (val)
- _export_item_print ((struct export_item *)val->data);
+ if (val)
+ _export_item_print((struct export_item *)val->data);
- return 0;
+ return 0;
}
/**
@@ -487,23 +494,22 @@ __exp_item_print_walk (dict_t *dict, char *key, data_t *val, void *tmp)
* Not for external use.
*/
static int
-__exp_file_print_walk (dict_t *dict, char *key, data_t *val, void *tmp)
+__exp_file_print_walk(dict_t *dict, char *key, data_t *val, void *tmp)
{
- if (val) {
- struct export_dir *dir = (struct export_dir *)val->data;
+ if (val) {
+ struct export_dir *dir = (struct export_dir *)val->data;
- printf ("%s ", key);
+ printf("%s ", key);
- if (dir->netgroups)
- dict_foreach (dir->netgroups, __exp_item_print_walk,
- NULL);
+ if (dir->netgroups)
+ dict_foreach(dir->netgroups, __exp_item_print_walk, NULL);
- if (dir->hosts)
- dict_foreach (dir->hosts, __exp_item_print_walk, NULL);
+ if (dir->hosts)
+ dict_foreach(dir->hosts, __exp_item_print_walk, NULL);
- printf ("\n");
- }
- return 0;
+ printf("\n");
+ }
+ return 0;
}
/**
@@ -514,29 +520,29 @@ __exp_file_print_walk (dict_t *dict, char *key, data_t *val, void *tmp)
* Not for external use.
*/
void
-exp_file_print (const struct exports_file *file)
+exp_file_print(const struct exports_file *file)
{
- GF_VALIDATE_OR_GOTO (GF_EXP, file, out);
- dict_foreach (file->exports_dict, __exp_file_print_walk, NULL);
+ GF_VALIDATE_OR_GOTO(GF_EXP, file, out);
+ dict_foreach(file->exports_dict, __exp_file_print_walk, NULL);
out:
- return;
+ return;
}
-#define __exp_line_get_opt_val(val, equals, ret, errlabel) \
- do { \
- (val) = (equals) + 1; \
- if (!(*(val))) { \
- (ret) = 1; \
- goto errlabel; \
- } \
- } while (0) \
+#define __exp_line_get_opt_val(val, equals, ret, errlabel) \
+ do { \
+ (val) = (equals) + 1; \
+ if (!(*(val))) { \
+ (ret) = 1; \
+ goto errlabel; \
+ } \
+ } while (0)
enum gf_exp_parse_status {
- GF_EXP_PARSE_SUCCESS = 0,
- GF_EXP_PARSE_ITEM_NOT_FOUND = 1,
- GF_EXP_PARSE_ITEM_FAILURE = 2,
- GF_EXP_PARSE_ITEM_NOT_IN_MOUNT_STATE = 3,
- GF_EXP_PARSE_LINE_IGNORING = 4,
+ GF_EXP_PARSE_SUCCESS = 0,
+ GF_EXP_PARSE_ITEM_NOT_FOUND = 1,
+ GF_EXP_PARSE_ITEM_FAILURE = 2,
+ GF_EXP_PARSE_ITEM_NOT_IN_MOUNT_STATE = 3,
+ GF_EXP_PARSE_LINE_IGNORING = 4,
};
/**
@@ -559,48 +565,48 @@ enum gf_exp_parse_status {
* Not for external use.
*/
static int
-__exp_line_opt_key_value_parse (char *option, struct export_options *opts)
+__exp_line_opt_key_value_parse(char *option, struct export_options *opts)
{
- char *equals = NULL;
- char *right = NULL;
- char *strmatch = option;
- int ret = -EINVAL;
+ char *equals = NULL;
+ char *right = NULL;
+ char *strmatch = option;
+ int ret = -EINVAL;
- GF_VALIDATE_OR_GOTO (GF_EXP, option, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, opts, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, option, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, opts, out);
- equals = strchr (option, '=');
- if (!equals) {
- ret = GF_EXP_PARSE_ITEM_FAILURE;
- goto out;
- }
-
- *equals = 0;
- /* Now that an '=' has been found the left side is the option and
- * the right side is the value. We simply have to compare those and
- * extract it.
- */
- if (strcmp (strmatch, "anonuid") == 0) {
- *equals = '=';
- /* Get the value for this option */
- __exp_line_get_opt_val (right, equals, ret, out);
- opts->anon_uid = gf_strdup (right);
- GF_CHECK_ALLOC (opts->anon_uid, ret, out);
- } else if (strcmp (strmatch, "sec") == 0) {
- *equals = '=';
- /* Get the value for this option */
- __exp_line_get_opt_val (right, equals, ret, out);
- opts->sec_type = gf_strdup (right);
- GF_CHECK_ALLOC (opts->sec_type, ret, out);
- } else {
- *equals = '=';
- ret = GF_EXP_PARSE_ITEM_FAILURE;
- goto out;
- }
+ equals = strchr(option, '=');
+ if (!equals) {
+ ret = GF_EXP_PARSE_ITEM_FAILURE;
+ goto out;
+ }
+
+ *equals = 0;
+ /* Now that an '=' has been found the left side is the option and
+ * the right side is the value. We simply have to compare those and
+ * extract it.
+ */
+ if (strcmp(strmatch, "anonuid") == 0) {
+ *equals = '=';
+ /* Get the value for this option */
+ __exp_line_get_opt_val(right, equals, ret, out);
+ opts->anon_uid = gf_strdup(right);
+ GF_CHECK_ALLOC(opts->anon_uid, ret, out);
+ } else if (strcmp(strmatch, "sec") == 0) {
+ *equals = '=';
+ /* Get the value for this option */
+ __exp_line_get_opt_val(right, equals, ret, out);
+ opts->sec_type = gf_strdup(right);
+ GF_CHECK_ALLOC(opts->sec_type, ret, out);
+ } else {
+ *equals = '=';
+ ret = GF_EXP_PARSE_ITEM_FAILURE;
+ goto out;
+ }
- ret = GF_EXP_PARSE_SUCCESS;
+ ret = GF_EXP_PARSE_SUCCESS;
out:
- return ret;
+ return ret;
}
/**
@@ -619,87 +625,87 @@ out:
* Not for external use.
*/
static int
-__exp_line_opt_parse (const char *opt_str, struct export_options **exp_opts)
+__exp_line_opt_parse(const char *opt_str, struct export_options **exp_opts)
{
- struct export_options *opts = NULL;
- char *strmatch = NULL;
- int ret = -EINVAL;
- char *equals = NULL;
+ struct export_options *opts = NULL;
+ char *strmatch = NULL;
+ int ret = -EINVAL;
+ char *equals = NULL;
- ret = parser_set_string (options_parser, opt_str);
- if (ret < 0)
- goto out;
+ ret = parser_set_string(options_parser, opt_str);
+ if (ret < 0)
+ goto out;
- while ((strmatch = parser_get_next_match (options_parser))) {
- if (!opts) {
- /* If the options have not been allocated,
- * allocate it.
- */
- opts = _export_options_init ();
- if (!opts) {
- ret = -ENOMEM;
- parser_unset_string (options_parser);
- goto out;
- }
- }
-
- /* First, check for all the boolean options Second, check for
- * an '=', and check the available options there. The string
- * parsing here gets slightly messy, but the concept itself
- * is pretty simple.
- */
- equals = strchr (strmatch, '=');
- if (strcmp (strmatch, "root") == 0)
- opts->root = _gf_true;
- else if (strcmp (strmatch, "ro") == 0)
- opts->rw = _gf_false;
- else if (strcmp (strmatch, "rw") == 0)
- opts->rw = _gf_true;
- else if (strcmp (strmatch, "nosuid") == 0)
- opts->nosuid = _gf_true;
- else if (equals) {
- ret = __exp_line_opt_key_value_parse (strmatch, opts);
- if (ret < 0) {
- /* This means invalid key value options were
- * specified, or memory allocation failed.
- * The ret value gets bubbled up to the caller.
- */
- GF_FREE (strmatch);
- parser_unset_string (options_parser);
- _export_options_deinit (opts);
- goto out;
- }
- } else
- /* Cannot change to gf_msg.
- * gf_msg not giving output to STDOUT
- * Bug id : BZ1215017
- */
- gf_log (GF_EXP, GF_LOG_WARNING,
- "Could not find any valid options for "
- "string: %s", strmatch);
- GF_FREE (strmatch);
+ while ((strmatch = parser_get_next_match(options_parser))) {
+ if (!opts) {
+ /* If the options have not been allocated,
+ * allocate it.
+ */
+ opts = _export_options_init();
+ if (!opts) {
+ ret = -ENOMEM;
+ parser_unset_string(options_parser);
+ goto out;
+ }
}
- if (!opts) {
- /* If opts is not allocated
- * that means no matches were found
- * which is a parse error. Not marking
- * it as "not found" because it is a parse
- * error to not have options.
+ /* First, check for all the boolean options Second, check for
+ * an '=', and check the available options there. The string
+ * parsing here gets slightly messy, but the concept itself
+ * is pretty simple.
+ */
+ equals = strchr(strmatch, '=');
+ if (strcmp(strmatch, "root") == 0)
+ opts->root = _gf_true;
+ else if (strcmp(strmatch, "ro") == 0)
+ opts->rw = _gf_false;
+ else if (strcmp(strmatch, "rw") == 0)
+ opts->rw = _gf_true;
+ else if (strcmp(strmatch, "nosuid") == 0)
+ opts->nosuid = _gf_true;
+ else if (equals) {
+ ret = __exp_line_opt_key_value_parse(strmatch, opts);
+ if (ret < 0) {
+ /* This means invalid key value options were
+ * specified, or memory allocation failed.
+ * The ret value gets bubbled up to the caller.
*/
- ret = GF_EXP_PARSE_ITEM_FAILURE;
- parser_unset_string (options_parser);
+ GF_FREE(strmatch);
+ parser_unset_string(options_parser);
+ _export_options_deinit(opts);
goto out;
- }
+ }
+ } else
+ /* Cannot change to gf_msg.
+ * gf_msg not giving output to STDOUT
+ * Bug id : BZ1215017
+ */
+ gf_log(GF_EXP, GF_LOG_WARNING,
+ "Could not find any valid options for "
+ "string: %s",
+ strmatch);
+ GF_FREE(strmatch);
+ }
+
+ if (!opts) {
+ /* If opts is not allocated
+ * that means no matches were found
+ * which is a parse error. Not marking
+ * it as "not found" because it is a parse
+ * error to not have options.
+ */
+ ret = GF_EXP_PARSE_ITEM_FAILURE;
+ parser_unset_string(options_parser);
+ goto out;
+ }
- *exp_opts = opts;
- parser_unset_string (options_parser);
- ret = GF_EXP_PARSE_SUCCESS;
+ *exp_opts = opts;
+ parser_unset_string(options_parser);
+ ret = GF_EXP_PARSE_SUCCESS;
out:
- return ret;
+ return ret;
}
-
/**
* __exp_line_ng_host_str_parse -- Parse the netgroup or host string
*
@@ -716,76 +722,76 @@ out:
* Not for external use.
*/
static int
-__exp_line_ng_host_str_parse (char *str, struct export_item **exp_item)
+__exp_line_ng_host_str_parse(char *str, struct export_item **exp_item)
{
- struct export_item *item = NULL;
- int ret = -EINVAL;
- char *parens = NULL;
- char *optstr = NULL;
- struct export_options *exp_opts = NULL;
- char *item_name = NULL;
-
- GF_VALIDATE_OR_GOTO (GF_EXP, str, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, exp_item, out);
-
- /* A netgroup/host string looks like this:
- * @test(sec=sys,rw,anonuid=0) or host(sec=sys,rw,anonuid=0)
- * We want to extract the name, 'test' or 'host'
- * Again, we could setup a regex and use it here,
- * but its simpler to find the '(' and copy until
- * there.
- */
- parens = strchr (str, '(');
- if (!parens) {
- /* Parse error if there are no parens. */
- ret = GF_EXP_PARSE_ITEM_FAILURE;
- goto out;
- }
+ struct export_item *item = NULL;
+ int ret = -EINVAL;
+ char *parens = NULL;
+ char *optstr = NULL;
+ struct export_options *exp_opts = NULL;
+ char *item_name = NULL;
+
+ GF_VALIDATE_OR_GOTO(GF_EXP, str, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, exp_item, out);
+
+ /* A netgroup/host string looks like this:
+ * @test(sec=sys,rw,anonuid=0) or host(sec=sys,rw,anonuid=0)
+ * We want to extract the name, 'test' or 'host'
+ * Again, we could setup a regex and use it here,
+ * but its simpler to find the '(' and copy until
+ * there.
+ */
+ parens = strchr(str, '(');
+ if (!parens) {
+ /* Parse error if there are no parens. */
+ ret = GF_EXP_PARSE_ITEM_FAILURE;
+ goto out;
+ }
- *parens = '\0'; /* Temporarily terminate it so we can do a copy */
+ *parens = '\0'; /* Temporarily terminate it so we can do a copy */
- if (strlen (str) > FQDN_MAX_LEN) {
- ret = GF_EXP_PARSE_ITEM_FAILURE;
- goto out;
- }
+ if (strlen(str) > FQDN_MAX_LEN) {
+ ret = GF_EXP_PARSE_ITEM_FAILURE;
+ goto out;
+ }
- /* Strip leading whitespaces */
- while (*str == ' ' || *str == '\t')
- str++;
+ /* Strip leading whitespaces */
+ while (*str == ' ' || *str == '\t')
+ str++;
- item_name = gf_strdup (str);
- GF_CHECK_ALLOC (item_name, ret, out);
+ item_name = gf_strdup(str);
+ GF_CHECK_ALLOC(item_name, ret, out);
- gf_msg_trace (GF_EXP, 0, "found hostname/netgroup: %s", item_name);
+ gf_msg_trace(GF_EXP, 0, "found hostname/netgroup: %s", item_name);
- /* Initialize an export item for this */
- item = _export_item_init ();
- GF_CHECK_ALLOC (item, ret, free_and_out);
- item->name = item_name;
+ /* Initialize an export item for this */
+ item = _export_item_init();
+ GF_CHECK_ALLOC(item, ret, free_and_out);
+ item->name = item_name;
- *parens = '('; /* Restore the string */
+ *parens = '('; /* Restore the string */
- /* Options start at the parentheses */
- optstr = parens;
+ /* Options start at the parentheses */
+ optstr = parens;
- ret = __exp_line_opt_parse (optstr, &exp_opts);
- if (ret != 0) {
- /* Bubble up the error to the caller */
- GF_REF_PUT (item);
- goto out;
- }
+ ret = __exp_line_opt_parse(optstr, &exp_opts);
+ if (ret != 0) {
+ /* Bubble up the error to the caller */
+ GF_REF_PUT(item);
+ goto out;
+ }
- item->opts = exp_opts;
+ item->opts = exp_opts;
- *exp_item = item;
+ *exp_item = item;
- ret = GF_EXP_PARSE_SUCCESS;
- goto out;
+ ret = GF_EXP_PARSE_SUCCESS;
+ goto out;
free_and_out:
- GF_FREE (item_name);
+ GF_FREE(item_name);
out:
- return ret;
+ return ret;
}
/**
@@ -816,75 +822,75 @@ out:
* Not for external use.
*/
static int
-__exp_line_ng_parse (const char *line, dict_t **ng_dict)
+__exp_line_ng_parse(const char *line, dict_t **ng_dict)
{
- dict_t *netgroups = NULL;
- char *strmatch = NULL;
- int ret = -EINVAL;
- struct export_item *exp_ng = NULL;
- data_t *ngdata = NULL;
-
- GF_VALIDATE_OR_GOTO (GF_EXP, line, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, ng_dict, out);
+ dict_t *netgroups = NULL;
+ char *strmatch = NULL;
+ int ret = -EINVAL;
+ struct export_item *exp_ng = NULL;
+ data_t *ngdata = NULL;
+
+ GF_VALIDATE_OR_GOTO(GF_EXP, line, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, ng_dict, out);
+
+ *ng_dict = NULL; /* Will be set if parse is successful */
+
+ /* Initialize a parser with the line to parse
+ * and the regex used to parse it.
+ */
+ ret = parser_set_string(netgroup_parser, line);
+ if (ret < 0) {
+ goto out;
+ }
- *ng_dict = NULL; /* Will be set if parse is successful */
+ gf_msg_trace(GF_EXP, 0, "parsing line: %s", line);
- /* Initialize a parser with the line to parse
- * and the regex used to parse it.
- */
- ret = parser_set_string (netgroup_parser, line);
- if (ret < 0) {
- goto out;
+ while ((strmatch = parser_get_next_match(netgroup_parser))) {
+ if (!netgroups) {
+ /* Allocate a new dict to store the netgroups. */
+ netgroups = dict_new();
+ if (!netgroups) {
+ ret = -ENOMEM;
+ goto free_and_out;
+ }
}
- gf_msg_trace (GF_EXP, 0, "parsing line: %s", line);
+ gf_msg_trace(GF_EXP, 0, "parsing netgroup: %s", strmatch);
- while ((strmatch = parser_get_next_match (netgroup_parser))) {
- if (!netgroups) {
- /* Allocate a new dict to store the netgroups. */
- netgroups = dict_new ();
- if (!netgroups) {
- ret = -ENOMEM;
- goto free_and_out;
- }
- }
+ ret = __exp_line_ng_host_str_parse(strmatch, &exp_ng);
- gf_msg_trace (GF_EXP, 0, "parsing netgroup: %s", strmatch);
-
- ret = __exp_line_ng_host_str_parse (strmatch, &exp_ng);
-
- if (ret != 0) {
- /* Parsing or other critical errors.
- * caller will handle return value.
- */
- _exp_dict_destroy (netgroups);
- goto free_and_out;
- }
+ if (ret != 0) {
+ /* Parsing or other critical errors.
+ * caller will handle return value.
+ */
+ _exp_dict_destroy(netgroups);
+ goto free_and_out;
+ }
- ngdata = bin_to_data (exp_ng, sizeof (*exp_ng));
- dict_set (netgroups, exp_ng->name, ngdata);
+ ngdata = bin_to_data(exp_ng, sizeof(*exp_ng));
+ dict_set(netgroups, exp_ng->name, ngdata);
- /* Free this matched string and continue parsing. */
- GF_FREE (strmatch);
- }
+ /* Free this matched string and continue parsing. */
+ GF_FREE(strmatch);
+ }
- /* If the netgroups dict was not allocated, then we know that
- * no matches were found.
- */
- if (!netgroups) {
- ret = GF_EXP_PARSE_ITEM_NOT_FOUND;
- parser_unset_string (netgroup_parser);
- goto out;
- }
+ /* If the netgroups dict was not allocated, then we know that
+ * no matches were found.
+ */
+ if (!netgroups) {
+ ret = GF_EXP_PARSE_ITEM_NOT_FOUND;
+ parser_unset_string(netgroup_parser);
+ goto out;
+ }
- ret = GF_EXP_PARSE_SUCCESS;
- *ng_dict = netgroups;
+ ret = GF_EXP_PARSE_SUCCESS;
+ *ng_dict = netgroups;
free_and_out:
- parser_unset_string (netgroup_parser);
- GF_FREE (strmatch);
+ parser_unset_string(netgroup_parser);
+ GF_FREE(strmatch);
out:
- return ret;
+ return ret;
}
/**
@@ -915,77 +921,75 @@ out:
* Not for external use.
*/
static int
-__exp_line_host_parse (const char *line, dict_t **host_dict)
+__exp_line_host_parse(const char *line, dict_t **host_dict)
{
- dict_t *hosts = NULL;
- char *strmatch = NULL;
- int ret = -EINVAL;
- struct export_item *exp_host = NULL;
- data_t *hostdata = NULL;
-
- GF_VALIDATE_OR_GOTO (GF_EXP, line, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, host_dict, out);
+ dict_t *hosts = NULL;
+ char *strmatch = NULL;
+ int ret = -EINVAL;
+ struct export_item *exp_host = NULL;
+ data_t *hostdata = NULL;
+
+ GF_VALIDATE_OR_GOTO(GF_EXP, line, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, host_dict, out);
+
+ *host_dict = NULL;
+
+ /* Initialize a parser with the line to parse and the regex used to
+ * parse it.
+ */
+ ret = parser_set_string(hostname_parser, line);
+ if (ret < 0) {
+ goto out;
+ }
- *host_dict = NULL;
+ gf_msg_trace(GF_EXP, 0, "parsing line: %s", line);
- /* Initialize a parser with the line to parse and the regex used to
- * parse it.
- */
- ret = parser_set_string (hostname_parser, line);
- if (ret < 0) {
- goto out;
+ while ((strmatch = parser_get_next_match(hostname_parser))) {
+ if (!hosts) {
+ /* Allocate a new dictto store the netgroups. */
+ hosts = dict_new();
+ GF_CHECK_ALLOC(hosts, ret, free_and_out);
}
- gf_msg_trace (GF_EXP, 0, "parsing line: %s", line);
-
- while ((strmatch = parser_get_next_match (hostname_parser))) {
- if (!hosts) {
- /* Allocate a new dictto store the netgroups. */
- hosts = dict_new ();
- GF_CHECK_ALLOC (hosts, ret, free_and_out);
- }
-
- gf_msg_trace (GF_EXP, 0, "parsing hostname: %s", strmatch);
+ gf_msg_trace(GF_EXP, 0, "parsing hostname: %s", strmatch);
- ret = __exp_line_ng_host_str_parse (strmatch, &exp_host);
+ ret = __exp_line_ng_host_str_parse(strmatch, &exp_host);
- if (ret != 0) {
- /* Parsing or other critical error, free allocated
- * memory and exit. The caller will handle the errors.
- */
- _exp_dict_destroy (hosts);
- goto free_and_out;
- }
-
- /* Insert export item structure into the hosts dict. */
- hostdata = bin_to_data (exp_host, sizeof (*exp_host));
- dict_set (hosts, exp_host->name, hostdata);
+ if (ret != 0) {
+ /* Parsing or other critical error, free allocated
+ * memory and exit. The caller will handle the errors.
+ */
+ _exp_dict_destroy(hosts);
+ goto free_and_out;
+ }
+ /* Insert export item structure into the hosts dict. */
+ hostdata = bin_to_data(exp_host, sizeof(*exp_host));
+ dict_set(hosts, exp_host->name, hostdata);
- /* Free this matched string and continue parsing.*/
- GF_FREE (strmatch);
- }
+ /* Free this matched string and continue parsing.*/
+ GF_FREE(strmatch);
+ }
- /* If the hosts dict was not allocated, then we know that
- * no matches were found.
- */
- if (!exp_host) {
- ret = GF_EXP_PARSE_ITEM_NOT_FOUND;
- parser_unset_string (hostname_parser);
- goto out;
- }
+ /* If the hosts dict was not allocated, then we know that
+ * no matches were found.
+ */
+ if (!exp_host) {
+ ret = GF_EXP_PARSE_ITEM_NOT_FOUND;
+ parser_unset_string(hostname_parser);
+ goto out;
+ }
- ret = GF_EXP_PARSE_SUCCESS;
- *host_dict = hosts;
+ ret = GF_EXP_PARSE_SUCCESS;
+ *host_dict = hosts;
free_and_out:
- parser_unset_string (hostname_parser);
- GF_FREE (strmatch);
+ parser_unset_string(hostname_parser);
+ GF_FREE(strmatch);
out:
- return ret;
+ return ret;
}
-
/**
* __exp_line_dir_parse -- Extract directory name from a line in the exports
* file.
@@ -1010,70 +1014,71 @@ out:
* Not for external use.
*/
static int
-__exp_line_dir_parse (const char *line, char **dirname, struct mount3_state *ms)
+__exp_line_dir_parse(const char *line, char **dirname, struct mount3_state *ms)
{
- char *dir = NULL;
- char *delim = NULL;
- int ret = -EINVAL;
- char *linedup = NULL;
- struct mnt3_export *mnt3export = NULL;
- size_t dirlen = 0;
-
- GF_VALIDATE_OR_GOTO (GF_EXP, line, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, dirname, out);
-
- /* Duplicate the line because we don't
- * want to modify the original string.
+ char *dir = NULL;
+ char *delim = NULL;
+ int ret = -EINVAL;
+ char *linedup = NULL;
+ struct mnt3_export *mnt3export = NULL;
+ size_t dirlen = 0;
+
+ GF_VALIDATE_OR_GOTO(GF_EXP, line, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, dirname, out);
+
+ /* Duplicate the line because we don't
+ * want to modify the original string.
+ */
+ linedup = strdupa(line);
+
+ /* We use strtok_r () here to split the string by space/tab and get the
+ * the result. We only need the first result of the split.
+ * a simple task. It is worth noting that dirnames always have to be
+ * validated against gluster's vol files so if they don't
+ * match it will be rejected.
+ */
+ dir = linedup;
+ delim = linedup + strcspn(linedup, " \t");
+ *delim = 0;
+
+ if (ms) {
+ /* Match the directory name with an existing
+ * export in the mount state.
*/
- linedup = strdupa (line);
-
- /* We use strtok_r () here to split the string by space/tab and get the
- * the result. We only need the first result of the split.
- * a simple task. It is worth noting that dirnames always have to be
- * validated against gluster's vol files so if they don't
- * match it will be rejected.
- */
- dir = linedup;
- delim = linedup + strcspn (linedup, " \t");
- *delim = 0;
-
- if (ms) {
- /* Match the directory name with an existing
- * export in the mount state.
- */
- mnt3export = mnt3_mntpath_to_export (ms, dir, _gf_true);
- if (!mnt3export) {
- gf_msg_debug (GF_EXP, 0, "%s not in mount state, "
- "ignoring!", dir);
- ret = GF_EXP_PARSE_ITEM_NOT_IN_MOUNT_STATE;
- goto out;
- }
- }
-
- /* Directories can be 1024 bytes in length, check
- * that the argument provided adheres to
- * that restriction.
- */
- if (strlen (dir) > DIR_MAX_LEN) {
- ret = -EINVAL;
- goto out;
+ mnt3export = mnt3_mntpath_to_export(ms, dir, _gf_true);
+ if (!mnt3export) {
+ gf_msg_debug(GF_EXP, 0,
+ "%s not in mount state, "
+ "ignoring!",
+ dir);
+ ret = GF_EXP_PARSE_ITEM_NOT_IN_MOUNT_STATE;
+ goto out;
}
+ }
+
+ /* Directories can be 1024 bytes in length, check
+ * that the argument provided adheres to
+ * that restriction.
+ */
+ if (strlen(dir) > DIR_MAX_LEN) {
+ ret = -EINVAL;
+ goto out;
+ }
- /* Copy the result of the split */
- dir = gf_strdup (dir);
- GF_CHECK_ALLOC (dir, ret, out);
-
- /* Ensure that trailing slashes are stripped before storing the name */
- dirlen = strlen (dir);
- if (dirlen > 0 && dir[dirlen - 1] == '/')
- dir[dirlen - 1] = '\0';
+ /* Copy the result of the split */
+ dir = gf_strdup(dir);
+ GF_CHECK_ALLOC(dir, ret, out);
+ /* Ensure that trailing slashes are stripped before storing the name */
+ dirlen = strlen(dir);
+ if (dirlen > 0 && dir[dirlen - 1] == '/')
+ dir[dirlen - 1] = '\0';
- /* Set the argument to point to the allocated string */
- *dirname = dir;
- ret = GF_EXP_PARSE_SUCCESS;
+ /* Set the argument to point to the allocated string */
+ *dirname = dir;
+ ret = GF_EXP_PARSE_SUCCESS;
out:
- return ret;
+ return ret;
}
/**
@@ -1121,126 +1126,126 @@ out:
* Not for external use.
*/
static int
-_exp_line_parse (const char *line, struct export_dir **dir,
- gf_boolean_t parse_full, struct mount3_state *ms)
+_exp_line_parse(const char *line, struct export_dir **dir,
+ gf_boolean_t parse_full, struct mount3_state *ms)
{
- struct export_dir *expdir = NULL;
- char *dirstr = NULL;
- dict_t *netgroups = NULL;
- dict_t *hosts = NULL;
- int ret = -EINVAL;
- gf_boolean_t netgroups_failed = _gf_false;
-
- GF_VALIDATE_OR_GOTO (GF_EXP, line, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, dir, out);
-
- if (*line == '#' || *line == ' ' || *line == '\t'
- || *line == '\0' || *line == '\n') {
- ret = GF_EXP_PARSE_LINE_IGNORING;
- goto out;
- }
-
- expdir = _export_dir_init ();
- if (!expdir) {
- *dir = NULL;
- ret = -ENOMEM;
- goto out;
- }
-
- /* Get the directory string from the line */
- ret = __exp_line_dir_parse (line, &dirstr, ms);
- if (ret < 0) {
- gf_msg (GF_EXP, GF_LOG_ERROR, 0, NFS_MSG_PARSE_DIR_FAIL,
- "Parsing directory failed: %s", strerror (-ret));
- /* If parsing the directory failed,
- * we should simply fail because there's
- * nothing else we can extract from the string to make
- * the data valuable.
- */
- goto free_and_out;
- }
-
- /* Set the dir str */
- expdir->dir_name = dirstr;
-
- /* Parse the netgroup part of the string */
- ret = __exp_line_ng_parse (line, &netgroups);
- if (ret < 0) {
- gf_msg (GF_EXP, GF_LOG_ERROR, -ret, NFS_MSG_PARSE_FAIL,
- "Critical error: %s", strerror (-ret));
- /* Return values less than 0
- * indicate critical failures (null parameters,
- * failure to allocate memory, etc).
- */
- goto free_and_out;
- }
- if (ret != 0) {
- if (ret == GF_EXP_PARSE_ITEM_FAILURE)
- /* Cannot change to gf_msg.
- * gf_msg not giving output to STDOUT
- * Bug id : BZ1215017
- */
- gf_log (GF_EXP, GF_LOG_WARNING,
- "Error parsing netgroups for: %s", line);
- /* Even though parsing failed for the netgroups we should let
- * host parsing proceed.
- */
- netgroups_failed = _gf_true;
- }
-
- /* Parse the host part of the string */
- ret = __exp_line_host_parse (line, &hosts);
- if (ret < 0) {
- gf_msg (GF_EXP, GF_LOG_ERROR, -ret, NFS_MSG_PARSE_FAIL,
- "Critical error: %s", strerror (-ret));
- goto free_and_out;
- }
- if (ret != 0) {
- if (ret == GF_EXP_PARSE_ITEM_FAILURE)
- gf_msg (GF_EXP, GF_LOG_WARNING, 0, NFS_MSG_PARSE_FAIL,
- "Error parsing hosts for: %s", line);
- /* If netgroups parsing failed, AND
- * host parsing failed, then there's something really
- * wrong with this line, so we're just going to
- * log it and fail out.
- */
- if (netgroups_failed)
- goto free_and_out;
- }
+ struct export_dir *expdir = NULL;
+ char *dirstr = NULL;
+ dict_t *netgroups = NULL;
+ dict_t *hosts = NULL;
+ int ret = -EINVAL;
+ gf_boolean_t netgroups_failed = _gf_false;
+
+ GF_VALIDATE_OR_GOTO(GF_EXP, line, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, dir, out);
+
+ if (*line == '#' || *line == ' ' || *line == '\t' || *line == '\0' ||
+ *line == '\n') {
+ ret = GF_EXP_PARSE_LINE_IGNORING;
+ goto out;
+ }
- expdir->hosts = hosts;
- expdir->netgroups = netgroups;
- *dir = expdir;
+ expdir = _export_dir_init();
+ if (!expdir) {
+ *dir = NULL;
+ ret = -ENOMEM;
goto out;
+ }
+
+ /* Get the directory string from the line */
+ ret = __exp_line_dir_parse(line, &dirstr, ms);
+ if (ret < 0) {
+ gf_msg(GF_EXP, GF_LOG_ERROR, 0, NFS_MSG_PARSE_DIR_FAIL,
+ "Parsing directory failed: %s", strerror(-ret));
+ /* If parsing the directory failed,
+ * we should simply fail because there's
+ * nothing else we can extract from the string to make
+ * the data valuable.
+ */
+ goto free_and_out;
+ }
+
+ /* Set the dir str */
+ expdir->dir_name = dirstr;
+
+ /* Parse the netgroup part of the string */
+ ret = __exp_line_ng_parse(line, &netgroups);
+ if (ret < 0) {
+ gf_msg(GF_EXP, GF_LOG_ERROR, -ret, NFS_MSG_PARSE_FAIL,
+ "Critical error: %s", strerror(-ret));
+ /* Return values less than 0
+ * indicate critical failures (null parameters,
+ * failure to allocate memory, etc).
+ */
+ goto free_and_out;
+ }
+ if (ret != 0) {
+ if (ret == GF_EXP_PARSE_ITEM_FAILURE)
+ /* Cannot change to gf_msg.
+ * gf_msg not giving output to STDOUT
+ * Bug id : BZ1215017
+ */
+ gf_log(GF_EXP, GF_LOG_WARNING, "Error parsing netgroups for: %s",
+ line);
+ /* Even though parsing failed for the netgroups we should let
+ * host parsing proceed.
+ */
+ netgroups_failed = _gf_true;
+ }
+
+ /* Parse the host part of the string */
+ ret = __exp_line_host_parse(line, &hosts);
+ if (ret < 0) {
+ gf_msg(GF_EXP, GF_LOG_ERROR, -ret, NFS_MSG_PARSE_FAIL,
+ "Critical error: %s", strerror(-ret));
+ goto free_and_out;
+ }
+ if (ret != 0) {
+ if (ret == GF_EXP_PARSE_ITEM_FAILURE)
+ gf_msg(GF_EXP, GF_LOG_WARNING, 0, NFS_MSG_PARSE_FAIL,
+ "Error parsing hosts for: %s", line);
+ /* If netgroups parsing failed, AND
+ * host parsing failed, then there's something really
+ * wrong with this line, so we're just going to
+ * log it and fail out.
+ */
+ if (netgroups_failed)
+ goto free_and_out;
+ }
+
+ expdir->hosts = hosts;
+ expdir->netgroups = netgroups;
+ *dir = expdir;
+ goto out;
free_and_out:
- _export_dir_deinit (expdir);
+ _export_dir_deinit(expdir);
out:
- return ret;
+ return ret;
}
struct export_item *
-exp_dir_get_netgroup (const struct export_dir *expdir, const char *netgroup)
+exp_dir_get_netgroup(const struct export_dir *expdir, const char *netgroup)
{
- struct export_item *lookup_res = NULL;
- data_t *dict_res = NULL;
+ struct export_item *lookup_res = NULL;
+ data_t *dict_res = NULL;
- GF_VALIDATE_OR_GOTO (GF_EXP, expdir, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, netgroup, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, expdir, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, netgroup, out);
- if (!expdir->netgroups)
- goto out;
+ if (!expdir->netgroups)
+ goto out;
- dict_res = dict_get (expdir->netgroups, (char *)netgroup);
- if (!dict_res) {
- gf_msg_debug (GF_EXP, 0, "%s not found for %s",
- netgroup, expdir->dir_name);
- goto out;
- }
+ dict_res = dict_get(expdir->netgroups, (char *)netgroup);
+ if (!dict_res) {
+ gf_msg_debug(GF_EXP, 0, "%s not found for %s", netgroup,
+ expdir->dir_name);
+ goto out;
+ }
- lookup_res = (struct export_item *)dict_res->data;
+ lookup_res = (struct export_item *)dict_res->data;
out:
- return lookup_res;
+ return lookup_res;
}
/**
* exp_dir_get_host -- Given a host string and an exports directory structure,
@@ -1254,35 +1259,33 @@ out:
* failure: NULL
*/
struct export_item *
-exp_dir_get_host (const struct export_dir *expdir, const char *host)
+exp_dir_get_host(const struct export_dir *expdir, const char *host)
{
- struct export_item *lookup_res = NULL;
- data_t *dict_res = NULL;
+ struct export_item *lookup_res = NULL;
+ data_t *dict_res = NULL;
- GF_VALIDATE_OR_GOTO (GF_EXP, expdir, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, host, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, expdir, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, host, out);
- if (!expdir->hosts)
- goto out;
+ if (!expdir->hosts)
+ goto out;
+
+ dict_res = dict_get(expdir->hosts, (char *)host);
+ if (!dict_res) {
+ gf_msg_debug(GF_EXP, 0, "%s not found for %s", host, expdir->dir_name);
- dict_res = dict_get (expdir->hosts, (char *)host);
+ /* Check if wildcards are allowed for the host */
+ dict_res = dict_get(expdir->hosts, "*");
if (!dict_res) {
- gf_msg_debug (GF_EXP, 0, "%s not found for %s",
- host, expdir->dir_name);
-
- /* Check if wildcards are allowed for the host */
- dict_res = dict_get (expdir->hosts, "*");
- if (!dict_res) {
- goto out;
- }
+ goto out;
}
+ }
- lookup_res = (struct export_item *)dict_res->data;
+ lookup_res = (struct export_item *)dict_res->data;
out:
- return lookup_res;
+ return lookup_res;
}
-
/**
* exp_file_get_dir -- Return an export dir given a directory name
* Does a lookup from the dict in the file structure.
@@ -1294,38 +1297,37 @@ out:
* failure: NULL
*/
struct export_dir *
-exp_file_get_dir (const struct exports_file *file, const char *dir)
+exp_file_get_dir(const struct exports_file *file, const char *dir)
{
- struct export_dir *lookup_res = NULL;
- data_t *dict_res = NULL;
- char *dirdup = NULL;
- size_t dirlen = 0;
+ struct export_dir *lookup_res = NULL;
+ data_t *dict_res = NULL;
+ char *dirdup = NULL;
+ size_t dirlen = 0;
- GF_VALIDATE_OR_GOTO (GF_EXP, file, out);
- GF_VALIDATE_OR_GOTO (GF_EXP, dir, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, file, out);
+ GF_VALIDATE_OR_GOTO(GF_EXP, dir, out);
- dirlen = strlen (dir);
- if (dirlen <= 0)
- goto out;
+ dirlen = strlen(dir);
+ if (dirlen <= 0)
+ goto out;
- dirdup = (char *)dir; /* Point at the directory */
+ dirdup = (char *)dir; /* Point at the directory */
- /* If directories don't contain a leading slash */
- if (*dir != '/') {
- dirdup = alloca (dirlen + 2); /* Leading slash & null byte */
- snprintf (dirdup, dirlen + 2, "/%s", dir);
- }
+ /* If directories don't contain a leading slash */
+ if (*dir != '/') {
+ dirdup = alloca(dirlen + 2); /* Leading slash & null byte */
+ snprintf(dirdup, dirlen + 2, "/%s", dir);
+ }
- dict_res = dict_get (file->exports_dict, dirdup);
- if (!dict_res) {
- gf_msg_debug (GF_EXP, 0, "%s not found in %s", dirdup,
- file->filename);
- goto out;
- }
+ dict_res = dict_get(file->exports_dict, dirdup);
+ if (!dict_res) {
+ gf_msg_debug(GF_EXP, 0, "%s not found in %s", dirdup, file->filename);
+ goto out;
+ }
- lookup_res = (struct export_dir *)dict_res->data;
+ lookup_res = (struct export_dir *)dict_res->data;
out:
- return lookup_res;
+ return lookup_res;
}
/**
@@ -1347,129 +1349,130 @@ out:
* Externally usable.
*/
int
-exp_file_parse (const char *filepath, struct exports_file **expfile,
- struct mount3_state *ms)
+exp_file_parse(const char *filepath, struct exports_file **expfile,
+ struct mount3_state *ms)
{
- FILE *fp = NULL;
- struct exports_file *file = NULL;
- size_t len = 0;
- int ret = -EINVAL;
- unsigned long line_number = 0;
- char *line = NULL;
- struct export_dir *expdir = NULL;
-
- /* Sets whether we we should parse the entire file or just that which
- * is present in the mount state */
- gf_boolean_t parse_complete_file = _gf_false;
-
- GF_VALIDATE_OR_GOTO (GF_EXP, expfile, parse_done);
-
- if (!ms) {
- /* If mount state is null that means that we
- * should go through and parse the whole file
- * since we don't have anything to compare against.
- */
- parse_complete_file = _gf_true;
+ FILE *fp = NULL;
+ struct exports_file *file = NULL;
+ size_t len = 0;
+ int ret = -EINVAL;
+ unsigned long line_number = 0;
+ char *line = NULL;
+ struct export_dir *expdir = NULL;
+
+ /* Sets whether we we should parse the entire file or just that which
+ * is present in the mount state */
+ gf_boolean_t parse_complete_file = _gf_false;
+
+ GF_VALIDATE_OR_GOTO(GF_EXP, expfile, parse_done);
+
+ if (!ms) {
+ /* If mount state is null that means that we
+ * should go through and parse the whole file
+ * since we don't have anything to compare against.
+ */
+ parse_complete_file = _gf_true;
+ }
+
+ fp = fopen(filepath, "r");
+ if (!fp) {
+ ret = -errno;
+ goto parse_done;
+ }
+
+ ret = _exp_init_parsers();
+ if (ret < 0)
+ goto parse_done;
+
+ /* Process the file line by line, with each line being parsed into
+ * an struct export_dir struct. If 'parse_complete_file' is set to TRUE
+ * then
+ */
+ while (getline(&line, &len, fp) != -1) {
+ line_number++; /* Keeping track of line number allows us to
+ * to log which line numbers were wrong
+ */
+ strtok(line, "\n"); /* removes the newline character from
+ * the line
+ */
+
+ /* Parse the line from the file into an struct export_dir
+ * structure. The process is as follows:
+ * Given a line like :
+ * "/vol @test(sec=sys,rw,anonuid=0) 10.35.11.31(sec=sys,rw)"
+ *
+ * This function will allocate an export dir and set its name
+ * to '/vol', using the function _exp_line_dir_parse ().
+ *
+ * Then it will extract the netgroups from the line, in this
+ * case it would be '@test(sec=sys,rw,anonuid=0)', and set the
+ * item structure's name to '@test'.
+ * It will also extract the options from that string and parse
+ * them into an struct export_options which will be pointed
+ * to by the item structure. This will be put into a dict
+ * which will be pointed to by the export directory structure.
+ *
+ * The same process happens above for the host string
+ * '10.35.11.32(sec=sys,rw)'
+ */
+ ret = _exp_line_parse(line, &expdir, parse_complete_file, ms);
+ if (ret == -ENOMEM) {
+ /* If we get memory allocation errors, we really should
+ * not continue parsing, so just free the allocated
+ * memory and exit.
+ */
+ goto free_and_done;
}
- fp = fopen (filepath, "r");
- if (!fp) {
- ret = -errno;
- goto parse_done;
+ if (ret < 0) {
+ gf_msg(GF_EXP, GF_LOG_ERROR, -ret, NFS_MSG_PARSE_FAIL,
+ "Failed to parse line #%lu", line_number);
+ continue; /* Skip entering this line and continue */
}
- ret = _exp_init_parsers ();
- if (ret < 0)
- goto parse_done;
+ if (ret == GF_EXP_PARSE_LINE_IGNORING) {
+ /* This just means the line was empty or started with a
+ * '#' or a ' ' and we are ignoring it.
+ */
+ gf_msg_debug(GF_EXP, 0,
+ "Ignoring line #%lu because it started "
+ "with a %c",
+ line_number, *line);
+ continue;
+ }
- /* Process the file line by line, with each line being parsed into
- * an struct export_dir struct. If 'parse_complete_file' is set to TRUE
- * then
- */
- while (getline (&line, &len, fp) != -1) {
- line_number++; /* Keeping track of line number allows us to
- * to log which line numbers were wrong
- */
- strtok (line, "\n"); /* removes the newline character from
- * the line
- */
-
- /* Parse the line from the file into an struct export_dir
- * structure. The process is as follows:
- * Given a line like :
- * "/vol @test(sec=sys,rw,anonuid=0) 10.35.11.31(sec=sys,rw)"
- *
- * This function will allocate an export dir and set its name
- * to '/vol', using the function _exp_line_dir_parse ().
- *
- * Then it will extract the netgroups from the line, in this
- * case it would be '@test(sec=sys,rw,anonuid=0)', and set the
- * item structure's name to '@test'.
- * It will also extract the options from that string and parse
- * them into an struct export_options which will be pointed
- * to by the item structure. This will be put into a dict
- * which will be pointed to by the export directory structure.
- *
- * The same process happens above for the host string
- * '10.35.11.32(sec=sys,rw)'
- */
- ret = _exp_line_parse (line, &expdir, parse_complete_file, ms);
- if (ret == -ENOMEM) {
- /* If we get memory allocation errors, we really should
- * not continue parsing, so just free the allocated
- * memory and exit.
- */
- goto free_and_done;
- }
-
- if (ret < 0) {
- gf_msg (GF_EXP, GF_LOG_ERROR, -ret, NFS_MSG_PARSE_FAIL,
- "Failed to parse line #%lu", line_number);
- continue; /* Skip entering this line and continue */
- }
-
- if (ret == GF_EXP_PARSE_LINE_IGNORING) {
- /* This just means the line was empty or started with a
- * '#' or a ' ' and we are ignoring it.
- */
- gf_msg_debug (GF_EXP, 0,
- "Ignoring line #%lu because it started "
- "with a %c", line_number, *line);
- continue;
- }
-
- if (!file) {
- file = _exports_file_init ();
- GF_CHECK_ALLOC_AND_LOG (GF_EXP, file, ret,
- "Allocation error while "
- "allocating file struct",
- parse_done);
-
- file->filename = gf_strdup (filepath);
- GF_CHECK_ALLOC_AND_LOG (GF_EXP, file, ret,
- "Allocation error while "
- "duping filepath",
- free_and_done);
- }
-
- /* If the parsing is successful store the export directory
- * in the file structure.
- */
- _exp_file_insert (file, expdir);
+ if (!file) {
+ file = _exports_file_init();
+ GF_CHECK_ALLOC_AND_LOG(GF_EXP, file, ret,
+ "Allocation error while "
+ "allocating file struct",
+ parse_done);
+
+ file->filename = gf_strdup(filepath);
+ GF_CHECK_ALLOC_AND_LOG(GF_EXP, file, ret,
+ "Allocation error while "
+ "duping filepath",
+ free_and_done);
}
- /* line got allocated through getline(), don't use GF_FREE() for it */
- free (line);
+ /* If the parsing is successful store the export directory
+ * in the file structure.
+ */
+ _exp_file_insert(file, expdir);
+ }
- *expfile = file;
- goto parse_done;
+ /* line got allocated through getline(), don't use GF_FREE() for it */
+ free(line);
+
+ *expfile = file;
+ goto parse_done;
free_and_done:
- exp_file_deinit (file);
+ exp_file_deinit(file);
parse_done:
- if (fp)
- fclose (fp);
- _exp_deinit_parsers ();
- return ret;
+ if (fp)
+ fclose(fp);
+ _exp_deinit_parsers();
+ return ret;
}