Blob Blame History Raw
From c44c4f3d98ad758037c24f81c05997c16755e433 Mon Sep 17 00:00:00 2001
From: Samikshan Bairagya <samikshan@gmail.com>
Date: Wed, 30 Nov 2016 14:35:59 +0530
Subject: [PATCH 211/227] glusterd, cli: Fix volume options output format in
 get-state cli

Currently the get-state cli outputs the volume options in the
following format:

Volume1.rebalance.skipped: 0
Volume1.rebalance.lookedup: 0
Volume1.rebalance.files: 0
Volume1.rebalance.data: 0Bytes
[Volume1.options]
features.barrier: on
transport.address-family: inet
performance.readdir-ahead: on
nfs.disable: on

Volume2.name: tv2
Volume2.id: 35854708-bb72-45a5-bdbd-77c51e5ebfb9
Volume2.type: Distribute

This above format is a valid ini file format syntactically, but is
not very easily parseable. This patch changes the format to look like
the following and should be more easily parseable:

Volume1.rebalance.skipped: 0
Volume1.rebalance.lookedup: 0
Volume1.rebalance.files: 0
Volume1.rebalance.data: 0Bytes
Volume1.options.features.barrier: on
Volume1.options.transport.address-family: inet
Volume1.options.performance.readdir-ahead: on
Volume1.options.nfs.disable: on

Volume2.name: tv2
Volume2.id: 35854708-bb72-45a5-bdbd-77c51e5ebfb9
Volume2.type: Distribute

>Reviewed-on: http://review.gluster.org/15975
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Shubhendu Tripathi <shtripat@redhat.com>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>

Change-Id: I9768b45de288d9817ec669d3a801874eb1914750
BUG: 1397257
Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/91885
Tested-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd-handler.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index a41960d..f8dc91b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -56,6 +56,7 @@
 #endif
 
 extern glusterd_op_info_t opinfo;
+static int volcount;
 
 int glusterd_big_locked_notify (struct rpc_clnt *rpc, void *mydata,
                                 rpc_clnt_event_t event,
@@ -4950,7 +4951,7 @@ glusterd_handle_get_vol_opt (rpcsvc_request_t *req)
 }
 
 static int
-glusterd_print_dict_options (dict_t *opts, char *key, data_t *val, void *data)
+glusterd_print_global_options (dict_t *opts, char *key, data_t *val, void *data)
 {
         FILE *fp = NULL;
 
@@ -4968,6 +4969,21 @@ out:
 }
 
 static int
+glusterd_print_volume_options (dict_t *opts, char *key, data_t *val, void *data)
+{
+        FILE *fp = NULL;
+
+        GF_VALIDATE_OR_GOTO (THIS->name, key, out);
+        GF_VALIDATE_OR_GOTO (THIS->name, val, out);
+        GF_VALIDATE_OR_GOTO (THIS->name, data, out);
+
+        fp = (FILE *) data;
+        fprintf (fp, "Volume%d.options.%s: %s\n", volcount, key, val->data);
+out:
+        return 0;
+}
+
+static int
 glusterd_print_snapinfo_by_vol (FILE *fp, glusterd_volinfo_t *volinfo, int volcount)
 {
         int                     ret = -1;
@@ -5130,7 +5146,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
         fprintf (fp, "\n[Global options]\n");
 
         if (priv->opts)
-                dict_foreach (priv->opts, glusterd_print_dict_options, fp);
+                dict_foreach (priv->opts, glusterd_print_global_options, fp);
 
         rcu_read_lock ();
         fprintf (fp, "\n[Peers]\n");
@@ -5353,10 +5369,11 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
                                  volinfo->rep_brick.dst_brick->hostname,
                                  volinfo->rep_brick.dst_brick->path);
                 }
-                fprintf (fp, "[Volume%d.options]\n", count);
+
+                volcount = count;
                 if (volinfo->dict)
                         dict_foreach (volinfo->dict,
-                                      glusterd_print_dict_options, fp);
+                                      glusterd_print_volume_options, fp);
 
                 fprintf (fp, "\n");
         }
-- 
2.9.3