2 Unix SMB/CIFS implementation.
4 test suite for SMB2 leases
6 Copyright (C) Zachary Loafman 2009
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/>.
22 #include "torture/util.h"
24 struct lease_break_info
{
25 struct torture_context
*tctx
;
27 struct smb2_lease_break lease_break
;
28 struct smb2_transport
*lease_transport
;
30 struct smb2_lease_break_ack lease_break_ack
;
34 struct smb2_handle oplock_handle
;
35 uint8_t held_oplock_level
;
41 #define CHECK_LEASE_BREAK(__lb, __oldstate, __state, __key) \
43 uint16_t __new = smb2_util_lease_state(__state); \
44 uint16_t __old = smb2_util_lease_state(__oldstate); \
45 CHECK_VAL((__lb)->new_lease_state, __new); \
46 CHECK_VAL((__lb)->current_lease.lease_state, __old); \
47 CHECK_VAL((__lb)->current_lease.lease_key.data[0], (__key)); \
48 CHECK_VAL((__lb)->current_lease.lease_key.data[1], ~(__key)); \
49 if (__old & (SMB2_LEASE_WRITE | SMB2_LEASE_HANDLE)) { \
50 CHECK_VAL((__lb)->break_flags, \
51 SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED); \
53 CHECK_VAL((__lb)->break_flags, 0); \
57 #define CHECK_LEASE_BREAK_ACK(__lba, __state, __key) \
59 CHECK_VAL((__lba)->out.reserved, 0); \
60 CHECK_VAL((__lba)->out.lease.lease_key.data[0], (__key)); \
61 CHECK_VAL((__lba)->out.lease.lease_key.data[1], ~(__key)); \
62 CHECK_VAL((__lba)->out.lease.lease_state, smb2_util_lease_state(__state)); \
63 CHECK_VAL((__lba)->out.lease.lease_flags, 0); \
64 CHECK_VAL((__lba)->out.lease.lease_duration, 0); \
67 #define CHECK_NO_BREAK(tctx) \
69 torture_wait_for_lease_break(tctx); \
70 CHECK_VAL(lease_break_info.failures, 0); \
71 CHECK_VAL(lease_break_info.count, 0); \
72 CHECK_VAL(lease_break_info.oplock_failures, 0); \
73 CHECK_VAL(lease_break_info.oplock_count, 0); \
76 #define CHECK_OPLOCK_BREAK(__brokento) \
78 torture_wait_for_lease_break(tctx); \
79 CHECK_VAL(lease_break_info.oplock_count, 1); \
80 CHECK_VAL(lease_break_info.oplock_failures, 0); \
81 CHECK_VAL(lease_break_info.oplock_level, \
82 smb2_util_oplock_level(__brokento)); \
83 lease_break_info.held_oplock_level = lease_break_info.oplock_level; \
86 #define _CHECK_BREAK_INFO(__oldstate, __state, __key) \
88 torture_wait_for_lease_break(tctx); \
89 CHECK_VAL(lease_break_info.failures, 0); \
90 CHECK_VAL(lease_break_info.count, 1); \
91 CHECK_LEASE_BREAK(&lease_break_info.lease_break, (__oldstate), \
92 (__state), (__key)); \
93 if (!lease_break_info.lease_skip_ack && \
94 (lease_break_info.lease_break.break_flags & \
95 SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED)) \
97 torture_wait_for_lease_break(tctx); \
98 CHECK_LEASE_BREAK_ACK(&lease_break_info.lease_break_ack, \
99 (__state), (__key)); \
103 #define _CHECK_BREAK_INFO_NOWAIT(__oldstate, __state, __key) \
105 CHECK_VAL(lease_break_info.failures, 0); \
106 CHECK_VAL(lease_break_info.count, 1); \
107 CHECK_LEASE_BREAK(&lease_break_info.lease_break, (__oldstate), \
108 (__state), (__key)); \
109 if (!lease_break_info.lease_skip_ack && \
110 (lease_break_info.lease_break.break_flags & \
111 SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED)) \
113 torture_wait_for_lease_break(tctx); \
114 CHECK_LEASE_BREAK_ACK(&lease_break_info.lease_break_ack, \
115 (__state), (__key)); \
119 #define CHECK_BREAK_INFO(__oldstate, __state, __key) \
121 _CHECK_BREAK_INFO(__oldstate, __state, __key); \
122 CHECK_VAL(lease_break_info.lease_break.new_epoch, 0); \
125 #define CHECK_BREAK_INFO_V2(__transport, __oldstate, __state, __key, __epoch) \
127 _CHECK_BREAK_INFO(__oldstate, __state, __key); \
128 CHECK_VAL(lease_break_info.lease_break.new_epoch, __epoch); \
129 if (!TARGET_IS_SAMBA3(tctx)) { \
130 CHECK_VAL((uintptr_t)lease_break_info.lease_transport, \
131 (uintptr_t)__transport); \
135 #define CHECK_BREAK_INFO_V2_NOWAIT(__transport, __oldstate, __state, __key, __epoch) \
137 _CHECK_BREAK_INFO_NOWAIT(__oldstate, __state, __key); \
138 CHECK_VAL(lease_break_info.lease_break.new_epoch, __epoch); \
139 if (!TARGET_IS_SAMBA3(tctx)) { \
140 CHECK_VAL((uintptr_t)lease_break_info.lease_transport, \
141 (uintptr_t)__transport); \
145 extern struct lease_break_info lease_break_info
;
147 bool torture_lease_handler(struct smb2_transport
*transport
,
148 const struct smb2_lease_break
*lb
,
150 bool torture_lease_ignore_handler(struct smb2_transport
*transport
,
151 const struct smb2_lease_break
*lb
,
153 void torture_wait_for_lease_break(struct torture_context
*tctx
);
155 static inline void torture_reset_lease_break_info(struct torture_context
*tctx
,
156 struct lease_break_info
*r
)