summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/graph-utils.h2
-rw-r--r--libglusterfs/src/graph.c71
-rw-r--r--libglusterfs/src/graph.y40
3 files changed, 51 insertions, 62 deletions
diff --git a/libglusterfs/src/graph-utils.h b/libglusterfs/src/graph-utils.h
index 359cdcc7a34..c1c8c36d703 100644
--- a/libglusterfs/src/graph-utils.h
+++ b/libglusterfs/src/graph-utils.h
@@ -26,4 +26,6 @@ glusterfs_graph_print_file (FILE *file, glusterfs_graph_t *graph);
char *
glusterfs_graph_print_buf (glusterfs_graph_t *graph);
+int glusterfs_xlator_link (xlator_t *pxl, xlator_t *cxl);
+void glusterfs_graph_set_first (glusterfs_graph_t *graph, xlator_t *xl);
#endif
diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c
index 0c63c194d01..c821b3c2abc 100644
--- a/libglusterfs/src/graph.c
+++ b/libglusterfs/src/graph.c
@@ -124,12 +124,54 @@ _log_if_option_is_invalid (xlator_t *xl, data_pair_t *pair)
int
+glusterfs_xlator_link (xlator_t *pxl, xlator_t *cxl)
+{
+ xlator_list_t *xlchild = NULL;
+ xlator_list_t *xlparent = NULL;
+ xlator_list_t **tmp = NULL;
+
+ xlparent = (void *) GF_CALLOC (1, sizeof (*xlparent),
+ gf_common_mt_xlator_list_t);
+ if (!xlparent)
+ return -1;
+
+ xlchild = (void *) GF_CALLOC (1, sizeof (*xlchild),
+ gf_common_mt_xlator_list_t);
+ if (!xlchild) {
+ GF_FREE (xlparent);
+
+ return -1;
+ }
+
+ xlparent->xlator = pxl;
+ for (tmp = &cxl->parents; *tmp; tmp = &(*tmp)->next);
+ *tmp = xlparent;
+
+ xlchild->xlator = cxl;
+ for (tmp = &pxl->children; *tmp; tmp = &(*tmp)->next);
+ *tmp = xlchild;
+
+ return 0;
+}
+
+
+void
+glusterfs_graph_set_first (glusterfs_graph_t *graph, xlator_t *xl)
+{
+ xl->next = graph->first;
+ if (graph->first)
+ ((xlator_t *)graph->first)->prev = xl;
+ graph->first = xl;
+
+ graph->xl_count++;
+}
+
+
+int
glusterfs_graph_insert (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx,
const char *type, const char *name)
{
xlator_t *ixl = NULL;
- xlator_list_t *xlchild = NULL;
- xlator_list_t *xlparent = NULL;
if (!ctx->master) {
gf_log ("glusterfs", GF_LOG_ERROR,
@@ -160,32 +202,11 @@ glusterfs_graph_insert (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx,
return -1;
}
-
- /* children */
- xlchild = GF_CALLOC (sizeof (*xlchild), 1, gf_common_mt_xlator_list_t);
- if (!xlchild)
+ if (glusterfs_xlator_link (ixl, graph->top) == -1)
goto err;
- xlchild->xlator = graph->top;
- ixl->children = xlchild; xlchild = NULL;
-
-
- /* parent */
- xlparent = GF_CALLOC (sizeof (*xlparent), 1,
- gf_common_mt_xlator_list_t);
- if (!xlparent)
- goto err;
- xlparent->xlator = ixl;
-
- ixl->next = graph->first;
- graph->first = ixl;
-
- xlparent->next = ((xlator_t *)graph->top)->parents;
- ((xlator_t *)graph->top)->parents = xlparent;
-
+ glusterfs_graph_set_first (graph, ixl);
graph->top = ixl;
- graph->xl_count++;
-
return 0;
err:
xlator_destroy (ixl);
diff --git a/libglusterfs/src/graph.y b/libglusterfs/src/graph.y
index 14afaae6475..19dfff0fd6e 100644
--- a/libglusterfs/src/graph.y
+++ b/libglusterfs/src/graph.y
@@ -30,6 +30,7 @@
#include <sys/wait.h>
#include "xlator.h"
+#include "graph-utils.h"
#include "logging.h"
static int new_volume (char *name);
@@ -270,9 +271,6 @@ volume_sub (char *sub)
{
extern int yylineno;
xlator_t *trav = NULL;
- xlator_list_t *xlchild = NULL;
- xlator_list_t *tmp = NULL;
- xlator_list_t *xlparent = NULL;
int ret = 0;
if (!sub) {
@@ -306,45 +304,13 @@ volume_sub (char *sub)
goto out;
}
- xlparent = (void *) GF_CALLOC (1, sizeof (*xlparent),
- gf_common_mt_xlator_list_t);
-
- if (!xlparent) {
- gf_log ("parser", GF_LOG_ERROR, "Out of memory");
- ret = -1;
- goto out;
- }
-
- xlparent->xlator = curr;
-
- tmp = trav->parents;
- if (tmp == NULL) {
- trav->parents = xlparent;
- } else {
- while (tmp->next)
- tmp = tmp->next;
- tmp->next = xlparent;
- }
-
- xlchild = (void *) GF_CALLOC (1, sizeof(*xlchild),
- gf_common_mt_xlator_list_t);
- if (!xlchild) {
+ ret = glusterfs_xlator_link (curr, trav);
+ if (ret) {
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
ret = -1;
goto out;
}
- xlchild->xlator = trav;
-
- tmp = curr->children;
- if (tmp == NULL) {
- curr->children = xlchild;
- } else {
- while (tmp->next)
- tmp = tmp->next;
- tmp->next = xlchild;
- }
-
gf_log ("parser", GF_LOG_TRACE, "child:%s->%s", curr->name, sub);
out: