Merge branch 'master' of ssh://git.samba.org/data/git/samba
[ira/wip.git] / source4 / torture / raw / lockbench.c
index 168131a6d291752f6c93bdea36d1a2cbde707a48..d20175a01897c409d395cf9f87d4d1c5e63a260f 100644 (file)
@@ -22,6 +22,7 @@
 #include "includes.h"
 #include "torture/torture.h"
 #include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
 #include "system/time.h"
 #include "system/filesys.h"
 #include "libcli/libcli.h"
@@ -30,6 +31,8 @@
 #include "lib/cmdline/popt_common.h"
 #include "libcli/composite/composite.h"
 #include "libcli/smb_composite/smb_composite.h"
+#include "libcli/resolve/resolve.h"
+#include "param/param.h"
 
 #define BASEDIR "\\benchlock"
 #define FNAME BASEDIR "\\lock.dat"
@@ -41,7 +44,8 @@ static int num_connected;
 enum lock_stage {LOCK_INITIAL, LOCK_LOCK, LOCK_UNLOCK};
 
 struct benchlock_state {
-       struct event_context *ev;
+       struct torture_context *tctx;
+       struct tevent_context *ev;
        struct smbcli_tree *tree;
        TALLOC_CTX *mem_ctx;
        int client_num;
@@ -53,10 +57,10 @@ struct benchlock_state {
        int lastcount;
        struct smbcli_request *req;
        struct smb_composite_connect reconnect;
-       struct timed_event *te;
+       struct tevent_timer *te;
 
        /* these are used for reconnections */
-       int dest_port;
+       const char **dest_ports;
        const char *dest_host;
        const char *called_name;
        const char *service_type;
@@ -108,15 +112,15 @@ static void lock_send(struct benchlock_state *state)
                DEBUG(0,("Failed to setup lock\n"));
                lock_failed++;
        }
-       state->req->async.private = state;
+       state->req->async.private_data = state;
        state->req->async.fn      = lock_completion;
 }
 
