summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/graph.c
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2010-10-02 07:30:39 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-10-02 06:30:23 -0700
commitef44323b4ba58fa8c1eb89105851983f828dd91b (patch)
treedcbfd98a87e1987145ab97366527b4e6e8900902 /libglusterfs/src/graph.c
parent067d0e476abe42f1e290039cb903928080e90d8d (diff)
volgen: reimplement volgen
Generating a volfile occurs in two steps: - Build a graph (ie, glusterfs_graph_t instance) by graph manipulation primitives - Write out the graph to a file by the the graph printing API. Graph builder routines can optionally make use of a "modifier dict", which can contain overrides wrt. volume options. This can be used for a "dry-run" graph generation. Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1750 (clean up volgen) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1750
Diffstat (limited to 'libglusterfs/src/graph.c')
-rw-r--r--libglusterfs/src/graph.c71
1 files changed, 46 insertions, 25 deletions
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);