tools/ctdb: Pass memory context for returning nodes in parse_nodestring
authorAmitay Isaacs <amitay@gmail.com>
Tue, 27 Aug 2013 04:46:08 +0000 (14:46 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 4 Oct 2013 05:15:35 +0000 (15:15 +1000)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
tests/src/ctdb_tool_libctdb.c
tools/ctdb.c

index e7e191a1bad4770431fa4fec264fbaacb826f956..7b6e6ca273ea3b47478b150f8678b86637bc69cd 100644 (file)
@@ -146,7 +146,7 @@ static void test_parse_nodestring(const char *nodestring_s,
 
        libctdb_test_read_nodemap(ctdb);
 
-       if (parse_nodestring(NULL, nodestring, CTDB_CURRENT_NODE, dd_ok,
+       if (parse_nodestring(NULL, NULL, nodestring, CTDB_CURRENT_NODE, dd_ok,
                             &nodes, &pnn_mode)) {
                print_nodes(nodes, pnn_mode);
        }
index b802f5e9bf89af64036ab6c43ebc433e21bd6188..552906816848a658e81024f43186d4c889a96f0e 100644 (file)
@@ -166,13 +166,14 @@ static TDB_DATA hextodata(TALLOC_CTX *mem_ctx, const char *str)
  * explicitly specified.
  */
 static bool parse_nodestring(struct ctdb_context *ctdb,
+                            TALLOC_CTX *mem_ctx,
                             const char * nodestring,
                             uint32_t current_pnn,
                             bool dd_ok,
                             uint32_t **nodes,
                             uint32_t *pnn_mode)
 {
-       TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
+       TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
        int n;
        uint32_t i;
        struct ctdb_node_map *nodemap;
@@ -188,7 +189,7 @@ static bool parse_nodestring(struct ctdb_context *ctdb,
        }
 
        if (nodestring != NULL) {
-               *nodes = talloc_array(tmp_ctx, uint32_t, 0);
+               *nodes = talloc_array(mem_ctx, uint32_t, 0);
                if (*nodes == NULL) {
                        goto failed;
                }
@@ -205,7 +206,7 @@ static bool parse_nodestring(struct ctdb_context *ctdb,
                                      NODE_FLAGS_DELETED)) && !dd_ok) {
                                        continue;
                                }
-                               *nodes = talloc_realloc(tmp_ctx, *nodes,
+                               *nodes = talloc_realloc(mem_ctx, *nodes,
                                                        uint32_t, n+1);
                                if (*nodes == NULL) {
                                        goto failed;
@@ -240,7 +241,7 @@ static bool parse_nodestring(struct ctdb_context *ctdb,
                                        exit(10);
                                }
 
-                               *nodes = talloc_realloc(ctdb, *nodes,
+                               *nodes = talloc_realloc(mem_ctx, *nodes,
                                                        uint32_t, n+1);
                                if (*nodes == NULL) {
                                        goto failed;
@@ -261,7 +262,7 @@ static bool parse_nodestring(struct ctdb_context *ctdb,
                }
        } else {
                /* default - no nodes specified */
-               *nodes = talloc_array(tmp_ctx, uint32_t, 1);
+               *nodes = talloc_array(mem_ctx, uint32_t, 1);
                if (*nodes == NULL) {
                        goto failed;
                }
@@ -1057,7 +1058,7 @@ static int control_nodestatus(struct ctdb_context *ctdb, int argc, const char **
                usage();
        }
 
-       if (!parse_nodestring(ctdb, argc == 1 ? argv[0] : NULL,
+       if (!parse_nodestring(ctdb, tmp_ctx, argc == 1 ? argv[0] : NULL,
                              options.pnn, true, &nodes, &pnn_mode)) {
                return -1;
        }
@@ -6321,7 +6322,7 @@ int main(int argc, const char *argv[])
        }
 
        /* setup the node number(s) to contact */
-       if (!parse_nodestring(ctdb, nodestring, CTDB_CURRENT_NODE, false,
+       if (!parse_nodestring(ctdb, ctdb, nodestring, CTDB_CURRENT_NODE, false,
                              &options.nodes, &options.pnn)) {
                usage();
        }