ctdb-tests: Factor out get_ctdb_iface_list()
authorMartin Schwenke <martin@meltin.net>
Sat, 3 Dec 2016 13:59:29 +0000 (00:59 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 19 Dec 2016 03:07:07 +0000 (04:07 +0100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/src/fake_ctdbd.c

index 39bae6005895c6f0e0c0a756f1f0212b4e14bc8b..a1b8052d705607f63e9f2aff9b240800f7101075 100644 (file)
@@ -2182,31 +2182,24 @@ static void control_db_get_health(TALLOC_CTX *mem_ctx,
        client_send_control(req, header, &reply);
 }
 
-static void control_get_ifaces(TALLOC_CTX *mem_ctx,
-                              struct tevent_req *req,
-                              struct ctdb_req_header *header,
-                              struct ctdb_req_control *request)
+static struct ctdb_iface_list *get_ctdb_iface_list(TALLOC_CTX *mem_ctx,
+                                                  struct ctdbd_context *ctdb)
 {
-       struct client_state *state = tevent_req_data(
-               req, struct client_state);
-       struct ctdbd_context *ctdb = state->ctdb;
-       struct ctdb_reply_control reply;
        struct ctdb_iface_list *iface_list;
        struct interface *iface;
        int i;
 
-       reply.rdata.opcode = request->opcode;
-
        iface_list = talloc_zero(mem_ctx, struct ctdb_iface_list);
        if (iface_list == NULL) {
-               goto fail;
+               goto done;
        }
 
        iface_list->num = ctdb->iface_map->num;
        iface_list->iface = talloc_array(iface_list, struct ctdb_iface,
                                         iface_list->num);
        if (iface_list->iface == NULL) {
-               goto fail;
+               TALLOC_FREE(iface_list);
+               goto done;
        }
 
        for (i=0; i<iface_list->num; i++) {
@@ -2219,6 +2212,28 @@ static void control_get_ifaces(TALLOC_CTX *mem_ctx,
                        sizeof(iface_list->iface[i].name));
        }
 
+done:
+       return iface_list;
+}
+
+static void control_get_ifaces(TALLOC_CTX *mem_ctx,
+                              struct tevent_req *req,
+                              struct ctdb_req_header *header,
+                              struct ctdb_req_control *request)
+{
+       struct client_state *state = tevent_req_data(
+               req, struct client_state);
+       struct ctdbd_context *ctdb = state->ctdb;
+       struct ctdb_reply_control reply;
+       struct ctdb_iface_list *iface_list;
+
+       reply.rdata.opcode = request->opcode;
+
+       iface_list = get_ctdb_iface_list(mem_ctx, ctdb);
+       if (iface_list == NULL) {
+               goto fail;
+       }
+
        reply.rdata.data.iface_list = iface_list;
        reply.status = 0;
        reply.errmsg = NULL;