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)
*** 19,43 ****
* CDDL HEADER END
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates.
! * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Dispatch function for SMB2_CHANGE_NOTIFY
*/
#include <smbsrv/smb2_kproto.h>
! static smb_sdrc_t smb2_change_notify_async(smb_request_t *);
smb_sdrc_t
smb2_change_notify(smb_request_t *sr)
{
- smb_node_t *node = NULL;
uint16_t StructSize;
uint16_t iFlags;
uint32_t oBufLength;
smb2fid_t smb2fid;
uint32_t CompletionFilter;
--- 19,43 ----
* CDDL HEADER END
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates.
! * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Dispatch function for SMB2_CHANGE_NOTIFY
*/
#include <smbsrv/smb2_kproto.h>
! /* For the output DataOffset fields in here. */
! #define DATA_OFF (SMB2_HDR_SIZE + 8)
smb_sdrc_t
smb2_change_notify(smb_request_t *sr)
{
uint16_t StructSize;
uint16_t iFlags;
uint32_t oBufLength;
smb2fid_t smb2fid;
uint32_t CompletionFilter;
*** 59,147 ****
&reserved); /* l */
if (rc || StructSize != 32)
return (SDRC_ERROR);
status = smb2sr_lookup_fid(sr, &smb2fid);
! if (status)
! goto puterror;
! node = sr->fid_ofile->f_node;
! if (node == NULL || !smb_node_is_dir(node)) {
! status = NT_STATUS_INVALID_PARAMETER;
! goto puterror;
! }
/*
! * Let Change Notify "go async", because it
! * may block indefinitely.
*/
! status = smb2sr_go_async(sr, smb2_change_notify_async);
! puterror:
! ASSERT(status != 0);
! smb2sr_put_error(sr, status);
! return (SDRC_SUCCESS);
! }
!
! static smb_sdrc_t
! smb2_change_notify_async(smb_request_t *sr)
! {
! uint16_t StructSize;
! uint16_t iFlags;
! uint32_t oBufLength;
! smb2fid_t smb2fid;
! uint32_t CompletionFilter;
! uint32_t reserved;
! uint32_t status;
! uint16_t DataOff;
! int rc = 0;
!
! /*
! * SMB2 Change Notify request
! */
! rc = smb_mbc_decodef(
! &sr->smb_data, "wwlqqll",
! &StructSize, /* w */
! &iFlags, /* w */
! &oBufLength, /* l */
! &smb2fid.persistent, /* q */
! &smb2fid.temporal, /* q */
! &CompletionFilter, /* l */
! &reserved); /* l */
! if (rc || StructSize != 32)
! return (SDRC_ERROR);
!
! status = smb2sr_lookup_fid(sr, &smb2fid);
! if (status != 0) {
! smb2sr_put_error(sr, status);
! return (SDRC_SUCCESS);
}
CompletionFilter &= FILE_NOTIFY_VALID_MASK;
if (iFlags & SMB2_WATCH_TREE)
! CompletionFilter |= NODE_FLAGS_WATCH_TREE;
if (oBufLength > smb2_max_trans)
oBufLength = smb2_max_trans;
- sr->raw_data.max_bytes = oBufLength;
! status = smb_notify_common(sr, &sr->raw_data, CompletionFilter);
! if (status != 0) {
smb2sr_put_error(sr, status);
- return (SDRC_SUCCESS);
}
/*
! * SMB2 Change Notify reply
*/
! DataOff = SMB2_HDR_SIZE + 8;
! oBufLength = MBC_LENGTH(&sr->raw_data);
! rc = smb_mbc_encodef(
&sr->reply, "wwlC",
9, /* StructSize */ /* w */
! DataOff, /* w */
oBufLength, /* l */
&sr->raw_data); /* C */
! if (rc)
! return (SDRC_ERROR);
! return (SDRC_SUCCESS);
}
--- 59,182 ----
&reserved); /* l */
if (rc || StructSize != 32)
return (SDRC_ERROR);
status = smb2sr_lookup_fid(sr, &smb2fid);
! DTRACE_SMB2_START(op__ChangeNotify, smb_request_t *, sr);
! if (status != 0)
! goto errout; /* Bad FID */
/*
! * Only deal with change notify last in a compound,
! * because it blocks indefinitely. This status gets
! * "sticky" handling in smb2sr_work().
*/
! if (sr->smb2_next_command != 0) {
! status = NT_STATUS_INSUFFICIENT_RESOURCES;
! goto errout;
}
CompletionFilter &= FILE_NOTIFY_VALID_MASK;
if (iFlags & SMB2_WATCH_TREE)
! CompletionFilter |= FILE_NOTIFY_CHANGE_EV_SUBDIR;
if (oBufLength > smb2_max_trans)
oBufLength = smb2_max_trans;
! /*
! * Check for events and consume, non-blocking.
! * Special return STATUS_PENDING means:
! * No events; caller must call "act2" next.
! * SMB2 does that in "async mode".
! */
! status = smb_notify_act1(sr, oBufLength, CompletionFilter);
! if (status == NT_STATUS_PENDING) {
! status = smb2sr_go_async(sr);
! if (status != 0)
! goto errout;
! status = smb_notify_act2(sr);
! if (status == NT_STATUS_PENDING) {
! /* See next: smb2_change_notify_finish */
! return (SDRC_SR_KEPT);
! }
! }
!
! errout:
! sr->smb2_status = status;
! DTRACE_SMB2_DONE(op__ChangeNotify, smb_request_t *, sr);
!
! if (NT_SC_SEVERITY(status) == NT_STATUS_SEVERITY_SUCCESS) {
! oBufLength = sr->raw_data.chain_offset;
! (void) smb_mbc_encodef(
! &sr->reply, "wwlC",
! 9, /* StructSize */ /* w */
! DATA_OFF, /* w */
! oBufLength, /* l */
! &sr->raw_data); /* C */
! } else {
smb2sr_put_error(sr, status);
}
+ return (SDRC_SUCCESS);
+ }
+
+ /*
+ * This is called via taskq_dispatch in smb_notify.c
+ * to finish up an NT transact notify change request.
+ * Build an SMB2 Change Notify reply and send it.
+ */
+ void
+ smb2_change_notify_finish(void *arg)
+ {
+ smb_request_t *sr = arg;
+ smb_disp_stats_t *sds;
+ uint32_t status;
+ uint32_t oBufLength;
+
+ SMB_REQ_VALID(sr);
+
/*
! * Common part of notify, puts data in sr->raw_data
*/
! status = smb_notify_act3(sr);
!
! /*
! * The prior thread returned SDRC_SR_KEPT and skiped
! * the dtrace DONE probe, so fire that here.
! */
! sr->smb2_status = status;
! DTRACE_SMB2_DONE(op__ChangeNotify, smb_request_t *, sr);
!
! if (NT_SC_SEVERITY(status) == NT_STATUS_SEVERITY_SUCCESS) {
! oBufLength = sr->raw_data.chain_offset;
! (void) smb_mbc_encodef(
&sr->reply, "wwlC",
9, /* StructSize */ /* w */
! DATA_OFF, /* w */
oBufLength, /* l */
&sr->raw_data); /* C */
! } else {
! smb2sr_put_error(sr, status);
! }
! /*
! * Record some statistics: (just tx bytes here)
! */
! sds = &sr->session->s_server->sv_disp_stats2[SMB2_CHANGE_NOTIFY];
! atomic_add_64(&sds->sdt_txb, (int64_t)(sr->reply.chain_offset));
!
! /*
! * Put (overwrite) the final SMB2 header,
! * sign, send.
! */
! (void) smb2_encode_header(sr, B_TRUE);
! if (sr->smb2_hdr_flags & SMB2_FLAGS_SIGNED)
! smb2_sign_reply(sr);
! smb2_send_reply(sr);
!
! mutex_enter(&sr->sr_mutex);
! sr->sr_state = SMB_REQ_STATE_COMPLETED;
! mutex_exit(&sr->sr_mutex);
!
! smb_request_free(sr);
}