From: Stefan Metzmacher Date: Wed, 10 Aug 2022 08:48:25 +0000 (+0000) Subject: s3:smbd: call set_file_oplock() after set_share_mode() X-Git-Tag: talloc-2.4.0~839 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bfdae92db09a2943a531f9dc0aa53c1c5c70f00;p=thirdparty%2Fsamba.git s3:smbd: call set_file_oplock() after set_share_mode() The important part is the call to get a kernel oplock is deferred until after set_share_mode(). The goal is to get the code between get_share_mode_lock() and set_share_mode() free of any blocking operation. As we were optimistic to get the oplock that was asked for, we need to remove_share_oplock() in order to set NO_OPLOCK also in the share_mode entry. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 596fa55eeed..4b22a0a703d 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -4170,20 +4170,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, if (oplock_type == LEASE_OPLOCK) { lease_key = &lease->lease_key; - - fsp->oplock_type = oplock_type; - - } else if (oplock_type != NO_OPLOCK) { - - fsp->oplock_type = oplock_type; - - status = set_file_oplock(fsp); - if (!NT_STATUS_IS_OK(status)) { - /* - * Could not get the kernel oplock - */ - fsp->oplock_type = oplock_type = NO_OPLOCK; - } } share_mode_flags_restrict(lck, access_mask, share_access, 0); @@ -4215,6 +4201,23 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, DBG_DEBUG("lease_state=%d\n", fsp->lease->lease.lease_state); } + fsp->oplock_type = oplock_type; + + if (fsp->oplock_type != NO_OPLOCK && fsp->oplock_type != LEASE_OPLOCK) { + /* + * Now ask for kernel oplocks + * and cleanup on failure. + */ + status = set_file_oplock(fsp); + if (!NT_STATUS_IS_OK(status)) { + /* + * Could not get the kernel oplock + */ + remove_share_oplock(lck, fsp); + fsp->oplock_type = oplock_type = NO_OPLOCK; + } + } + /* Should we atomically (to the client at least) truncate ? */ if ((!new_file_created) && (flags2 & O_TRUNC) &&