| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
SMB2 bench test suite |
| 5 |
|
| 6 |
Copyright (C) Stefan Metzmacher 2022 |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3 of the License, or |
| 11 |
(at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "includes.h" |
| 23 |
#include "lib/param/param.h" |
| 24 |
#include "libcli/smb2/smb2.h" |
| 25 |
#include "libcli/smb2/smb2_calls.h" |
| 26 |
#include "libcli/smb/smbXcli_base.h" |
| 27 |
#include "torture/torture.h" |
| 28 |
#include "torture/util.h" |
| 29 |
#include "torture/smb2/proto.h" |
| 30 |
#include "librpc/gen_ndr/ndr_security.h" |
| 31 |
#include "libcli/security/security.h" |
| 32 |
|
| 33 |
#include "system/filesys.h" |
| 34 |
#include "auth/credentials/credentials.h" |
| 35 |
#include "lib/cmdline/cmdline.h" |
| 36 |
#include "librpc/gen_ndr/security.h" |
| 37 |
#include "lib/events/events.h" |
| 38 |
|
| 39 |
#define FNAME "test_create.dat" |
| 40 |
#define DNAME "smb2_open" |
| 41 |
|
| 42 |
#define CHECK_STATUS(status, correct) do { \ |
| 43 |
if (!NT_STATUS_EQUAL(status, correct)) { \ |
| 44 |
torture_result(tctx, TORTURE_FAIL, \ |
| 45 |
"(%s) Incorrect status %s - should be %s\n", \ |
| 46 |
__location__, nt_errstr(status), nt_errstr(correct)); \ |
| 47 |
return false; \ |
| 48 |
}} while (0) |
| 49 |
|
| 50 |
#define CHECK_EQUAL(v, correct) do { \ |
| 51 |
if (v != correct) { \ |
| 52 |
torture_result(tctx, TORTURE_FAIL, \ |
| 53 |
"(%s) Incorrect value for %s 0x%08llx - " \ |
| 54 |
"should be 0x%08llx\n", \ |
| 55 |
__location__, #v, \ |
| 56 |
(unsigned long long)v, \ |
| 57 |
(unsigned long long)correct); \ |
| 58 |
return false; \ |
| 59 |
}} while (0) |
| 60 |
|
| 61 |
#define CHECK_TIME(t, field) do { \ |
| 62 |
time_t t1, t2; \ |
| 63 |
finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \ |
| 64 |
finfo.all_info.in.file.handle = h1; \ |
| 65 |
status = smb2_getinfo_file(tree, tctx, &finfo); \ |
| 66 |
CHECK_STATUS(status, NT_STATUS_OK); \ |
| 67 |
t1 = t & ~1; \ |
| 68 |
t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \ |
| 69 |
if (abs(t1-t2) > 2) { \ |
| 70 |
torture_result(tctx, TORTURE_FAIL, \ |
| 71 |
"(%s) wrong time for field %s %s - %s\n", \ |
| 72 |
__location__, #field, \ |
| 73 |
timestring(tctx, t1), \ |
| 74 |
timestring(tctx, t2)); \ |
| 75 |
dump_all_info(tctx, &finfo); \ |
| 76 |
ret = false; \ |
| 77 |
}} while (0) |
| 78 |
|
| 79 |
#define CHECK_NTTIME(t, field) do { \ |
| 80 |
NTTIME t2; \ |
| 81 |
finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \ |
| 82 |
finfo.all_info.in.file.handle = h1; \ |
| 83 |
status = smb2_getinfo_file(tree, tctx, &finfo); \ |
| 84 |
CHECK_STATUS(status, NT_STATUS_OK); \ |
| 85 |
t2 = finfo.all_info.out.field; \ |
| 86 |
if (llabs((int64_t)(t-t2)) > 20000) { \ |
| 87 |
torture_result(tctx, TORTURE_FAIL, \ |
| 88 |
"(%s) wrong time for field %s %s - %s\n", \ |
| 89 |
__location__, #field, \ |
| 90 |
nt_time_string(tctx, t), \ |
| 91 |
nt_time_string(tctx, t2)); \ |
| 92 |
dump_all_info(tctx, &finfo); \ |
| 93 |
ret = false; \ |
| 94 |
}} while (0) |
| 95 |
|
| 96 |
#define CHECK_ALL_INFO(v, field) do { \ |
| 97 |
finfo.all_info.level = RAW_FILEINFO_ALL_INFORMATION; \ |
| 98 |
finfo.all_info.in.file.handle = h1; \ |
| 99 |
status = smb2_getinfo_file(tree, tctx, &finfo); \ |
| 100 |
CHECK_STATUS(status, NT_STATUS_OK); \ |
| 101 |
if ((v) != (finfo.all_info.out.field)) { \ |
| 102 |
torture_result(tctx, TORTURE_FAIL, \ |
| 103 |
"(%s) wrong value for field %s 0x%x - 0x%x\n", \ |
| 104 |
__location__, #field, (int)v,\ |
| 105 |
(int)(finfo.all_info.out.field)); \ |
| 106 |
dump_all_info(tctx, &finfo); \ |
| 107 |
ret = false; \ |
| 108 |
}} while (0) |
| 109 |
|
| 110 |
#define CHECK_VAL(v, correct) do { \ |
| 111 |
if ((v) != (correct)) { \ |
| 112 |
torture_result(tctx, TORTURE_FAIL, \ |
| 113 |
"(%s) wrong value for %s 0x%x - should be 0x%x\n", \ |
| 114 |
__location__, #v, (int)(v), (int)correct); \ |
| 115 |
ret = false; \ |
| 116 |
}} while (0) |
| 117 |
|
| 118 |
#define SET_ATTRIB(sattrib) do { \ |
| 119 |
union smb_setfileinfo sfinfo; \ |
| 120 |
ZERO_STRUCT(sfinfo.basic_info.in); \ |
| 121 |
sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \ |
| 122 |
sfinfo.basic_info.in.file.handle = h1; \ |
| 123 |
sfinfo.basic_info.in.attrib = sattrib; \ |
| 124 |
status = smb2_setinfo_file(tree, &sfinfo); \ |
| 125 |
if (!NT_STATUS_IS_OK(status)) { \ |
| 126 |
torture_comment(tctx, \ |
| 127 |
"(%s) Failed to set attrib 0x%x on %s\n", \ |
| 128 |
__location__, (unsigned int)(sattrib), fname); \ |
| 129 |
}} while (0) |
| 130 |
|
| 131 |
/* |
| 132 |
stress testing keepalive iops |
| 133 |
*/ |
| 134 |
|
| 135 |
struct test_smb2_bench_echo_conn; |
| 136 |
struct test_smb2_bench_echo_loop; |
| 137 |
|
| 138 |
struct test_smb2_bench_echo_state { |
| 139 |
struct torture_context *tctx; |
| 140 |
size_t num_conns; |
| 141 |
struct test_smb2_bench_echo_conn *conns; |
| 142 |
size_t num_loops; |
| 143 |
struct test_smb2_bench_echo_loop *loops; |
| 144 |
size_t pending_loops; |
| 145 |
struct timeval starttime; |
| 146 |
int timecount; |
| 147 |
int timelimit; |
| 148 |
uint64_t num_finished; |
| 149 |
double total_latency; |
| 150 |
double min_latency; |
| 151 |
double max_latency; |
| 152 |
bool ok; |
| 153 |
bool stop; |
| 154 |
}; |
| 155 |
|
| 156 |
struct test_smb2_bench_echo_conn { |
| 157 |
struct test_smb2_bench_echo_state *state; |
| 158 |
int idx; |
| 159 |
struct smb2_tree *tree; |
| 160 |
}; |
| 161 |
|
| 162 |
struct test_smb2_bench_echo_loop { |
| 163 |
struct test_smb2_bench_echo_state *state; |
| 164 |
struct test_smb2_bench_echo_conn *conn; |
| 165 |
int idx; |
| 166 |
struct tevent_immediate *im; |
| 167 |
struct tevent_req *req; |
| 168 |
struct timeval starttime; |
| 169 |
uint64_t num_started; |
| 170 |
uint64_t num_finished; |
| 171 |
uint64_t total_finished; |
| 172 |
uint64_t max_finished; |
| 173 |
double total_latency; |
| 174 |
double min_latency; |
| 175 |
double max_latency; |
| 176 |
NTSTATUS error; |
| 177 |
}; |
| 178 |
|
| 179 |
static void test_smb2_bench_echo_loop_do( |
| 180 |
struct test_smb2_bench_echo_loop *loop); |
| 181 |
|
| 182 |
static void test_smb2_bench_echo_loop_start(struct tevent_context *ctx, |
| 183 |
struct tevent_immediate *im, |
| 184 |
void *private_data) |
| 185 |
{ |
| 186 |
struct test_smb2_bench_echo_loop *loop = |
| 187 |
(struct test_smb2_bench_echo_loop *) |
| 188 |
private_data; |
| 189 |
|
| 190 |
test_smb2_bench_echo_loop_do(loop); |
| 191 |
} |
| 192 |
|
| 193 |
static void test_smb2_bench_echo_loop_done(struct tevent_req *req); |
| 194 |
|
| 195 |
static void test_smb2_bench_echo_loop_do( |
| 196 |
struct test_smb2_bench_echo_loop *loop) |
| 197 |
{ |
| 198 |
struct test_smb2_bench_echo_state *state = loop->state; |
| 199 |
|
| 200 |
loop->num_started += 1; |
| 201 |
loop->starttime = timeval_current(); |
| 202 |
loop->req = smb2cli_echo_send(state->loops, |
| 203 |
state->tctx->ev, |
| 204 |
loop->conn->tree->session->transport->conn, |
| 205 |
1000); |
| 206 |
torture_assert_goto(state->tctx, loop->req != NULL, |
| 207 |
state->ok, asserted, "smb2cli_echo_send"); |
| 208 |
|
| 209 |
tevent_req_set_callback(loop->req, |
| 210 |
test_smb2_bench_echo_loop_done, |
| 211 |
loop); |
| 212 |
return; |
| 213 |
asserted: |
| 214 |
state->stop = true; |
| 215 |
} |
| 216 |
|
| 217 |
static void test_smb2_bench_echo_loop_done(struct tevent_req *req) |
| 218 |
{ |
| 219 |
struct test_smb2_bench_echo_loop *loop = |
| 220 |
(struct test_smb2_bench_echo_loop *) |
| 221 |
_tevent_req_callback_data(req); |
| 222 |
struct test_smb2_bench_echo_state *state = loop->state; |
| 223 |
double latency = timeval_elapsed(&loop->starttime); |
| 224 |
TALLOC_CTX *frame = talloc_stackframe(); |
| 225 |
|
| 226 |
torture_assert_goto(state->tctx, loop->req == req, |
| 227 |
state->ok, asserted, __location__); |
| 228 |
loop->error = smb2cli_echo_recv(req); |
| 229 |
torture_assert_ntstatus_ok_goto(state->tctx, loop->error, |
| 230 |
state->ok, asserted, __location__); |
| 231 |
SMB_ASSERT(latency >= 0.000001); |
| 232 |
|
| 233 |
if (loop->num_finished == 0) { |
| 234 |
/* first round */ |
| 235 |
loop->min_latency = latency; |
| 236 |
loop->max_latency = latency; |
| 237 |
} |
| 238 |
|
| 239 |
loop->num_finished += 1; |
| 240 |
loop->total_finished += 1; |
| 241 |
loop->total_latency += latency; |
| 242 |
|
| 243 |
if (latency < loop->min_latency) { |
| 244 |
loop->min_latency = latency; |
| 245 |
} |
| 246 |
|
| 247 |
if (latency > loop->max_latency) { |
| 248 |
loop->max_latency = latency; |
| 249 |
} |
| 250 |
|
| 251 |
if (loop->total_finished >= loop->max_finished) { |
| 252 |
if (state->pending_loops > 0) { |
| 253 |
state->pending_loops -= 1; |
| 254 |
} |
| 255 |
if (state->pending_loops == 0) { |
| 256 |
goto asserted; |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
TALLOC_FREE(frame); |
| 261 |
test_smb2_bench_echo_loop_do(loop); |
| 262 |
return; |
| 263 |
asserted: |
| 264 |
state->stop = true; |
| 265 |
TALLOC_FREE(frame); |
| 266 |
} |
| 267 |
|
| 268 |
static void test_smb2_bench_echo_progress(struct tevent_context *ev, |
| 269 |
struct tevent_timer *te, |
| 270 |
struct timeval current_time, |
| 271 |
void *private_data) |
| 272 |
{ |
| 273 |
struct test_smb2_bench_echo_state *state = |
| 274 |
(struct test_smb2_bench_echo_state *)private_data; |
| 275 |
uint64_t num_echos = 0; |
| 276 |
double total_echo_latency = 0; |
| 277 |
double min_echo_latency = 0; |
| 278 |
double max_echo_latency = 0; |
| 279 |
double avs_echo_latency = 0; |
| 280 |
size_t i; |
| 281 |
|
| 282 |
state->timecount += 1; |
| 283 |
|
| 284 |
for (i=0;i<state->num_loops;i++) { |
| 285 |
struct test_smb2_bench_echo_loop *loop = |
| 286 |
&state->loops[i]; |
| 287 |
|
| 288 |
num_echos += loop->num_finished; |
| 289 |
total_echo_latency += loop->total_latency; |
| 290 |
if (min_echo_latency == 0.0 && loop->min_latency != 0.0) { |
| 291 |
min_echo_latency = loop->min_latency; |
| 292 |
} |
| 293 |
if (loop->min_latency < min_echo_latency) { |
| 294 |
min_echo_latency = loop->min_latency; |
| 295 |
} |
| 296 |
if (max_echo_latency == 0.0) { |
| 297 |
max_echo_latency = loop->max_latency; |
| 298 |
} |
| 299 |
if (loop->max_latency > max_echo_latency) { |
| 300 |
max_echo_latency = loop->max_latency; |
| 301 |
} |
| 302 |
loop->num_finished = 0; |
| 303 |
loop->total_latency = 0.0; |
| 304 |
} |
| 305 |
|
| 306 |
state->num_finished += num_echos; |
| 307 |
state->total_latency += total_echo_latency; |
| 308 |
if (state->min_latency == 0.0 && min_echo_latency != 0.0) { |
| 309 |
state->min_latency = min_echo_latency; |
| 310 |
} |
| 311 |
if (min_echo_latency < state->min_latency) { |
| 312 |
state->min_latency = min_echo_latency; |
| 313 |
} |
| 314 |
if (state->max_latency == 0.0) { |
| 315 |
state->max_latency = max_echo_latency; |
| 316 |
} |
| 317 |
if (max_echo_latency > state->max_latency) { |
| 318 |
state->max_latency = max_echo_latency; |
| 319 |
} |
| 320 |
|
| 321 |
if (state->timecount < state->timelimit) { |
| 322 |
te = tevent_add_timer(state->tctx->ev, |
| 323 |
state, |
| 324 |
timeval_current_ofs(1, 0), |
| 325 |
test_smb2_bench_echo_progress, |
| 326 |
state); |
| 327 |
torture_assert_goto(state->tctx, te != NULL, |
| 328 |
state->ok, asserted, "tevent_add_timer"); |
| 329 |
|
| 330 |
if (!torture_setting_bool(state->tctx, "progress", true)) { |
| 331 |
return; |
| 332 |
} |
| 333 |
|
| 334 |
avs_echo_latency = total_echo_latency / num_echos; |
| 335 |
|
| 336 |
torture_comment(state->tctx, |
| 337 |
"%.2f second: " |
| 338 |
"echo[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] \r", |
| 339 |
timeval_elapsed(&state->starttime), |
| 340 |
(unsigned long long)num_echos, |
| 341 |
avs_echo_latency, |
| 342 |
min_echo_latency, |
| 343 |
max_echo_latency); |
| 344 |
return; |
| 345 |
} |
| 346 |
|
| 347 |
avs_echo_latency = state->total_latency / state->num_finished; |
| 348 |
num_echos = state->num_finished / state->timelimit; |
| 349 |
|
| 350 |
torture_comment(state->tctx, |
| 351 |
"%.2f second: " |
| 352 |
"echo[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f]\n", |
| 353 |
timeval_elapsed(&state->starttime), |
| 354 |
(unsigned long long)num_echos, |
| 355 |
avs_echo_latency, |
| 356 |
state->min_latency, |
| 357 |
state->max_latency); |
| 358 |
|
| 359 |
asserted: |
| 360 |
state->stop = true; |
| 361 |
} |
| 362 |
|
| 363 |
static bool test_smb2_bench_echo(struct torture_context *tctx, |
| 364 |
struct smb2_tree *tree) |
| 365 |
{ |
| 366 |
struct test_smb2_bench_echo_state *state = NULL; |
| 367 |
bool ret = true; |
| 368 |
int torture_nprocs = torture_setting_int(tctx, "nprocs", 4); |
| 369 |
int torture_qdepth = torture_setting_int(tctx, "qdepth", 1); |
| 370 |
size_t i; |
| 371 |
size_t li = 0; |
| 372 |
int looplimit = torture_setting_int(tctx, "looplimit", -1); |
| 373 |
int timelimit = torture_setting_int(tctx, "timelimit", 10); |
| 374 |
struct tevent_timer *te = NULL; |
| 375 |
uint32_t timeout_msec; |
| 376 |
|
| 377 |
state = talloc_zero(tctx, struct test_smb2_bench_echo_state); |
| 378 |
torture_assert(tctx, state != NULL, __location__); |
| 379 |
state->tctx = tctx; |
| 380 |
state->num_conns = torture_nprocs; |
| 381 |
state->conns = talloc_zero_array(state, |
| 382 |
struct test_smb2_bench_echo_conn, |
| 383 |
state->num_conns); |
| 384 |
torture_assert(tctx, state->conns != NULL, __location__); |
| 385 |
state->num_loops = torture_nprocs * torture_qdepth; |
| 386 |
state->loops = talloc_zero_array(state, |
| 387 |
struct test_smb2_bench_echo_loop, |
| 388 |
state->num_loops); |
| 389 |
torture_assert(tctx, state->loops != NULL, __location__); |
| 390 |
state->ok = true; |
| 391 |
state->timelimit = MAX(timelimit, 1); |
| 392 |
|
| 393 |
timeout_msec = tree->session->transport->options.request_timeout * 1000; |
| 394 |
|
| 395 |
torture_comment(tctx, "Opening %zu connections\n", state->num_conns); |
| 396 |
|
| 397 |
for (i=0;i<state->num_conns;i++) { |
| 398 |
struct smb2_tree *ct = NULL; |
| 399 |
DATA_BLOB out_input_buffer = data_blob_null; |
| 400 |
DATA_BLOB out_output_buffer = data_blob_null; |
| 401 |
size_t pcli; |
| 402 |
|
| 403 |
state->conns[i].state = state; |
| 404 |
state->conns[i].idx = i; |
| 405 |
|
| 406 |
if (state->num_conns == 1) { |
| 407 |
/* |
| 408 |
* Use the existing connection |
| 409 |
*/ |
| 410 |
state->conns[i].tree = ct = tree; |
| 411 |
} else { |
| 412 |
if (!torture_smb2_connection(tctx, &ct)) { |
| 413 |
torture_comment(tctx, |
| 414 |
"Failed opening %zu/%zu connections\n", |
| 415 |
i, state->num_conns); |
| 416 |
return false; |
| 417 |
} |
| 418 |
state->conns[i].tree = talloc_steal(state->conns, ct); |
| 419 |
} |
| 420 |
|
| 421 |
smb2cli_conn_set_max_credits(ct->session->transport->conn, 8192); |
| 422 |
smb2cli_ioctl(ct->session->transport->conn, |
| 423 |
timeout_msec, |
| 424 |
ct->session->smbXcli, |
| 425 |
ct->smbXcli, |
| 426 |
UINT64_MAX, /* in_fid_persistent */ |
| 427 |
UINT64_MAX, /* in_fid_volatile */ |
| 428 |
UINT32_MAX, |
| 429 |
0, /* in_max_input_length */ |
| 430 |
NULL, /* in_input_buffer */ |
| 431 |
1, /* in_max_output_length */ |
| 432 |
NULL, /* in_output_buffer */ |
| 433 |
SMB2_IOCTL_FLAG_IS_FSCTL, |
| 434 |
ct, |
| 435 |
&out_input_buffer, |
| 436 |
&out_output_buffer); |
| 437 |
torture_assert(tctx, |
| 438 |
smbXcli_conn_is_connected(ct->session->transport->conn), |
| 439 |
"smbXcli_conn_is_connected"); |
| 440 |
|
| 441 |
for (pcli = 0; pcli < torture_qdepth; pcli++) { |
| 442 |
struct test_smb2_bench_echo_loop *loop = &state->loops[li]; |
| 443 |
|
| 444 |
loop->idx = li++; |
| 445 |
if (looplimit != -1) { |
| 446 |
loop->max_finished = looplimit; |
| 447 |
} else { |
| 448 |
loop->max_finished = UINT64_MAX; |
| 449 |
} |
| 450 |
loop->state = state; |
| 451 |
loop->conn = &state->conns[i]; |
| 452 |
loop->im = tevent_create_immediate(state->loops); |
| 453 |
torture_assert(tctx, loop->im != NULL, __location__); |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
for (li = 0; li <state->num_loops; li++) { |
| 458 |
struct test_smb2_bench_echo_loop *loop = &state->loops[li]; |
| 459 |
|
| 460 |
tevent_schedule_immediate(loop->im, |
| 461 |
tctx->ev, |
| 462 |
test_smb2_bench_echo_loop_start, |
| 463 |
loop); |
| 464 |
} |
| 465 |
|
| 466 |
torture_comment(tctx, "Opened %zu connections with qdepth=%d => %zu loops\n", |
| 467 |
state->num_conns, torture_qdepth, state->num_loops); |
| 468 |
|
| 469 |
torture_comment(tctx, "Running for %d seconds\n", state->timelimit); |
| 470 |
|
| 471 |
state->starttime = timeval_current(); |
| 472 |
state->pending_loops = state->num_loops; |
| 473 |
|
| 474 |
te = tevent_add_timer(tctx->ev, |
| 475 |
state, |
| 476 |
timeval_current_ofs(1, 0), |
| 477 |
test_smb2_bench_echo_progress, |
| 478 |
state); |
| 479 |
torture_assert(tctx, te != NULL, __location__); |
| 480 |
|
| 481 |
while (!state->stop) { |
| 482 |
int rc = tevent_loop_once(tctx->ev); |
| 483 |
torture_assert_int_equal(tctx, rc, 0, "tevent_loop_once"); |
| 484 |
} |
| 485 |
|
| 486 |
torture_comment(tctx, "%.2f seconds\n", timeval_elapsed(&state->starttime)); |
| 487 |
TALLOC_FREE(state); |
| 488 |
return ret; |
| 489 |
} |
| 490 |
|
| 491 |
/* |
| 492 |
stress testing path base operations |
| 493 |
e.g. contention on lockting.tdb records |
| 494 |
*/ |
| 495 |
|
| 496 |
struct test_smb2_bench_path_contention_shared_conn; |
| 497 |
struct test_smb2_bench_path_contention_shared_loop; |
| 498 |
|
| 499 |
struct test_smb2_bench_path_contention_shared_state { |
| 500 |
struct torture_context *tctx; |
| 501 |
size_t num_conns; |
| 502 |
struct test_smb2_bench_path_contention_shared_conn *conns; |
| 503 |
size_t num_loops; |
| 504 |
struct test_smb2_bench_path_contention_shared_loop *loops; |
| 505 |
struct timeval starttime; |
| 506 |
int timecount; |
| 507 |
int timelimit; |
| 508 |
struct { |
| 509 |
uint64_t num_finished; |
| 510 |
double total_latency; |
| 511 |
double min_latency; |
| 512 |
double max_latency; |
| 513 |
} opens; |
| 514 |
struct { |
| 515 |
uint64_t num_finished; |
| 516 |
double total_latency; |
| 517 |
double min_latency; |
| 518 |
double max_latency; |
| 519 |
} closes; |
| 520 |
bool ok; |
| 521 |
bool stop; |
| 522 |
}; |
| 523 |
|
| 524 |
struct test_smb2_bench_path_contention_shared_conn { |
| 525 |
struct test_smb2_bench_path_contention_shared_state *state; |
| 526 |
int idx; |
| 527 |
struct smb2_tree *tree; |
| 528 |
}; |
| 529 |
|
| 530 |
struct test_smb2_bench_path_contention_shared_loop { |
| 531 |
struct test_smb2_bench_path_contention_shared_state *state; |
| 532 |
struct test_smb2_bench_path_contention_shared_conn *conn; |
| 533 |
int idx; |
| 534 |
struct tevent_immediate *im; |
| 535 |
struct { |
| 536 |
struct smb2_create io; |
| 537 |
struct smb2_request *req; |
| 538 |
struct timeval starttime; |
| 539 |
uint64_t num_started; |
| 540 |
uint64_t num_finished; |
| 541 |
double total_latency; |
| 542 |
double min_latency; |
| 543 |
double max_latency; |
| 544 |
} opens; |
| 545 |
struct { |
| 546 |
struct smb2_close io; |
| 547 |
struct smb2_request *req; |
| 548 |
struct timeval starttime; |
| 549 |
uint64_t num_started; |
| 550 |
uint64_t num_finished; |
| 551 |
double total_latency; |
| 552 |
double min_latency; |
| 553 |
double max_latency; |
| 554 |
} closes; |
| 555 |
NTSTATUS error; |
| 556 |
}; |
| 557 |
|
| 558 |
static void test_smb2_bench_path_contention_loop_open( |
| 559 |
struct test_smb2_bench_path_contention_shared_loop *loop); |
| 560 |
|
| 561 |
static void test_smb2_bench_path_contention_loop_start(struct tevent_context *ctx, |
| 562 |
struct tevent_immediate *im, |
| 563 |
void *private_data) |
| 564 |
{ |
| 565 |
struct test_smb2_bench_path_contention_shared_loop *loop = |
| 566 |
(struct test_smb2_bench_path_contention_shared_loop *) |
| 567 |
private_data; |
| 568 |
|
| 569 |
test_smb2_bench_path_contention_loop_open(loop); |
| 570 |
} |
| 571 |
|
| 572 |
static void test_smb2_bench_path_contention_loop_opened(struct smb2_request *req); |
| 573 |
|
| 574 |
static void test_smb2_bench_path_contention_loop_open( |
| 575 |
struct test_smb2_bench_path_contention_shared_loop *loop) |
| 576 |
{ |
| 577 |
struct test_smb2_bench_path_contention_shared_state *state = loop->state; |
| 578 |
|
| 579 |
loop->opens.num_started += 1; |
| 580 |
loop->opens.starttime = timeval_current(); |
| 581 |
loop->opens.req = smb2_create_send(loop->conn->tree, &loop->opens.io); |
| 582 |
torture_assert_goto(state->tctx, loop->opens.req != NULL, |
| 583 |
state->ok, asserted, "smb2_create_send"); |
| 584 |
|
| 585 |
loop->opens.req->async.fn = test_smb2_bench_path_contention_loop_opened; |
| 586 |
loop->opens.req->async.private_data = loop; |
| 587 |
return; |
| 588 |
asserted: |
| 589 |
state->stop = true; |
| 590 |
} |
| 591 |
|
| 592 |
static void test_smb2_bench_path_contention_loop_close( |
| 593 |
struct test_smb2_bench_path_contention_shared_loop *loop); |
| 594 |
|
| 595 |
static void test_smb2_bench_path_contention_loop_opened(struct smb2_request *req) |
| 596 |
{ |
| 597 |
struct test_smb2_bench_path_contention_shared_loop *loop = |
| 598 |
(struct test_smb2_bench_path_contention_shared_loop *) |
| 599 |
req->async.private_data; |
| 600 |
struct test_smb2_bench_path_contention_shared_state *state = loop->state; |
| 601 |
double latency = timeval_elapsed(&loop->opens.starttime); |
| 602 |
TALLOC_CTX *frame = talloc_stackframe(); |
| 603 |
|
| 604 |
torture_assert_goto(state->tctx, loop->opens.req == req, |
| 605 |
state->ok, asserted, __location__); |
| 606 |
loop->error = smb2_create_recv(req, frame, &loop->opens.io); |
| 607 |
torture_assert_ntstatus_ok_goto(state->tctx, loop->error, |
| 608 |
state->ok, asserted, __location__); |
| 609 |
ZERO_STRUCT(loop->opens.io.out.blobs); |
| 610 |
SMB_ASSERT(latency >= 0.000001); |
| 611 |
|
| 612 |
if (loop->opens.num_finished == 0) { |
| 613 |
/* first round */ |
| 614 |
loop->opens.min_latency = latency; |
| 615 |
loop->opens.max_latency = latency; |
| 616 |
} |
| 617 |
|
| 618 |
loop->opens.num_finished += 1; |
| 619 |
loop->opens.total_latency += latency; |
| 620 |
|
| 621 |
if (latency < loop->opens.min_latency) { |
| 622 |
loop->opens.min_latency = latency; |
| 623 |
} |
| 624 |
|
| 625 |
if (latency > loop->opens.max_latency) { |
| 626 |
loop->opens.max_latency = latency; |
| 627 |
} |
| 628 |
|
| 629 |
TALLOC_FREE(frame); |
| 630 |
test_smb2_bench_path_contention_loop_close(loop); |
| 631 |
return; |
| 632 |
asserted: |
| 633 |
state->stop = true; |
| 634 |
TALLOC_FREE(frame); |
| 635 |
} |
| 636 |
|
| 637 |
static void test_smb2_bench_path_contention_loop_closed(struct smb2_request *req); |
| 638 |
|
| 639 |
static void test_smb2_bench_path_contention_loop_close( |
| 640 |
struct test_smb2_bench_path_contention_shared_loop *loop) |
| 641 |
{ |
| 642 |
struct test_smb2_bench_path_contention_shared_state *state = loop->state; |
| 643 |
|
| 644 |
loop->closes.num_started += 1; |
| 645 |
loop->closes.starttime = timeval_current(); |
| 646 |
loop->closes.io.in.file = loop->opens.io.out.file; |
| 647 |
loop->closes.req = smb2_close_send(loop->conn->tree, &loop->closes.io); |
| 648 |
torture_assert_goto(state->tctx, loop->closes.req != NULL, |
| 649 |
state->ok, asserted, "smb2_close_send"); |
| 650 |
|
| 651 |
loop->closes.req->async.fn = test_smb2_bench_path_contention_loop_closed; |
| 652 |
loop->closes.req->async.private_data = loop; |
| 653 |
return; |
| 654 |
asserted: |
| 655 |
state->stop = true; |
| 656 |
} |
| 657 |
|
| 658 |
static void test_smb2_bench_path_contention_loop_closed(struct smb2_request *req) |
| 659 |
{ |
| 660 |
struct test_smb2_bench_path_contention_shared_loop *loop = |
| 661 |
(struct test_smb2_bench_path_contention_shared_loop *) |
| 662 |
req->async.private_data; |
| 663 |
struct test_smb2_bench_path_contention_shared_state *state = loop->state; |
| 664 |
double latency = timeval_elapsed(&loop->closes.starttime); |
| 665 |
|
| 666 |
torture_assert_goto(state->tctx, loop->closes.req == req, |
| 667 |
state->ok, asserted, __location__); |
| 668 |
loop->error = smb2_close_recv(req, &loop->closes.io); |
| 669 |
torture_assert_ntstatus_ok_goto(state->tctx, loop->error, |
| 670 |
state->ok, asserted, __location__); |
| 671 |
SMB_ASSERT(latency >= 0.000001); |
| 672 |
if (loop->closes.num_finished == 0) { |
| 673 |
/* first round */ |
| 674 |
loop->closes.min_latency = latency; |
| 675 |
loop->closes.max_latency = latency; |
| 676 |
} |
| 677 |
loop->closes.num_finished += 1; |
| 678 |
|
| 679 |
loop->closes.total_latency += latency; |
| 680 |
|
| 681 |
if (latency < loop->closes.min_latency) { |
| 682 |
loop->closes.min_latency = latency; |
| 683 |
} |
| 684 |
|
| 685 |
if (latency > loop->closes.max_latency) { |
| 686 |
loop->closes.max_latency = latency; |
| 687 |
} |
| 688 |
|
| 689 |
test_smb2_bench_path_contention_loop_open(loop); |
| 690 |
return; |
| 691 |
asserted: |
| 692 |
state->stop = true; |
| 693 |
} |
| 694 |
|
| 695 |
static void test_smb2_bench_path_contention_progress(struct tevent_context *ev, |
| 696 |
struct tevent_timer *te, |
| 697 |
struct timeval current_time, |
| 698 |
void *private_data) |
| 699 |
{ |
| 700 |
struct test_smb2_bench_path_contention_shared_state *state = |
| 701 |
(struct test_smb2_bench_path_contention_shared_state *)private_data; |
| 702 |
uint64_t num_opens = 0; |
| 703 |
double total_open_latency = 0; |
| 704 |
double min_open_latency = 0; |
| 705 |
double max_open_latency = 0; |
| 706 |
double avs_open_latency = 0; |
| 707 |
uint64_t num_closes = 0; |
| 708 |
double total_close_latency = 0; |
| 709 |
double min_close_latency = 0; |
| 710 |
double max_close_latency = 0; |
| 711 |
double avs_close_latency = 0; |
| 712 |
size_t i; |
| 713 |
|
| 714 |
state->timecount += 1; |
| 715 |
|
| 716 |
for (i=0;i<state->num_loops;i++) { |
| 717 |
struct test_smb2_bench_path_contention_shared_loop *loop = |
| 718 |
&state->loops[i]; |
| 719 |
|
| 720 |
num_opens += loop->opens.num_finished; |
| 721 |
total_open_latency += loop->opens.total_latency; |
| 722 |
if (min_open_latency == 0.0 && loop->opens.min_latency != 0.0) { |
| 723 |
min_open_latency = loop->opens.min_latency; |
| 724 |
} |
| 725 |
if (loop->opens.min_latency < min_open_latency) { |
| 726 |
min_open_latency = loop->opens.min_latency; |
| 727 |
} |
| 728 |
if (max_open_latency == 0.0) { |
| 729 |
max_open_latency = loop->opens.max_latency; |
| 730 |
} |
| 731 |
if (loop->opens.max_latency > max_open_latency) { |
| 732 |
max_open_latency = loop->opens.max_latency; |
| 733 |
} |
| 734 |
loop->opens.num_finished = 0; |
| 735 |
loop->opens.total_latency = 0.0; |
| 736 |
|
| 737 |
num_closes += loop->closes.num_finished; |
| 738 |
total_close_latency += loop->closes.total_latency; |
| 739 |
if (min_close_latency == 0.0 && loop->closes.min_latency != 0.0) { |
| 740 |
min_close_latency = loop->closes.min_latency; |
| 741 |
} |
| 742 |
if (loop->closes.min_latency < min_close_latency) { |
| 743 |
min_close_latency = loop->closes.min_latency; |
| 744 |
} |
| 745 |
if (max_close_latency == 0.0) { |
| 746 |
max_close_latency = loop->closes.max_latency; |
| 747 |
} |
| 748 |
if (loop->closes.max_latency > max_close_latency) { |
| 749 |
max_close_latency = loop->closes.max_latency; |
| 750 |
} |
| 751 |
loop->closes.num_finished = 0; |
| 752 |
loop->closes.total_latency = 0.0; |
| 753 |
} |
| 754 |
|
| 755 |
state->opens.num_finished += num_opens; |
| 756 |
state->opens.total_latency += total_open_latency; |
| 757 |
if (state->opens.min_latency == 0.0 && min_open_latency != 0.0) { |
| 758 |
state->opens.min_latency = min_open_latency; |
| 759 |
} |
| 760 |
if (min_open_latency < state->opens.min_latency) { |
| 761 |
state->opens.min_latency = min_open_latency; |
| 762 |
} |
| 763 |
if (state->opens.max_latency == 0.0) { |
| 764 |
state->opens.max_latency = max_open_latency; |
| 765 |
} |
| 766 |
if (max_open_latency > state->opens.max_latency) { |
| 767 |
state->opens.max_latency = max_open_latency; |
| 768 |
} |
| 769 |
|
| 770 |
state->closes.num_finished += num_closes; |
| 771 |
state->closes.total_latency += total_close_latency; |
| 772 |
if (state->closes.min_latency == 0.0 && min_close_latency != 0.0) { |
| 773 |
state->closes.min_latency = min_close_latency; |
| 774 |
} |
| 775 |
if (min_close_latency < state->closes.min_latency) { |
| 776 |
state->closes.min_latency = min_close_latency; |
| 777 |
} |
| 778 |
if (state->closes.max_latency == 0.0) { |
| 779 |
state->closes.max_latency = max_close_latency; |
| 780 |
} |
| 781 |
if (max_close_latency > state->closes.max_latency) { |
| 782 |
state->closes.max_latency = max_close_latency; |
| 783 |
} |
| 784 |
|
| 785 |
if (state->timecount < state->timelimit) { |
| 786 |
te = tevent_add_timer(state->tctx->ev, |
| 787 |
state, |
| 788 |
timeval_current_ofs(1, 0), |
| 789 |
test_smb2_bench_path_contention_progress, |
| 790 |
state); |
| 791 |
torture_assert_goto(state->tctx, te != NULL, |
| 792 |
state->ok, asserted, "tevent_add_timer"); |
| 793 |
|
| 794 |
if (!torture_setting_bool(state->tctx, "progress", true)) { |
| 795 |
return; |
| 796 |
} |
| 797 |
|
| 798 |
avs_open_latency = total_open_latency / num_opens; |
| 799 |
avs_close_latency = total_close_latency / num_closes; |
| 800 |
|
| 801 |
torture_comment(state->tctx, |
| 802 |
"%.2f second: " |
| 803 |
"open[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] " |
| 804 |
"close[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] \r", |
| 805 |
timeval_elapsed(&state->starttime), |
| 806 |
(unsigned long long)num_opens, |
| 807 |
avs_open_latency, |
| 808 |
min_open_latency, |
| 809 |
max_open_latency, |
| 810 |
(unsigned long long)num_closes, |
| 811 |
avs_close_latency, |
| 812 |
min_close_latency, |
| 813 |
max_close_latency); |
| 814 |
return; |
| 815 |
} |
| 816 |
|
| 817 |
avs_open_latency = state->opens.total_latency / state->opens.num_finished; |
| 818 |
avs_close_latency = state->closes.total_latency / state->closes.num_finished; |
| 819 |
num_opens = state->opens.num_finished / state->timelimit; |
| 820 |
num_closes = state->closes.num_finished / state->timelimit; |
| 821 |
|
| 822 |
torture_comment(state->tctx, |
| 823 |
"%.2f second: " |
| 824 |
"open[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] " |
| 825 |
"close[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f]\n", |
| 826 |
timeval_elapsed(&state->starttime), |
| 827 |
(unsigned long long)num_opens, |
| 828 |
avs_open_latency, |
| 829 |
state->opens.min_latency, |
| 830 |
state->opens.max_latency, |
| 831 |
(unsigned long long)num_closes, |
| 832 |
avs_close_latency, |
| 833 |
state->closes.min_latency, |
| 834 |
state->closes.max_latency); |
| 835 |
|
| 836 |
asserted: |
| 837 |
state->stop = true; |
| 838 |
} |
| 839 |
|
| 840 |
bool test_smb2_bench_path_contention_shared(struct torture_context *tctx, |
| 841 |
struct smb2_tree *tree) |
| 842 |
{ |
| 843 |
struct test_smb2_bench_path_contention_shared_state *state = NULL; |
| 844 |
bool ret = true; |
| 845 |
int torture_nprocs = torture_setting_int(tctx, "nprocs", 4); |
| 846 |
int torture_qdepth = torture_setting_int(tctx, "qdepth", 1); |
| 847 |
size_t i; |
| 848 |
size_t li = 0; |
| 849 |
int timelimit = torture_setting_int(tctx, "timelimit", 10); |
| 850 |
const char *path = torture_setting_string(tctx, "bench_path", ""); |
| 851 |
struct smb2_create open_io = { .level = RAW_OPEN_SMB2, }; |
| 852 |
struct smb2_close close_io = { .level = RAW_CLOSE_SMB2, }; |
| 853 |
struct tevent_timer *te = NULL; |
| 854 |
uint32_t timeout_msec; |
| 855 |
|
| 856 |
state = talloc_zero(tctx, struct test_smb2_bench_path_contention_shared_state); |
| 857 |
torture_assert(tctx, state != NULL, __location__); |
| 858 |
state->tctx = tctx; |
| 859 |
state->num_conns = torture_nprocs; |
| 860 |
state->conns = talloc_zero_array(state, |
| 861 |
struct test_smb2_bench_path_contention_shared_conn, |
| 862 |
state->num_conns); |
| 863 |
torture_assert(tctx, state->conns != NULL, __location__); |
| 864 |
state->num_loops = torture_nprocs * torture_qdepth; |
| 865 |
state->loops = talloc_zero_array(state, |
| 866 |
struct test_smb2_bench_path_contention_shared_loop, |
| 867 |
state->num_loops); |
| 868 |
torture_assert(tctx, state->loops != NULL, __location__); |
| 869 |
state->ok = true; |
| 870 |
state->timelimit = MAX(timelimit, 1); |
| 871 |
|
| 872 |
open_io.in.desired_access = SEC_DIR_READ_ATTRIBUTE; |
| 873 |
open_io.in.alloc_size = 0; |
| 874 |
open_io.in.file_attributes = 0; |
| 875 |
open_io.in.share_access = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE; |
| 876 |
open_io.in.create_disposition = FILE_OPEN; |
| 877 |
open_io.in.create_options = FILE_OPEN_REPARSE_POINT; |
| 878 |
open_io.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS; |
| 879 |
open_io.in.security_flags = 0; |
| 880 |
open_io.in.fname = path; |
| 881 |
open_io.in.create_flags = NTCREATEX_FLAGS_EXTENDED; |
| 882 |
open_io.in.oplock_level = SMB2_OPLOCK_LEVEL_NONE; |
| 883 |
|
| 884 |
timeout_msec = tree->session->transport->options.request_timeout * 1000; |
| 885 |
|
| 886 |
torture_comment(tctx, "Opening %zd connections\n", state->num_conns); |
| 887 |
|
| 888 |
for (i=0;i<state->num_conns;i++) { |
| 889 |
struct smb2_tree *ct = NULL; |
| 890 |
DATA_BLOB out_input_buffer = data_blob_null; |
| 891 |
DATA_BLOB out_output_buffer = data_blob_null; |
| 892 |
size_t pcli; |
| 893 |
|
| 894 |
state->conns[i].state = state; |
| 895 |
state->conns[i].idx = i; |
| 896 |
|
| 897 |
if (state->num_conns == 1) { |
| 898 |
/* |
| 899 |
* Use the existing connection |
| 900 |
*/ |
| 901 |
state->conns[i].tree = ct = tree; |
| 902 |
} else { |
| 903 |
if (!torture_smb2_connection(tctx, &ct)) { |
| 904 |
torture_comment(tctx, |
| 905 |
"Failed opening %zu/%zu connections\n", |
| 906 |
i, state->num_conns); |
| 907 |
return false; |
| 908 |
} |
| 909 |
state->conns[i].tree = talloc_steal(state->conns, ct); |
| 910 |
} |
| 911 |
|
| 912 |
smb2cli_conn_set_max_credits(ct->session->transport->conn, 8192); |
| 913 |
smb2cli_ioctl(ct->session->transport->conn, |
| 914 |
timeout_msec, |
| 915 |
ct->session->smbXcli, |
| 916 |
ct->smbXcli, |
| 917 |
UINT64_MAX, /* in_fid_persistent */ |
| 918 |
UINT64_MAX, /* in_fid_volatile */ |
| 919 |
UINT32_MAX, |
| 920 |
0, /* in_max_input_length */ |
| 921 |
NULL, /* in_input_buffer */ |
| 922 |
1, /* in_max_output_length */ |
| 923 |
NULL, /* in_output_buffer */ |
| 924 |
SMB2_IOCTL_FLAG_IS_FSCTL, |
| 925 |
ct, |
| 926 |
&out_input_buffer, |
| 927 |
&out_output_buffer); |
| 928 |
torture_assert(tctx, |
| 929 |
smbXcli_conn_is_connected(ct->session->transport->conn), |
| 930 |
"smbXcli_conn_is_connected"); |
| 931 |
for (pcli = 0; pcli < torture_qdepth; pcli++) { |
| 932 |
struct test_smb2_bench_path_contention_shared_loop *loop = &state->loops[li]; |
| 933 |
|
| 934 |
loop->idx = li++; |
| 935 |
loop->state = state; |
| 936 |
loop->conn = &state->conns[i]; |
| 937 |
loop->im = tevent_create_immediate(state->loops); |
| 938 |
torture_assert(tctx, loop->im != NULL, __location__); |
| 939 |
loop->opens.io = open_io; |
| 940 |
loop->closes.io = close_io; |
| 941 |
} |
| 942 |
} |
| 943 |
|
| 944 |
for (li = 0; li <state->num_loops; li++) { |
| 945 |
struct test_smb2_bench_path_contention_shared_loop *loop = &state->loops[li]; |
| 946 |
|
| 947 |
tevent_schedule_immediate(loop->im, |
| 948 |
tctx->ev, |
| 949 |
test_smb2_bench_path_contention_loop_start, |
| 950 |
loop); |
| 951 |
} |
| 952 |
|
| 953 |
torture_comment(tctx, "Opened %zu connections with qdepth=%d => %zu loops\n", |
| 954 |
state->num_conns, torture_qdepth, state->num_loops); |
| 955 |
|
| 956 |
torture_comment(tctx, "Running for %d seconds\n", state->timelimit); |
| 957 |
|
| 958 |
state->starttime = timeval_current(); |
| 959 |
|
| 960 |
te = tevent_add_timer(tctx->ev, |
| 961 |
state, |
| 962 |
timeval_current_ofs(1, 0), |
| 963 |
test_smb2_bench_path_contention_progress, |
| 964 |
state); |
| 965 |
torture_assert(tctx, te != NULL, __location__); |
| 966 |
|
| 967 |
while (!state->stop) { |
| 968 |
int rc = tevent_loop_once(tctx->ev); |
| 969 |
torture_assert_int_equal(tctx, rc, 0, "tevent_loop_once"); |
| 970 |
} |
| 971 |
|
| 972 |
torture_comment(tctx, "%.2f seconds\n", timeval_elapsed(&state->starttime)); |
| 973 |
TALLOC_FREE(state); |
| 974 |
return ret; |
| 975 |
} |
| 976 |
|
| 977 |
/* |
| 978 |
stress testing read iops |
| 979 |
*/ |
| 980 |
|
| 981 |
struct test_smb2_bench_read_conn; |
| 982 |
struct test_smb2_bench_read_loop; |
| 983 |
|
| 984 |
struct test_smb2_bench_read_state { |
| 985 |
struct torture_context *tctx; |
| 986 |
size_t num_conns; |
| 987 |
struct test_smb2_bench_read_conn *conns; |
| 988 |
size_t num_loops; |
| 989 |
struct test_smb2_bench_read_loop *loops; |
| 990 |
size_t pending_loops; |
| 991 |
uint32_t io_size; |
| 992 |
struct timeval starttime; |
| 993 |
int timecount; |
| 994 |
int timelimit; |
| 995 |
uint64_t num_finished; |
| 996 |
double total_latency; |
| 997 |
double min_latency; |
| 998 |
double max_latency; |
| 999 |
bool ok; |
| 1000 |
bool stop; |
| 1001 |
}; |
| 1002 |
|
| 1003 |
struct test_smb2_bench_read_conn { |
| 1004 |
struct test_smb2_bench_read_state *state; |
| 1005 |
int idx; |
| 1006 |
struct smb2_tree *tree; |
| 1007 |
}; |
| 1008 |
|
| 1009 |
struct test_smb2_bench_read_loop { |
| 1010 |
struct test_smb2_bench_read_state *state; |
| 1011 |
struct test_smb2_bench_read_conn *conn; |
| 1012 |
int idx; |
| 1013 |
struct tevent_immediate *im; |
| 1014 |
char *fname; |
| 1015 |
struct smb2_handle handle; |
| 1016 |
struct tevent_req *req; |
| 1017 |
struct timeval starttime; |
| 1018 |
uint64_t num_started; |
| 1019 |
uint64_t num_finished; |
| 1020 |
uint64_t total_finished; |
| 1021 |
uint64_t max_finished; |
| 1022 |
double total_latency; |
| 1023 |
double min_latency; |
| 1024 |
double max_latency; |
| 1025 |
NTSTATUS error; |
| 1026 |
}; |
| 1027 |
|
| 1028 |
static void test_smb2_bench_read_loop_do( |
| 1029 |
struct test_smb2_bench_read_loop *loop); |
| 1030 |
|
| 1031 |
static void test_smb2_bench_read_loop_start(struct tevent_context *ctx, |
| 1032 |
struct tevent_immediate *im, |
| 1033 |
void *private_data) |
| 1034 |
{ |
| 1035 |
struct test_smb2_bench_read_loop *loop = |
| 1036 |
(struct test_smb2_bench_read_loop *) |
| 1037 |
private_data; |
| 1038 |
|
| 1039 |
test_smb2_bench_read_loop_do(loop); |
| 1040 |
} |
| 1041 |
|
| 1042 |
static void test_smb2_bench_read_loop_done(struct tevent_req *req); |
| 1043 |
|
| 1044 |
static void test_smb2_bench_read_loop_do( |
| 1045 |
struct test_smb2_bench_read_loop *loop) |
| 1046 |
{ |
| 1047 |
struct test_smb2_bench_read_state *state = loop->state; |
| 1048 |
uint32_t timeout_msec; |
| 1049 |
|
| 1050 |
timeout_msec = loop->conn->tree->session->transport->options.request_timeout * 1000; |
| 1051 |
|
| 1052 |
loop->num_started += 1; |
| 1053 |
loop->starttime = timeval_current(); |
| 1054 |
loop->req = smb2cli_read_send(state->loops, |
| 1055 |
state->tctx->ev, |
| 1056 |
loop->conn->tree->session->transport->conn, |
| 1057 |
timeout_msec, |
| 1058 |
loop->conn->tree->session->smbXcli, |
| 1059 |
loop->conn->tree->smbXcli, |
| 1060 |
state->io_size, /* length */ |
| 1061 |
0, /* offset */ |
| 1062 |
loop->handle.data[0],/* fid_persistent */ |
| 1063 |
loop->handle.data[1],/* fid_volatile */ |
| 1064 |
state->io_size, /* minimum_count */ |
| 1065 |
0); /* remaining_bytes */ |
| 1066 |
torture_assert_goto(state->tctx, loop->req != NULL, |
| 1067 |
state->ok, asserted, "smb2cli_read_send"); |
| 1068 |
|
| 1069 |
tevent_req_set_callback(loop->req, |
| 1070 |
test_smb2_bench_read_loop_done, |
| 1071 |
loop); |
| 1072 |
return; |
| 1073 |
asserted: |
| 1074 |
state->stop = true; |
| 1075 |
} |
| 1076 |
|
| 1077 |
static void test_smb2_bench_read_loop_done(struct tevent_req *req) |
| 1078 |
{ |
| 1079 |
struct test_smb2_bench_read_loop *loop = |
| 1080 |
(struct test_smb2_bench_read_loop *) |
| 1081 |
_tevent_req_callback_data(req); |
| 1082 |
struct test_smb2_bench_read_state *state = loop->state; |
| 1083 |
double latency = timeval_elapsed(&loop->starttime); |
| 1084 |
TALLOC_CTX *frame = talloc_stackframe(); |
| 1085 |
uint8_t *data = NULL; |
| 1086 |
uint32_t data_length = 0; |
| 1087 |
|
| 1088 |
torture_assert_goto(state->tctx, loop->req == req, |
| 1089 |
state->ok, asserted, __location__); |
| 1090 |
loop->error = smb2cli_read_recv(req, frame, &data, &data_length); |
| 1091 |
torture_assert_ntstatus_ok_goto(state->tctx, loop->error, |
| 1092 |
state->ok, asserted, __location__); |
| 1093 |
torture_assert_u32_equal_goto(state->tctx, data_length, state->io_size, |
| 1094 |
state->ok, asserted, __location__); |
| 1095 |
SMB_ASSERT(latency >= 0.000001); |
| 1096 |
|
| 1097 |
if (loop->num_finished == 0) { |
| 1098 |
/* first round */ |
| 1099 |
loop->min_latency = latency; |
| 1100 |
loop->max_latency = latency; |
| 1101 |
} |
| 1102 |
|
| 1103 |
loop->num_finished += 1; |
| 1104 |
loop->total_finished += 1; |
| 1105 |
loop->total_latency += latency; |
| 1106 |
|
| 1107 |
if (latency < loop->min_latency) { |
| 1108 |
loop->min_latency = latency; |
| 1109 |
} |
| 1110 |
|
| 1111 |
if (latency > loop->max_latency) { |
| 1112 |
loop->max_latency = latency; |
| 1113 |
} |
| 1114 |
|
| 1115 |
if (loop->total_finished >= loop->max_finished) { |
| 1116 |
if (state->pending_loops > 0) { |
| 1117 |
state->pending_loops -= 1; |
| 1118 |
} |
| 1119 |
if (state->pending_loops == 0) { |
| 1120 |
goto asserted; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
TALLOC_FREE(frame); |
| 1125 |
test_smb2_bench_read_loop_do(loop); |
| 1126 |
return; |
| 1127 |
asserted: |
| 1128 |
state->stop = true; |
| 1129 |
TALLOC_FREE(frame); |
| 1130 |
} |
| 1131 |
|
| 1132 |
static void test_smb2_bench_read_progress(struct tevent_context *ev, |
| 1133 |
struct tevent_timer *te, |
| 1134 |
struct timeval current_time, |
| 1135 |
void *private_data) |
| 1136 |
{ |
| 1137 |
struct test_smb2_bench_read_state *state = |
| 1138 |
(struct test_smb2_bench_read_state *)private_data; |
| 1139 |
uint64_t num_reads = 0; |
| 1140 |
double total_read_latency = 0; |
| 1141 |
double min_read_latency = 0; |
| 1142 |
double max_read_latency = 0; |
| 1143 |
double avs_read_latency = 0; |
| 1144 |
size_t i; |
| 1145 |
|
| 1146 |
state->timecount += 1; |
| 1147 |
|
| 1148 |
for (i=0;i<state->num_loops;i++) { |
| 1149 |
struct test_smb2_bench_read_loop *loop = |
| 1150 |
&state->loops[i]; |
| 1151 |
|
| 1152 |
num_reads += loop->num_finished; |
| 1153 |
total_read_latency += loop->total_latency; |
| 1154 |
if (min_read_latency == 0.0 && loop->min_latency != 0.0) { |
| 1155 |
min_read_latency = loop->min_latency; |
| 1156 |
} |
| 1157 |
if (loop->min_latency < min_read_latency) { |
| 1158 |
min_read_latency = loop->min_latency; |
| 1159 |
} |
| 1160 |
if (max_read_latency == 0.0) { |
| 1161 |
max_read_latency = loop->max_latency; |
| 1162 |
} |
| 1163 |
if (loop->max_latency > max_read_latency) { |
| 1164 |
max_read_latency = loop->max_latency; |
| 1165 |
} |
| 1166 |
loop->num_finished = 0; |
| 1167 |
loop->total_latency = 0.0; |
| 1168 |
} |
| 1169 |
|
| 1170 |
state->num_finished += num_reads; |
| 1171 |
state->total_latency += total_read_latency; |
| 1172 |
if (state->min_latency == 0.0 && min_read_latency != 0.0) { |
| 1173 |
state->min_latency = min_read_latency; |
| 1174 |
} |
| 1175 |
if (min_read_latency < state->min_latency) { |
| 1176 |
state->min_latency = min_read_latency; |
| 1177 |
} |
| 1178 |
if (state->max_latency == 0.0) { |
| 1179 |
state->max_latency = max_read_latency; |
| 1180 |
} |
| 1181 |
if (max_read_latency > state->max_latency) { |
| 1182 |
state->max_latency = max_read_latency; |
| 1183 |
} |
| 1184 |
|
| 1185 |
if (state->timecount < state->timelimit) { |
| 1186 |
te = tevent_add_timer(state->tctx->ev, |
| 1187 |
state, |
| 1188 |
timeval_current_ofs(1, 0), |
| 1189 |
test_smb2_bench_read_progress, |
| 1190 |
state); |
| 1191 |
torture_assert_goto(state->tctx, te != NULL, |
| 1192 |
state->ok, asserted, "tevent_add_timer"); |
| 1193 |
|
| 1194 |
if (!torture_setting_bool(state->tctx, "progress", true)) { |
| 1195 |
return; |
| 1196 |
} |
| 1197 |
|
| 1198 |
avs_read_latency = total_read_latency / num_reads; |
| 1199 |
|
| 1200 |
torture_comment(state->tctx, |
| 1201 |
"%.2f second: " |
| 1202 |
"read[num/s=%llu,bytes/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] \r", |
| 1203 |
timeval_elapsed(&state->starttime), |
| 1204 |
(unsigned long long)num_reads, |
| 1205 |
(unsigned long long)num_reads*state->io_size, |
| 1206 |
avs_read_latency, |
| 1207 |
min_read_latency, |
| 1208 |
max_read_latency); |
| 1209 |
return; |
| 1210 |
} |
| 1211 |
|
| 1212 |
avs_read_latency = state->total_latency / state->num_finished; |
| 1213 |
num_reads = state->num_finished / state->timelimit; |
| 1214 |
|
| 1215 |
torture_comment(state->tctx, |
| 1216 |
"%.2f second: " |
| 1217 |
"read[num/s=%llu,bytes/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f]\n", |
| 1218 |
timeval_elapsed(&state->starttime), |
| 1219 |
(unsigned long long)num_reads, |
| 1220 |
(unsigned long long)num_reads*state->io_size, |
| 1221 |
avs_read_latency, |
| 1222 |
state->min_latency, |
| 1223 |
state->max_latency); |
| 1224 |
|
| 1225 |
asserted: |
| 1226 |
state->stop = true; |
| 1227 |
} |
| 1228 |
|
| 1229 |
static bool test_smb2_bench_read(struct torture_context *tctx, |
| 1230 |
struct smb2_tree *tree) |
| 1231 |
{ |
| 1232 |
struct test_smb2_bench_read_state *state = NULL; |
| 1233 |
bool ret = true; |
| 1234 |
int torture_nprocs = torture_setting_int(tctx, "nprocs", 4); |
| 1235 |
int torture_qdepth = torture_setting_int(tctx, "qdepth", 1); |
| 1236 |
int torture_io_size = torture_setting_int(tctx, "io_size", 4096); |
| 1237 |
size_t i; |
| 1238 |
size_t li = 0; |
| 1239 |
int looplimit = torture_setting_int(tctx, "looplimit", -1); |
| 1240 |
int timelimit = torture_setting_int(tctx, "timelimit", 10); |
| 1241 |
struct tevent_timer *te = NULL; |
| 1242 |
uint32_t timeout_msec; |
| 1243 |
const char *dname = "bench_read_dir"; |
| 1244 |
const char *unique = generate_random_str(tctx, 8); |
| 1245 |
struct smb2_handle dh; |
| 1246 |
NTSTATUS status; |
| 1247 |
|
| 1248 |
smb2_deltree(tree, dname); |
| 1249 |
|
| 1250 |
status = torture_smb2_testdir(tree, dname, &dh); |
| 1251 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1252 |
status = smb2_util_close(tree, dh); |
| 1253 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1254 |
|
| 1255 |
state = talloc_zero(tctx, struct test_smb2_bench_read_state); |
| 1256 |
torture_assert(tctx, state != NULL, __location__); |
| 1257 |
state->tctx = tctx; |
| 1258 |
state->num_conns = torture_nprocs; |
| 1259 |
state->conns = talloc_zero_array(state, |
| 1260 |
struct test_smb2_bench_read_conn, |
| 1261 |
state->num_conns); |
| 1262 |
torture_assert(tctx, state->conns != NULL, __location__); |
| 1263 |
state->num_loops = torture_nprocs * torture_qdepth; |
| 1264 |
state->loops = talloc_zero_array(state, |
| 1265 |
struct test_smb2_bench_read_loop, |
| 1266 |
state->num_loops); |
| 1267 |
torture_assert(tctx, state->loops != NULL, __location__); |
| 1268 |
state->ok = true; |
| 1269 |
state->timelimit = MAX(timelimit, 1); |
| 1270 |
state->io_size = MAX(torture_io_size, 1); |
| 1271 |
state->io_size = MIN(state->io_size, 16*1024*1024); |
| 1272 |
|
| 1273 |
timeout_msec = tree->session->transport->options.request_timeout * 1000; |
| 1274 |
|
| 1275 |
torture_comment(tctx, "Opening %zu connections\n", state->num_conns); |
| 1276 |
|
| 1277 |
for (i=0;i<state->num_conns;i++) { |
| 1278 |
struct smb2_tree *ct = NULL; |
| 1279 |
DATA_BLOB out_input_buffer = data_blob_null; |
| 1280 |
DATA_BLOB out_output_buffer = data_blob_null; |
| 1281 |
size_t pcli; |
| 1282 |
|
| 1283 |
state->conns[i].state = state; |
| 1284 |
state->conns[i].idx = i; |
| 1285 |
|
| 1286 |
if (state->num_conns == 1) { |
| 1287 |
/* |
| 1288 |
* Use the existing connection |
| 1289 |
*/ |
| 1290 |
state->conns[i].tree = ct = tree; |
| 1291 |
} else { |
| 1292 |
if (!torture_smb2_connection(tctx, &ct)) { |
| 1293 |
torture_comment(tctx, |
| 1294 |
"Failed opening %zu/%zu connections\n", |
| 1295 |
i, state->num_conns); |
| 1296 |
return false; |
| 1297 |
} |
| 1298 |
state->conns[i].tree = talloc_steal(state->conns, ct); |
| 1299 |
} |
| 1300 |
|
| 1301 |
smb2cli_conn_set_max_credits(ct->session->transport->conn, 8192); |
| 1302 |
smb2cli_ioctl(ct->session->transport->conn, |
| 1303 |
timeout_msec, |
| 1304 |
ct->session->smbXcli, |
| 1305 |
ct->smbXcli, |
| 1306 |
UINT64_MAX, /* in_fid_persistent */ |
| 1307 |
UINT64_MAX, /* in_fid_volatile */ |
| 1308 |
UINT32_MAX, |
| 1309 |
0, /* in_max_input_length */ |
| 1310 |
NULL, /* in_input_buffer */ |
| 1311 |
1, /* in_max_output_length */ |
| 1312 |
NULL, /* in_output_buffer */ |
| 1313 |
SMB2_IOCTL_FLAG_IS_FSCTL, |
| 1314 |
ct, |
| 1315 |
&out_input_buffer, |
| 1316 |
&out_output_buffer); |
| 1317 |
torture_assert(tctx, |
| 1318 |
smbXcli_conn_is_connected(ct->session->transport->conn), |
| 1319 |
"smbXcli_conn_is_connected"); |
| 1320 |
|
| 1321 |
for (pcli = 0; pcli < torture_qdepth; pcli++) { |
| 1322 |
struct test_smb2_bench_read_loop *loop = &state->loops[li]; |
| 1323 |
struct smb2_create cr; |
| 1324 |
union smb_setfileinfo sfinfo; |
| 1325 |
|
| 1326 |
loop->idx = li++; |
| 1327 |
if (looplimit != -1) { |
| 1328 |
loop->max_finished = looplimit; |
| 1329 |
} else { |
| 1330 |
loop->max_finished = UINT64_MAX; |
| 1331 |
} |
| 1332 |
loop->state = state; |
| 1333 |
loop->conn = &state->conns[i]; |
| 1334 |
loop->im = tevent_create_immediate(state->loops); |
| 1335 |
torture_assert(tctx, loop->im != NULL, __location__); |
| 1336 |
|
| 1337 |
loop->fname = talloc_asprintf(state->loops, |
| 1338 |
"%s\\%s_loop_%zu_conn_%zu_loop_%zu.dat", |
| 1339 |
dname, unique, li, i, pcli); |
| 1340 |
torture_assert(tctx, loop->fname != NULL, __location__); |
| 1341 |
|
| 1342 |
/* reasonable default parameters */ |
| 1343 |
ZERO_STRUCT(cr); |
| 1344 |
cr.in.create_flags = NTCREATEX_FLAGS_EXTENDED; |
| 1345 |
cr.in.alloc_size = state->io_size; |
| 1346 |
cr.in.desired_access = SEC_RIGHTS_FILE_ALL; |
| 1347 |
cr.in.file_attributes = FILE_ATTRIBUTE_NORMAL; |
| 1348 |
cr.in.share_access = NTCREATEX_SHARE_ACCESS_NONE; |
| 1349 |
cr.in.create_disposition = NTCREATEX_DISP_CREATE; |
| 1350 |
cr.in.create_options = |
| 1351 |
NTCREATEX_OPTIONS_DELETE_ON_CLOSE | |
| 1352 |
NTCREATEX_OPTIONS_NON_DIRECTORY_FILE; |
| 1353 |
cr.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS; |
| 1354 |
cr.in.security_flags = 0; |
| 1355 |
cr.in.fname = loop->fname; |
| 1356 |
status = smb2_create(state->conns[i].tree, tctx, &cr); |
| 1357 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1358 |
loop->handle = cr.out.file.handle; |
| 1359 |
|
| 1360 |
ZERO_STRUCT(sfinfo); |
| 1361 |
sfinfo.end_of_file_info.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION; |
| 1362 |
sfinfo.end_of_file_info.in.file.handle = loop->handle; |
| 1363 |
sfinfo.end_of_file_info.in.size = state->io_size; |
| 1364 |
status = smb2_setinfo_file(state->conns[i].tree, &sfinfo); |
| 1365 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1366 |
} |
| 1367 |
} |
| 1368 |
|
| 1369 |
for (li = 0; li <state->num_loops; li++) { |
| 1370 |
struct test_smb2_bench_read_loop *loop = &state->loops[li]; |
| 1371 |
|
| 1372 |
tevent_schedule_immediate(loop->im, |
| 1373 |
tctx->ev, |
| 1374 |
test_smb2_bench_read_loop_start, |
| 1375 |
loop); |
| 1376 |
} |
| 1377 |
|
| 1378 |
torture_comment(tctx, "Opened %zu connections with qdepth=%d => %zu loops\n", |
| 1379 |
state->num_conns, torture_qdepth, state->num_loops); |
| 1380 |
|
| 1381 |
torture_comment(tctx, "Running for %d seconds\n", state->timelimit); |
| 1382 |
|
| 1383 |
state->starttime = timeval_current(); |
| 1384 |
state->pending_loops = state->num_loops; |
| 1385 |
|
| 1386 |
te = tevent_add_timer(tctx->ev, |
| 1387 |
state, |
| 1388 |
timeval_current_ofs(1, 0), |
| 1389 |
test_smb2_bench_read_progress, |
| 1390 |
state); |
| 1391 |
torture_assert(tctx, te != NULL, __location__); |
| 1392 |
|
| 1393 |
while (!state->stop) { |
| 1394 |
int rc = tevent_loop_once(tctx->ev); |
| 1395 |
torture_assert_int_equal(tctx, rc, 0, "tevent_loop_once"); |
| 1396 |
} |
| 1397 |
|
| 1398 |
torture_comment(tctx, "%.2f seconds\n", timeval_elapsed(&state->starttime)); |
| 1399 |
TALLOC_FREE(state); |
| 1400 |
smb2_deltree(tree, dname); |
| 1401 |
return ret; |
| 1402 |
} |
| 1403 |
|
| 1404 |
/* |
| 1405 |
stress testing write iops |
| 1406 |
*/ |
| 1407 |
|
| 1408 |
struct test_smb2_bench_write_conn; |
| 1409 |
struct test_smb2_bench_write_loop; |
| 1410 |
|
| 1411 |
struct test_smb2_bench_write_state { |
| 1412 |
struct torture_context *tctx; |
| 1413 |
size_t num_conns; |
| 1414 |
struct test_smb2_bench_write_conn *conns; |
| 1415 |
size_t num_loops; |
| 1416 |
struct test_smb2_bench_write_loop *loops; |
| 1417 |
size_t pending_loops; |
| 1418 |
uint32_t io_size; |
| 1419 |
uint8_t *data_buffer; |
| 1420 |
struct timeval starttime; |
| 1421 |
int timecount; |
| 1422 |
int timelimit; |
| 1423 |
uint64_t num_finished; |
| 1424 |
double total_latency; |
| 1425 |
double min_latency; |
| 1426 |
double max_latency; |
| 1427 |
bool ok; |
| 1428 |
bool stop; |
| 1429 |
}; |
| 1430 |
|
| 1431 |
struct test_smb2_bench_write_conn { |
| 1432 |
struct test_smb2_bench_write_state *state; |
| 1433 |
int idx; |
| 1434 |
struct smb2_tree *tree; |
| 1435 |
}; |
| 1436 |
|
| 1437 |
struct test_smb2_bench_write_loop { |
| 1438 |
struct test_smb2_bench_write_state *state; |
| 1439 |
struct test_smb2_bench_write_conn *conn; |
| 1440 |
int idx; |
| 1441 |
struct tevent_immediate *im; |
| 1442 |
char *fname; |
| 1443 |
struct smb2_handle handle; |
| 1444 |
struct tevent_req *req; |
| 1445 |
struct timeval starttime; |
| 1446 |
uint64_t num_started; |
| 1447 |
uint64_t num_finished; |
| 1448 |
uint64_t total_finished; |
| 1449 |
uint64_t max_finished; |
| 1450 |
double total_latency; |
| 1451 |
double min_latency; |
| 1452 |
double max_latency; |
| 1453 |
NTSTATUS error; |
| 1454 |
}; |
| 1455 |
|
| 1456 |
static void test_smb2_bench_write_loop_do( |
| 1457 |
struct test_smb2_bench_write_loop *loop); |
| 1458 |
|
| 1459 |
static void test_smb2_bench_write_loop_start(struct tevent_context *ctx, |
| 1460 |
struct tevent_immediate *im, |
| 1461 |
void *private_data) |
| 1462 |
{ |
| 1463 |
struct test_smb2_bench_write_loop *loop = |
| 1464 |
(struct test_smb2_bench_write_loop *) |
| 1465 |
private_data; |
| 1466 |
|
| 1467 |
test_smb2_bench_write_loop_do(loop); |
| 1468 |
} |
| 1469 |
|
| 1470 |
static void test_smb2_bench_write_loop_done(struct tevent_req *req); |
| 1471 |
|
| 1472 |
static void test_smb2_bench_write_loop_do( |
| 1473 |
struct test_smb2_bench_write_loop *loop) |
| 1474 |
{ |
| 1475 |
struct test_smb2_bench_write_state *state = loop->state; |
| 1476 |
uint32_t timeout_msec; |
| 1477 |
|
| 1478 |
timeout_msec = loop->conn->tree->session->transport->options.request_timeout * 1000; |
| 1479 |
|
| 1480 |
loop->num_started += 1; |
| 1481 |
loop->starttime = timeval_current(); |
| 1482 |
loop->req = smb2cli_write_send(state->loops, |
| 1483 |
state->tctx->ev, |
| 1484 |
loop->conn->tree->session->transport->conn, |
| 1485 |
timeout_msec, |
| 1486 |
loop->conn->tree->session->smbXcli, |
| 1487 |
loop->conn->tree->smbXcli, |
| 1488 |
state->io_size, /* length */ |
| 1489 |
0, /* offset */ |
| 1490 |
loop->handle.data[0],/* fid_persistent */ |
| 1491 |
loop->handle.data[1],/* fid_volatile */ |
| 1492 |
0, /* remaining_bytes */ |
| 1493 |
0, /* flags */ |
| 1494 |
state->data_buffer); |
| 1495 |
torture_assert_goto(state->tctx, loop->req != NULL, |
| 1496 |
state->ok, asserted, "smb2cli_write_send"); |
| 1497 |
|
| 1498 |
tevent_req_set_callback(loop->req, |
| 1499 |
test_smb2_bench_write_loop_done, |
| 1500 |
loop); |
| 1501 |
return; |
| 1502 |
asserted: |
| 1503 |
state->stop = true; |
| 1504 |
} |
| 1505 |
|
| 1506 |
static void test_smb2_bench_write_loop_done(struct tevent_req *req) |
| 1507 |
{ |
| 1508 |
struct test_smb2_bench_write_loop *loop = |
| 1509 |
(struct test_smb2_bench_write_loop *) |
| 1510 |
_tevent_req_callback_data(req); |
| 1511 |
struct test_smb2_bench_write_state *state = loop->state; |
| 1512 |
double latency = timeval_elapsed(&loop->starttime); |
| 1513 |
uint32_t data_length = 0; |
| 1514 |
|
| 1515 |
torture_assert_goto(state->tctx, loop->req == req, |
| 1516 |
state->ok, asserted, __location__); |
| 1517 |
loop->error = smb2cli_write_recv(req, &data_length); |
| 1518 |
torture_assert_ntstatus_ok_goto(state->tctx, loop->error, |
| 1519 |
state->ok, asserted, __location__); |
| 1520 |
torture_assert_u32_equal_goto(state->tctx, data_length, state->io_size, |
| 1521 |
state->ok, asserted, __location__); |
| 1522 |
SMB_ASSERT(latency >= 0.000001); |
| 1523 |
|
| 1524 |
if (loop->num_finished == 0) { |
| 1525 |
/* first round */ |
| 1526 |
loop->min_latency = latency; |
| 1527 |
loop->max_latency = latency; |
| 1528 |
} |
| 1529 |
|
| 1530 |
loop->num_finished += 1; |
| 1531 |
loop->total_finished += 1; |
| 1532 |
loop->total_latency += latency; |
| 1533 |
|
| 1534 |
if (latency < loop->min_latency) { |
| 1535 |
loop->min_latency = latency; |
| 1536 |
} |
| 1537 |
|
| 1538 |
if (latency > loop->max_latency) { |
| 1539 |
loop->max_latency = latency; |
| 1540 |
} |
| 1541 |
|
| 1542 |
if (loop->total_finished >= loop->max_finished) { |
| 1543 |
if (state->pending_loops > 0) { |
| 1544 |
state->pending_loops -= 1; |
| 1545 |
} |
| 1546 |
if (state->pending_loops == 0) { |
| 1547 |
goto asserted; |
| 1548 |
} |
| 1549 |
} |
| 1550 |
|
| 1551 |
test_smb2_bench_write_loop_do(loop); |
| 1552 |
return; |
| 1553 |
asserted: |
| 1554 |
state->stop = true; |
| 1555 |
} |
| 1556 |
|
| 1557 |
static void test_smb2_bench_write_progress(struct tevent_context *ev, |
| 1558 |
struct tevent_timer *te, |
| 1559 |
struct timeval current_time, |
| 1560 |
void *private_data) |
| 1561 |
{ |
| 1562 |
struct test_smb2_bench_write_state *state = |
| 1563 |
(struct test_smb2_bench_write_state *)private_data; |
| 1564 |
uint64_t num_writes = 0; |
| 1565 |
double total_write_latency = 0; |
| 1566 |
double min_write_latency = 0; |
| 1567 |
double max_write_latency = 0; |
| 1568 |
double avs_write_latency = 0; |
| 1569 |
size_t i; |
| 1570 |
|
| 1571 |
state->timecount += 1; |
| 1572 |
|
| 1573 |
for (i=0;i<state->num_loops;i++) { |
| 1574 |
struct test_smb2_bench_write_loop *loop = |
| 1575 |
&state->loops[i]; |
| 1576 |
|
| 1577 |
num_writes += loop->num_finished; |
| 1578 |
total_write_latency += loop->total_latency; |
| 1579 |
if (min_write_latency == 0.0 && loop->min_latency != 0.0) { |
| 1580 |
min_write_latency = loop->min_latency; |
| 1581 |
} |
| 1582 |
if (loop->min_latency < min_write_latency) { |
| 1583 |
min_write_latency = loop->min_latency; |
| 1584 |
} |
| 1585 |
if (max_write_latency == 0.0) { |
| 1586 |
max_write_latency = loop->max_latency; |
| 1587 |
} |
| 1588 |
if (loop->max_latency > max_write_latency) { |
| 1589 |
max_write_latency = loop->max_latency; |
| 1590 |
} |
| 1591 |
loop->num_finished = 0; |
| 1592 |
loop->total_latency = 0.0; |
| 1593 |
} |
| 1594 |
|
| 1595 |
state->num_finished += num_writes; |
| 1596 |
state->total_latency += total_write_latency; |
| 1597 |
if (state->min_latency == 0.0 && min_write_latency != 0.0) { |
| 1598 |
state->min_latency = min_write_latency; |
| 1599 |
} |
| 1600 |
if (min_write_latency < state->min_latency) { |
| 1601 |
state->min_latency = min_write_latency; |
| 1602 |
} |
| 1603 |
if (state->max_latency == 0.0) { |
| 1604 |
state->max_latency = max_write_latency; |
| 1605 |
} |
| 1606 |
if (max_write_latency > state->max_latency) { |
| 1607 |
state->max_latency = max_write_latency; |
| 1608 |
} |
| 1609 |
|
| 1610 |
if (state->timecount < state->timelimit) { |
| 1611 |
te = tevent_add_timer(state->tctx->ev, |
| 1612 |
state, |
| 1613 |
timeval_current_ofs(1, 0), |
| 1614 |
test_smb2_bench_write_progress, |
| 1615 |
state); |
| 1616 |
torture_assert_goto(state->tctx, te != NULL, |
| 1617 |
state->ok, asserted, "tevent_add_timer"); |
| 1618 |
|
| 1619 |
if (!torture_setting_bool(state->tctx, "progress", true)) { |
| 1620 |
return; |
| 1621 |
} |
| 1622 |
|
| 1623 |
avs_write_latency = total_write_latency / num_writes; |
| 1624 |
|
| 1625 |
torture_comment(state->tctx, |
| 1626 |
"%.2f second: " |
| 1627 |
"write[num/s=%llu,bytes/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] \r", |
| 1628 |
timeval_elapsed(&state->starttime), |
| 1629 |
(unsigned long long)num_writes, |
| 1630 |
(unsigned long long)num_writes*state->io_size, |
| 1631 |
avs_write_latency, |
| 1632 |
min_write_latency, |
| 1633 |
max_write_latency); |
| 1634 |
return; |
| 1635 |
} |
| 1636 |
|
| 1637 |
avs_write_latency = state->total_latency / state->num_finished; |
| 1638 |
num_writes = state->num_finished / state->timelimit; |
| 1639 |
|
| 1640 |
torture_comment(state->tctx, |
| 1641 |
"%.2f second: " |
| 1642 |
"write[num/s=%llu,bytes/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f]\n", |
| 1643 |
timeval_elapsed(&state->starttime), |
| 1644 |
(unsigned long long)num_writes, |
| 1645 |
(unsigned long long)num_writes*state->io_size, |
| 1646 |
avs_write_latency, |
| 1647 |
state->min_latency, |
| 1648 |
state->max_latency); |
| 1649 |
|
| 1650 |
asserted: |
| 1651 |
state->stop = true; |
| 1652 |
} |
| 1653 |
|
| 1654 |
static bool test_smb2_bench_write(struct torture_context *tctx, |
| 1655 |
struct smb2_tree *tree) |
| 1656 |
{ |
| 1657 |
struct test_smb2_bench_write_state *state = NULL; |
| 1658 |
bool ret = true; |
| 1659 |
int torture_nprocs = torture_setting_int(tctx, "nprocs", 4); |
| 1660 |
int torture_qdepth = torture_setting_int(tctx, "qdepth", 1); |
| 1661 |
int torture_io_size = torture_setting_int(tctx, "io_size", 4096); |
| 1662 |
size_t i; |
| 1663 |
size_t li = 0; |
| 1664 |
int looplimit = torture_setting_int(tctx, "looplimit", -1); |
| 1665 |
int timelimit = torture_setting_int(tctx, "timelimit", 10); |
| 1666 |
struct tevent_timer *te = NULL; |
| 1667 |
uint32_t timeout_msec; |
| 1668 |
const char *dname = "bench_write_dir"; |
| 1669 |
const char *unique = generate_random_str(tctx, 8); |
| 1670 |
struct smb2_handle dh; |
| 1671 |
NTSTATUS status; |
| 1672 |
|
| 1673 |
smb2_deltree(tree, dname); |
| 1674 |
|
| 1675 |
status = torture_smb2_testdir(tree, dname, &dh); |
| 1676 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1677 |
status = smb2_util_close(tree, dh); |
| 1678 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1679 |
|
| 1680 |
state = talloc_zero(tctx, struct test_smb2_bench_write_state); |
| 1681 |
torture_assert(tctx, state != NULL, __location__); |
| 1682 |
state->tctx = tctx; |
| 1683 |
state->num_conns = torture_nprocs; |
| 1684 |
state->conns = talloc_zero_array(state, |
| 1685 |
struct test_smb2_bench_write_conn, |
| 1686 |
state->num_conns); |
| 1687 |
torture_assert(tctx, state->conns != NULL, __location__); |
| 1688 |
state->num_loops = torture_nprocs * torture_qdepth; |
| 1689 |
state->loops = talloc_zero_array(state, |
| 1690 |
struct test_smb2_bench_write_loop, |
| 1691 |
state->num_loops); |
| 1692 |
torture_assert(tctx, state->loops != NULL, __location__); |
| 1693 |
state->ok = true; |
| 1694 |
state->timelimit = MAX(timelimit, 1); |
| 1695 |
state->io_size = MAX(torture_io_size, 1); |
| 1696 |
state->io_size = MIN(state->io_size, 16*1024*1024); |
| 1697 |
state->data_buffer = talloc_zero_array(state, uint8_t, state->io_size); |
| 1698 |
torture_assert(tctx, state->data_buffer != NULL, __location__); |
| 1699 |
|
| 1700 |
timeout_msec = tree->session->transport->options.request_timeout * 1000; |
| 1701 |
|
| 1702 |
torture_comment(tctx, "Opening %zu connections\n", state->num_conns); |
| 1703 |
|
| 1704 |
for (i=0;i<state->num_conns;i++) { |
| 1705 |
struct smb2_tree *ct = NULL; |
| 1706 |
DATA_BLOB out_input_buffer = data_blob_null; |
| 1707 |
DATA_BLOB out_output_buffer = data_blob_null; |
| 1708 |
size_t pcli; |
| 1709 |
|
| 1710 |
state->conns[i].state = state; |
| 1711 |
state->conns[i].idx = i; |
| 1712 |
|
| 1713 |
if (state->num_conns == 1) { |
| 1714 |
/* |
| 1715 |
* Use the existing connection |
| 1716 |
*/ |
| 1717 |
state->conns[i].tree = ct = tree; |
| 1718 |
} else { |
| 1719 |
if (!torture_smb2_connection(tctx, &ct)) { |
| 1720 |
torture_comment(tctx, |
| 1721 |
"Failed opening %zu/%zu connections\n", |
| 1722 |
i, state->num_conns); |
| 1723 |
return false; |
| 1724 |
} |
| 1725 |
state->conns[i].tree = talloc_steal(state->conns, ct); |
| 1726 |
} |
| 1727 |
|
| 1728 |
smb2cli_conn_set_max_credits(ct->session->transport->conn, 8192); |
| 1729 |
smb2cli_ioctl(ct->session->transport->conn, |
| 1730 |
timeout_msec, |
| 1731 |
ct->session->smbXcli, |
| 1732 |
ct->smbXcli, |
| 1733 |
UINT64_MAX, /* in_fid_persistent */ |
| 1734 |
UINT64_MAX, /* in_fid_volatile */ |
| 1735 |
UINT32_MAX, |
| 1736 |
0, /* in_max_input_length */ |
| 1737 |
NULL, /* in_input_buffer */ |
| 1738 |
1, /* in_max_output_length */ |
| 1739 |
NULL, /* in_output_buffer */ |
| 1740 |
SMB2_IOCTL_FLAG_IS_FSCTL, |
| 1741 |
ct, |
| 1742 |
&out_input_buffer, |
| 1743 |
&out_output_buffer); |
| 1744 |
torture_assert(tctx, |
| 1745 |
smbXcli_conn_is_connected(ct->session->transport->conn), |
| 1746 |
"smbXcli_conn_is_connected"); |
| 1747 |
|
| 1748 |
for (pcli = 0; pcli < torture_qdepth; pcli++) { |
| 1749 |
struct test_smb2_bench_write_loop *loop = &state->loops[li]; |
| 1750 |
struct smb2_create cr; |
| 1751 |
union smb_setfileinfo sfinfo; |
| 1752 |
|
| 1753 |
loop->idx = li++; |
| 1754 |
if (looplimit != -1) { |
| 1755 |
loop->max_finished = looplimit; |
| 1756 |
} else { |
| 1757 |
loop->max_finished = UINT64_MAX; |
| 1758 |
} |
| 1759 |
loop->state = state; |
| 1760 |
loop->conn = &state->conns[i]; |
| 1761 |
loop->im = tevent_create_immediate(state->loops); |
| 1762 |
torture_assert(tctx, loop->im != NULL, __location__); |
| 1763 |
|
| 1764 |
loop->fname = talloc_asprintf(state->loops, |
| 1765 |
"%s\\%s_loop_%zu_conn_%zu_loop_%zu.dat", |
| 1766 |
dname, unique, li, i, pcli); |
| 1767 |
torture_assert(tctx, loop->fname != NULL, __location__); |
| 1768 |
|
| 1769 |
/* reasonable default parameters */ |
| 1770 |
ZERO_STRUCT(cr); |
| 1771 |
cr.in.create_flags = NTCREATEX_FLAGS_EXTENDED; |
| 1772 |
cr.in.alloc_size = state->io_size; |
| 1773 |
cr.in.desired_access = SEC_RIGHTS_FILE_ALL; |
| 1774 |
cr.in.file_attributes = FILE_ATTRIBUTE_NORMAL; |
| 1775 |
cr.in.share_access = NTCREATEX_SHARE_ACCESS_NONE; |
| 1776 |
cr.in.create_disposition = NTCREATEX_DISP_CREATE; |
| 1777 |
cr.in.create_options = |
| 1778 |
NTCREATEX_OPTIONS_DELETE_ON_CLOSE | |
| 1779 |
NTCREATEX_OPTIONS_NON_DIRECTORY_FILE; |
| 1780 |
cr.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS; |
| 1781 |
cr.in.security_flags = 0; |
| 1782 |
cr.in.fname = loop->fname; |
| 1783 |
status = smb2_create(state->conns[i].tree, tctx, &cr); |
| 1784 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1785 |
loop->handle = cr.out.file.handle; |
| 1786 |
|
| 1787 |
ZERO_STRUCT(sfinfo); |
| 1788 |
sfinfo.end_of_file_info.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION; |
| 1789 |
sfinfo.end_of_file_info.in.file.handle = loop->handle; |
| 1790 |
sfinfo.end_of_file_info.in.size = state->io_size; |
| 1791 |
status = smb2_setinfo_file(state->conns[i].tree, &sfinfo); |
| 1792 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1793 |
} |
| 1794 |
} |
| 1795 |
|
| 1796 |
for (li = 0; li <state->num_loops; li++) { |
| 1797 |
struct test_smb2_bench_write_loop *loop = &state->loops[li]; |
| 1798 |
|
| 1799 |
tevent_schedule_immediate(loop->im, |
| 1800 |
tctx->ev, |
| 1801 |
test_smb2_bench_write_loop_start, |
| 1802 |
loop); |
| 1803 |
} |
| 1804 |
|
| 1805 |
torture_comment(tctx, "Opened %zu connections with qdepth=%d => %zu loops\n", |
| 1806 |
state->num_conns, torture_qdepth, state->num_loops); |
| 1807 |
|
| 1808 |
torture_comment(tctx, "Running for %d seconds\n", state->timelimit); |
| 1809 |
|
| 1810 |
state->starttime = timeval_current(); |
| 1811 |
state->pending_loops = state->num_loops; |
| 1812 |
|
| 1813 |
te = tevent_add_timer(tctx->ev, |
| 1814 |
state, |
| 1815 |
timeval_current_ofs(1, 0), |
| 1816 |
test_smb2_bench_write_progress, |
| 1817 |
state); |
| 1818 |
torture_assert(tctx, te != NULL, __location__); |
| 1819 |
|
| 1820 |
while (!state->stop) { |
| 1821 |
int rc = tevent_loop_once(tctx->ev); |
| 1822 |
torture_assert_int_equal(tctx, rc, 0, "tevent_loop_once"); |
| 1823 |
} |
| 1824 |
|
| 1825 |
torture_comment(tctx, "%.2f seconds\n", timeval_elapsed(&state->starttime)); |
| 1826 |
TALLOC_FREE(state); |
| 1827 |
smb2_deltree(tree, dname); |
| 1828 |
return ret; |
| 1829 |
} |
| 1830 |
|
| 1831 |
/* |
| 1832 |
stress testing session setups |
| 1833 |
*/ |
| 1834 |
|
| 1835 |
struct test_smb2_bench_session_setup_shared_conn; |
| 1836 |
struct test_smb2_bench_session_setup_shared_loop; |
| 1837 |
|
| 1838 |
struct test_smb2_bench_session_setup_shared_state { |
| 1839 |
struct torture_context *tctx; |
| 1840 |
struct cli_credentials *credentials; |
| 1841 |
struct gensec_settings *gensec_settings; |
| 1842 |
size_t num_conns; |
| 1843 |
struct test_smb2_bench_session_setup_shared_conn *conns; |
| 1844 |
size_t num_loops; |
| 1845 |
struct test_smb2_bench_session_setup_shared_loop *loops; |
| 1846 |
struct timeval starttime; |
| 1847 |
int timecount; |
| 1848 |
int timelimit; |
| 1849 |
struct { |
| 1850 |
uint64_t num_finished; |
| 1851 |
double total_latency; |
| 1852 |
double min_latency; |
| 1853 |
double max_latency; |
| 1854 |
} setups; |
| 1855 |
struct { |
| 1856 |
uint64_t num_finished; |
| 1857 |
double total_latency; |
| 1858 |
double min_latency; |
| 1859 |
double max_latency; |
| 1860 |
} logoffs; |
| 1861 |
bool ok; |
| 1862 |
bool stop; |
| 1863 |
}; |
| 1864 |
|
| 1865 |
struct test_smb2_bench_session_setup_shared_conn { |
| 1866 |
struct test_smb2_bench_session_setup_shared_state *state; |
| 1867 |
int idx; |
| 1868 |
struct smb2_transport *transport; |
| 1869 |
}; |
| 1870 |
|
| 1871 |
struct test_smb2_bench_session_setup_shared_loop { |
| 1872 |
struct test_smb2_bench_session_setup_shared_state *state; |
| 1873 |
struct test_smb2_bench_session_setup_shared_conn *conn; |
| 1874 |
int idx; |
| 1875 |
struct smb2_session *session; |
| 1876 |
struct tevent_immediate *im; |
| 1877 |
struct { |
| 1878 |
struct tevent_req *req; |
| 1879 |
struct timeval starttime; |
| 1880 |
uint64_t num_started; |
| 1881 |
uint64_t num_finished; |
| 1882 |
double total_latency; |
| 1883 |
double min_latency; |
| 1884 |
double max_latency; |
| 1885 |
} setups; |
| 1886 |
struct { |
| 1887 |
struct smb2_request *req; |
| 1888 |
struct timeval starttime; |
| 1889 |
uint64_t num_started; |
| 1890 |
uint64_t num_finished; |
| 1891 |
double total_latency; |
| 1892 |
double min_latency; |
| 1893 |
double max_latency; |
| 1894 |
} logoffs; |
| 1895 |
NTSTATUS error; |
| 1896 |
}; |
| 1897 |
|
| 1898 |
static void test_smb2_bench_session_setup_loop_do_setup( |
| 1899 |
struct test_smb2_bench_session_setup_shared_loop *loop); |
| 1900 |
|
| 1901 |
static void test_smb2_bench_session_setup_loop_start(struct tevent_context *ctx, |
| 1902 |
struct tevent_immediate *im, |
| 1903 |
void *private_data) |
| 1904 |
{ |
| 1905 |
struct test_smb2_bench_session_setup_shared_loop *loop = |
| 1906 |
(struct test_smb2_bench_session_setup_shared_loop *) |
| 1907 |
private_data; |
| 1908 |
|
| 1909 |
test_smb2_bench_session_setup_loop_do_setup(loop); |
| 1910 |
} |
| 1911 |
|
| 1912 |
static void test_smb2_bench_session_setup_loop_done_setup(struct tevent_req *subreq); |
| 1913 |
|
| 1914 |
static void test_smb2_bench_session_setup_loop_do_setup( |
| 1915 |
struct test_smb2_bench_session_setup_shared_loop *loop) |
| 1916 |
{ |
| 1917 |
struct test_smb2_bench_session_setup_shared_state *state = loop->state; |
| 1918 |
|
| 1919 |
loop->session = smb2_session_init(loop->conn->transport, |
| 1920 |
state->tctx->lp_ctx, |
| 1921 |
state->gensec_settings, |
| 1922 |
loop->conn->transport); |
| 1923 |
torture_assert_goto(state->tctx, loop->session != NULL, |
| 1924 |
state->ok, asserted, "smb2_session_init"); |
| 1925 |
talloc_steal(state->conns, loop->conn->transport); |
| 1926 |
|
| 1927 |
loop->setups.num_started += 1; |
| 1928 |
loop->setups.starttime = timeval_current(); |
| 1929 |
loop->setups.req = smb2_session_setup_spnego_send(loop->session, |
| 1930 |
state->tctx->ev, |
| 1931 |
loop->session, |
| 1932 |
state->credentials, |
| 1933 |
0); /* previous_session_id */ |
| 1934 |
torture_assert_goto(state->tctx, loop->setups.req != NULL, |
| 1935 |
state->ok, asserted, |
| 1936 |
"smb2_session_setup_spnego_send"); |
| 1937 |
|
| 1938 |
tevent_req_set_callback(loop->setups.req, |
| 1939 |
test_smb2_bench_session_setup_loop_done_setup, |
| 1940 |
loop); |
| 1941 |
return; |
| 1942 |
asserted: |
| 1943 |
state->stop = true; |
| 1944 |
} |
| 1945 |
|
| 1946 |
static void test_smb2_bench_session_setup_loop_do_logoff( |
| 1947 |
struct test_smb2_bench_session_setup_shared_loop *loop); |
| 1948 |
|
| 1949 |
static void test_smb2_bench_session_setup_loop_done_setup(struct tevent_req *subreq) |
| 1950 |
{ |
| 1951 |
struct test_smb2_bench_session_setup_shared_loop *loop = |
| 1952 |
(struct test_smb2_bench_session_setup_shared_loop *) |
| 1953 |
tevent_req_callback_data_void(subreq); |
| 1954 |
struct test_smb2_bench_session_setup_shared_state *state = loop->state; |
| 1955 |
double latency = timeval_elapsed(&loop->setups.starttime); |
| 1956 |
TALLOC_CTX *frame = talloc_stackframe(); |
| 1957 |
|
| 1958 |
torture_assert_goto(state->tctx, loop->setups.req == subreq, |
| 1959 |
state->ok, asserted, __location__); |
| 1960 |
loop->setups.req = NULL; |
| 1961 |
loop->error = smb2_session_setup_spnego_recv(subreq); |
| 1962 |
TALLOC_FREE(subreq); |
| 1963 |
torture_assert_ntstatus_ok_goto(state->tctx, loop->error, |
| 1964 |
state->ok, asserted, __location__); |
| 1965 |
SMB_ASSERT(latency >= 0.000001); |
| 1966 |
|
| 1967 |
if (loop->setups.num_finished == 0) { |
| 1968 |
/* first round */ |
| 1969 |
loop->setups.min_latency = latency; |
| 1970 |
loop->setups.max_latency = latency; |
| 1971 |
} |
| 1972 |
|
| 1973 |
loop->setups.num_finished += 1; |
| 1974 |
loop->setups.total_latency += latency; |
| 1975 |
|
| 1976 |
if (latency < loop->setups.min_latency) { |
| 1977 |
loop->setups.min_latency = latency; |
| 1978 |
} |
| 1979 |
|
| 1980 |
if (latency > loop->setups.max_latency) { |
| 1981 |
loop->setups.max_latency = latency; |
| 1982 |
} |
| 1983 |
|
| 1984 |
TALLOC_FREE(frame); |
| 1985 |
test_smb2_bench_session_setup_loop_do_logoff(loop); |
| 1986 |
return; |
| 1987 |
asserted: |
| 1988 |
state->stop = true; |
| 1989 |
TALLOC_FREE(frame); |
| 1990 |
} |
| 1991 |
|
| 1992 |
static void test_smb2_bench_session_setup_loop_done_logoff(struct smb2_request *req); |
| 1993 |
|
| 1994 |
static void test_smb2_bench_session_setup_loop_do_logoff( |
| 1995 |
struct test_smb2_bench_session_setup_shared_loop *loop) |
| 1996 |
{ |
| 1997 |
struct test_smb2_bench_session_setup_shared_state *state = loop->state; |
| 1998 |
|
| 1999 |
loop->logoffs.num_started += 1; |
| 2000 |
loop->logoffs.starttime = timeval_current(); |
| 2001 |
loop->logoffs.req = smb2_logoff_send(loop->session); |
| 2002 |
torture_assert_goto(state->tctx, loop->logoffs.req != NULL, |
| 2003 |
state->ok, asserted, "smb2_logoff_send"); |
| 2004 |
|
| 2005 |
loop->logoffs.req->async.fn = test_smb2_bench_session_setup_loop_done_logoff; |
| 2006 |
loop->logoffs.req->async.private_data = loop; |
| 2007 |
return; |
| 2008 |
asserted: |
| 2009 |
state->stop = true; |
| 2010 |
} |
| 2011 |
|
| 2012 |
static void test_smb2_bench_session_setup_loop_done_logoff(struct smb2_request *req) |
| 2013 |
{ |
| 2014 |
struct test_smb2_bench_session_setup_shared_loop *loop = |
| 2015 |
(struct test_smb2_bench_session_setup_shared_loop *) |
| 2016 |
req->async.private_data; |
| 2017 |
struct test_smb2_bench_session_setup_shared_state *state = loop->state; |
| 2018 |
double latency = timeval_elapsed(&loop->logoffs.starttime); |
| 2019 |
|
| 2020 |
torture_assert_goto(state->tctx, loop->logoffs.req == req, |
| 2021 |
state->ok, asserted, __location__); |
| 2022 |
loop->error = smb2_logoff_recv(req); |
| 2023 |
torture_assert_ntstatus_ok_goto(state->tctx, loop->error, |
| 2024 |
state->ok, asserted, __location__); |
| 2025 |
TALLOC_FREE(loop->session); |
| 2026 |
SMB_ASSERT(latency >= 0.000001); |
| 2027 |
if (loop->logoffs.num_finished == 0) { |
| 2028 |
/* first round */ |
| 2029 |
loop->logoffs.min_latency = latency; |
| 2030 |
loop->logoffs.max_latency = latency; |
| 2031 |
} |
| 2032 |
loop->logoffs.num_finished += 1; |
| 2033 |
|
| 2034 |
loop->logoffs.total_latency += latency; |
| 2035 |
|
| 2036 |
if (latency < loop->logoffs.min_latency) { |
| 2037 |
loop->logoffs.min_latency = latency; |
| 2038 |
} |
| 2039 |
|
| 2040 |
if (latency > loop->logoffs.max_latency) { |
| 2041 |
loop->logoffs.max_latency = latency; |
| 2042 |
} |
| 2043 |
|
| 2044 |
test_smb2_bench_session_setup_loop_do_setup(loop); |
| 2045 |
return; |
| 2046 |
asserted: |
| 2047 |
state->stop = true; |
| 2048 |
} |
| 2049 |
|
| 2050 |
static void test_smb2_bench_session_setup_progress(struct tevent_context *ev, |
| 2051 |
struct tevent_timer *te, |
| 2052 |
struct timeval current_time, |
| 2053 |
void *private_data) |
| 2054 |
{ |
| 2055 |
struct test_smb2_bench_session_setup_shared_state *state = |
| 2056 |
(struct test_smb2_bench_session_setup_shared_state *)private_data; |
| 2057 |
uint64_t num_setups = 0; |
| 2058 |
double total_setup_latency = 0; |
| 2059 |
double min_setup_latency = 0; |
| 2060 |
double max_setup_latency = 0; |
| 2061 |
double avs_setup_latency = 0; |
| 2062 |
uint64_t num_logoffs = 0; |
| 2063 |
double total_logoff_latency = 0; |
| 2064 |
double min_logoff_latency = 0; |
| 2065 |
double max_logoff_latency = 0; |
| 2066 |
double avs_logoff_latency = 0; |
| 2067 |
size_t i; |
| 2068 |
|
| 2069 |
state->timecount += 1; |
| 2070 |
|
| 2071 |
for (i=0;i<state->num_loops;i++) { |
| 2072 |
struct test_smb2_bench_session_setup_shared_loop *loop = |
| 2073 |
&state->loops[i]; |
| 2074 |
|
| 2075 |
num_setups += loop->setups.num_finished; |
| 2076 |
total_setup_latency += loop->setups.total_latency; |
| 2077 |
if (min_setup_latency == 0.0 && loop->setups.min_latency != 0.0) { |
| 2078 |
min_setup_latency = loop->setups.min_latency; |
| 2079 |
} |
| 2080 |
if (loop->setups.min_latency < min_setup_latency) { |
| 2081 |
min_setup_latency = loop->setups.min_latency; |
| 2082 |
} |
| 2083 |
if (max_setup_latency == 0.0) { |
| 2084 |
max_setup_latency = loop->setups.max_latency; |
| 2085 |
} |
| 2086 |
if (loop->setups.max_latency > max_setup_latency) { |
| 2087 |
max_setup_latency = loop->setups.max_latency; |
| 2088 |
} |
| 2089 |
loop->setups.num_finished = 0; |
| 2090 |
loop->setups.total_latency = 0.0; |
| 2091 |
|
| 2092 |
num_logoffs += loop->logoffs.num_finished; |
| 2093 |
total_logoff_latency += loop->logoffs.total_latency; |
| 2094 |
if (min_logoff_latency == 0.0 && loop->logoffs.min_latency != 0.0) { |
| 2095 |
min_logoff_latency = loop->logoffs.min_latency; |
| 2096 |
} |
| 2097 |
if (loop->logoffs.min_latency < min_logoff_latency) { |
| 2098 |
min_logoff_latency = loop->logoffs.min_latency; |
| 2099 |
} |
| 2100 |
if (max_logoff_latency == 0.0) { |
| 2101 |
max_logoff_latency = loop->logoffs.max_latency; |
| 2102 |
} |
| 2103 |
if (loop->logoffs.max_latency > max_logoff_latency) { |
| 2104 |
max_logoff_latency = loop->logoffs.max_latency; |
| 2105 |
} |
| 2106 |
loop->logoffs.num_finished = 0; |
| 2107 |
loop->logoffs.total_latency = 0.0; |
| 2108 |
} |
| 2109 |
|
| 2110 |
state->setups.num_finished += num_setups; |
| 2111 |
state->setups.total_latency += total_setup_latency; |
| 2112 |
if (state->setups.min_latency == 0.0 && min_setup_latency != 0.0) { |
| 2113 |
state->setups.min_latency = min_setup_latency; |
| 2114 |
} |
| 2115 |
if (min_setup_latency < state->setups.min_latency) { |
| 2116 |
state->setups.min_latency = min_setup_latency; |
| 2117 |
} |
| 2118 |
if (state->setups.max_latency == 0.0) { |
| 2119 |
state->setups.max_latency = max_setup_latency; |
| 2120 |
} |
| 2121 |
if (max_setup_latency > state->setups.max_latency) { |
| 2122 |
state->setups.max_latency = max_setup_latency; |
| 2123 |
} |
| 2124 |
|
| 2125 |
state->logoffs.num_finished += num_logoffs; |
| 2126 |
state->logoffs.total_latency += total_logoff_latency; |
| 2127 |
if (state->logoffs.min_latency == 0.0 && min_logoff_latency != 0.0) { |
| 2128 |
state->logoffs.min_latency = min_logoff_latency; |
| 2129 |
} |
| 2130 |
if (min_logoff_latency < state->logoffs.min_latency) { |
| 2131 |
state->logoffs.min_latency = min_logoff_latency; |
| 2132 |
} |
| 2133 |
if (state->logoffs.max_latency == 0.0) { |
| 2134 |
state->logoffs.max_latency = max_logoff_latency; |
| 2135 |
} |
| 2136 |
if (max_logoff_latency > state->logoffs.max_latency) { |
| 2137 |
state->logoffs.max_latency = max_logoff_latency; |
| 2138 |
} |
| 2139 |
|
| 2140 |
if (state->timecount < state->timelimit) { |
| 2141 |
te = tevent_add_timer(state->tctx->ev, |
| 2142 |
state, |
| 2143 |
timeval_current_ofs(1, 0), |
| 2144 |
test_smb2_bench_session_setup_progress, |
| 2145 |
state); |
| 2146 |
torture_assert_goto(state->tctx, te != NULL, |
| 2147 |
state->ok, asserted, "tevent_add_timer"); |
| 2148 |
|
| 2149 |
if (!torture_setting_bool(state->tctx, "progress", true)) { |
| 2150 |
return; |
| 2151 |
} |
| 2152 |
|
| 2153 |
avs_setup_latency = total_setup_latency / num_setups; |
| 2154 |
avs_logoff_latency = total_logoff_latency / num_logoffs; |
| 2155 |
|
| 2156 |
torture_comment(state->tctx, |
| 2157 |
"%.2f second: " |
| 2158 |
"setup[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] " |
| 2159 |
"logoff[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] \r", |
| 2160 |
timeval_elapsed(&state->starttime), |
| 2161 |
(unsigned long long)num_setups, |
| 2162 |
avs_setup_latency, |
| 2163 |
min_setup_latency, |
| 2164 |
max_setup_latency, |
| 2165 |
(unsigned long long)num_logoffs, |
| 2166 |
avs_logoff_latency, |
| 2167 |
min_logoff_latency, |
| 2168 |
max_logoff_latency); |
| 2169 |
return; |
| 2170 |
} |
| 2171 |
|
| 2172 |
avs_setup_latency = state->setups.total_latency / state->setups.num_finished; |
| 2173 |
avs_logoff_latency = state->logoffs.total_latency / state->logoffs.num_finished; |
| 2174 |
num_setups = state->setups.num_finished / state->timelimit; |
| 2175 |
num_logoffs = state->logoffs.num_finished / state->timelimit; |
| 2176 |
|
| 2177 |
torture_comment(state->tctx, |
| 2178 |
"%.2f second: " |
| 2179 |
"setup[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f] " |
| 2180 |
"logoff[num/s=%llu,avslat=%.6f,minlat=%.6f,maxlat=%.6f]\n", |
| 2181 |
timeval_elapsed(&state->starttime), |
| 2182 |
(unsigned long long)num_setups, |
| 2183 |
avs_setup_latency, |
| 2184 |
state->setups.min_latency, |
| 2185 |
state->setups.max_latency, |
| 2186 |
(unsigned long long)num_logoffs, |
| 2187 |
avs_logoff_latency, |
| 2188 |
state->logoffs.min_latency, |
| 2189 |
state->logoffs.max_latency); |
| 2190 |
|
| 2191 |
asserted: |
| 2192 |
state->stop = true; |
| 2193 |
} |
| 2194 |
|
| 2195 |
static bool test_smb2_bench_session_setup(struct torture_context *tctx, |
| 2196 |
struct smb2_tree *tree) |
| 2197 |
{ |
| 2198 |
struct test_smb2_bench_session_setup_shared_state *state = NULL; |
| 2199 |
bool ret = true; |
| 2200 |
int torture_nprocs = torture_setting_int(tctx, "nprocs", 4); |
| 2201 |
int torture_qdepth = torture_setting_int(tctx, "qdepth", 1); |
| 2202 |
size_t i; |
| 2203 |
size_t li = 0; |
| 2204 |
int timelimit = torture_setting_int(tctx, "timelimit", 10); |
| 2205 |
struct tevent_timer *te = NULL; |
| 2206 |
uint32_t timeout_msec; |
| 2207 |
|
| 2208 |
state = talloc_zero(tctx, struct test_smb2_bench_session_setup_shared_state); |
| 2209 |
torture_assert(tctx, state != NULL, __location__); |
| 2210 |
state->tctx = tctx; |
| 2211 |
state->credentials = samba_cmdline_get_creds(); |
| 2212 |
torture_assert(tctx, state->credentials != NULL, __location__); |
| 2213 |
state->gensec_settings = lpcfg_gensec_settings(state, tctx->lp_ctx); |
| 2214 |
torture_assert(tctx, state->gensec_settings != NULL, __location__); |
| 2215 |
state->num_conns = torture_nprocs; |
| 2216 |
state->conns = talloc_zero_array(state, |
| 2217 |
struct test_smb2_bench_session_setup_shared_conn, |
| 2218 |
state->num_conns); |
| 2219 |
torture_assert(tctx, state->conns != NULL, __location__); |
| 2220 |
state->num_loops = torture_nprocs * torture_qdepth; |
| 2221 |
state->loops = talloc_zero_array(state, |
| 2222 |
struct test_smb2_bench_session_setup_shared_loop, |
| 2223 |
state->num_loops); |
| 2224 |
torture_assert(tctx, state->loops != NULL, __location__); |
| 2225 |
state->ok = true; |
| 2226 |
state->timelimit = MAX(timelimit, 1); |
| 2227 |
|
| 2228 |
timeout_msec = tree->session->transport->options.request_timeout * 1000; |
| 2229 |
|
| 2230 |
torture_comment(tctx, "Opening %zd connections\n", state->num_conns); |
| 2231 |
|
| 2232 |
for (i=0;i<state->num_conns;i++) { |
| 2233 |
struct smb2_tree *ct = NULL; |
| 2234 |
DATA_BLOB out_input_buffer = data_blob_null; |
| 2235 |
DATA_BLOB out_output_buffer = data_blob_null; |
| 2236 |
size_t pcli; |
| 2237 |
|
| 2238 |
state->conns[i].state = state; |
| 2239 |
state->conns[i].idx = i; |
| 2240 |
|
| 2241 |
if (state->num_conns == 1) { |
| 2242 |
/* |
| 2243 |
* Use the existing connection |
| 2244 |
*/ |
| 2245 |
ct = tree; |
| 2246 |
} else { |
| 2247 |
if (!torture_smb2_connection(tctx, &ct)) { |
| 2248 |
torture_comment(tctx, |
| 2249 |
"Failed opening %zu/%zu connections\n", |
| 2250 |
i, state->num_conns); |
| 2251 |
return false; |
| 2252 |
} |
| 2253 |
talloc_steal(state->conns, ct); |
| 2254 |
} |
| 2255 |
state->conns[i].transport = ct->session->transport; |
| 2256 |
|
| 2257 |
smb2cli_conn_set_max_credits(ct->session->transport->conn, 8192); |
| 2258 |
smb2cli_ioctl(ct->session->transport->conn, |
| 2259 |
timeout_msec, |
| 2260 |
ct->session->smbXcli, |
| 2261 |
ct->smbXcli, |
| 2262 |
UINT64_MAX, /* in_fid_persistent */ |
| 2263 |
UINT64_MAX, /* in_fid_volatile */ |
| 2264 |
UINT32_MAX, |
| 2265 |
0, /* in_max_input_length */ |
| 2266 |
NULL, /* in_input_buffer */ |
| 2267 |
1, /* in_max_output_length */ |
| 2268 |
NULL, /* in_output_buffer */ |
| 2269 |
SMB2_IOCTL_FLAG_IS_FSCTL, |
| 2270 |
ct, |
| 2271 |
&out_input_buffer, |
| 2272 |
&out_output_buffer); |
| 2273 |
torture_assert(tctx, |
| 2274 |
smbXcli_conn_is_connected(ct->session->transport->conn), |
| 2275 |
"smbXcli_conn_is_connected"); |
| 2276 |
for (pcli = 0; pcli < torture_qdepth; pcli++) { |
| 2277 |
struct test_smb2_bench_session_setup_shared_loop *loop = &state->loops[li]; |
| 2278 |
|
| 2279 |
loop->idx = li++; |
| 2280 |
loop->state = state; |
| 2281 |
loop->conn = &state->conns[i]; |
| 2282 |
loop->im = tevent_create_immediate(state->loops); |
| 2283 |
torture_assert(tctx, loop->im != NULL, __location__); |
| 2284 |
} |
| 2285 |
} |
| 2286 |
|
| 2287 |
for (li = 0; li <state->num_loops; li++) { |
| 2288 |
struct test_smb2_bench_session_setup_shared_loop *loop = &state->loops[li]; |
| 2289 |
|
| 2290 |
tevent_schedule_immediate(loop->im, |
| 2291 |
tctx->ev, |
| 2292 |
test_smb2_bench_session_setup_loop_start, |
| 2293 |
loop); |
| 2294 |
} |
| 2295 |
|
| 2296 |
torture_comment(tctx, "Opened %zu connections with qdepth=%d => %zu loops\n", |
| 2297 |
state->num_conns, torture_qdepth, state->num_loops); |
| 2298 |
|
| 2299 |
torture_comment(tctx, "Running for %d seconds\n", state->timelimit); |
| 2300 |
|
| 2301 |
state->starttime = timeval_current(); |
| 2302 |
|
| 2303 |
te = tevent_add_timer(tctx->ev, |
| 2304 |
state, |
| 2305 |
timeval_current_ofs(1, 0), |
| 2306 |
test_smb2_bench_session_setup_progress, |
| 2307 |
state); |
| 2308 |
torture_assert(tctx, te != NULL, __location__); |
| 2309 |
|
| 2310 |
while (!state->stop) { |
| 2311 |
int rc = tevent_loop_once(tctx->ev); |
| 2312 |
torture_assert_int_equal(tctx, rc, 0, "tevent_loop_once"); |
| 2313 |
} |
| 2314 |
|
| 2315 |
torture_comment(tctx, "%.2f seconds\n", timeval_elapsed(&state->starttime)); |
| 2316 |
TALLOC_FREE(state); |
| 2317 |
return ret; |
| 2318 |
} |
| 2319 |
|
| 2320 |
struct torture_suite *torture_smb2_bench_init(TALLOC_CTX *ctx) |
| 2321 |
{ |
| 2322 |
struct torture_suite *suite = torture_suite_create(ctx, "bench"); |
| 2323 |
|
| 2324 |
torture_suite_add_1smb2_test(suite, "oplock1", test_smb2_bench_oplock); |
| 2325 |
torture_suite_add_1smb2_test(suite, "echo", test_smb2_bench_echo); |
| 2326 |
torture_suite_add_1smb2_test(suite, "path-contention-shared", test_smb2_bench_path_contention_shared); |
| 2327 |
torture_suite_add_1smb2_test(suite, "read", test_smb2_bench_read); |
| 2328 |
torture_suite_add_1smb2_test(suite, "write", test_smb2_bench_write); |
| 2329 |
torture_suite_add_1smb2_test(suite, "session-setup", test_smb2_bench_session_setup); |
| 2330 |
|
| 2331 |
suite->description = talloc_strdup(suite, "SMB2-BENCH tests"); |
| 2332 |
|
| 2333 |
return suite; |
| 2334 |
} |