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;
74 if (torture_setting_bool(tctx
, "progress", true)) {
75 torture_comment(tctx
, "%d\r", i
);
79 asprintf(&fname
, "\\torture.%u", n
);
81 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
85 fnum
= smbcli_open(c
->tree
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
);
87 torture_comment(tctx
, "open failed (%s)\n", smbcli_errstr(c
->tree
));
92 if (smbcli_write(c
->tree
, fnum
, 0, &pid
, 0, sizeof(pid
)) != sizeof(pid
)) {
93 torture_comment(tctx
, "write failed (%s)\n", smbcli_errstr(c
->tree
));
98 if (smbcli_write(c
->tree
, fnum
, 0, buf
,
99 sizeof(pid
)+(j
*sizeof(buf
)),
100 sizeof(buf
)) != sizeof(buf
)) {
101 torture_comment(tctx
, "write failed (%s)\n", smbcli_errstr(c
->tree
));
108 if (smbcli_read(c
->tree
, fnum
, &pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
109 torture_comment(tctx
, "read failed (%s)\n", smbcli_errstr(c
->tree
));
114 torture_comment(tctx
, "data corruption!\n");
118 if (NT_STATUS_IS_ERR(smbcli_close(c
->tree
, fnum
))) {
119 torture_comment(tctx
, "close failed (%s)\n", smbcli_errstr(c
->tree
));
123 if (NT_STATUS_IS_ERR(smbcli_unlink(c
->tree
, fname
))) {
124 torture_comment(tctx
, "unlink failed (%s)\n", smbcli_errstr(c
->tree
));
128 if (NT_STATUS_IS_ERR(smbcli_unlock(c
->tree
, fnum2
, n
*sizeof(int), sizeof(int)))) {
129 torture_comment(tctx
, "unlock failed (%s)\n", smbcli_errstr(c
->tree
));
135 smbcli_close(c
->tree
, fnum2
);
136 smbcli_unlink(c
->tree
, lockfname
);
138 torture_comment(tctx
, "%d\n", i
);
143 bool run_torture(struct torture_context
*tctx
, struct smbcli_state
*cli
, int dummy
)
145 return rw_torture(tctx
, cli
);
150 see how many RPC pipes we can open at once
152 bool run_pipe_number(struct torture_context
*tctx
,
153 struct smbcli_state
*cli1
)
155 const char *pipe_name
= "\\WKSSVC";
160 fnum
= smbcli_nt_create_full(cli1
->tree
, pipe_name
, 0, SEC_FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
161 NTCREATEX_SHARE_ACCESS_READ
|NTCREATEX_SHARE_ACCESS_WRITE
, NTCREATEX_DISP_OPEN_IF
, 0, 0);
164 torture_comment(tctx
, "Open of pipe %s failed with error (%s)\n", pipe_name
, smbcli_errstr(cli1
->tree
));
168 if (torture_setting_bool(tctx
, "progress", true)) {
169 torture_comment(tctx
, "%d\r", num_pipes
);
174 torture_comment(tctx
, "pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
182 open N connections to the server and just hold them open
183 used for testing performance when there are N idle users
186 bool torture_holdcon(struct torture_context
*tctx
)
189 struct smbcli_state
**cli
;
192 torture_comment(tctx
, "Opening %d connections\n", torture_numops
);
194 cli
= malloc_array_p(struct smbcli_state
*, torture_numops
);
196 for (i
=0;i
<torture_numops
;i
++) {
197 if (!torture_open_connection(&cli
[i
], tctx
, i
)) {
200 if (torture_setting_bool(tctx
, "progress", true)) {
201 torture_comment(tctx
, "opened %d connections\r", i
+1);
206 torture_comment(tctx
, "\nStarting pings\n");
209 for (i
=0;i
<torture_numops
;i
++) {
212 status
= smbcli_chkpath(cli
[i
]->tree
, "\\");
213 if (!NT_STATUS_IS_OK(status
)) {
214 torture_comment(tctx
, "Connection %d is dead\n", i
);
222 if (num_dead
== torture_numops
) {
223 torture_comment(tctx
, "All connections dead - finishing\n");
227 torture_comment(tctx
, ".");
235 open a file N times on the server and just hold them open
236 used for testing performance when there are N file handles
239 bool torture_holdopen(struct torture_context
*tctx
,
240 struct smbcli_state
*cli
)
243 const char *fname
= "\\holdopen.dat";
246 smbcli_unlink(cli
->tree
, fname
);
248 fnum
= smbcli_open(cli
->tree
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
250 torture_comment(tctx
, "open of %s failed (%s)\n", fname
, smbcli_errstr(cli
->tree
));
254 smbcli_close(cli
->tree
, fnum
);
256 for (i
=0;i
<torture_numops
;i
++) {
259 op
.generic
.level
= RAW_OPEN_NTCREATEX
;
260 op
.ntcreatex
.in
.root_fid
.fnum
= 0;
261 op
.ntcreatex
.in
.flags
= 0;
262 op
.ntcreatex
.in
.access_mask
= SEC_FILE_WRITE_DATA
;
263 op
.ntcreatex
.in
.create_options
= 0;
264 op
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
265 op
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_MASK
;
266 op
.ntcreatex
.in
.alloc_size
= 0;
267 op
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
268 op
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
269 op
.ntcreatex
.in
.security_flags
= 0;
270 op
.ntcreatex
.in
.fname
= fname
;
271 status
= smb_raw_open(cli
->tree
, tctx
, &op
);
272 if (!NT_STATUS_IS_OK(status
)) {
273 torture_warning(tctx
, "open %d failed\n", i
);
277 if (torture_setting_bool(tctx
, "progress", true)) {
278 torture_comment(tctx
, "opened %d file\r", i
);
283 torture_comment(tctx
, "\nStarting pings\n");
288 status
= smb_raw_echo(cli
->transport
, &ec
);
289 torture_comment(tctx
, ".");
296 test how many open files this server supports on the one socket
298 bool torture_maxfid_test(struct torture_context
*tctx
, struct smbcli_state
*cli
)
300 #define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d"
302 int fnums
[0x11000], i
;
303 int retries
=4, maxfid
;
307 torture_comment(tctx
, "failed to connect\n");
311 if (smbcli_deltree(cli
->tree
, "\\maxfid") == -1) {
312 torture_comment(tctx
, "Failed to deltree \\maxfid - %s\n",
313 smbcli_errstr(cli
->tree
));
316 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli
->tree
, "\\maxfid"))) {
317 torture_comment(tctx
, "Failed to mkdir \\maxfid, error=%s\n",
318 smbcli_errstr(cli
->tree
));
322 torture_comment(tctx
, "Testing maximum number of open files\n");
324 for (i
=0; i
<0x11000; i
++) {
326 asprintf(&fname
, "\\maxfid\\fid%d", i
/1000);
327 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli
->tree
, fname
))) {
328 torture_comment(tctx
, "Failed to mkdir %s, error=%s\n",
329 fname
, smbcli_errstr(cli
->tree
));
334 asprintf(&fname
, MAXFID_TEMPLATE
, i
/1000, i
,(int)getpid());
335 if ((fnums
[i
] = smbcli_open(cli
->tree
, fname
,
336 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
)) ==
338 torture_comment(tctx
, "open of %s failed (%s)\n",
339 fname
, smbcli_errstr(cli
->tree
));
340 torture_comment(tctx
, "maximum fnum is %d\n", i
);
344 if (torture_setting_bool(tctx
, "progress", true)) {
345 torture_comment(tctx
, "%6d\r", i
);
349 torture_comment(tctx
, "%6d\n", i
);
353 torture_comment(tctx
, "cleaning up\n");
354 for (i
=0;i
<maxfid
;i
++) {
355 asprintf(&fname
, MAXFID_TEMPLATE
, i
/1000, i
,(int)getpid());
356 if (NT_STATUS_IS_ERR(smbcli_close(cli
->tree
, fnums
[i
]))) {
357 torture_comment(tctx
, "Close of fnum %d failed - %s\n", fnums
[i
], smbcli_errstr(cli
->tree
));
359 if (NT_STATUS_IS_ERR(smbcli_unlink(cli
->tree
, fname
))) {
360 torture_comment(tctx
, "unlink of %s failed (%s)\n",
361 fname
, smbcli_errstr(cli
->tree
));
366 if (torture_setting_bool(tctx
, "progress", true)) {
367 torture_comment(tctx
, "%6d\r", i
);
371 torture_comment(tctx
, "%6d\n", 0);
373 if (smbcli_deltree(cli
->tree
, "\\maxfid") == -1) {
374 torture_comment(tctx
, "Failed to deltree \\maxfid - %s\n",
375 smbcli_errstr(cli
->tree
));
379 torture_comment(tctx
, "maxfid test finished\n");
382 #undef MAXFID_TEMPLATE
388 sees what IOCTLs are supported
390 bool torture_ioctl_test(struct torture_context
*tctx
,
391 struct smbcli_state
*cli
)
393 uint16_t device
, function
;
395 const char *fname
= "\\ioctl.dat";
397 union smb_ioctl parms
;
400 mem_ctx
= talloc_named_const(tctx
, 0, "ioctl_test");
402 smbcli_unlink(cli
->tree
, fname
);
404 fnum
= smbcli_open(cli
->tree
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
406 torture_comment(tctx
, "open of %s failed (%s)\n", fname
, smbcli_errstr(cli
->tree
));
410 parms
.ioctl
.level
= RAW_IOCTL_IOCTL
;
411 parms
.ioctl
.in
.file
.fnum
= fnum
;
412 parms
.ioctl
.in
.request
= IOCTL_QUERY_JOB_INFO
;
413 status
= smb_raw_ioctl(cli
->tree
, mem_ctx
, &parms
);
414 torture_comment(tctx
, "ioctl job info: %s\n", smbcli_errstr(cli
->tree
));
416 for (device
=0;device
<0x100;device
++) {
417 torture_comment(tctx
, "Testing device=0x%x\n", device
);
418 for (function
=0;function
<0x100;function
++) {
419 parms
.ioctl
.in
.request
= (device
<< 16) | function
;
420 status
= smb_raw_ioctl(cli
->tree
, mem_ctx
, &parms
);
422 if (NT_STATUS_IS_OK(status
)) {
423 torture_comment(tctx
, "ioctl device=0x%x function=0x%x OK : %d bytes\n",
424 device
, function
, (int)parms
.ioctl
.out
.blob
.length
);
432 static void benchrw_callback(struct smbcli_request
*req
);
448 struct benchrw_state
{
449 struct torture_context
*tctx
;
454 struct smbcli_tree
*cli
;
459 int num_parallel_requests
;
461 enum benchrw_stage mode
;
467 const char *workgroup
;
469 unsigned int writeblocks
;
470 unsigned int blocksize
;
471 unsigned int writeratio
;
472 int num_parallel_requests
;
477 init params using lpcfg_parm_xxx
478 return number of unclist entries
480 static int init_benchrw_params(struct torture_context
*tctx
,
483 char **unc_list
= NULL
;
484 int num_unc_names
= 0, conn_index
=0, empty_lines
=0;
486 lpar
->retry
= torture_setting_int(tctx
, "retry",3);
487 lpar
->blocksize
= torture_setting_int(tctx
, "blocksize",65535);
488 lpar
->writeblocks
= torture_setting_int(tctx
, "writeblocks",15);
489 lpar
->writeratio
= torture_setting_int(tctx
, "writeratio",5);
490 lpar
->num_parallel_requests
= torture_setting_int(
491 tctx
, "parallel_requests", 5);
492 lpar
->workgroup
= lpcfg_workgroup(tctx
->lp_ctx
);
494 p
= torture_setting_string(tctx
, "unclist", NULL
);
497 unc_list
= file_lines_load(p
, &num_unc_names
, 0, NULL
);
498 if (!unc_list
|| num_unc_names
<= 0) {
499 torture_comment(tctx
, "Failed to load unc names list "
504 lpar
->unc
= talloc_array(tctx
, struct unclist
*,
505 (num_unc_names
-empty_lines
));
506 for(conn_index
= 0; conn_index
< num_unc_names
; conn_index
++) {
507 /* ignore empty lines */
508 if(strlen(unc_list
[conn_index
% num_unc_names
])==0){
512 if (!smbcli_parse_unc(
513 unc_list
[conn_index
% num_unc_names
],
516 tctx
, "Failed to parse UNC "
518 unc_list
[conn_index
% num_unc_names
]);
521 lpar
->unc
[conn_index
-empty_lines
] =
522 talloc(tctx
, struct unclist
);
523 lpar
->unc
[conn_index
-empty_lines
]->host
= h
;
524 lpar
->unc
[conn_index
-empty_lines
]->share
= s
;
526 return num_unc_names
-empty_lines
;
528 lpar
->unc
= talloc_array(tctx
, struct unclist
*, 1);
529 lpar
->unc
[0] = talloc(tctx
,struct unclist
);
530 lpar
->unc
[0]->host
= torture_setting_string(tctx
, "host",
532 lpar
->unc
[0]->share
= torture_setting_string(tctx
, "share",
539 Called when the reads & writes are finished. closes the file.
541 static NTSTATUS
benchrw_close(struct torture_context
*tctx
,
542 struct smbcli_request
*req
,
543 struct benchrw_state
*state
)
545 union smb_close close_parms
;
547 NT_STATUS_NOT_OK_RETURN(req
->status
);
549 torture_comment(tctx
, "Close file %d (%d)\n",state
->nr
,state
->fnum
);
550 close_parms
.close
.level
= RAW_CLOSE_CLOSE
;
551 close_parms
.close
.in
.file
.fnum
= state
->fnum
;
552 close_parms
.close
.in
.write_time
= 0;
553 state
->mode
=CLOSE_FILE
;
555 req
= smb_raw_close_send(state
->cli
, &close_parms
);
556 NT_STATUS_HAVE_NO_MEMORY(req
);
557 /*register the callback function!*/
558 req
->async
.fn
= benchrw_callback
;
559 req
->async
.private_data
= state
;
564 static NTSTATUS
benchrw_readwrite(struct torture_context
*tctx
,
565 struct benchrw_state
*state
);
566 static void benchrw_callback(struct smbcli_request
*req
);
568 static void benchrw_rw_callback(struct smbcli_request
*req
)
570 struct benchrw_state
*state
= req
->async
.private_data
;
571 struct torture_context
*tctx
= state
->tctx
;
573 if (!NT_STATUS_IS_OK(req
->status
)) {
579 state
->num_parallel_requests
--;
581 if ((state
->completed
>= torture_numops
)
582 && (state
->num_parallel_requests
== 0)) {
583 benchrw_callback(req
);
590 if (state
->completed
+ state
->num_parallel_requests
592 benchrw_readwrite(tctx
, state
);
597 Called when the initial write is completed is done. write or read a file.
599 static NTSTATUS
benchrw_readwrite(struct torture_context
*tctx
,
600 struct benchrw_state
*state
)
602 struct smbcli_request
*req
;
606 /* randomize between writes and reads*/
607 if (random() % state
->lpcfg_params
->writeratio
== 0) {
608 torture_comment(tctx
, "Callback WRITE file:%d (%d/%d)\n",
609 state
->nr
,state
->completed
,torture_numops
);
610 wr
.generic
.level
= RAW_WRITE_WRITEX
;
611 wr
.writex
.in
.file
.fnum
= state
->fnum
;
612 wr
.writex
.in
.offset
= 0;
613 wr
.writex
.in
.wmode
= 0 ;
614 wr
.writex
.in
.remaining
= 0;
615 wr
.writex
.in
.count
= state
->lpcfg_params
->blocksize
;
616 wr
.writex
.in
.data
= state
->buffer
;
618 req
= smb_raw_write_send(state
->cli
,&wr
);
621 torture_comment(tctx
,
622 "Callback READ file:%d (%d/%d) Offset:%d\n",
623 state
->nr
,state
->completed
,torture_numops
,
624 (state
->readcnt
*state
->lpcfg_params
->blocksize
));
625 rd
.generic
.level
= RAW_READ_READX
;
626 rd
.readx
.in
.file
.fnum
= state
->fnum
;
627 rd
.readx
.in
.offset
= state
->readcnt
*state
->lpcfg_params
->blocksize
;
628 rd
.readx
.in
.mincnt
= state
->lpcfg_params
->blocksize
;
629 rd
.readx
.in
.maxcnt
= rd
.readx
.in
.mincnt
;
630 rd
.readx
.in
.remaining
= 0 ;
631 rd
.readx
.out
.data
= state
->buffer
;
632 rd
.readx
.in
.read_for_execute
= false;
633 if(state
->readcnt
< state
->lpcfg_params
->writeblocks
){
636 /*start reading from beginn of file*/
639 req
= smb_raw_read_send(state
->cli
,&rd
);
641 state
->num_parallel_requests
+= 1;
642 NT_STATUS_HAVE_NO_MEMORY(req
);
643 /*register the callback function!*/
644 req
->async
.fn
= benchrw_rw_callback
;
645 req
->async
.private_data
= state
;
651 Called when the open is done. writes to the file.
653 static NTSTATUS
benchrw_open(struct torture_context
*tctx
,
654 struct smbcli_request
*req
,
655 struct benchrw_state
*state
)
658 if(state
->mode
== OPEN_FILE
){
660 status
= smb_raw_open_recv(req
,tctx
,(
661 union smb_open
*)state
->req_params
);
662 NT_STATUS_NOT_OK_RETURN(status
);
664 state
->fnum
= ((union smb_open
*)state
->req_params
)
665 ->openx
.out
.file
.fnum
;
666 torture_comment(tctx
, "File opened (%d)\n",state
->fnum
);
667 state
->mode
=INITIAL_WRITE
;
670 torture_comment(tctx
, "Write initial test file:%d (%d/%d)\n",state
->nr
,
671 (state
->writecnt
+1)*state
->lpcfg_params
->blocksize
,
672 (state
->lpcfg_params
->writeblocks
*state
->lpcfg_params
->blocksize
));
673 wr
.generic
.level
= RAW_WRITE_WRITEX
;
674 wr
.writex
.in
.file
.fnum
= state
->fnum
;
675 wr
.writex
.in
.offset
= state
->writecnt
*
676 state
->lpcfg_params
->blocksize
;
677 wr
.writex
.in
.wmode
= 0 ;
678 wr
.writex
.in
.remaining
= (state
->lpcfg_params
->writeblocks
*
679 state
->lpcfg_params
->blocksize
)-
680 ((state
->writecnt
+1)*state
->
681 lpcfg_params
->blocksize
);
682 wr
.writex
.in
.count
= state
->lpcfg_params
->blocksize
;
683 wr
.writex
.in
.data
= state
->buffer
;
685 if(state
->writecnt
== state
->lpcfg_params
->writeblocks
){
686 state
->mode
=READ_WRITE_DATA
;
688 req
= smb_raw_write_send(state
->cli
,&wr
);
689 NT_STATUS_HAVE_NO_MEMORY(req
);
691 /*register the callback function!*/
692 req
->async
.fn
= benchrw_callback
;
693 req
->async
.private_data
= state
;
698 Called when the mkdir is done. Opens a file.
700 static NTSTATUS
benchrw_mkdir(struct torture_context
*tctx
,
701 struct smbcli_request
*req
,
702 struct benchrw_state
*state
)
704 union smb_open
*open_parms
;
707 NT_STATUS_NOT_OK_RETURN(req
->status
);
709 /* open/create the files */
710 torture_comment(tctx
, "Open File %d/%d\n",state
->nr
+1,
711 torture_setting_int(tctx
, "nprocs", 4));
712 open_parms
=talloc_zero(tctx
, union smb_open
);
713 NT_STATUS_HAVE_NO_MEMORY(open_parms
);
714 open_parms
->openx
.level
= RAW_OPEN_OPENX
;
715 open_parms
->openx
.in
.flags
= 0;
716 open_parms
->openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
717 open_parms
->openx
.in
.search_attrs
=
718 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
;
719 open_parms
->openx
.in
.file_attrs
= 0;
720 open_parms
->openx
.in
.write_time
= 0;
721 open_parms
->openx
.in
.open_func
= OPENX_OPEN_FUNC_CREATE
;
722 open_parms
->openx
.in
.size
= 0;
723 open_parms
->openx
.in
.timeout
= 0;
724 open_parms
->openx
.in
.fname
= state
->fname
;
726 writedata
= talloc_size(tctx
,state
->lpcfg_params
->blocksize
);
727 NT_STATUS_HAVE_NO_MEMORY(writedata
);
728 generate_random_buffer(writedata
,state
->lpcfg_params
->blocksize
);
729 state
->buffer
=writedata
;
732 state
->req_params
=open_parms
;
733 state
->mode
=OPEN_FILE
;
735 req
= smb_raw_open_send(state
->cli
,open_parms
);
736 NT_STATUS_HAVE_NO_MEMORY(req
);
738 /*register the callback function!*/
739 req
->async
.fn
= benchrw_callback
;
740 req
->async
.private_data
= state
;
746 handler for completion of a sub-request of the bench-rw test
748 static void benchrw_callback(struct smbcli_request
*req
)
750 struct benchrw_state
*state
= req
->async
.private_data
;
751 struct torture_context
*tctx
= state
->tctx
;
753 /*dont send new requests when torture_numops is reached*/
754 if ((state
->mode
== READ_WRITE_DATA
)
755 && (state
->completed
>= torture_numops
)) {
756 state
->mode
=MAX_OPS_REACHED
;
759 switch (state
->mode
) {
762 if (!NT_STATUS_IS_OK(benchrw_mkdir(tctx
, req
,state
))) {
763 torture_comment(tctx
, "Failed to create the test "
765 nt_errstr(req
->status
));
772 if (!NT_STATUS_IS_OK(benchrw_open(tctx
, req
,state
))){
773 torture_comment(tctx
, "Failed to open/write the "
775 nt_errstr(req
->status
));
781 case READ_WRITE_DATA
:
782 while (state
->num_parallel_requests
783 < state
->lpcfg_params
->num_parallel_requests
) {
785 status
= benchrw_readwrite(tctx
,state
);
786 if (!NT_STATUS_IS_OK(status
)){
787 torture_comment(tctx
, "Failed to read/write "
789 nt_errstr(req
->status
));
795 case MAX_OPS_REACHED
:
796 if (!NT_STATUS_IS_OK(benchrw_close(tctx
,req
,state
))){
797 torture_comment(tctx
, "Failed to read/write/close "
799 nt_errstr(req
->status
));
805 torture_comment(tctx
, "File %d closed\n",state
->nr
);
806 if (!NT_STATUS_IS_OK(req
->status
)) {
807 torture_comment(tctx
, "Failed to close the "
809 nt_errstr(req
->status
));
821 /* open connection async callback function*/
822 static void async_open_callback(struct composite_context
*con
)
824 struct benchrw_state
*state
= con
->async
.private_data
;
825 struct torture_context
*tctx
= state
->tctx
;
826 int retry
= state
->lpcfg_params
->retry
;
828 if (NT_STATUS_IS_OK(con
->status
)) {
829 state
->cli
=((struct smb_composite_connect
*)
830 state
->req_params
)->out
.tree
;
831 state
->mode
=CLEANUP_TESTDIR
;
833 if(state
->writecnt
< retry
){
834 torture_comment(tctx
, "Failed to open connection: "
835 "%d, Retry (%d/%d)\n",
836 state
->nr
,state
->writecnt
,retry
);
841 torture_comment(tctx
, "Failed to open connection "
843 state
->nr
, nt_errstr(con
->status
));
851 establishs a smbcli_tree from scratch (async)
853 static struct composite_context
*torture_connect_async(
854 struct torture_context
*tctx
,
855 struct smb_composite_connect
*smb
,
857 struct tevent_context
*ev
,
860 const char *workgroup
)
862 torture_comment(tctx
, "Open Connection to %s/%s\n",host
,share
);
863 smb
->in
.dest_host
=talloc_strdup(mem_ctx
,host
);
864 smb
->in
.service
=talloc_strdup(mem_ctx
,share
);
865 smb
->in
.dest_ports
=lpcfg_smb_ports(tctx
->lp_ctx
);
866 smb
->in
.socket_options
= lpcfg_socket_options(tctx
->lp_ctx
);
867 smb
->in
.called_name
= strupper_talloc(mem_ctx
, host
);
868 smb
->in
.service_type
=NULL
;
869 smb
->in
.credentials
=cmdline_credentials
;
870 smb
->in
.fallback_to_anonymous
=false;
871 smb
->in
.gensec_settings
= lpcfg_gensec_settings(mem_ctx
, tctx
->lp_ctx
);
872 smb
->in
.workgroup
=workgroup
;
873 lpcfg_smbcli_options(tctx
->lp_ctx
, &smb
->in
.options
);
874 lpcfg_smbcli_session_options(tctx
->lp_ctx
, &smb
->in
.session_options
);
876 return smb_composite_connect_send(smb
,mem_ctx
,
877 lpcfg_resolve_context(tctx
->lp_ctx
),ev
);
880 bool run_benchrw(struct torture_context
*tctx
)
882 struct smb_composite_connect
*smb_con
;
883 const char *fname
= "\\rwtest.dat";
884 struct smbcli_request
*req
;
885 struct benchrw_state
**state
;
886 int i
, num_unc_names
;
887 struct tevent_context
*ev
;
888 struct composite_context
*req1
;
889 struct params lpparams
;
890 union smb_mkdir parms
;
893 int torture_nprocs
= torture_setting_int(tctx
, "nprocs", 4);
895 torture_comment(tctx
, "Start BENCH-READWRITE num_ops=%d "
897 torture_numops
, torture_nprocs
);
899 /*init talloc context*/
901 state
= talloc_array(tctx
, struct benchrw_state
*, torture_nprocs
);
903 /* init params using lpcfg_parm_xxx */
904 num_unc_names
= init_benchrw_params(tctx
,&lpparams
);
906 /* init private data structs*/
907 for(i
= 0; i
<torture_nprocs
;i
++){
908 state
[i
]=talloc(tctx
,struct benchrw_state
);
909 state
[i
]->tctx
= tctx
;
910 state
[i
]->completed
=0;
911 state
[i
]->num_parallel_requests
=0;
912 state
[i
]->lpcfg_params
=&lpparams
;
914 state
[i
]->dname
=talloc_asprintf(tctx
,"benchrw%d",i
);
915 state
[i
]->fname
=talloc_asprintf(tctx
,"%s%s",
916 state
[i
]->dname
,fname
);
917 state
[i
]->mode
=START
;
918 state
[i
]->writecnt
=0;
921 torture_comment(tctx
, "Starting async requests\n");
922 while(finished
!= torture_nprocs
){
924 for(i
= 0; i
<torture_nprocs
;i
++){
925 switch (state
[i
]->mode
){
926 /*open multiple connections with the same userid */
929 tctx
,struct smb_composite_connect
) ;
930 state
[i
]->req_params
=smb_con
;
931 state
[i
]->mode
=OPEN_CONNECTION
;
932 req1
= torture_connect_async(
933 tctx
, smb_con
, tctx
,ev
,
934 lpparams
.unc
[i
% num_unc_names
]->host
,
935 lpparams
.unc
[i
% num_unc_names
]->share
,
937 /* register callback fn + private data */
938 req1
->async
.fn
= async_open_callback
;
939 req1
->async
.private_data
=state
[i
];
941 /*setup test dirs (sync)*/
942 case CLEANUP_TESTDIR
:
943 torture_comment(tctx
, "Setup test dir %d\n",i
);
944 smb_raw_exit(state
[i
]->cli
->session
);
945 if (smbcli_deltree(state
[i
]->cli
,
946 state
[i
]->dname
) == -1) {
949 "Unable to delete %s - %s\n",
951 smbcli_errstr(state
[i
]->cli
));
952 state
[i
]->mode
=ERROR
;
955 state
[i
]->mode
=MK_TESTDIR
;
956 parms
.mkdir
.level
= RAW_MKDIR_MKDIR
;
957 parms
.mkdir
.in
.path
= state
[i
]->dname
;
958 req
= smb_raw_mkdir_send(state
[i
]->cli
,&parms
);
959 /* register callback fn + private data */
960 req
->async
.fn
= benchrw_callback
;
961 req
->async
.private_data
=state
[i
];
963 /* error occured , finish */
968 /* cleanup , close connection */
970 torture_comment(tctx
, "Deleting test dir %s "
971 "%d/%d\n",state
[i
]->dname
,
973 smbcli_deltree(state
[i
]->cli
,state
[i
]->dname
);
974 if (NT_STATUS_IS_ERR(smb_tree_disconnect(
976 torture_comment(tctx
, "ERROR: Tree "
977 "disconnect failed");
978 state
[i
]->mode
=ERROR
;
981 state
[i
]->mode
=FINISHED
;
986 tevent_loop_once(ev
);