diff options
Diffstat (limited to 'libglusterfs/src/graph.y')
| -rw-r--r-- | libglusterfs/src/graph.y | 211 |
1 files changed, 113 insertions, 98 deletions
diff --git a/libglusterfs/src/graph.y b/libglusterfs/src/graph.y index 92267c4c743..e63febdc08b 100644 --- a/libglusterfs/src/graph.y +++ b/libglusterfs/src/graph.y @@ -18,12 +18,15 @@ #include <sys/mman.h> #include <sys/types.h> #include <sys/wait.h> +#include <pthread.h> #define RELAX_POISONING -#include "xlator.h" -#include "graph-utils.h" -#include "logging.h" +#include "glusterfs/xlator.h" +#include "glusterfs/graph-utils.h" +#include "glusterfs/logging.h" +#include "glusterfs/syscall.h" +#include "glusterfs/libglusterfs-messages.h" static int new_volume (char *name); static int volume_type (char *type); @@ -37,8 +40,8 @@ static void option_error (void); #define YYSTYPE char * #define GF_CMD_BUFFER_LEN (8 * GF_UNIT_KB) -int yyerror (const char *); -int yylex (); +int graphyyerror (const char *); +int graphyylex (); %} @@ -78,11 +81,11 @@ glusterfs_graph_t *construct; static void type_error (void) { - extern int yylineno; + extern int graphyylineno; - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_VOLFILE_PARSE_ERROR, "Volume %s, before line %d: Please specify volume type", - curr->name, yylineno); + curr->name, graphyylineno); return; } @@ -90,11 +93,11 @@ type_error (void) static void sub_error (void) { - extern int yylineno; + extern int graphyylineno; - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_VOLFILE_PARSE_ERROR, "Volume %s, before line %d: Please specify subvolumes", - curr->name, yylineno); + curr->name, graphyylineno); return; } @@ -102,12 +105,12 @@ sub_error (void) static void option_error (void) { - extern int yylineno; + extern int graphyylineno; - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_VOLFILE_PARSE_ERROR, "Volume %s, before line %d: Please specify " "option <key> <value>", - curr->name, yylineno); + curr->name, graphyylineno); return; } @@ -115,21 +118,20 @@ option_error (void) static int new_volume (char *name) { - extern int yylineno; + extern int graphyylineno; xlator_t *trav = NULL; int ret = 0; if (!name) { - gf_log ("parser", GF_LOG_DEBUG, - "Invalid argument name: '%s'", name); + gf_msg_debug ("parser", 0,"Invalid argument name"); ret = -1; goto out; } if (curr) { - gf_log ("parser", GF_LOG_ERROR, - "new volume (%s) defintion in line %d unexpected", - name, yylineno); + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "new volume (%s) definition in line %d unexpected", + name, graphyylineno); ret = -1; goto out; } @@ -138,7 +140,6 @@ new_volume (char *name) gf_common_mt_xlator_t); if (!curr) { - gf_log ("parser", GF_LOG_ERROR, "Out of memory"); ret = -1; goto out; } @@ -147,9 +148,9 @@ new_volume (char *name) while (trav) { if (!strcmp (name, trav->name)) { - gf_log ("parser", GF_LOG_ERROR, - "Line %d: volume '%s' defined again", - yylineno, name); + gf_msg ("parser", GF_LOG_ERROR, 0, + LG_MSG_VOLFILE_PARSE_ERROR, "Line %d: volume " + "'%s' defined again", graphyylineno, name); ret = -1; goto out; } @@ -163,7 +164,8 @@ new_volume (char *name) goto out; } - curr->options = get_new_dict (); + INIT_LIST_HEAD(&curr->volume_options); + curr->options = dict_new (); if (!curr->options) { GF_FREE (curr->name); @@ -181,8 +183,9 @@ new_volume (char *name) construct->first = curr; construct->xl_count++; + curr->xl_id = construct->xl_count; - gf_log ("parser", GF_LOG_TRACE, "New node for '%s'", name); + gf_msg_trace ("parser", 0, "New node for '%s'", name); out: GF_FREE (name); @@ -194,26 +197,26 @@ out: static int volume_type (char *type) { - extern int yylineno; + extern int graphyylineno; int32_t ret = 0; if (!type) { - gf_log ("parser", GF_LOG_DEBUG, "Invalid argument type"); + gf_msg_debug ("parser", 0, "Invalid argument type"); ret = -1; goto out; } ret = xlator_set_type (curr, type); if (ret) { - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Volume '%s', line %d: type '%s' is not valid or " "not found on this machine", - curr->name, yylineno, type); + curr->name, graphyylineno, type); ret = -1; goto out; } - gf_log ("parser", GF_LOG_TRACE, "Type:%s:%s", curr->name, type); + gf_msg_trace ("parser", 0, "Type:%s:%s", curr->name, type); out: GF_FREE (type); @@ -225,30 +228,30 @@ out: static int volume_option (char *key, char *value) { - extern int yylineno; + extern int graphyylineno; int ret = 0; char *set_value = NULL; if (!key || !value){ - gf_log ("parser", GF_LOG_ERROR, "Invalid argument"); + gf_msg ("parser", GF_LOG_ERROR, 0, + LG_MSG_INVALID_VOLFILE_ENTRY, "Invalid argument"); ret = -1; goto out; } set_value = gf_strdup (value); - ret = dict_set_dynstr (curr->options, key, set_value); + ret = dict_set_option (curr->options, key, set_value); if (ret == 1) { - gf_log ("parser", GF_LOG_ERROR, - "Volume '%s', line %d: duplicate entry " - "('option %s') present", - curr->name, yylineno, key); + gf_msg ("parser", GF_LOG_ERROR, 0, + LG_MSG_INVALID_VOLFILE_ENTRY, "Volume '%s', line %d: " + "duplicate entry ('option %s') present", + curr->name, graphyylineno, key); ret = -1; goto out; } - gf_log ("parser", GF_LOG_TRACE, "Option:%s:%s:%s", - curr->name, key, value); + gf_msg_trace ("parser", 0, "Option:%s:%s:%s", curr->name, key, value); out: GF_FREE (key); @@ -261,12 +264,13 @@ out: static int volume_sub (char *sub) { - extern int yylineno; + extern int graphyylineno; xlator_t *trav = NULL; int ret = 0; if (!sub) { - gf_log ("parser", GF_LOG_ERROR, "Invalid subvolumes argument"); + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Invalid subvolumes argument"); ret = -1; goto out; } @@ -280,30 +284,28 @@ volume_sub (char *sub) } if (!trav) { - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_SUB_VOLUME_ERROR, "Volume '%s', line %d: subvolume '%s' is not defined " - "prior to usage", - curr->name, yylineno, sub); + "prior to usage",curr->name, graphyylineno, sub); ret = -1; goto out; } if (trav == curr) { - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Volume '%s', line %d: has '%s' itself as subvolume", - curr->name, yylineno, sub); + curr->name, graphyylineno, sub); ret = -1; goto out; } ret = glusterfs_xlator_link (curr, trav); if (ret) { - gf_log ("parser", GF_LOG_ERROR, "Out of memory"); ret = -1; goto out; } - gf_log ("parser", GF_LOG_TRACE, "child:%s->%s", curr->name, sub); + gf_msg_trace ("parser", 0, "child:%s->%s", curr->name, sub); out: GF_FREE (sub); @@ -316,11 +318,11 @@ static int volume_end (void) { if (!curr->fops) { - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR, "\"type\" not specified for volume %s", curr->name); return -1; } - gf_log ("parser", GF_LOG_TRACE, "end:%s", curr->name); + gf_msg_trace ("parser", 0, "end:%s", curr->name); curr = NULL; return 0; @@ -328,55 +330,52 @@ volume_end (void) int -yywrap () +graphyywrap () { return 1; } int -yyerror (const char *str) +graphyyerror (const char *str) { - extern char *yytext; - extern int yylineno; - - if (curr && curr->name && yytext) { - if (!strcmp (yytext, "volume")) { - gf_log ("parser", GF_LOG_ERROR, - "'end-volume' not defined for volume '%s'", - curr->name); - } else if (!strcmp (yytext, "type")) { - gf_log ("parser", GF_LOG_ERROR, + extern char *graphyytext; + extern int graphyylineno; + + if (curr && curr->name && graphyytext) { + if (!strcmp (graphyytext, "volume")) { + gf_msg ("parser", GF_LOG_ERROR, 0, + LG_MSG_VOLUME_ERROR, "'end-volume' not" + " defined for volume '%s'", curr->name); + } else if (!strcmp (graphyytext, "type")) { + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR, "line %d: duplicate 'type' defined for " - "volume '%s'", - yylineno, curr->name); - } else if (!strcmp (yytext, "subvolumes")) { - gf_log ("parser", GF_LOG_ERROR, - "line %d: duplicate 'subvolumes' defined for " - "volume '%s'", - yylineno, curr->name); + "volume '%s'", graphyylineno, curr->name); + } else if (!strcmp (graphyytext, "subvolumes")) { + gf_msg ("parser", GF_LOG_ERROR, 0, + LG_MSG_SUB_VOLUME_ERROR, "line %d: duplicate " + "'subvolumes' defined for volume '%s'", + graphyylineno, curr->name); } else if (curr) { - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_SYNTAX_ERROR, "syntax error: line %d (volume '%s'): \"%s\"" "\nallowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume'()", - yylineno, curr->name, - yytext); + graphyylineno, curr->name, graphyytext); } else { - gf_log ("parser", GF_LOG_ERROR, + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_SYNTAX_ERROR, "syntax error: line %d (just after volume " "'%s'): \"%s\"\n(%s)", - yylineno, curr->name, - yytext, + graphyylineno, curr->name, graphyytext, "allowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume'"); } } else { - gf_log ("parser", GF_LOG_ERROR, - "syntax error in line %d: \"%s\" \n" + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_SYNTAX_ERROR, + "syntax error in line %d: \"%s\"\n" "(allowed tokens are 'volume', 'type', " "'subvolumes', 'option', 'end-volume')\n", - yylineno, yytext); + graphyylineno, graphyytext); } return -1; @@ -394,7 +393,8 @@ execute_cmd (char *cmd, char **result, size_t size) fpp = popen (cmd, "r"); if (!fpp) { - gf_log ("parser", GF_LOG_ERROR, "%s: failed to popen", cmd); + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_FILE_OP_FAILED, + "%s: failed to popen", cmd); return -1; } @@ -444,7 +444,6 @@ preprocess (FILE *srcfp, FILE *dstfp) cmd = GF_CALLOC (cmd_buf_size, 1, gf_common_mt_char); if (cmd == NULL) { - gf_log ("parser", GF_LOG_ERROR, "Out of memory"); return -1; } @@ -452,7 +451,6 @@ preprocess (FILE *srcfp, FILE *dstfp) gf_common_mt_char); if (result == NULL) { GF_FREE (cmd); - gf_log ("parser", GF_LOG_ERROR, "Out of memory"); return -1; } @@ -481,6 +479,7 @@ preprocess (FILE *srcfp, FILE *dstfp) cmd_buf_size *= 2; cmd = GF_REALLOC (cmd, cmd_buf_size); if (cmd == NULL) { + GF_FREE (result); return -1; } @@ -513,15 +512,16 @@ preprocess (FILE *srcfp, FILE *dstfp) } if (in_backtick) { - gf_log ("parser", GF_LOG_ERROR, - "Unterminated backtick in volume specfication file at line (%d), column (%d).", - line, column); + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR, + "Unterminated backtick in volume specification file at " + "line (%d), column (%d).", line, column); ret = -1; } out: fseek (srcfp, 0L, SEEK_SET); fseek (dstfp, 0L, SEEK_SET); + GF_FREE (cmd); GF_FREE (result); @@ -529,7 +529,7 @@ out: } -extern FILE *yyin; +extern FILE *graphyyin; glusterfs_graph_t * glusterfs_graph_new () @@ -543,6 +543,9 @@ glusterfs_graph_new () INIT_LIST_HEAD (&graph->list); + pthread_mutex_init(&graph->mutex, NULL); + pthread_cond_init(&graph->child_down_cond, NULL); + gettimeofday (&graph->dob, NULL); return graph; @@ -556,36 +559,47 @@ glusterfs_graph_construct (FILE *fp) int tmp_fd = -1; glusterfs_graph_t *graph = NULL; FILE *tmp_file = NULL; - char template[PATH_MAX] = {0}; + char template[] = "/tmp/tmp.XXXXXX"; + static pthread_mutex_t graph_mutex = PTHREAD_MUTEX_INITIALIZER; graph = glusterfs_graph_new (); if (!graph) goto err; - strcpy (template, "/tmp/tmp.XXXXXX"); + /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ tmp_fd = mkstemp (template); if (-1 == tmp_fd) goto err; + ret = sys_unlink (template); + if (ret < 0) { + gf_msg ("parser", GF_LOG_WARNING, 0, LG_MSG_FILE_OP_FAILED, + "Unable to delete file: %s", template); + } + tmp_file = fdopen (tmp_fd, "w+b"); if (!tmp_file) goto err; ret = preprocess (fp, tmp_file); if (ret < 0) { - gf_log ("parser", GF_LOG_ERROR, "parsing of backticks failed"); + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_BACKTICK_PARSE_FAILED, + "parsing of backticks failed"); goto err; } - yyin = tmp_file; - construct = graph; - ret = yyparse (); - construct = NULL; + pthread_mutex_lock (&graph_mutex); + { + graphyyin = tmp_file; + construct = graph; + ret = yyparse (); + construct = NULL; + } + pthread_mutex_unlock (&graph_mutex); if (ret == 1) { - gf_log ("parser", GF_LOG_DEBUG, - "parsing of volfile failed, please review it " - "once more"); + gf_msg_debug ("parser", 0, "parsing of volfile failed, please " + "review it once more"); goto err; } @@ -595,9 +609,10 @@ err: if (tmp_file) { fclose (tmp_file); } else { - gf_log ("parser", GF_LOG_ERROR, "cannot create temporary file"); + gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_FILE_OP_FAILED, + "cannot create temporary file"); if (-1 != tmp_fd) - close (tmp_fd); + sys_close (tmp_fd); } glusterfs_graph_destroy (graph); |
