summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/graph-print.c
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/graph-print.c')
-rw-r--r--libglusterfs/src/graph-print.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/libglusterfs/src/graph-print.c b/libglusterfs/src/graph-print.c
index 53d8643ee..d860d63b3 100644
--- a/libglusterfs/src/graph-print.c
+++ b/libglusterfs/src/graph-print.c
@@ -1,20 +1,11 @@
/*
- Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
This file is part of GlusterFS.
- GlusterFS is free software; you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- GlusterFS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see
- <http://www.gnu.org/licenses/>.
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
*/
#ifndef _CONFIG_H
@@ -26,7 +17,6 @@
#include "common-utils.h"
#include "xlator.h"
-#include "graph-mem-types.h"
#include "graph-utils.h"
@@ -34,6 +24,7 @@
struct gf_printer {
ssize_t (*write) (struct gf_printer *gp, char *buf, size_t len);
void *priv;
+ int len;
};
static ssize_t
@@ -90,19 +81,31 @@ gpprintf (struct gf_printer *gp, const char *format, ...)
return ret;
}
+#define GPPRINTF(gp, fmt, ...) do { \
+ ret = gpprintf (gp, fmt, ## __VA_ARGS__); \
+ if (ret == -1) \
+ goto out; \
+ else \
+ gp->len += ret; \
+ } while (0)
+
static int
-glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
+_print_volume_options (dict_t *d, char *k, data_t *v,
+ void *tmp)
{
-#define GPPRINTF(gp, fmt, ...) do { \
- ret = gpprintf (gp, fmt, ## __VA_ARGS__); \
- if (ret == -1) \
- goto out; \
- else \
- len += ret; \
-} while (0)
+ struct gf_printer *gp = tmp;
+ int ret = 0;
+ GPPRINTF (gp, " option %s %s\n", k, v->data);
+ return 0;
+out:
+ /* means, it is a failure */
+ return -1;
+}
+static int
+glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
+{
xlator_t *trav = NULL;
- data_pair_t *pair = NULL;
xlator_list_t *xch = NULL;
int ret = 0;
ssize_t len = 0;
@@ -115,11 +118,9 @@ glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
GPPRINTF (gp, "volume %s\n type %s\n", trav->name,
trav->type);
- for (pair = trav->options->members_list; pair && pair->next;
- pair = pair->next);
- for (; pair; pair = pair->prev)
- GPPRINTF (gp, " option %s %s\n", pair->key,
- pair->value->data);
+ ret = dict_foreach (trav->options, _print_volume_options, gp);
+ if (ret)
+ goto out;
if (trav->children) {
GPPRINTF (gp, " subvolumes");
@@ -135,7 +136,8 @@ glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
GPPRINTF (gp, "\n");
}
- out:
+out:
+ len = gp->len;
if (ret == -1) {
gf_log ("graph-print", GF_LOG_ERROR, "printing failed");
@@ -152,7 +154,7 @@ glusterfs_graph_print_file (FILE *file, glusterfs_graph_t *graph)
{
struct gf_printer gp = { .write = gp_write_file,
.priv = file
- };
+ };
return glusterfs_graph_print (&gp, graph);
}
@@ -166,7 +168,7 @@ glusterfs_graph_print_buf (glusterfs_graph_t *graph)
char *buf = NULL;
struct gf_printer gp = { .write = gp_write_buf,
.priv = &iov
- };
+ };
f = fopen ("/dev/null", "a");
if (!f) {
@@ -180,10 +182,8 @@ glusterfs_graph_print_buf (glusterfs_graph_t *graph)
if (len == -1)
return NULL;
- buf = GF_CALLOC (1, len + 1, gf_graph_mt_buf);
+ buf = GF_CALLOC (1, len + 1, gf_common_mt_graph_buf);
if (!buf) {
- gf_log ("graph-print", GF_LOG_ERROR, "Out of memory");
-
return NULL;
}
iov.iov_base = buf;