2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
5 Copyright (C) Jelmer Vernooij 2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/raw/raw_proto.h"
24 #include "system/time.h"
25 #include "system/wait.h"
26 #include "system/filesys.h"
27 #include "../libcli/smb/smb_constants.h"
28 #include "libcli/libcli.h"
29 #include "lib/events/events.h"
30 #include "libcli/resolve/resolve.h"
31 #include "torture/smbtorture.h"
32 #include "torture/util.h"
33 #include "libcli/smb_composite/smb_composite.h"
34 #include "libcli/composite/composite.h"
35 #include "param/param.h"
36 #include "torture/basic/proto.h"
38 extern struct cli_credentials *cmdline_credentials;
40 static bool wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len)
42 while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) {
43 if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return false;
49 static bool rw_torture(struct torture_context *tctx, struct smbcli_state *c)
51 const char *lockfname = "\\torture.lck";
55 pid_t pid2, pid = getpid();
60 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
63 fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE);
65 torture_comment(tctx, "open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree));
69 generate_random_buffer(buf, sizeof(buf));
71 for (i=0;i<torture_numops;i++) {
72 unsigned int n = (unsigned int)random()%10;
76 if (torture_setting_bool(tctx, "progress", true)) {
77 torture_comment(tctx, "%d\r", i);
81 ret = asprintf(&fname, "\\torture.%u", n);
82 torture_assert(tctx, ret != -1, "asprintf failed");
84 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
88 fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
90 torture_comment(tctx, "open failed (%s)\n", smbcli_errstr(c->tree));
95 if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) {
96 torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree));
101 if (smbcli_write(c->tree, fnum, 0, buf,
102 sizeof(pid)+(j*sizeof(buf)),
103 sizeof(buf)) != sizeof(buf)) {
104 torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree));
111 if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) {
112 torture_comment(tctx, "read failed (%s)\n", smbcli_errstr(c->tree));
117 torture_comment(tctx, "data corruption!\n");
121 if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
122 torture_comment(tctx, "close failed (%s)\n", smbcli_errstr(c->tree));
126 if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) {
127 torture_comment(tctx, "unlink failed (%s)\n", smbcli_errstr(c->tree));
131 if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) {
132 torture_comment(tctx, "unlock failed (%s)\n", smbcli_errstr(c->tree));
138 smbcli_close(c->tree, fnum2);
139 smbcli_unlink(c->tree, lockfname);
141 torture_comment(tctx, "%d\n", i);
146 bool run_torture(struct torture_context *tctx, struct smbcli_state *cli, int dummy)
148 return rw_torture(tctx, cli);
153 see how many RPC pipes we can open at once
155 bool run_pipe_number(struct torture_context *tctx,
156 struct smbcli_state *cli1)
158 const char *pipe_name = "\\WKSSVC";
163 fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
164 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
167 torture_comment(tctx, "Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree));
171 if (torture_setting_bool(tctx, "progress", true)) {
172 torture_comment(tctx, "%d\r", num_pipes);
177 torture_comment(tctx, "pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
185 open N connections to the server and just hold them open
186 used for testing performance when there are N idle users
189 bool torture_holdcon(struct torture_context *tctx)
192 struct smbcli_state **cli;
195 torture_comment(tctx, "Opening %d connections\n", torture_numops);
197 cli = malloc_array_p(struct smbcli_state *, torture_numops);
199 for (i=0;i<torture_numops;i++) {
200 if (!torture_open_connection(&cli[i], tctx, i)) {
203 if (torture_setting_bool(tctx, "progress", true)) {
204 torture_comment(tctx, "opened %d connections\r", i+1);
209 torture_comment(tctx, "\nStarting pings\n");
212 for (i=0;i<torture_numops;i++) {
215 status = smbcli_chkpath(cli[i]->tree, "\\");
216 if (!NT_STATUS_IS_OK(status)) {
217 torture_comment(tctx, "Connection %d is dead\n", i);
225 if (num_dead == torture_numops) {
226 torture_comment(tctx, "All connections dead - finishing\n");
230 torture_comment(tctx, ".");
238 open a file N times on the server and just hold them open
239 used for testing performance when there are N file handles
242 bool torture_holdopen(struct torture_context *tctx,
243 struct smbcli_state *cli)
246 const char *fname = "\\holdopen.dat";
249 smbcli_unlink(cli->tree, fname);
251 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
253 torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
257 smbcli_close(cli->tree, fnum);
259 for (i=0;i<torture_numops;i++) {
262 op.generic.level = RAW_OPEN_NTCREATEX;
263 op.ntcreatex.in.root_fid.fnum = 0;
264 op.ntcreatex.in.flags = 0;
265 op.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
266 op.ntcreatex.in.create_options = 0;
267 op.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
268 op.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
269 op.ntcreatex.in.alloc_size = 0;
270 op.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
271 op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
272 op.ntcreatex.in.security_flags = 0;
273 op.ntcreatex.in.fname = fname;
274 status = smb_raw_open(cli->tree, tctx, &op);
275 if (!NT_STATUS_IS_OK(status)) {
276 torture_warning(tctx, "open %d failed\n", i);
280 if (torture_setting_bool(tctx, "progress", true)) {
281 torture_comment(tctx, "opened %d file\r", i);
286 torture_comment(tctx, "\nStarting pings\n");
291 status = smb_raw_echo(cli->transport, &ec);
292 torture_comment(tctx, ".");
299 test how many open files this server supports on the one socket
301 bool torture_maxfid_test(struct torture_context *tctx, struct smbcli_state *cli)
303 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
305 int fnums[0x11000], i;
306 int retries=4, maxfid;
311 torture_comment(tctx, "failed to connect\n");
315 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
316 torture_comment(tctx, "Failed to deltree \\maxfid - %s\n",
317 smbcli_errstr(cli->tree));
320 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) {
321 torture_comment(tctx, "Failed to mkdir \\maxfid, error=%s\n",
322 smbcli_errstr(cli->tree));
326 torture_comment(tctx, "Testing maximum number of open files\n");
328 for (i=0; i<0x11000; i++) {
330 ret = asprintf(&fname, "\\maxfid\\fid%d", i/1000);
331 torture_assert(tctx, ret != -1, "asprintf failed");
332 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
333 torture_comment(tctx, "Failed to mkdir %s, error=%s\n",
334 fname, smbcli_errstr(cli->tree));
339 ret = asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
340 torture_assert(tctx, ret != -1, "asprintf failed");
341 if ((fnums[i] = smbcli_open(cli->tree, fname,
342 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
344 torture_comment(tctx, "open of %s failed (%s)\n",
345 fname, smbcli_errstr(cli->tree));
346 torture_comment(tctx, "maximum fnum is %d\n", i);
350 if (torture_setting_bool(tctx, "progress", true)) {
351 torture_comment(tctx, "%6d\r", i);
355 torture_comment(tctx, "%6d\n", i);
359 torture_comment(tctx, "cleaning up\n");
360 for (i=0;i<maxfid;i++) {
361 ret = asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
362 torture_assert(tctx, ret != -1, "asprintf failed");
363 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
364 torture_comment(tctx, "Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree));
366 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
367 torture_comment(tctx, "unlink of %s failed (%s)\n",
368 fname, smbcli_errstr(cli->tree));
373 if (torture_setting_bool(tctx, "progress", true)) {
374 torture_comment(tctx, "%6d\r", i);
378 torture_comment(tctx, "%6d\n", 0);
380 if (smbcli_deltree(cli->tree, "\\maxfid") == -1) {
381 torture_comment(tctx, "Failed to deltree \\maxfid - %s\n",
382 smbcli_errstr(cli->tree));
386 torture_comment(tctx, "maxfid test finished\n");
389 #undef MAXFID_TEMPLATE
395 sees what IOCTLs are supported
397 bool torture_ioctl_test(struct torture_context *tctx,
398 struct smbcli_state *cli)
400 uint16_t device, function;
402 const char *fname = "\\ioctl.dat";
404 union smb_ioctl parms;
407 mem_ctx = talloc_named_const(tctx, 0, "ioctl_test");
409 smbcli_unlink(cli->tree, fname);
411 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
413 torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
417 parms.ioctl.level = RAW_IOCTL_IOCTL;
418 parms.ioctl.in.file.fnum = fnum;
419 parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
420 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
421 torture_comment(tctx, "ioctl job info: %s\n", smbcli_errstr(cli->tree));
423 for (device=0;device<0x100;device++) {
424 torture_comment(tctx, "Testing device=0x%x\n", device);
425 for (function=0;function<0x100;function++) {
426 parms.ioctl.in.request = (device << 16) | function;
427 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
429 if (NT_STATUS_IS_OK(status)) {
430 torture_comment(tctx, "ioctl device=0x%x function=0x%x OK : %d bytes\n",
431 device, function, (int)parms.ioctl.out.blob.length);
439 static void benchrw_callback(struct smbcli_request *req);
455 struct benchrw_state {
456 struct torture_context *tctx;
461 struct smbcli_tree *cli;
466 int num_parallel_requests;
468 enum benchrw_stage mode;
474 const char *workgroup;
476 unsigned int writeblocks;
477 unsigned int blocksize;
478 unsigned int writeratio;
479 int num_parallel_requests;
484 init params using lpcfg_parm_xxx
485 return number of unclist entries
487 static int init_benchrw_params(struct torture_context *tctx,
490 char **unc_list = NULL;
491 int num_unc_names = 0, conn_index=0, empty_lines=0;
493 lpar->retry = torture_setting_int(tctx, "retry",3);
494 lpar->blocksize = torture_setting_int(tctx, "blocksize",65535);
495 lpar->writeblocks = torture_setting_int(tctx, "writeblocks",15);
496 lpar->writeratio = torture_setting_int(tctx, "writeratio",5);
497 lpar->num_parallel_requests = torture_setting_int(
498 tctx, "parallel_requests", 5);
499 lpar->workgroup = lpcfg_workgroup(tctx->lp_ctx);
501 p = torture_setting_string(tctx, "unclist", NULL);
504 unc_list = file_lines_load(p, &num_unc_names, 0, NULL);
505 if (!unc_list || num_unc_names <= 0) {
506 torture_comment(tctx, "Failed to load unc names list "
511 lpar->unc = talloc_array(tctx, struct unclist *,
512 (num_unc_names-empty_lines));
513 for(conn_index = 0; conn_index < num_unc_names; conn_index++) {
514 /* ignore empty lines */
515 if(strlen(unc_list[conn_index % num_unc_names])==0){
519 if (!smbcli_parse_unc(
520 unc_list[conn_index % num_unc_names],
523 tctx, "Failed to parse UNC "
525 unc_list[conn_index % num_unc_names]);
528 lpar->unc[conn_index-empty_lines] =
529 talloc(tctx, struct unclist);
530 lpar->unc[conn_index-empty_lines]->host = h;
531 lpar->unc[conn_index-empty_lines]->share = s;
533 return num_unc_names-empty_lines;
535 lpar->unc = talloc_array(tctx, struct unclist *, 1);
536 lpar->unc[0] = talloc(tctx,struct unclist);
537 lpar->unc[0]->host = torture_setting_string(tctx, "host",
539 lpar->unc[0]->share = torture_setting_string(tctx, "share",
546 Called when the reads & writes are finished. closes the file.
548 static NTSTATUS benchrw_close(struct torture_context *tctx,
549 struct smbcli_request *req,
550 struct benchrw_state *state)
552 union smb_close close_parms;
554 NT_STATUS_NOT_OK_RETURN(req->status);
556 torture_comment(tctx, "Close file %d (%d)\n",state->nr,state->fnum);
557 close_parms.close.level = RAW_CLOSE_CLOSE;
558 close_parms.close.in.file.fnum = state->fnum ;
559 close_parms.close.in.write_time = 0;
560 state->mode=CLOSE_FILE;
562 req = smb_raw_close_send(state->cli, &close_parms);
563 NT_STATUS_HAVE_NO_MEMORY(req);
564 /*register the callback function!*/
565 req->async.fn = benchrw_callback;
566 req->async.private_data = state;
571 static NTSTATUS benchrw_readwrite(struct torture_context *tctx,
572 struct benchrw_state *state);
573 static void benchrw_callback(struct smbcli_request *req);
575 static void benchrw_rw_callback(struct smbcli_request *req)
577 struct benchrw_state *state = req->async.private_data;
578 struct torture_context *tctx = state->tctx;
580 if (!NT_STATUS_IS_OK(req->status)) {
586 state->num_parallel_requests--;
588 if ((state->completed >= torture_numops)
589 && (state->num_parallel_requests == 0)) {
590 benchrw_callback(req);
597 if (state->completed + state->num_parallel_requests
599 benchrw_readwrite(tctx, state);
604 Called when the initial write is completed is done. write or read a file.
606 static NTSTATUS benchrw_readwrite(struct torture_context *tctx,
607 struct benchrw_state *state)
609 struct smbcli_request *req;
613 /* randomize between writes and reads*/
614 if (random() % state->lpcfg_params->writeratio == 0) {
615 torture_comment(tctx, "Callback WRITE file:%d (%d/%d)\n",
616 state->nr,state->completed,torture_numops);
617 wr.generic.level = RAW_WRITE_WRITEX ;
618 wr.writex.in.file.fnum = state->fnum ;
619 wr.writex.in.offset = 0;
620 wr.writex.in.wmode = 0 ;
621 wr.writex.in.remaining = 0;
622 wr.writex.in.count = state->lpcfg_params->blocksize;
623 wr.writex.in.data = state->buffer;
625 req = smb_raw_write_send(state->cli,&wr);
628 torture_comment(tctx,
629 "Callback READ file:%d (%d/%d) Offset:%d\n",
630 state->nr,state->completed,torture_numops,
631 (state->readcnt*state->lpcfg_params->blocksize));
632 rd.generic.level = RAW_READ_READX;
633 rd.readx.in.file.fnum = state->fnum ;
634 rd.readx.in.offset = state->readcnt*state->lpcfg_params->blocksize;
635 rd.readx.in.mincnt = state->lpcfg_params->blocksize;
636 rd.readx.in.maxcnt = rd.readx.in.mincnt;
637 rd.readx.in.remaining = 0 ;
638 rd.readx.out.data = state->buffer;
639 rd.readx.in.read_for_execute = false;
640 if(state->readcnt < state->lpcfg_params->writeblocks){
643 /*start reading from beginn of file*/
646 req = smb_raw_read_send(state->cli,&rd);
648 state->num_parallel_requests += 1;
649 NT_STATUS_HAVE_NO_MEMORY(req);
650 /*register the callback function!*/
651 req->async.fn = benchrw_rw_callback;
652 req->async.private_data = state;
658 Called when the open is done. writes to the file.
660 static NTSTATUS benchrw_open(struct torture_context *tctx,
661 struct smbcli_request *req,
662 struct benchrw_state *state)
665 if(state->mode == OPEN_FILE){
667 status = smb_raw_open_recv(req,tctx,(
668 union smb_open*)state->req_params);
669 NT_STATUS_NOT_OK_RETURN(status);
671 state->fnum = ((union smb_open*)state->req_params)
672 ->openx.out.file.fnum;
673 torture_comment(tctx, "File opened (%d)\n",state->fnum);
674 state->mode=INITIAL_WRITE;
677 torture_comment(tctx, "Write initial test file:%d (%d/%d)\n",state->nr,
678 (state->writecnt+1)*state->lpcfg_params->blocksize,
679 (state->lpcfg_params->writeblocks*state->lpcfg_params->blocksize));
680 wr.generic.level = RAW_WRITE_WRITEX ;
681 wr.writex.in.file.fnum = state->fnum ;
682 wr.writex.in.offset = state->writecnt *
683 state->lpcfg_params->blocksize;
684 wr.writex.in.wmode = 0 ;
685 wr.writex.in.remaining = (state->lpcfg_params->writeblocks *
686 state->lpcfg_params->blocksize)-
687 ((state->writecnt+1)*state->
688 lpcfg_params->blocksize);
689 wr.writex.in.count = state->lpcfg_params->blocksize;
690 wr.writex.in.data = state->buffer;
692 if(state->writecnt == state->lpcfg_params->writeblocks){
693 state->mode=READ_WRITE_DATA;
695 req = smb_raw_write_send(state->cli,&wr);
696 NT_STATUS_HAVE_NO_MEMORY(req);
698 /*register the callback function!*/
699 req->async.fn = benchrw_callback;
700 req->async.private_data = state;
705 Called when the mkdir is done. Opens a file.
707 static NTSTATUS benchrw_mkdir(struct torture_context *tctx,
708 struct smbcli_request *req,
709 struct benchrw_state *state)
711 union smb_open *open_parms;
714 NT_STATUS_NOT_OK_RETURN(req->status);
716 /* open/create the files */
717 torture_comment(tctx, "Open File %d/%d\n",state->nr+1,
718 torture_setting_int(tctx, "nprocs", 4));
719 open_parms=talloc_zero(tctx, union smb_open);
720 NT_STATUS_HAVE_NO_MEMORY(open_parms);
721 open_parms->openx.level = RAW_OPEN_OPENX;
722 open_parms->openx.in.flags = 0;
723 open_parms->openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
724 open_parms->openx.in.search_attrs =
725 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
726 open_parms->openx.in.file_attrs = 0;
727 open_parms->openx.in.write_time = 0;
728 open_parms->openx.in.open_func = OPENX_OPEN_FUNC_CREATE;
729 open_parms->openx.in.size = 0;
730 open_parms->openx.in.timeout = 0;
731 open_parms->openx.in.fname = state->fname;
733 writedata = talloc_size(tctx,state->lpcfg_params->blocksize);
734 NT_STATUS_HAVE_NO_MEMORY(writedata);
735 generate_random_buffer(writedata,state->lpcfg_params->blocksize);
736 state->buffer=writedata;
739 state->req_params=open_parms;
740 state->mode=OPEN_FILE;
742 req = smb_raw_open_send(state->cli,open_parms);
743 NT_STATUS_HAVE_NO_MEMORY(req);
745 /*register the callback function!*/
746 req->async.fn = benchrw_callback;
747 req->async.private_data = state;
753 handler for completion of a sub-request of the bench-rw test
755 static void benchrw_callback(struct smbcli_request *req)
757 struct benchrw_state *state = req->async.private_data;
758 struct torture_context *tctx = state->tctx;
760 /*don't send new requests when torture_numops is reached*/
761 if ((state->mode == READ_WRITE_DATA)
762 && (state->completed >= torture_numops)) {
763 state->mode=MAX_OPS_REACHED;
766 switch (state->mode) {
769 if (!NT_STATUS_IS_OK(benchrw_mkdir(tctx, req,state))) {
770 torture_comment(tctx, "Failed to create the test "
772 nt_errstr(req->status));
779 if (!NT_STATUS_IS_OK(benchrw_open(tctx, req,state))){
780 torture_comment(tctx, "Failed to open/write the "
782 nt_errstr(req->status));
788 case READ_WRITE_DATA:
789 while (state->num_parallel_requests
790 < state->lpcfg_params->num_parallel_requests) {
792 status = benchrw_readwrite(tctx,state);
793 if (!NT_STATUS_IS_OK(status)){
794 torture_comment(tctx, "Failed to read/write "
796 nt_errstr(req->status));
802 case MAX_OPS_REACHED:
803 if (!NT_STATUS_IS_OK(benchrw_close(tctx,req,state))){
804 torture_comment(tctx, "Failed to read/write/close "
806 nt_errstr(req->status));
812 torture_comment(tctx, "File %d closed\n",state->nr);
813 if (!NT_STATUS_IS_OK(req->status)) {
814 torture_comment(tctx, "Failed to close the "
816 nt_errstr(req->status));
828 /* open connection async callback function*/
829 static void async_open_callback(struct composite_context *con)
831 struct benchrw_state *state = con->async.private_data;
832 struct torture_context *tctx = state->tctx;
833 int retry = state->lpcfg_params->retry;
835 if (NT_STATUS_IS_OK(con->status)) {
836 state->cli=((struct smb_composite_connect*)
837 state->req_params)->out.tree;
838 state->mode=CLEANUP_TESTDIR;
840 if(state->writecnt < retry){
841 torture_comment(tctx, "Failed to open connection: "
842 "%d, Retry (%d/%d)\n",
843 state->nr,state->writecnt,retry);
848 torture_comment(tctx, "Failed to open connection "
850 state->nr, nt_errstr(con->status));
858 establishs a smbcli_tree from scratch (async)
860 static struct composite_context *torture_connect_async(
861 struct torture_context *tctx,
862 struct smb_composite_connect *smb,
864 struct tevent_context *ev,
867 const char *workgroup)
869 torture_comment(tctx, "Open Connection to %s/%s\n",host,share);
870 smb->in.dest_host=talloc_strdup(mem_ctx,host);
871 smb->in.service=talloc_strdup(mem_ctx,share);
872 smb->in.dest_ports=lpcfg_smb_ports(tctx->lp_ctx);
873 smb->in.socket_options = lpcfg_socket_options(tctx->lp_ctx);
874 smb->in.called_name = strupper_talloc(mem_ctx, host);
875 smb->in.service_type=NULL;
876 smb->in.credentials=cmdline_credentials;
877 smb->in.fallback_to_anonymous=false;
878 smb->in.gensec_settings = lpcfg_gensec_settings(mem_ctx, tctx->lp_ctx);
879 smb->in.workgroup=workgroup;
880 lpcfg_smbcli_options(tctx->lp_ctx, &smb->in.options);
881 lpcfg_smbcli_session_options(tctx->lp_ctx, &smb->in.session_options);
883 return smb_composite_connect_send(smb,mem_ctx,
884 lpcfg_resolve_context(tctx->lp_ctx),ev);
887 bool run_benchrw(struct torture_context *tctx)
889 struct smb_composite_connect *smb_con;
890 const char *fname = "\\rwtest.dat";
891 struct smbcli_request *req;
892 struct benchrw_state **state;
893 int i , num_unc_names;
894 struct tevent_context *ev ;
895 struct composite_context *req1;
896 struct params lpparams;
897 union smb_mkdir parms;
900 int torture_nprocs = torture_setting_int(tctx, "nprocs", 4);
902 torture_comment(tctx, "Start BENCH-READWRITE num_ops=%d "
904 torture_numops, torture_nprocs);
906 /*init talloc context*/
908 state = talloc_array(tctx, struct benchrw_state *, torture_nprocs);
910 /* init params using lpcfg_parm_xxx */
911 num_unc_names = init_benchrw_params(tctx,&lpparams);
913 /* init private data structs*/
914 for(i = 0; i<torture_nprocs;i++){
915 state[i]=talloc(tctx,struct benchrw_state);
916 state[i]->tctx = tctx;
917 state[i]->completed=0;
918 state[i]->num_parallel_requests=0;
919 state[i]->lpcfg_params=&lpparams;
921 state[i]->dname=talloc_asprintf(tctx,"benchrw%d",i);
922 state[i]->fname=talloc_asprintf(tctx,"%s%s",
923 state[i]->dname,fname);
924 state[i]->mode=START;
925 state[i]->writecnt=0;
928 torture_comment(tctx, "Starting async requests\n");
929 while(finished != torture_nprocs){
931 for(i = 0; i<torture_nprocs;i++){
932 switch (state[i]->mode){
933 /*open multiple connections with the same userid */
936 tctx,struct smb_composite_connect) ;
937 state[i]->req_params=smb_con;
938 state[i]->mode=OPEN_CONNECTION;
939 req1 = torture_connect_async(
940 tctx, smb_con, tctx,ev,
941 lpparams.unc[i % num_unc_names]->host,
942 lpparams.unc[i % num_unc_names]->share,
944 /* register callback fn + private data */
945 req1->async.fn = async_open_callback;
946 req1->async.private_data=state[i];
948 /*setup test dirs (sync)*/
949 case CLEANUP_TESTDIR:
950 torture_comment(tctx, "Setup test dir %d\n",i);
951 smb_raw_exit(state[i]->cli->session);
952 if (smbcli_deltree(state[i]->cli,
953 state[i]->dname) == -1) {
956 "Unable to delete %s - %s\n",
958 smbcli_errstr(state[i]->cli));
959 state[i]->mode=ERROR;
962 state[i]->mode=MK_TESTDIR;
963 parms.mkdir.level = RAW_MKDIR_MKDIR;
964 parms.mkdir.in.path = state[i]->dname;
965 req = smb_raw_mkdir_send(state[i]->cli,&parms);
966 /* register callback fn + private data */
967 req->async.fn = benchrw_callback;
968 req->async.private_data=state[i];
970 /* error occurred , finish */
975 /* cleanup , close connection */
977 torture_comment(tctx, "Deleting test dir %s "
978 "%d/%d\n",state[i]->dname,
980 smbcli_deltree(state[i]->cli,state[i]->dname);
981 if (NT_STATUS_IS_ERR(smb_tree_disconnect(
983 torture_comment(tctx, "ERROR: Tree "
984 "disconnect failed");
985 state[i]->mode=ERROR;
988 state[i]->mode=FINISHED;
993 tevent_loop_once(ev);