Print this page
NEX-18696 SMB2 change notify STATUS_NOTIFY_CLEANUP annoys apple
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
NEX-15555 SMB2 async redesign
NEX-15061 smtorture smb2.lock.cancel.cancel is failed
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Also follow-up change to:
NEX-1643 dtrace provider for smbsrv (remove "done2" probes,
which don't make sense with the new async design)
NEX-15555 SMB2 async redesign
NEX-15061 smtorture smb2.lock.cancel.cancel is failed
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Also follow-up change to:
NEX-1643 dtrace provider for smbsrv (remove "done2" probes,
which don't make sense with the new async design)
NEX-1643 dtrace provider for smbsrv
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
NEX-6402 SMB2 change notify response wrong when STATUS_NOTIFY_ENUM_DIR
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
NEX-3906 Prefer that SMB change notify not tie up a worker thread
NEX-5278 SMB notify should buffer per file handle
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
SMB-122 smbd core dumps in smbd_dc_update / smb_log
SMB-117 Win7 fails to open security properties
SMB-11 SMB2 message parse & dispatch
SMB-12 SMB2 Negotiate Protocol
SMB-13 SMB2 Session Setup
SMB-14 SMB2 Logoff
SMB-15 SMB2 Tree Connect
SMB-16 SMB2 Tree Disconnect
SMB-17 SMB2 Create
SMB-18 SMB2 Close
SMB-19 SMB2 Flush
SMB-20 SMB2 Read
SMB-21 SMB2 Write
SMB-22 SMB2 Lock/Unlock
SMB-23 SMB2 Ioctl
SMB-24 SMB2 Cancel
SMB-25 SMB2 Echo
SMB-26 SMB2 Query Dir
SMB-27 SMB2 Change Notify
SMB-28 SMB2 Query Info
SMB-29 SMB2 Set Info
SMB-30 SMB2 Oplocks
SMB-53 SMB2 Create Context options
(SMB2 code review cleanup 1, 2, 3)
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/smbsrv/smb2_change_notify.c
+++ new/usr/src/uts/common/fs/smbsrv/smb2_change_notify.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates.
24 - * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
24 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
25 25 */
26 26
27 27 /*
28 28 * Dispatch function for SMB2_CHANGE_NOTIFY
29 29 */
30 30
31 31 #include <smbsrv/smb2_kproto.h>
32 32
33 -static smb_sdrc_t smb2_change_notify_async(smb_request_t *);
33 +/* For the output DataOffset fields in here. */
34 +#define DATA_OFF (SMB2_HDR_SIZE + 8)
34 35
35 36 smb_sdrc_t
36 37 smb2_change_notify(smb_request_t *sr)
37 38 {
38 - smb_node_t *node = NULL;
39 39 uint16_t StructSize;
40 40 uint16_t iFlags;
41 41 uint32_t oBufLength;
42 42 smb2fid_t smb2fid;
43 43 uint32_t CompletionFilter;
44 44 uint32_t reserved;
45 45 uint32_t status;
46 46 int rc = 0;
47 47
48 48 /*
49 49 * SMB2 Change Notify request
50 50 */
51 51 rc = smb_mbc_decodef(
52 52 &sr->smb_data, "wwlqqll",
53 53 &StructSize, /* w */
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
54 54 &iFlags, /* w */
55 55 &oBufLength, /* l */
56 56 &smb2fid.persistent, /* q */
57 57 &smb2fid.temporal, /* q */
58 58 &CompletionFilter, /* l */
59 59 &reserved); /* l */
60 60 if (rc || StructSize != 32)
61 61 return (SDRC_ERROR);
62 62
63 63 status = smb2sr_lookup_fid(sr, &smb2fid);
64 - if (status)
65 - goto puterror;
64 + DTRACE_SMB2_START(op__ChangeNotify, smb_request_t *, sr);
66 65
67 - node = sr->fid_ofile->f_node;
68 - if (node == NULL || !smb_node_is_dir(node)) {
69 - status = NT_STATUS_INVALID_PARAMETER;
70 - goto puterror;
66 + if (status != 0)
67 + goto errout; /* Bad FID */
68 +
69 + /*
70 + * Only deal with change notify last in a compound,
71 + * because it blocks indefinitely. This status gets
72 + * "sticky" handling in smb2sr_work().
73 + */
74 + if (sr->smb2_next_command != 0) {
75 + status = NT_STATUS_INSUFFICIENT_RESOURCES;
76 + goto errout;
71 77 }
72 78
79 + CompletionFilter &= FILE_NOTIFY_VALID_MASK;
80 + if (iFlags & SMB2_WATCH_TREE)
81 + CompletionFilter |= FILE_NOTIFY_CHANGE_EV_SUBDIR;
82 +
83 + if (oBufLength > smb2_max_trans)
84 + oBufLength = smb2_max_trans;
85 +
73 86 /*
74 - * Let Change Notify "go async", because it
75 - * may block indefinitely.
87 + * Check for events and consume, non-blocking.
88 + * Special return STATUS_PENDING means:
89 + * No events; caller must call "act2" next.
90 + * SMB2 does that in "async mode".
76 91 */
77 - status = smb2sr_go_async(sr, smb2_change_notify_async);
78 -puterror:
79 - ASSERT(status != 0);
80 - smb2sr_put_error(sr, status);
92 + status = smb_notify_act1(sr, oBufLength, CompletionFilter);
93 + if (status == NT_STATUS_PENDING) {
94 + status = smb2sr_go_async(sr);
95 + if (status != 0)
96 + goto errout;
97 + status = smb_notify_act2(sr);
98 + if (status == NT_STATUS_PENDING) {
99 + /* See next: smb2_change_notify_finish */
100 + return (SDRC_SR_KEPT);
101 + }
102 + }
103 +
104 +errout:
105 + sr->smb2_status = status;
106 + DTRACE_SMB2_DONE(op__ChangeNotify, smb_request_t *, sr);
107 +
108 + if (NT_SC_SEVERITY(status) == NT_STATUS_SEVERITY_SUCCESS) {
109 + oBufLength = sr->raw_data.chain_offset;
110 + (void) smb_mbc_encodef(
111 + &sr->reply, "wwlC",
112 + 9, /* StructSize */ /* w */
113 + DATA_OFF, /* w */
114 + oBufLength, /* l */
115 + &sr->raw_data); /* C */
116 + } else {
117 + smb2sr_put_error(sr, status);
118 + }
119 +
81 120 return (SDRC_SUCCESS);
82 121 }
83 122
84 -static smb_sdrc_t
85 -smb2_change_notify_async(smb_request_t *sr)
123 +/*
124 + * This is called via taskq_dispatch in smb_notify.c
125 + * to finish up an NT transact notify change request.
126 + * Build an SMB2 Change Notify reply and send it.
127 + */
128 +void
129 +smb2_change_notify_finish(void *arg)
86 130 {
87 - uint16_t StructSize;
88 - uint16_t iFlags;
89 - uint32_t oBufLength;
90 - smb2fid_t smb2fid;
91 - uint32_t CompletionFilter;
92 - uint32_t reserved;
131 + smb_request_t *sr = arg;
132 + smb_disp_stats_t *sds;
93 133 uint32_t status;
94 - uint16_t DataOff;
95 - int rc = 0;
134 + uint32_t oBufLength;
96 135
136 + SMB_REQ_VALID(sr);
137 +
97 138 /*
98 - * SMB2 Change Notify request
139 + * Common part of notify, puts data in sr->raw_data
99 140 */
100 - rc = smb_mbc_decodef(
101 - &sr->smb_data, "wwlqqll",
102 - &StructSize, /* w */
103 - &iFlags, /* w */
104 - &oBufLength, /* l */
105 - &smb2fid.persistent, /* q */
106 - &smb2fid.temporal, /* q */
107 - &CompletionFilter, /* l */
108 - &reserved); /* l */
109 - if (rc || StructSize != 32)
110 - return (SDRC_ERROR);
141 + status = smb_notify_act3(sr);
111 142
112 - status = smb2sr_lookup_fid(sr, &smb2fid);
113 - if (status != 0) {
114 - smb2sr_put_error(sr, status);
115 - return (SDRC_SUCCESS);
116 - }
143 + /*
144 + * The prior thread returned SDRC_SR_KEPT and skiped
145 + * the dtrace DONE probe, so fire that here.
146 + */
147 + sr->smb2_status = status;
148 + DTRACE_SMB2_DONE(op__ChangeNotify, smb_request_t *, sr);
117 149
118 - CompletionFilter &= FILE_NOTIFY_VALID_MASK;
119 - if (iFlags & SMB2_WATCH_TREE)
120 - CompletionFilter |= NODE_FLAGS_WATCH_TREE;
121 -
122 - if (oBufLength > smb2_max_trans)
123 - oBufLength = smb2_max_trans;
124 - sr->raw_data.max_bytes = oBufLength;
125 -
126 - status = smb_notify_common(sr, &sr->raw_data, CompletionFilter);
127 - if (status != 0) {
150 + if (NT_SC_SEVERITY(status) == NT_STATUS_SEVERITY_SUCCESS) {
151 + oBufLength = sr->raw_data.chain_offset;
152 + (void) smb_mbc_encodef(
153 + &sr->reply, "wwlC",
154 + 9, /* StructSize */ /* w */
155 + DATA_OFF, /* w */
156 + oBufLength, /* l */
157 + &sr->raw_data); /* C */
158 + } else {
128 159 smb2sr_put_error(sr, status);
129 - return (SDRC_SUCCESS);
130 160 }
131 161
132 162 /*
133 - * SMB2 Change Notify reply
163 + * Record some statistics: (just tx bytes here)
134 164 */
135 - DataOff = SMB2_HDR_SIZE + 8;
136 - oBufLength = MBC_LENGTH(&sr->raw_data);
137 - rc = smb_mbc_encodef(
138 - &sr->reply, "wwlC",
139 - 9, /* StructSize */ /* w */
140 - DataOff, /* w */
141 - oBufLength, /* l */
142 - &sr->raw_data); /* C */
143 - if (rc)
144 - return (SDRC_ERROR);
165 + sds = &sr->session->s_server->sv_disp_stats2[SMB2_CHANGE_NOTIFY];
166 + atomic_add_64(&sds->sdt_txb, (int64_t)(sr->reply.chain_offset));
145 167
146 - return (SDRC_SUCCESS);
168 + /*
169 + * Put (overwrite) the final SMB2 header,
170 + * sign, send.
171 + */
172 + (void) smb2_encode_header(sr, B_TRUE);
173 + if (sr->smb2_hdr_flags & SMB2_FLAGS_SIGNED)
174 + smb2_sign_reply(sr);
175 + smb2_send_reply(sr);
176 +
177 + mutex_enter(&sr->sr_mutex);
178 + sr->sr_state = SMB_REQ_STATE_COMPLETED;
179 + mutex_exit(&sr->sr_mutex);
180 +
181 + smb_request_free(sr);
147 182 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX