Patchwork [v2,BUG:1750,4/4] volgen: add a precise getter function which considers default values as well

login
register
Submitter Csaba Henk
Date 2010-10-03 00:14:16
Message ID <1286064856-4044-4-git-send-email-csaba@gluster.com>
Download mbox | patch
Permalink /patch/5204/
State Accepted
Headers show

Comments

Csaba Henk - 2010-10-03 00:14:16
Signed-off-by: Csaba Henk <csaba@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-volgen.c |   31 +++++++++++++++++++++++++++
 xlators/mgmt/glusterd/src/glusterd-volgen.h |    2 +
 2 files changed, 33 insertions(+), 0 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index f83cdef..619e329 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -413,6 +413,37 @@  volgen_graph_set_options (glusterfs_graph_t *graph, dict_t *dict)
 }
 
 static int
+optget_option_handler (glusterfs_graph_t *graph, struct volopt_map_entry2 *vme2,
+                       void *param)
+{
+        struct volopt_map_entry2 *vme2x = param;
+
+        if (strcmp (vme2->key, vme2x->key) == 0)
+                vme2x->value = vme2->value;
+
+        return 0;
+}
+
+/* This getter considers defaults also. */
+int
+glusterd_volinfo_get (glusterd_volinfo_t *volinfo, char *key, char **value)
+{
+        struct volopt_map_entry2 vme2 = {0,};
+        int ret = 0;
+
+        vme2.key = key;
+
+        ret = volgen_graph_set_options_generic (NULL, volinfo->dict, &vme2,
+                                                &optget_option_handler);
+        if (ret)
+                return -1;
+
+        *value = vme2.value;
+
+        return 0;
+}
+
+static int
 volgen_graph_merge_sub (glusterfs_graph_t *dgraph, glusterfs_graph_t *sgraph)
 {
         xlator_t *trav = NULL;
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h
index 3e877fd..fe706ef 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
@@ -46,4 +46,6 @@  int glusterd_create_nfs_volfile ();
 int glusterd_delete_volfile (glusterd_volinfo_t *volinfo,
                              glusterd_brickinfo_t *brickinfo);
 
+int glusterd_volinfo_get (glusterd_volinfo_t *volinfo, char *key, char **value);
+
 #endif