2007-04-05 10:23:06 +04:00
/*
Unix SMB / CIFS implementation .
open benchmark
Copyright ( C ) Andrew Tridgell 2007
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-04-05 10:23:06 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2007-04-05 10:23:06 +04:00
*/
# include "includes.h"
# include "torture/torture.h"
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2007-04-05 10:23:06 +04:00
# include "system/time.h"
# include "system/filesys.h"
# include "libcli/libcli.h"
# include "torture/util.h"
# include "lib/events/events.h"
# include "lib/cmdline/popt_common.h"
2007-05-22 03:33:26 +04:00
# include "libcli/composite/composite.h"
# include "libcli/smb_composite/smb_composite.h"
2008-01-03 03:39:01 +03:00
# include "libcli/resolve/resolve.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2011-03-19 02:42:42 +03:00
# include "torture/raw/proto.h"
2011-09-23 10:35:17 +04:00
# include "libcli/smb/smbXcli_base.h"
# include "../lib/util/util_net.h"
2007-04-05 10:23:06 +04:00
# define BASEDIR "\\benchopen"
static int nprocs ;
static int open_failed ;
2008-03-17 11:59:30 +03:00
static int close_failed ;
2007-04-05 10:23:06 +04:00
static char * * fnames ;
2007-05-22 03:33:26 +04:00
static int num_connected ;
2008-12-29 22:24:57 +03:00
static struct tevent_timer * report_te ;
2007-05-22 08:53:05 +04:00
2007-04-05 10:23:06 +04:00
struct benchopen_state {
2007-12-03 17:53:07 +03:00
struct torture_context * tctx ;
2007-05-22 03:33:26 +04:00
TALLOC_CTX * mem_ctx ;
2008-12-29 22:24:57 +03:00
struct tevent_context * ev ;
2007-04-05 10:23:06 +04:00
struct smbcli_state * cli ;
2007-05-22 03:33:26 +04:00
struct smbcli_tree * tree ;
int client_num ;
2008-03-17 14:11:44 +03:00
int close_fnum ;
int open_fnum ;
int close_file_num ;
int open_file_num ;
int pending_file_num ;
int next_file_num ;
2007-04-05 10:23:06 +04:00
int count ;
2007-05-22 03:33:26 +04:00
int lastcount ;
2007-04-05 10:23:06 +04:00
union smb_open open_parms ;
2008-03-17 11:59:30 +03:00
int open_retries ;
2007-04-05 10:23:06 +04:00
union smb_close close_parms ;
struct smbcli_request * req_open ;
struct smbcli_request * req_close ;
2007-05-22 03:33:26 +04:00
struct smb_composite_connect reconnect ;
2008-12-29 22:24:57 +03:00
struct tevent_timer * te ;
2007-05-22 03:33:26 +04:00
/* these are used for reconnections */
2008-01-04 02:21:50 +03:00
const char * * dest_ports ;
2007-05-22 03:33:26 +04:00
const char * dest_host ;
const char * called_name ;
const char * service_type ;
2007-04-05 10:23:06 +04:00
} ;
2007-05-22 03:33:26 +04:00
static void next_open ( struct benchopen_state * state ) ;
2008-12-29 22:24:57 +03:00
static void reopen_connection ( struct tevent_context * ev , struct tevent_timer * te ,
2007-05-22 03:33:26 +04:00
struct timeval t , void * private_data ) ;
/*
complete an async reconnect
*/
static void reopen_connection_complete ( struct composite_context * ctx )
{
struct benchopen_state * state = ( struct benchopen_state * ) ctx - > async . private_data ;
NTSTATUS status ;
struct smb_composite_connect * io = & state - > reconnect ;
status = smb_composite_connect_recv ( ctx , state - > mem_ctx ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-05-29 12:22:45 +04:00
talloc_free ( state - > te ) ;
2010-05-25 23:23:55 +04:00
state - > te = tevent_add_timer ( state - > ev , state - > mem_ctx ,
2007-05-29 12:22:45 +04:00
timeval_current_ofs ( 1 , 0 ) ,
reopen_connection , state ) ;
2007-05-22 03:33:26 +04:00
return ;
}
state - > tree = io - > out . tree ;
num_connected + + ;
2008-03-17 14:11:44 +03:00
DEBUG ( 0 , ( " [%u] reconnect to %s finished (%u connected) \n " ,
state - > client_num , state - > dest_host , num_connected ) ) ;
2007-05-22 03:33:26 +04:00
2008-03-17 14:11:44 +03:00
state - > open_fnum = - 1 ;
state - > close_fnum = - 1 ;
2007-05-26 07:24:08 +04:00
next_open ( state ) ;
2007-05-22 03:33:26 +04:00
}
/*
reopen a connection
*/
2008-12-29 22:24:57 +03:00
static void reopen_connection ( struct tevent_context * ev , struct tevent_timer * te ,
2007-05-22 03:33:26 +04:00
struct timeval t , void * private_data )
{
struct benchopen_state * state = ( struct benchopen_state * ) private_data ;
struct composite_context * ctx ;
struct smb_composite_connect * io = & state - > reconnect ;
char * host , * share ;
2007-05-29 12:30:41 +04:00
state - > te = NULL ;
2007-12-03 17:53:07 +03:00
if ( ! torture_get_conn_index ( state - > client_num , state - > mem_ctx , state - > tctx , & host , & share ) ) {
2007-05-22 03:33:26 +04:00
DEBUG ( 0 , ( " Can't find host/share for reconnect?! \n " ) ) ;
exit ( 1 ) ;
}
io - > in . dest_host = state - > dest_host ;
2008-01-04 02:21:50 +03:00
io - > in . dest_ports = state - > dest_ports ;
2010-07-16 08:32:42 +04:00
io - > in . socket_options = lpcfg_socket_options ( state - > tctx - > lp_ctx ) ;
2007-05-22 03:33:26 +04:00
io - > in . called_name = state - > called_name ;
io - > in . service = share ;
io - > in . service_type = state - > service_type ;
io - > in . credentials = cmdline_credentials ;
2007-10-07 02:28:14 +04:00
io - > in . fallback_to_anonymous = false ;
2010-07-16 08:32:42 +04:00
io - > in . workgroup = lpcfg_workgroup ( state - > tctx - > lp_ctx ) ;
io - > in . gensec_settings = lpcfg_gensec_settings ( state - > mem_ctx , state - > tctx - > lp_ctx ) ;
lpcfg_smbcli_options ( state - > tctx - > lp_ctx , & io - > in . options ) ;
lpcfg_smbcli_session_options ( state - > tctx - > lp_ctx , & io - > in . session_options ) ;
2007-05-22 03:33:26 +04:00
/* kill off the remnants of the old connection */
talloc_free ( state - > tree ) ;
state - > tree = NULL ;
2008-03-17 14:11:44 +03:00
state - > open_fnum = - 1 ;
state - > close_fnum = - 1 ;
2007-05-22 03:33:26 +04:00
2008-01-03 03:39:01 +03:00
ctx = smb_composite_connect_send ( io , state - > mem_ctx ,
2010-07-16 08:32:42 +04:00
lpcfg_resolve_context ( state - > tctx - > lp_ctx ) ,
2008-01-03 03:39:01 +03:00
state - > ev ) ;
2007-05-22 03:33:26 +04:00
if ( ctx = = NULL ) {
DEBUG ( 0 , ( " Failed to setup async reconnect \n " ) ) ;
exit ( 1 ) ;
}
ctx - > async . fn = reopen_connection_complete ;
ctx - > async . private_data = state ;
}
2007-04-05 10:23:06 +04:00
static void open_completed ( struct smbcli_request * req ) ;
static void close_completed ( struct smbcli_request * req ) ;
static void next_open ( struct benchopen_state * state )
{
state - > count + + ;
2008-03-17 14:11:44 +03:00
state - > pending_file_num = state - > next_file_num ;
state - > next_file_num = ( state - > next_file_num + 1 ) % ( 3 * nprocs ) ;
2007-05-26 07:24:08 +04:00
2008-03-17 14:11:44 +03:00
DEBUG ( 2 , ( " [%d] opening %u \n " , state - > client_num , state - > pending_file_num ) ) ;
2007-04-05 10:23:06 +04:00
state - > open_parms . ntcreatex . level = RAW_OPEN_NTCREATEX ;
state - > open_parms . ntcreatex . in . flags = 0 ;
2009-10-15 11:26:19 +04:00
state - > open_parms . ntcreatex . in . root_fid . fnum = 0 ;
2007-04-05 10:23:06 +04:00
state - > open_parms . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
state - > open_parms . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
state - > open_parms . ntcreatex . in . alloc_size = 0 ;
state - > open_parms . ntcreatex . in . share_access = 0 ;
state - > open_parms . ntcreatex . in . open_disposition = NTCREATEX_DISP_OVERWRITE_IF ;
state - > open_parms . ntcreatex . in . create_options = 0 ;
state - > open_parms . ntcreatex . in . impersonation = 0 ;
state - > open_parms . ntcreatex . in . security_flags = 0 ;
2008-03-17 14:11:44 +03:00
state - > open_parms . ntcreatex . in . fname = fnames [ state - > pending_file_num ] ;
2007-04-05 10:23:06 +04:00
2007-05-22 03:33:26 +04:00
state - > req_open = smb_raw_open_send ( state - > tree , & state - > open_parms ) ;
2007-04-05 10:23:06 +04:00
state - > req_open - > async . fn = open_completed ;
2009-02-02 12:17:00 +03:00
state - > req_open - > async . private_data = state ;
2007-05-22 08:53:05 +04:00
}
2007-04-05 10:23:06 +04:00
2007-05-22 08:53:05 +04:00
static void next_close ( struct benchopen_state * state )
{
2008-03-17 14:11:44 +03:00
if ( state - > close_fnum = = - 1 ) {
2007-05-26 07:24:08 +04:00
return ;
}
2008-03-17 14:11:44 +03:00
DEBUG ( 2 , ( " [%d] closing %d (fnum[%d]) \n " ,
state - > client_num , state - > close_file_num , state - > close_fnum ) ) ;
2007-04-05 10:23:06 +04:00
state - > close_parms . close . level = RAW_CLOSE_CLOSE ;
2008-03-17 14:11:44 +03:00
state - > close_parms . close . in . file . fnum = state - > close_fnum ;
2007-04-05 10:23:06 +04:00
state - > close_parms . close . in . write_time = 0 ;
2007-05-22 03:33:26 +04:00
state - > req_close = smb_raw_close_send ( state - > tree , & state - > close_parms ) ;
2007-04-05 10:23:06 +04:00
state - > req_close - > async . fn = close_completed ;
2009-02-02 12:17:00 +03:00
state - > req_close - > async . private_data = state ;
2007-04-05 10:23:06 +04:00
}
/*
called when a open completes
*/
static void open_completed ( struct smbcli_request * req )
{
2009-02-02 12:17:00 +03:00
struct benchopen_state * state = ( struct benchopen_state * ) req - > async . private_data ;
2007-05-22 03:33:26 +04:00
TALLOC_CTX * tmp_ctx = talloc_new ( state - > mem_ctx ) ;
2007-04-05 10:23:06 +04:00
NTSTATUS status ;
status = smb_raw_open_recv ( req , tmp_ctx , & state - > open_parms ) ;
talloc_free ( tmp_ctx ) ;
state - > req_open = NULL ;
2007-05-22 03:33:26 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_END_OF_FILE ) | |
2010-02-04 12:19:05 +03:00
NT_STATUS_EQUAL ( status , NT_STATUS_LOCAL_DISCONNECT ) | |
NT_STATUS_EQUAL ( status , NT_STATUS_CONNECTION_RESET ) ) {
2007-05-22 03:33:26 +04:00
talloc_free ( state - > tree ) ;
talloc_free ( state - > cli ) ;
state - > tree = NULL ;
state - > cli = NULL ;
num_connected - - ;
2008-03-17 14:11:44 +03:00
DEBUG ( 0 , ( " [%u] reopening connection to %s \n " ,
state - > client_num , state - > dest_host ) ) ;
2007-05-29 12:22:45 +04:00
talloc_free ( state - > te ) ;
2010-05-25 23:23:55 +04:00
state - > te = tevent_add_timer ( state - > ev , state - > mem_ctx ,
2007-05-29 12:22:45 +04:00
timeval_current_ofs ( 1 , 0 ) ,
reopen_connection , state ) ;
2007-05-22 03:33:26 +04:00
return ;
}
2007-04-05 10:23:06 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_SHARING_VIOLATION ) ) {
2008-03-17 14:11:44 +03:00
DEBUG ( 2 , ( " [%d] retrying open %d \n " ,
state - > client_num , state - > pending_file_num ) ) ;
2008-03-17 11:59:30 +03:00
state - > open_retries + + ;
2007-05-22 03:33:26 +04:00
state - > req_open = smb_raw_open_send ( state - > tree , & state - > open_parms ) ;
2007-04-05 10:23:06 +04:00
state - > req_open - > async . fn = open_completed ;
2009-02-02 12:17:00 +03:00
state - > req_open - > async . private_data = state ;
2007-04-05 10:23:06 +04:00
return ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
open_failed + + ;
2008-03-17 14:11:44 +03:00
DEBUG ( 0 , ( " [%u] open failed %d - %s \n " ,
state - > client_num , state - > pending_file_num ,
nt_errstr ( status ) ) ) ;
2007-04-05 10:23:06 +04:00
return ;
}
2008-03-17 14:11:44 +03:00
state - > close_file_num = state - > open_file_num ;
state - > close_fnum = state - > open_fnum ;
state - > open_file_num = state - > pending_file_num ;
state - > open_fnum = state - > open_parms . ntcreatex . out . file . fnum ;
2007-04-05 10:23:06 +04:00
2008-03-17 14:11:44 +03:00
DEBUG ( 2 , ( " [%d] open completed %d (fnum[%d]) \n " ,
state - > client_num , state - > open_file_num , state - > open_fnum ) ) ;
2007-05-26 07:24:08 +04:00
2008-03-17 14:11:44 +03:00
if ( state - > close_fnum ! = - 1 ) {
2007-05-26 07:24:08 +04:00
next_close ( state ) ;
}
next_open ( state ) ;
2007-04-05 10:23:06 +04:00
}
/*
called when a close completes
*/
static void close_completed ( struct smbcli_request * req )
{
2009-02-02 12:17:00 +03:00
struct benchopen_state * state = ( struct benchopen_state * ) req - > async . private_data ;
2007-04-05 10:23:06 +04:00
NTSTATUS status = smbcli_request_simple_recv ( req ) ;
state - > req_close = NULL ;
2007-05-22 03:33:26 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_END_OF_FILE ) | |
2010-02-04 12:19:05 +03:00
NT_STATUS_EQUAL ( status , NT_STATUS_LOCAL_DISCONNECT ) | |
NT_STATUS_EQUAL ( status , NT_STATUS_CONNECTION_RESET ) ) {
2007-05-22 03:33:26 +04:00
talloc_free ( state - > tree ) ;
talloc_free ( state - > cli ) ;
state - > tree = NULL ;
state - > cli = NULL ;
num_connected - - ;
2008-03-17 14:11:44 +03:00
DEBUG ( 0 , ( " [%u] reopening connection to %s \n " ,
state - > client_num , state - > dest_host ) ) ;
2007-05-29 12:22:45 +04:00
talloc_free ( state - > te ) ;
2010-05-25 23:23:55 +04:00
state - > te = tevent_add_timer ( state - > ev , state - > mem_ctx ,
2007-05-29 12:22:45 +04:00
timeval_current_ofs ( 1 , 0 ) ,
reopen_connection , state ) ;
2007-05-22 03:33:26 +04:00
return ;
}
2007-04-05 10:23:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-03-17 11:59:30 +03:00
close_failed + + ;
2008-03-17 14:11:44 +03:00
DEBUG ( 0 , ( " [%u] close failed %d (fnum[%d]) - %s \n " ,
state - > client_num , state - > close_file_num ,
state - > close_fnum ,
nt_errstr ( status ) ) ) ;
2007-04-05 10:23:06 +04:00
return ;
}
2008-03-17 14:11:44 +03:00
DEBUG ( 2 , ( " [%d] close completed %d (fnum[%d]) \n " ,
state - > client_num , state - > close_file_num ,
state - > close_fnum ) ) ;
2007-05-22 08:53:05 +04:00
}
2007-04-05 10:23:06 +04:00
2007-05-25 16:21:29 +04:00
static void echo_completion ( struct smbcli_request * req )
{
2009-02-02 12:17:00 +03:00
struct benchopen_state * state = ( struct benchopen_state * ) req - > async . private_data ;
2007-05-25 16:21:29 +04:00
NTSTATUS status = smbcli_request_simple_recv ( req ) ;
2007-05-29 11:32:28 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_END_OF_FILE ) | |
2010-02-04 12:19:05 +03:00
NT_STATUS_EQUAL ( status , NT_STATUS_LOCAL_DISCONNECT ) | |
NT_STATUS_EQUAL ( status , NT_STATUS_CONNECTION_RESET ) ) {
2007-05-25 16:21:29 +04:00
talloc_free ( state - > tree ) ;
state - > tree = NULL ;
num_connected - - ;
2008-03-17 14:11:44 +03:00
DEBUG ( 0 , ( " [%u] reopening connection to %s \n " ,
state - > client_num , state - > dest_host ) ) ;
2007-05-29 12:22:45 +04:00
talloc_free ( state - > te ) ;
2010-05-25 23:23:55 +04:00
state - > te = tevent_add_timer ( state - > ev , state - > mem_ctx ,
2007-05-29 12:22:45 +04:00
timeval_current_ofs ( 1 , 0 ) ,
reopen_connection , state ) ;
2007-05-25 16:21:29 +04:00
}
}
2008-12-29 22:24:57 +03:00
static void report_rate ( struct tevent_context * ev , struct tevent_timer * te ,
2007-05-22 03:33:26 +04:00
struct timeval t , void * private_data )
{
struct benchopen_state * state = talloc_get_type ( private_data ,
struct benchopen_state ) ;
int i ;
for ( i = 0 ; i < nprocs ; i + + ) {
printf ( " %5u " , ( unsigned ) ( state [ i ] . count - state [ i ] . lastcount ) ) ;
state [ i ] . lastcount = state [ i ] . count ;
}
printf ( " \r " ) ;
fflush ( stdout ) ;
2010-05-25 23:23:55 +04:00
report_te = tevent_add_timer ( ev , state , timeval_current_ofs ( 1 , 0 ) ,
2007-05-26 07:24:08 +04:00
report_rate , state ) ;
2007-05-25 14:43:06 +04:00
/* send an echo on each interface to ensure it stays alive - this helps
with IP takeover */
for ( i = 0 ; i < nprocs ; i + + ) {
struct smb_echo p ;
2007-05-25 16:21:29 +04:00
struct smbcli_request * req ;
2007-05-25 16:35:03 +04:00
if ( ! state [ i ] . tree ) {
continue ;
}
2007-05-25 16:21:29 +04:00
p . in . repeat_count = 1 ;
2007-05-25 14:43:06 +04:00
p . in . size = 0 ;
p . in . data = NULL ;
2007-05-25 16:21:29 +04:00
req = smb_raw_echo_send ( state [ i ] . tree - > session - > transport , & p ) ;
2009-02-02 12:17:00 +03:00
req - > async . private_data = & state [ i ] ;
2007-05-25 16:21:29 +04:00
req - > async . fn = echo_completion ;
2007-05-25 14:43:06 +04:00
}
2007-05-22 03:33:26 +04:00
}
2007-04-05 10:23:06 +04:00
/*
benchmark open calls
*/
2007-10-07 02:28:14 +04:00
bool torture_bench_open ( struct torture_context * torture )
2007-04-05 10:23:06 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2007-04-05 10:23:06 +04:00
TALLOC_CTX * mem_ctx = talloc_new ( torture ) ;
int i ;
int timelimit = torture_setting_int ( torture , " timelimit " , 10 ) ;
struct timeval tv ;
struct benchopen_state * state ;
2008-03-17 11:59:30 +03:00
int total = 0 ;
int total_retries = 0 ;
int minops = 0 ;
2007-10-07 02:28:14 +04:00
bool progress = false ;
2007-05-22 03:33:26 +04:00
progress = torture_setting_bool ( torture , " progress " , true ) ;
2007-04-05 10:23:06 +04:00
2007-08-28 04:16:58 +04:00
nprocs = torture_setting_int ( torture , " nprocs " , 4 ) ;
2007-04-05 10:23:06 +04:00
state = talloc_zero_array ( mem_ctx , struct benchopen_state , nprocs ) ;
printf ( " Opening %d connections \n " , nprocs ) ;
for ( i = 0 ; i < nprocs ; i + + ) {
2011-09-23 10:35:17 +04:00
const struct sockaddr_storage * dest_ss ;
char addrstr [ INET6_ADDRSTRLEN ] ;
const char * dest_str ;
uint16_t dest_port ;
2007-12-03 17:53:07 +03:00
state [ i ] . tctx = torture ;
2007-05-22 03:33:26 +04:00
state [ i ] . mem_ctx = talloc_new ( state ) ;
state [ i ] . client_num = i ;
2008-04-17 03:19:20 +04:00
state [ i ] . ev = torture - > ev ;
if ( ! torture_open_connection_ev ( & state [ i ] . cli , i , torture , torture - > ev ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2007-04-05 10:23:06 +04:00
}
2011-09-23 10:35:17 +04:00
talloc_steal ( state [ i ] . mem_ctx , state [ i ] . cli ) ;
2007-05-22 03:33:26 +04:00
state [ i ] . tree = state [ i ] . cli - > tree ;
2011-09-23 10:35:17 +04:00
dest_ss = smbXcli_conn_remote_sockaddr (
state [ i ] . tree - > session - > transport - > conn ) ;
dest_str = print_sockaddr ( addrstr , sizeof ( addrstr ) , dest_ss ) ;
dest_port = get_sockaddr_port ( dest_ss ) ;
state [ i ] . dest_host = talloc_strdup ( state [ i ] . mem_ctx , dest_str ) ;
2008-01-04 02:21:50 +03:00
state [ i ] . dest_ports = talloc_array ( state [ i ] . mem_ctx ,
const char * , 2 ) ;
state [ i ] . dest_ports [ 0 ] = talloc_asprintf ( state [ i ] . dest_ports ,
2011-09-23 10:35:17 +04:00
" %u " , dest_port ) ;
2008-01-04 02:21:50 +03:00
state [ i ] . dest_ports [ 1 ] = NULL ;
2007-05-22 03:33:26 +04:00
state [ i ] . called_name = talloc_strdup ( state [ i ] . mem_ctx ,
2011-09-23 10:35:17 +04:00
smbXcli_conn_remote_name ( state [ i ] . tree - > session - > transport - > conn ) ) ;
state [ i ] . service_type = talloc_strdup ( state [ i ] . mem_ctx , " ????? " ) ;
2007-04-05 10:23:06 +04:00
}
2007-05-22 03:33:26 +04:00
num_connected = i ;
2007-04-05 10:23:06 +04:00
if ( ! torture_setup_dir ( state [ 0 ] . cli , BASEDIR ) ) {
goto failed ;
}
2007-05-26 07:24:08 +04:00
fnames = talloc_array ( mem_ctx , char * , 3 * nprocs ) ;
for ( i = 0 ; i < 3 * nprocs ; i + + ) {
2007-04-05 10:23:06 +04:00
fnames [ i ] = talloc_asprintf ( fnames , " %s \\ file%d.dat " , BASEDIR , i ) ;
}
for ( i = 0 ; i < nprocs ; i + + ) {
2008-03-17 14:11:44 +03:00
/* all connections start with the same file */
state [ i ] . next_file_num = 0 ;
state [ i ] . open_fnum = - 1 ;
state [ i ] . close_fnum = - 1 ;
2007-05-26 07:24:08 +04:00
next_open ( & state [ i ] ) ;
2007-04-05 10:23:06 +04:00
}
tv = timeval_current ( ) ;
2007-05-22 03:33:26 +04:00
if ( progress ) {
2010-05-25 23:23:55 +04:00
report_te = tevent_add_timer ( torture - > ev , state , timeval_current_ofs ( 1 , 0 ) ,
2007-05-26 07:24:08 +04:00
report_rate , state ) ;
2007-05-22 03:33:26 +04:00
}
2007-04-05 10:23:06 +04:00
printf ( " Running for %d seconds \n " , timelimit ) ;
while ( timeval_elapsed ( & tv ) < timelimit ) {
2010-05-25 23:23:55 +04:00
tevent_loop_once ( torture - > ev ) ;
2007-04-05 10:23:06 +04:00
if ( open_failed ) {
2007-05-22 03:33:26 +04:00
DEBUG ( 0 , ( " open failed \n " ) ) ;
2007-04-05 10:23:06 +04:00
goto failed ;
}
2008-03-17 11:59:30 +03:00
if ( close_failed ) {
DEBUG ( 0 , ( " open failed \n " ) ) ;
goto failed ;
}
2007-04-05 10:23:06 +04:00
}
2007-05-26 07:24:08 +04:00
talloc_free ( report_te ) ;
2008-03-17 14:11:44 +03:00
if ( progress ) {
for ( i = 0 ; i < nprocs ; i + + ) {
printf ( " " ) ;
}
printf ( " \r " ) ;
}
2007-05-26 07:24:08 +04:00
2007-04-05 10:23:06 +04:00
minops = state [ 0 ] . count ;
for ( i = 0 ; i < nprocs ; i + + ) {
2008-03-17 11:59:30 +03:00
total + = state [ i ] . count ;
total_retries + = state [ i ] . open_retries ;
printf ( " [%d] %u ops (%u retries) \n " ,
i , state [ i ] . count , state [ i ] . open_retries ) ;
2007-04-05 10:23:06 +04:00
if ( state [ i ] . count < minops ) minops = state [ i ] . count ;
}
2008-03-17 11:59:30 +03:00
printf ( " %.2f ops/second (%d retries) \n " ,
total / timeval_elapsed ( & tv ) , total_retries ) ;
2007-04-05 10:23:06 +04:00
if ( minops < 0.5 * total / nprocs ) {
printf ( " Failed: unbalanced open \n " ) ;
goto failed ;
}
for ( i = 0 ; i < nprocs ; i + + ) {
talloc_free ( state [ i ] . req_open ) ;
talloc_free ( state [ i ] . req_close ) ;
2007-05-22 03:33:26 +04:00
smb_raw_exit ( state [ i ] . tree - > session ) ;
2007-04-05 10:23:06 +04:00
}
2007-05-22 03:33:26 +04:00
smbcli_deltree ( state [ 0 ] . tree , BASEDIR ) ;
2007-04-05 10:23:06 +04:00
talloc_free ( mem_ctx ) ;
return ret ;
failed :
talloc_free ( mem_ctx ) ;
2007-10-07 02:28:14 +04:00
return false ;
2007-04-05 10:23:06 +04:00
}