s4:smbtorture: add BASE-BENCH-HOLDOPEN
[ira/wip.git] / source4 / torture / basic / misc.c
index f11b90f44884e91b6e3d49f5c50b512281e49aa8..ab79d798fc52be4bad1d5d0d7b8f26b77594c639 100644 (file)
@@ -28,8 +28,6 @@
 #include "libcli/libcli.h"
 #include "lib/events/events.h"
 #include "libcli/resolve/resolve.h"
-#include "auth/credentials/credentials.h"
-#include "librpc/gen_ndr/ndr_nbt.h"
 #include "torture/smbtorture.h"
 #include "torture/util.h"
 #include "libcli/smb_composite/smb_composite.h"
@@ -232,6 +230,69 @@ bool torture_holdcon(struct torture_context *tctx)
        return true;
 }
 
+/*
+  open a file N times on the server and just hold them open
+  used for testing performance when there are N file handles
+  alopenn
+ */
+bool torture_holdopen(struct torture_context *tctx,
+                     struct smbcli_state *cli)
+{
+       int i, fnum;
+       const char *fname = "\\holdopen.dat";
+       NTSTATUS status;
+
+       smbcli_unlink(cli->tree, fname);
+
+       fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+       if (fnum == -1) {
+               torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
+               return false;
+       }
+
+       smbcli_close(cli->tree, fnum);
+
+       for (i=0;i<torture_numops;i++) {
+               union smb_open op;
+
+               op.generic.level = RAW_OPEN_NTCREATEX;
+               op.ntcreatex.in.root_fid.fnum = 0;
+               op.ntcreatex.in.flags = 0;
+               op.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
+               op.ntcreatex.in.create_options = 0;
+               op.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+               op.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+               op.ntcreatex.in.alloc_size = 0;
+               op.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+               op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+               op.ntcreatex.in.security_flags = 0;
+               op.ntcreatex.in.fname = fname;
+               status = smb_raw_open(cli->tree, tctx, &op);
+               if (!NT_STATUS_IS_OK(status)) {
+                       torture_warning(tctx, "open %d failed\n", i);
+                       continue;
+               }
+
+               if (torture_setting_bool(tctx, "progress", true)) {
+                       torture_comment(tctx, "opened %d file\r", i);
+                       fflush(stdout);
+               }
+       }
+
+       torture_comment(tctx, "\nStarting pings\n");
+
+       while (1) {
+               struct smb_echo ec;
+
+               status = smb_raw_echo(cli->transport, &ec);
+               torture_comment(tctx, ".");
+               fflush(stdout);
+               sleep(15);
+       }
+
+       return true;
+}
+
 /*
 test how many open files this server supports on the one socket
 */
@@ -510,7 +571,7 @@ static NTSTATUS benchrw_close(struct torture_context *tctx,
        NT_STATUS_HAVE_NO_MEMORY(req);
        /*register the callback function!*/
        req->async.fn = benchrw_callback;
-       req->async.private = state;
+       req->async.private_data = state;
        
        return NT_STATUS_OK;
 }
@@ -521,7 +582,7 @@ static void benchrw_callback(struct smbcli_request *req);
 
 static void benchrw_rw_callback(struct smbcli_request *req)
 {
-       struct benchrw_state *state = req->async.private;
+       struct benchrw_state *state = req->async.private_data;
        struct torture_context *tctx = state->tctx;
 
        if (!NT_STATUS_IS_OK(req->status)) {
@@ -596,7 +657,7 @@ static NTSTATUS benchrw_readwrite(struct torture_context *tctx,
        NT_STATUS_HAVE_NO_MEMORY(req);
        /*register the callback function!*/
        req->async.fn = benchrw_rw_callback;
-       req->async.private = state;
+       req->async.private_data = state;
        
        return NT_STATUS_OK;
 }
@@ -644,7 +705,7 @@ static NTSTATUS benchrw_open(struct torture_context *tctx,
        
        /*register the callback function!*/
        req->async.fn = benchrw_callback;
-       req->async.private = state;
+       req->async.private_data = state;
        return NT_STATUS_OK;
 } 
 
@@ -691,7 +752,7 @@ static NTSTATUS benchrw_mkdir(struct torture_context *tctx,
        
        /*register the callback function!*/
        req->async.fn = benchrw_callback;
-       req->async.private = state;
+       req->async.private_data = state;
                
        return NT_STATUS_OK;
 }
@@ -701,7 +762,7 @@ static NTSTATUS benchrw_mkdir(struct torture_context *tctx,
 */
 static void benchrw_callback(struct smbcli_request *req)
 {
-       struct benchrw_state *state = req->async.private;
+       struct benchrw_state *state = req->async.private_data;
        struct torture_context *tctx = state->tctx;
        
        /*dont send new requests when torture_numops is reached*/
@@ -808,7 +869,7 @@ static struct composite_context *torture_connect_async(
                                struct torture_context *tctx,
                                struct smb_composite_connect *smb,
                                TALLOC_CTX *mem_ctx,
-                               struct event_context *ev,
+                               struct tevent_context *ev,
                                const char *host,
                                const char *share,
                                const char *workgroup)
@@ -839,7 +900,7 @@ bool run_benchrw(struct torture_context *tctx)
        struct smbcli_request *req;
        struct benchrw_state **state;
        int i , num_unc_names;
-       struct event_context    *ev     ;       
+       struct tevent_context   *ev     ;       
        struct composite_context *req1;
        struct params lpparams;
        union smb_mkdir parms;
@@ -913,7 +974,7 @@ bool run_benchrw(struct torture_context *tctx)
                                req = smb_raw_mkdir_send(state[i]->cli,&parms);
                                /* register callback fn + private data */
                                req->async.fn = benchrw_callback;
-                               req->async.private=state[i];
+                               req->async.private_data=state[i];
                                break;
                        /* error occured , finish */
                        case ERROR: