summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--glusterfsd/src/glusterfsd.c2
-rw-r--r--libglusterfs/src/common-utils.c95
-rw-r--r--libglusterfs/src/common-utils.h2
-rw-r--r--libglusterfs/src/xlator.c18
-rw-r--r--libglusterfs/src/xlator.h5
5 files changed, 108 insertions, 14 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index 28de24e8da6..1c746d9c44a 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -1765,7 +1765,7 @@ glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp)
goto out;
}
- gf_log_volume_file (fp);
+ gf_log_dump_graph (fp, graph);
ret = 0;
out:
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index c49e6d1f564..9375c5d407a 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -268,30 +268,101 @@ err:
}
+struct xldump {
+ int lineno;
+ FILE *logfp;
+};
+
+
+static int
+nprintf (struct xldump *dump, const char *fmt, ...)
+{
+ va_list ap;
+ int ret = 0;
+
+
+ ret += fprintf (dump->logfp, "%3d: ", ++dump->lineno);
+
+ va_start (ap, fmt);
+ ret += vfprintf (dump->logfp, fmt, ap);
+ va_end (ap);
+
+ ret += fprintf (dump->logfp, "\n");
+
+ return ret;
+}
+
+
+static int
+xldump_options (dict_t *this, char *key, data_t *value, void *d)
+{
+ nprintf (d, " option %s %s", key, value->data);
+ return 0;
+}
+
+
+static void
+xldump_subvolumes (xlator_t *this, void *d)
+{
+ xlator_list_t *subv = NULL;
+ int len = 0;
+ char *subvstr = NULL;
+
+ subv = this->children;
+ if (!this->children)
+ return;
+
+ for (subv = this->children; subv; subv = subv->next)
+ len += (strlen (subv->xlator->name) + 1);
+
+ subvstr = GF_CALLOC (1, len, gf_common_mt_strdup);
+
+ len = 0;
+ for (subv = this->children; subv; subv= subv->next)
+ len += sprintf (subvstr + len, "%s%s", subv->xlator->name,
+ subv->next ? " " : "");
+
+ nprintf (d, " subvolumes %s", subvstr);
+
+ GF_FREE (subvstr);
+}
+
+
+static void
+xldump (xlator_t *each, void *d)
+{
+ nprintf (d, "volume %s", each->name);
+ nprintf (d, " type %s", each->type);
+ dict_foreach (each->options, xldump_options, d);
+
+ xldump_subvolumes (each, d);
+
+ nprintf (d, "end-volume");
+ nprintf (d, "");
+}
+
+
void
-gf_log_volume_file (FILE *specfp)
+gf_log_dump_graph (FILE *specfp, glusterfs_graph_t *graph)
{
- int lcount = 0;
- char data[GF_UNIT_KB];
glusterfs_ctx_t *ctx;
+ struct xldump xld = {0, };
- ctx = THIS->ctx;
- fseek (specfp, 0L, SEEK_SET);
+ ctx = THIS->ctx;
+ xld.logfp = ctx->log.gf_log_logfile;
- fprintf (ctx->log.gf_log_logfile, "Given volfile:\n");
+ fprintf (ctx->log.gf_log_logfile, "Final graph:\n");
fprintf (ctx->log.gf_log_logfile,
"+---------------------------------------"
"---------------------------------------+\n");
- while (fgets (data, GF_UNIT_KB, specfp) != NULL){
- lcount++;
- fprintf (ctx->log.gf_log_logfile, "%3d: %s", lcount, data);
- }
+
+ xlator_foreach_depth_first (graph->top, xldump, &xld);
+
fprintf (ctx->log.gf_log_logfile,
- "\n+---------------------------------------"
+ "+---------------------------------------"
"---------------------------------------+\n");
fflush (ctx->log.gf_log_logfile);
- fseek (specfp, 0L, SEEK_SET);
}
static void
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 48416460e45..08a791e8bac 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -107,7 +107,7 @@ void gf_global_variable_init(void);
in_addr_t gf_resolve_ip (const char *hostname, void **dnscache);
-void gf_log_volume_file (FILE *specfp);
+void gf_log_dump_graph (FILE *specfp, glusterfs_graph_t *graph);
void gf_print_trace (int32_t signal, glusterfs_ctx_t *ctx);
#define VECTORSIZE(count) (count * (sizeof (struct iovec)))
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 3fb6eeebb09..9bde4fa8f6c 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -322,6 +322,24 @@ out:
}
+void
+xlator_foreach_depth_first (xlator_t *this,
+ void (*fn)(xlator_t *each, void *data),
+ void *data)
+{
+ xlator_list_t *subv = NULL;
+
+ subv = this->children;
+
+ while (subv) {
+ xlator_foreach_depth_first (subv->xlator, fn, data);
+ subv = subv->next;
+ }
+
+ fn (this, data);
+}
+
+
xlator_t *
xlator_search_by_name (xlator_t *any, const char *name)
{
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 1e21b63c55d..607f0dcecee 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -864,6 +864,11 @@ void xlator_foreach (xlator_t *this,
void *data),
void *data);
+void xlator_foreach_depth_first (xlator_t *this,
+ void (*fn) (xlator_t *each,
+ void *data),
+ void *data);
+
xlator_t *xlator_search_by_name (xlator_t *any, const char *name);
xlator_t *xlator_search_by_xl_type (xlator_t *any, const char *type);