-static void reopen_connection(struct event_context *ev, struct timed_event *te, 
+static void reopen_connection(struct tevent_context *ev, struct tevent_timer *te, 
                              struct timeval t, void *private_data);
 
 
-static void reopen_file(struct event_context *ev, struct timed_event *te, 
+static void reopen_file(struct tevent_context *ev, struct tevent_timer *te, 
                                      struct timeval t, void *private_data)
 {
        struct benchlock_state *state = (struct benchlock_state *)private_data;
@@ -167,7 +171,7 @@ static void reopen_connection_complete(struct composite_context *ctx)
 /*
   reopen a connection
  */
-static void reopen_connection(struct event_context *ev, struct timed_event *te, 
+static void reopen_connection(struct tevent_context *ev, struct tevent_timer *te, 
                              struct timeval t, void *private_data)
 {
        struct benchlock_state *state = (struct benchlock_state *)private_data;
@@ -177,25 +181,32 @@ static void reopen_connection(struct event_context *ev, struct timed_event *te,
 
        state->te = NULL;
 
-       if (!torture_get_conn_index(state->client_num, state->mem_ctx, &host, &share)) {
+       if (!torture_get_conn_index(state->client_num, state->mem_ctx, state->tctx, &host, &share)) {
                DEBUG(0,("Can't find host/share for reconnect?!\n"));
                exit(1);
        }
 
        io->in.dest_host    = state->dest_host;
-       io->in.port         = state->dest_port;
+       io->in.dest_ports   = state->dest_ports;
+       io->in.gensec_settings = lp_gensec_settings(state->mem_ctx, state->tctx->lp_ctx);
+       io->in.socket_options = lp_socket_options(state->tctx->lp_ctx);
        io->in.called_name  = state->called_name;
        io->in.service      = share;
        io->in.service_type = state->service_type;
        io->in.credentials  = cmdline_credentials;
-       io->in.fallback_to_anonymous = False;
-       io->in.workgroup    = lp_workgroup();
+       io->in.fallback_to_anonymous = false;
+       io->in.workgroup    = lp_workgroup(state->tctx->lp_ctx);
+       io->in.iconv_convenience = lp_iconv_convenience(state->tctx->lp_ctx);
+       lp_smbcli_options(state->tctx->lp_ctx, &io->in.options);
+       lp_smbcli_session_options(state->tctx->lp_ctx, &io->in.session_options);
 
        /* kill off the remnants of the old connection */
        talloc_free(state->tree);
        state->tree = NULL;
 
-       ctx = smb_composite_connect_send(io, state->mem_ctx, state->ev);
+       ctx = smb_composite_connect_send(io, state->mem_ctx, 
+                                        lp_resolve_context(state->tctx->lp_ctx),
+                                        state->ev);
        if (ctx == NULL) {
                DEBUG(0,("Failed to setup async reconnect\n"));
                exit(1);
@@ -211,7 +222,7 @@ static void reopen_connection(struct event_context *ev, struct timed_event *te,
 */
 static void lock_completion(struct smbcli_request *req)
 {
-       struct benchlock_state *state = (struct benchlock_state *)req->async.private;
+       struct benchlock_state *state = (struct benchlock_state *)req->async.private_data;
        NTSTATUS status = smbcli_request_simple_recv(req);
        state->req = NULL;
        if (!NT_STATUS_IS_OK(status)) {
@@ -251,8 +262,7 @@ static void lock_completion(struct smbcli_request *req)
 
 static void echo_completion(struct smbcli_request *req)
 {
-       struct benchlock_state *state = talloc_get_type(req->async.private, 
-                                                       struct benchlock_state);
+       struct benchlock_state *state = (struct benchlock_state *)req->async.private_data;
        NTSTATUS status = smbcli_request_simple_recv(req);
        if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE) ||
            NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT)) {
@@ -267,7 +277,7 @@ static void echo_completion(struct smbcli_request *req)
        }
 }
 
-static void report_rate(struct event_context *ev, struct timed_event *te, 
+static void report_rate(struct tevent_context *ev, struct tevent_timer *te, 
                        struct timeval t, void *private_data)
 {
        struct benchlock_state *state = talloc_get_type(private_data, 
@@ -295,7 +305,7 @@ static void report_rate(struct event_context *ev, struct timed_event *te,
                p.in.size = 0;
                p.in.data = NULL;
                req = smb_raw_echo_send(state[i].tree->session->transport, &p);
-               req->async.private = state;
+               req->async.private_data = &state[i];
                req->async.fn      = echo_completion;
        }
 }
@@ -303,14 +313,13 @@ static void report_rate(struct event_context *ev, struct timed_event *te,
 /* 
    benchmark locking calls
 */
-BOOL torture_bench_lock(struct torture_context *torture)
+bool torture_bench_lock(struct torture_context *torture)
 {
-       BOOL ret = True;
+       bool ret = true;
        TALLOC_CTX *mem_ctx = talloc_new(torture);
        int i;
        int timelimit = torture_setting_int(torture, "timelimit", 10);
        struct timeval tv;
-       struct event_context *ev = event_context_find(mem_ctx);
        struct benchlock_state *state;
        int total = 0, minops=0;
        struct smbcli_state *cli;
@@ -318,23 +327,29 @@ BOOL torture_bench_lock(struct torture_context *torture)
 
        progress = torture_setting_bool(torture, "progress", true);
 
-       nprocs = lp_parm_int(-1, "torture", "nprocs", 4);
+       nprocs = torture_setting_int(torture, "nprocs", 4);
 
        state = talloc_zero_array(mem_ctx, struct benchlock_state, nprocs);
 
        printf("Opening %d connections\n", nprocs);
        for (i=0;i<nprocs;i++) {
+               state[i].tctx = torture;
                state[i].mem_ctx = talloc_new(state);
                state[i].client_num = i;
-               state[i].ev = ev;
-               if (!torture_open_connection_ev(&cli, i, ev)) {
-                       return False;
+               state[i].ev = torture->ev;
+               if (!torture_open_connection_ev(&cli, i, torture, torture->ev)) {
+                       return false;
                }
                talloc_steal(mem_ctx, state);
                state[i].tree = cli->tree;
                state[i].dest_host = talloc_strdup(state[i].mem_ctx, 
                                                   cli->tree->session->transport->socket->hostname);
-               state[i].dest_port = cli->tree->session->transport->socket->port;
+               state[i].dest_ports = talloc_array(state[i].mem_ctx, 
+                                                  const char *, 2);
+               state[i].dest_ports[0] = talloc_asprintf(state[i].dest_ports, 
+                                                        "%u", 
+                                                        cli->tree->session->transport->socket->port);
+               state[i].dest_ports[1] = NULL;
                state[i].called_name  = talloc_strdup(state[i].mem_ctx,
                                                      cli->tree->session->transport->called.name);
                state[i].service_type = talloc_strdup(state[i].mem_ctx,
@@ -363,12 +378,12 @@ BOOL torture_bench_lock(struct torture_context *torture)
        tv = timeval_current(); 
 
        if (progress) {
-               event_add_timed(ev, state, timeval_current_ofs(1, 0), report_rate, state);
+               event_add_timed(torture->ev, state, timeval_current_ofs(1, 0), report_rate, state);
        }
 
        printf("Running for %d seconds\n", timelimit);
        while (timeval_elapsed(&tv) < timelimit) {
-               event_loop_once(ev);
+               event_loop_once(torture->ev);
 
                if (lock_failed) {
                        DEBUG(0,("locking failed\n"));
@@ -394,9 +409,10 @@ BOOL torture_bench_lock(struct torture_context *torture)
 
        smbcli_deltree(state[0].tree, BASEDIR);
        talloc_free(mem_ctx);
+       printf("\n");
        return ret;
 
 failed:
        talloc_free(mem_ctx);
-       return False;
+       return false;
 }