[PATCH v2] smbtorture: Add smb2.maxfid

Jeremy Allison jra at samba.org
Tue Jul 12 21:52:25 UTC 2016


On Tue, Jul 12, 2016 at 11:28:32AM -0700, Christof Schmitt wrote:
> Here is a slightly updated version of the patch. The original version
> did not close the file handle of the share directory. With the change to
> close it early, the number of files to open should match the server
> configuration (e.g. from 'max open files').

LGTM. What result did you get from Windows ?

> From 94ff0ebc43e4ef8e8ce5fb0e31d10418cd9f128b Mon Sep 17 00:00:00 2001
> From: Christof Schmitt <cs at samba.org>
> Date: Mon, 11 Jul 2016 11:32:19 -0700
> Subject: [PATCH] smbtorture: Add smb2.maxfid
> 
> This is the same as base.maxfid, but for the SMB2 protocol: Keep opening
> file handles until an error is returned, print the number of file
> handles opened and finally close the file handles again.
> 
> Signed-off-by: Christof Schmitt <cs at samba.org>
> ---
>  source4/torture/smb2/maxfid.c      | 138 +++++++++++++++++++++++++++++++++++++
>  source4/torture/smb2/smb2.c        |   1 +
>  source4/torture/smb2/wscript_build |   2 +-
>  3 files changed, 140 insertions(+), 1 deletion(-)
>  create mode 100644 source4/torture/smb2/maxfid.c
> 
> diff --git a/source4/torture/smb2/maxfid.c b/source4/torture/smb2/maxfid.c
> new file mode 100644
> index 0000000..b34f062
> --- /dev/null
> +++ b/source4/torture/smb2/maxfid.c
> @@ -0,0 +1,138 @@
> +/*
> +   Unix SMB/CIFS implementation.
> +
> +   SMB2 maxfid test
> +
> +   Copyright (C) Christof Schmitt 2016
> +
> +   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
> +   the Free Software Foundation; either version 3 of the License, or
> +   (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
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +*/
> +
> +#include "includes.h"
> +#include "libcli/smb2/smb2.h"
> +#include "libcli/smb2/smb2_calls.h"
> +
> +#include "torture/torture.h"
> +#include "torture/smb2/proto.h"
> +
> +bool torture_smb2_maxfid(struct torture_context *tctx)
> +{
> +	bool ret = true;
> +	NTSTATUS status;
> +	struct smb2_tree *tree = NULL;
> +	const char *dname = "smb2_maxfid";
> +	int i, maxfid;
> +	struct smb2_handle dir_handle = { };
> +	struct smb2_handle handles[0x11000];
> +
> +	if (!torture_smb2_connection(tctx, &tree)) {
> +		return false;
> +	}
> +
> +	smb2_deltree(tree, dname);
> +
> +	status = torture_smb2_testdir(tree, dname, &dir_handle);
> +	torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
> +					"torture_smb2_testdir failed");
> +	smb2_util_close(tree, dir_handle);
> +
> +	torture_comment(tctx, "Creating subdirectories\n");
> +
> +	for (i = 0; i < ARRAY_SIZE(handles); i += 1000) {
> +		char *name;
> +		struct smb2_create create = { };
> +		struct smb2_close close = { };
> +
> +		name = talloc_asprintf(tctx, "%s\\%d", dname, i / 1000);
> +		torture_assert_goto(tctx, (name != NULL), ret, done,
> +				    "no memory for directory name\n");
> +
> +		create.in.desired_access = SEC_RIGHTS_DIR_ALL;
> +		create.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
> +		create.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
> +		create.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
> +			NTCREATEX_SHARE_ACCESS_WRITE |
> +			NTCREATEX_SHARE_ACCESS_DELETE;
> +		create.in.create_disposition = NTCREATEX_DISP_CREATE;
> +		create.in.fname = name;
> +
> +		status = smb2_create(tree, tctx, &create);
> +		talloc_free(name);
> +
> +		torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
> +						"CREATE directory %s failed\n");
> +
> +		close.in.file.handle = create.out.file.handle;
> +		status = smb2_close(tree, &close);
> +		torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
> +						"CLOSE directory %s failed\n");
> +	}
> +
> +	torture_comment(tctx, "Testing maximum number of open files\n");
> +
> +	for (i = 0; i < ARRAY_SIZE(handles); i++) {
> +		char *name;
> +		struct smb2_create create = { };
> +
> +		name = talloc_asprintf(tctx, "%s\\%d\\%d", dname, i / 1000, i);
> +		torture_assert_goto(tctx, (name != NULL), ret, done,
> +				    "no memory for file name\n");
> +
> +		create.in.desired_access = SEC_RIGHTS_DIR_ALL;
> +		create.in.create_options = 0;
> +		create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
> +		create.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
> +			NTCREATEX_SHARE_ACCESS_WRITE |
> +			NTCREATEX_SHARE_ACCESS_DELETE;
> +		create.in.create_disposition = NTCREATEX_DISP_CREATE;
> +		create.in.fname = name;
> +
> +		status = smb2_create(tree, tctx, &create);
> +		if (!NT_STATUS_IS_OK(status)) {
> +			torture_comment(tctx, "create of %s failed: %s\n",
> +					name, nt_errstr(status));
> +			talloc_free(name);
> +			break;
> +		}
> +		talloc_free(name);
> +
> +		handles[i] = create.out.file.handle;
> +	}
> +
> +	maxfid = i;
> +	torture_comment(tctx, "Maximum number of open files: %d\n", maxfid);
> +
> +	torture_comment(tctx, "Cleanup open files\n");
> +
> +	for (i = 0; i < maxfid; i++) {
> +		union smb_setfileinfo sfinfo = { };
> +
> +		sfinfo.disposition_info.in.delete_on_close = 1;
> +		sfinfo.generic.level = RAW_SFILEINFO_DISPOSITION_INFORMATION;
> +		sfinfo.generic.in.file.handle = handles[i];
> +
> +		status = smb2_setinfo_file(tree, &sfinfo);
> +		torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
> +						"SETINFO failed\n");
> +
> +		status = smb2_util_close(tree, handles[i]);
> +		torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
> +						"CLOSE failed\n");
> +	}
> +
> +done:
> +	smb2_deltree(tree, dname);
> +
> +	return ret;
> +}
> diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c
> index be632cc..ca07992 100644
> --- a/source4/torture/smb2/smb2.c
> +++ b/source4/torture/smb2/smb2.c
> @@ -171,6 +171,7 @@ NTSTATUS torture_smb2_init(void)
>  	torture_suite_add_suite(suite, torture_smb2_session_init());
>  	torture_suite_add_suite(suite, torture_smb2_replay_init());
>  	torture_suite_add_simple_test(suite, "dosmode", torture_smb2_dosmode);
> +	torture_suite_add_simple_test(suite, "maxfid", torture_smb2_maxfid);
>  
>  	torture_suite_add_suite(suite, torture_smb2_doc_init());
>  
> diff --git a/source4/torture/smb2/wscript_build b/source4/torture/smb2/wscript_build
> index f404356..e667f00 100644
> --- a/source4/torture/smb2/wscript_build
> +++ b/source4/torture/smb2/wscript_build
> @@ -3,7 +3,7 @@
>  bld.SAMBA_MODULE('TORTURE_SMB2',
>  	source='''connect.c scan.c util.c getinfo.c setinfo.c lock.c notify.c
>  	smb2.c durable_open.c durable_v2_open.c oplock.c dir.c lease.c create.c
> -	acls.c read.c compound.c streams.c ioctl.c rename.c
> +	acls.c read.c compound.c streams.c ioctl.c rename.c maxfid.c
>  	session.c delete-on-close.c replay.c notify_disabled.c dosmode.c''',
>  	subsystem='smbtorture',
>  	deps='LIBCLI_SMB2 POPT_CREDENTIALS torture NDR_IOCTL',
> -- 
> 1.8.3.1
> 




More information about the samba-technical mailing list