2 Unix SMB/CIFS implementation.
6 Copyright (C) Christof Schmitt 2016
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
29 bool torture_smb2_maxfid(struct torture_context
*tctx
)
33 struct smb2_tree
*tree
= NULL
;
34 const char *dname
= "smb2_maxfid";
36 struct smb2_handle
*handles
, dir_handle
= { };
40 * We limited this to 65520 as socket_wrapper has a limit of
41 * 65535 (0xfff0) open sockets.
43 * It could be increased by setting the following env variable:
45 * SOCKET_WRAPPER_MAX_SOCKETS=100000
47 max_handles
= torture_setting_int(tctx
, "maxopenfiles", 65520);
49 if (!torture_smb2_connection(tctx
, &tree
)) {
53 handles
= talloc_array(tctx
, struct smb2_handle
, max_handles
);
55 torture_fail(tctx
, "Could not allocate handles array.\n");
59 smb2_deltree(tree
, dname
);
61 status
= torture_smb2_testdir(tree
, dname
, &dir_handle
);
62 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
63 "torture_smb2_testdir failed");
64 smb2_util_close(tree
, dir_handle
);
66 torture_comment(tctx
, "Creating subdirectories\n");
68 for (i
= 0; i
< max_handles
; i
+= 1000) {
70 struct smb2_create create
= { };
71 struct smb2_close close
= { };
73 name
= talloc_asprintf(tctx
, "%s\\%zu", dname
, i
/ 1000);
74 torture_assert_goto(tctx
, (name
!= NULL
), ret
, done
,
75 "no memory for directory name\n");
77 create
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
78 create
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
79 create
.in
.file_attributes
= FILE_ATTRIBUTE_DIRECTORY
;
80 create
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
81 NTCREATEX_SHARE_ACCESS_WRITE
|
82 NTCREATEX_SHARE_ACCESS_DELETE
;
83 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
84 create
.in
.fname
= name
;
86 status
= smb2_create(tree
, tctx
, &create
);
89 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
90 "CREATE directory failed\n");
92 close
.in
.file
.handle
= create
.out
.file
.handle
;
93 status
= smb2_close(tree
, &close
);
94 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
95 "CLOSE directory failed\n");
98 torture_comment(tctx
, "Testing maximum number of open files\n");
100 for (i
= 0; i
< max_handles
; i
++) {
102 struct smb2_create create
= { };
104 name
= talloc_asprintf(tctx
, "%s\\%zu\\%zu", dname
, i
/ 1000, i
);
105 torture_assert_goto(tctx
, (name
!= NULL
), ret
, done
,
106 "no memory for file name\n");
108 create
.in
.desired_access
= SEC_RIGHTS_DIR_ALL
;
109 create
.in
.create_options
= 0;
110 create
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
111 create
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
112 NTCREATEX_SHARE_ACCESS_WRITE
|
113 NTCREATEX_SHARE_ACCESS_DELETE
;
114 create
.in
.create_disposition
= NTCREATEX_DISP_CREATE
;
115 create
.in
.fname
= name
;
117 status
= smb2_create(tree
, tctx
, &create
);
118 if (!NT_STATUS_IS_OK(status
)) {
119 torture_comment(tctx
, "create of %s failed: %s\n",
120 name
, nt_errstr(status
));
126 handles
[i
] = create
.out
.file
.handle
;
130 if (maxfid
== max_handles
) {
131 torture_comment(tctx
, "Reached test limit of %zu open files. "
132 "Adjust to higher test with "
133 "--option=torture:maxopenfiles=NNN\n", maxfid
);
136 torture_comment(tctx
, "Cleanup open files\n");
138 for (i
= 0; i
< maxfid
; i
++) {
139 status
= smb2_util_close(tree
, handles
[i
]);
140 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
145 smb2_deltree(tree
, dname
);
146 talloc_free(handles
);