static int _print_volume_options(dict_t *d, char *k, data_t *v, void *tmp) { 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) { #define GPPRINTF(gp, fmt, ...) do { \ ret = gpprintf (gp, fmt, ## __VA_ARGS__); \ if (ret == -1) \ goto out; \ else \ len += ret; \ } while (0) xlator_t *trav = NULL; data_pair_t *pair = NULL; xlator_list_t *xch = NULL; int ret = 0; ssize_t len = 0; if (!graph->first) return 0; for (trav = graph->first; trav->next; trav = trav->next); for (; trav; trav = trav->prev) { 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); if (trav->children) { GPPRINTF (gp, " subvolumes"); for (xch = trav->children; xch; xch = xch->next) GPPRINTF (gp, " %s", xch->xlator->name); GPPRINTF (gp, "\n"); } GPPRINTF (gp, "end-volume\n"); if (trav != graph->first) GPPRINTF (gp, "\n"); } out: if (ret == -1) { gf_log ("graph-print", GF_LOG_ERROR, "printing failed"); return -1; } return len; #undef GPPRINTF }
static int glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph) { xlator_t *trav = NULL; xlator_list_t *xch = NULL; int ret = 0; ssize_t len = 0; if (!graph->first) return 0; for (trav = graph->first; trav->next; trav = trav->next); for (; trav; trav = trav->prev) { GPPRINTF (gp, "volume %s\n type %s\n", trav->name, trav->type); ret = dict_foreach (trav->options, _print_volume_options, gp); if (ret) goto out; if (trav->children) { GPPRINTF (gp, " subvolumes"); for (xch = trav->children; xch; xch = xch->next) GPPRINTF (gp, " %s", xch->xlator->name); GPPRINTF (gp, "\n"); } GPPRINTF (gp, "end-volume\n"); if (trav != graph->first) GPPRINTF (gp, "\n"); } out: len = gp->len; if (ret == -1) { gf_msg ("graph-print", GF_LOG_ERROR, 0, LG_MSG_PRINT_FAILED, "printing failed"); return -1; } return len; #undef GPPRINTF }