diff options
| author | Anand Avati <avati@redhat.com> | 2013-03-21 15:09:01 -0700 | 
|---|---|---|
| committer | Anand Avati <avati@redhat.com> | 2013-03-24 23:30:46 -0700 | 
| commit | e701fb2713510f80a8a45c932637bcb52b5a103e (patch) | |
| tree | 845fdf0c0e5d4c029e15a733f3e458df0167b682 /libglusterfs/src/common-utils.c | |
| parent | 71cb0ad45b5be318e0ea2df91ea17e4c448a2a52 (diff) | |
glusterfsd: dump the in-memory graph rather than volfile
Currently we have been printing in the logfile, the volfile
verbatim as received from the server. However we perform
pre-processing on the graph we receive from the server, like
adding ACL translator, applying --xlator-option cli params,
etc.
So print the serialized in-memory graph as the "volfile" in
the log. This can be very handy to double check if certain
--xlator-option param actually got applied or not, and in
general is showing a "truer" representation of the real graph
actually used.
Change-Id: I0221dc56e21111b48a1ee3e5fe17a5ef820dc0c6
BUG: 924504
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/4708
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src/common-utils.c')
| -rw-r--r-- | libglusterfs/src/common-utils.c | 95 | 
1 files changed, 83 insertions, 12 deletions
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  | 
