diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c index 8f1e94b5773..c944fe45c64 100644 --- a/source4/torture/smb2/create.c +++ b/source4/torture/smb2/create.c @@ -3112,11 +3112,14 @@ done: */ struct test_smb2_bench_path_contention_shared_conn; +struct test_smb2_bench_path_contention_shared_loop; struct test_smb2_bench_path_contention_shared_state { struct torture_context *tctx; size_t num_conns; struct test_smb2_bench_path_contention_shared_conn *conns; + size_t num_loops; + struct test_smb2_bench_path_contention_shared_loop *loops; struct timeval starttime; int timecount; int timelimit; @@ -3140,6 +3143,12 @@ struct test_smb2_bench_path_contention_shared_conn { struct test_smb2_bench_path_contention_shared_state *state; int idx; struct smb2_tree *tree; +}; + +struct test_smb2_bench_path_contention_shared_loop { + struct test_smb2_bench_path_contention_shared_state *state; + struct test_smb2_bench_path_contention_shared_conn *conn; + int idx; struct tevent_immediate *im; struct { struct smb2_create io; @@ -3164,138 +3173,138 @@ struct test_smb2_bench_path_contention_shared_conn { NTSTATUS error; }; -static void test_smb2_bench_path_contention_conn_open( - struct test_smb2_bench_path_contention_shared_conn *conn); +static void test_smb2_bench_path_contention_loop_open( + struct test_smb2_bench_path_contention_shared_loop *loop); -static void test_smb2_bench_path_contention_conn_start(struct tevent_context *ctx, +static void test_smb2_bench_path_contention_loop_start(struct tevent_context *ctx, struct tevent_immediate *im, void *private_data) { - struct test_smb2_bench_path_contention_shared_conn *conn = - (struct test_smb2_bench_path_contention_shared_conn *) + struct test_smb2_bench_path_contention_shared_loop *loop = + (struct test_smb2_bench_path_contention_shared_loop *) private_data; - test_smb2_bench_path_contention_conn_open(conn); + test_smb2_bench_path_contention_loop_open(loop); } -static void test_smb2_bench_path_contention_conn_opened(struct smb2_request *req); +static void test_smb2_bench_path_contention_loop_opened(struct smb2_request *req); -static void test_smb2_bench_path_contention_conn_open( - struct test_smb2_bench_path_contention_shared_conn *conn) +static void test_smb2_bench_path_contention_loop_open( + struct test_smb2_bench_path_contention_shared_loop *loop) { - struct test_smb2_bench_path_contention_shared_state *state = conn->state; + struct test_smb2_bench_path_contention_shared_state *state = loop->state; - conn->opens.num_started += 1; - conn->opens.starttime = timeval_current(); - conn->opens.req = smb2_create_send(conn->tree, &conn->opens.io); - torture_assert_goto(state->tctx, conn->opens.req != NULL, + loop->opens.num_started += 1; + loop->opens.starttime = timeval_current(); + loop->opens.req = smb2_create_send(loop->conn->tree, &loop->opens.io); + torture_assert_goto(state->tctx, loop->opens.req != NULL, state->ok, asserted, "smb2_create_send"); - conn->opens.req->async.fn = test_smb2_bench_path_contention_conn_opened; - conn->opens.req->async.private_data = conn; + loop->opens.req->async.fn = test_smb2_bench_path_contention_loop_opened; + loop->opens.req->async.private_data = loop; return; asserted: state->stop = true; } -static void test_smb2_bench_path_contention_conn_close( - struct test_smb2_bench_path_contention_shared_conn *conn); +static void test_smb2_bench_path_contention_loop_close( + struct test_smb2_bench_path_contention_shared_loop *loop); -static void test_smb2_bench_path_contention_conn_opened(struct smb2_request *req) +static void test_smb2_bench_path_contention_loop_opened(struct smb2_request *req) { - struct test_smb2_bench_path_contention_shared_conn *conn = - (struct test_smb2_bench_path_contention_shared_conn *) + struct test_smb2_bench_path_contention_shared_loop *loop = + (struct test_smb2_bench_path_contention_shared_loop *) req->async.private_data; - struct test_smb2_bench_path_contention_shared_state *state = conn->state; - double latency = timeval_elapsed(&conn->opens.starttime); + struct test_smb2_bench_path_contention_shared_state *state = loop->state; + double latency = timeval_elapsed(&loop->opens.starttime); TALLOC_CTX *frame = talloc_stackframe(); - torture_assert_goto(state->tctx, conn->opens.req == req, + torture_assert_goto(state->tctx, loop->opens.req == req, state->ok, asserted, __location__); - conn->error = smb2_create_recv(req, frame, &conn->opens.io); - torture_assert_ntstatus_ok_goto(state->tctx, conn->error, + loop->error = smb2_create_recv(req, frame, &loop->opens.io); + torture_assert_ntstatus_ok_goto(state->tctx, loop->error, state->ok, asserted, __location__); - ZERO_STRUCT(conn->opens.io.out.blobs); + ZERO_STRUCT(loop->opens.io.out.blobs); SMB_ASSERT(latency >= 0.000001); - if (conn->opens.num_finished == 0) { + if (loop->opens.num_finished == 0) { /* first round */ - conn->opens.min_latency = latency; - conn->opens.max_latency = latency; + loop->opens.min_latency = latency; + loop->opens.max_latency = latency; } - conn->opens.num_finished += 1; - conn->opens.total_latency += latency; + loop->opens.num_finished += 1; + loop->opens.total_latency += latency; - if (latency < conn->opens.min_latency) { - conn->opens.min_latency = latency; + if (latency < loop->opens.min_latency) { + loop->opens.min_latency = latency; } - if (latency > conn->opens.max_latency) { - conn->opens.max_latency = latency; + if (latency > loop->opens.max_latency) { + loop->opens.max_latency = latency; } TALLOC_FREE(frame); - test_smb2_bench_path_contention_conn_close(conn); + test_smb2_bench_path_contention_loop_close(loop); return; asserted: state->stop = true; TALLOC_FREE(frame); } -static void test_smb2_bench_path_contention_conn_closed(struct smb2_request *req); +static void test_smb2_bench_path_contention_loop_closed(struct smb2_request *req); -static void test_smb2_bench_path_contention_conn_close( - struct test_smb2_bench_path_contention_shared_conn *conn) +static void test_smb2_bench_path_contention_loop_close( + struct test_smb2_bench_path_contention_shared_loop *loop) { - struct test_smb2_bench_path_contention_shared_state *state = conn->state; + struct test_smb2_bench_path_contention_shared_state *state = loop->state; - conn->closes.num_started += 1; - conn->closes.starttime = timeval_current(); - conn->closes.io.in.file = conn->opens.io.out.file; - conn->closes.req = smb2_close_send(conn->tree, &conn->closes.io); - torture_assert_goto(state->tctx, conn->closes.req != NULL, + loop->closes.num_started += 1; + loop->closes.starttime = timeval_current(); + loop->closes.io.in.file = loop->opens.io.out.file; + loop->closes.req = smb2_close_send(loop->conn->tree, &loop->closes.io); + torture_assert_goto(state->tctx, loop->closes.req != NULL, state->ok, asserted, "smb2_close_send"); - conn->closes.req->async.fn = test_smb2_bench_path_contention_conn_closed; - conn->closes.req->async.private_data = conn; + loop->closes.req->async.fn = test_smb2_bench_path_contention_loop_closed; + loop->closes.req->async.private_data = loop; return; asserted: state->stop = true; } -static void test_smb2_bench_path_contention_conn_closed(struct smb2_request *req) +static void test_smb2_bench_path_contention_loop_closed(struct smb2_request *req) { - struct test_smb2_bench_path_contention_shared_conn *conn = - (struct test_smb2_bench_path_contention_shared_conn *) + struct test_smb2_bench_path_contention_shared_loop *loop = + (struct test_smb2_bench_path_contention_shared_loop *) req->async.private_data; - struct test_smb2_bench_path_contention_shared_state *state = conn->state; - double latency = timeval_elapsed(&conn->closes.starttime); + struct test_smb2_bench_path_contention_shared_state *state = loop->state; + double latency = timeval_elapsed(&loop->closes.starttime); - torture_assert_goto(state->tctx, conn->closes.req == req, + torture_assert_goto(state->tctx, loop->closes.req == req, state->ok, asserted, __location__); - conn->error = smb2_close_recv(req, &conn->closes.io); - torture_assert_ntstatus_ok_goto(state->tctx, conn->error, + loop->error = smb2_close_recv(req, &loop->closes.io); + torture_assert_ntstatus_ok_goto(state->tctx, loop->error, state->ok, asserted, __location__); SMB_ASSERT(latency >= 0.000001); - if (conn->closes.num_finished == 0) { + if (loop->closes.num_finished == 0) { /* first round */ - conn->closes.min_latency = latency; - conn->closes.max_latency = latency; + loop->closes.min_latency = latency; + loop->closes.max_latency = latency; } - conn->closes.num_finished += 1; + loop->closes.num_finished += 1; - conn->closes.total_latency += latency; + loop->closes.total_latency += latency; - if (latency < conn->closes.min_latency) { - conn->closes.min_latency = latency; + if (latency < loop->closes.min_latency) { + loop->closes.min_latency = latency; } - if (latency > conn->closes.max_latency) { - conn->closes.max_latency = latency; + if (latency > loop->closes.max_latency) { + loop->closes.max_latency = latency; } - test_smb2_bench_path_contention_conn_open(conn); + test_smb2_bench_path_contention_loop_open(loop); return; asserted: state->stop = true; @@ -3322,43 +3331,43 @@ static void test_smb2_bench_path_contention_progress(struct tevent_context *ev, state->timecount += 1; - for (i=0;inum_conns;i++) { - struct test_smb2_bench_path_contention_shared_conn *conn = - &state->conns[i]; + for (i=0;inum_loops;i++) { + struct test_smb2_bench_path_contention_shared_loop *loop = + &state->loops[i]; - num_opens += conn->opens.num_finished; - total_open_latency += conn->opens.total_latency; - if (min_open_latency == 0.0 && conn->opens.min_latency != 0.0) { - min_open_latency = conn->opens.min_latency; + num_opens += loop->opens.num_finished; + total_open_latency += loop->opens.total_latency; + if (min_open_latency == 0.0 && loop->opens.min_latency != 0.0) { + min_open_latency = loop->opens.min_latency; } - if (conn->opens.min_latency < min_open_latency) { - min_open_latency = conn->opens.min_latency; + if (loop->opens.min_latency < min_open_latency) { + min_open_latency = loop->opens.min_latency; } if (max_open_latency == 0.0) { - max_open_latency = conn->opens.max_latency; + max_open_latency = loop->opens.max_latency; } - if (conn->opens.max_latency > max_open_latency) { - max_open_latency = conn->opens.max_latency; + if (loop->opens.max_latency > max_open_latency) { + max_open_latency = loop->opens.max_latency; } - conn->opens.num_finished = 0; - conn->opens.total_latency = 0.0; + loop->opens.num_finished = 0; + loop->opens.total_latency = 0.0; - num_closes += conn->closes.num_finished; - total_close_latency += conn->closes.total_latency; - if (min_close_latency == 0.0 && conn->closes.min_latency != 0.0) { - min_close_latency = conn->closes.min_latency; + num_closes += loop->closes.num_finished; + total_close_latency += loop->closes.total_latency; + if (min_close_latency == 0.0 && loop->closes.min_latency != 0.0) { + min_close_latency = loop->closes.min_latency; } - if (conn->closes.min_latency < min_close_latency) { - min_close_latency = conn->closes.min_latency; + if (loop->closes.min_latency < min_close_latency) { + min_close_latency = loop->closes.min_latency; } if (max_close_latency == 0.0) { - max_close_latency = conn->closes.max_latency; + max_close_latency = loop->closes.max_latency; } - if (conn->closes.max_latency > max_close_latency) { - max_close_latency = conn->closes.max_latency; + if (loop->closes.max_latency > max_close_latency) { + max_close_latency = loop->closes.max_latency; } - conn->closes.num_finished = 0; - conn->closes.total_latency = 0.0; + loop->closes.num_finished = 0; + loop->closes.total_latency = 0.0; } state->opens.num_finished += num_opens; @@ -3452,21 +3461,29 @@ static bool test_smb2_bench_path_contention_shared(struct torture_context *tctx, struct test_smb2_bench_path_contention_shared_state *state = NULL; bool ret = true; int torture_nprocs = torture_setting_int(tctx, "nprocs", 4); + int torture_qdepth = torture_setting_int(tctx, "qdepth", 1); size_t i; + size_t li = 0; int timelimit = torture_setting_int(tctx, "timelimit", 10); const char *path = torture_setting_string(tctx, "bench_path", ""); struct smb2_create open_io = { .level = RAW_OPEN_SMB2, }; struct smb2_close close_io = { .level = RAW_CLOSE_SMB2, }; struct tevent_timer *te = NULL; + uint32_t timeout_msec; state = talloc_zero(tctx, struct test_smb2_bench_path_contention_shared_state); torture_assert(tctx, state != NULL, __location__); state->tctx = tctx; + state->num_conns = torture_nprocs; state->conns = talloc_zero_array(state, struct test_smb2_bench_path_contention_shared_conn, - torture_nprocs); + state->num_conns); torture_assert(tctx, state->conns != NULL, __location__); - state->num_conns = torture_nprocs; + state->num_loops = torture_nprocs * torture_qdepth; + state->loops = talloc_zero_array(state, + struct test_smb2_bench_path_contention_shared_loop, + state->num_loops); + torture_assert(tctx, state->loops != NULL, __location__); state->ok = true; state->timelimit = MAX(timelimit, 1); @@ -3482,29 +3499,64 @@ static bool test_smb2_bench_path_contention_shared(struct torture_context *tctx, open_io.in.create_flags = NTCREATEX_FLAGS_EXTENDED; open_io.in.oplock_level = SMB2_OPLOCK_LEVEL_NONE; + timeout_msec = tree->session->transport->options.request_timeout * 1000; + torture_comment(tctx, "Opening %zd connections\n", state->num_conns); for (i=0;inum_conns;i++) { + struct smb2_tree *ct = NULL; + DATA_BLOB out_input_buffer = data_blob_null; + DATA_BLOB out_output_buffer = data_blob_null; + size_t pcli; + state->conns[i].state = state; state->conns[i].idx = i; - state->conns[i].im = tevent_create_immediate(state->conns); - torture_assert(tctx, state->conns[i].im != NULL, __location__); - if (!torture_smb2_connection(tctx, &state->conns[i].tree)) { + if (!torture_smb2_connection(tctx, &ct)) { torture_comment(tctx, "Failed opening %zd/%zd connections\n", i, state->num_conns); return false; } - talloc_steal(state->conns, state->conns[i].tree); - state->conns[i].opens.io = open_io; - state->conns[i].closes.io = close_io; + state->conns[i].tree = talloc_steal(state->conns, ct); - tevent_schedule_immediate(state->conns[i].im, - tctx->ev, - test_smb2_bench_path_contention_conn_start, - &state->conns[i]); + smb2cli_conn_set_max_credits(ct->session->transport->conn, 8192); + smb2cli_ioctl(ct->session->transport->conn, + timeout_msec, + ct->session->smbXcli, + ct->smbXcli, + UINT64_MAX, /* in_fid_persistent */ + UINT64_MAX, /* in_fid_volatile */ + UINT32_MAX, + 0, /* in_max_input_length */ + NULL, /* in_input_buffer */ + 1, /* in_max_output_length */ + NULL, /* in_output_buffer */ + SMB2_IOCTL_FLAG_IS_FSCTL, + ct, + &out_input_buffer, + &out_output_buffer); + torture_assert(tctx, + smbXcli_conn_is_connected(ct->session->transport->conn), + "smbXcli_conn_is_connected"); + for (pcli = 0; pcli < torture_qdepth; pcli++) { + struct test_smb2_bench_path_contention_shared_loop *loop = &state->loops[li]; + + loop->idx = li++; + loop->state = state; + loop->conn = &state->conns[i]; + loop->im = tevent_create_immediate(state->loops); + torture_assert(tctx, loop->im != NULL, __location__); + loop->opens.io = open_io; + loop->closes.io = close_io; + + tevent_schedule_immediate(loop->im, + tctx->ev, + test_smb2_bench_path_contention_loop_start, + loop); + } } - torture_comment(tctx, "Opened %zd connections\n", state->num_conns); + torture_comment(tctx, "Opened %zu connections with qdepth=%d => %zu loops\n", + state->num_conns, torture_qdepth, state->num_loops); torture_comment(tctx, "Running for %d seconds\n", state->timelimit);