From: Michael Adam Date: Sun, 15 May 2016 21:24:08 +0000 (+0200) Subject: smbd:close: only remove kernel share modes if they had been taken at open X-Git-Tag: samba-4.4.4~19 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=8ac105e900758c164a7bb223f7297b265b1189ee;p=thirdparty%2Fsamba.git smbd:close: only remove kernel share modes if they had been taken at open This avoids errors due to 'not implemented' for SMB_VFS_KERNEL_FLOCK on some file systems like glusterfs (with the vfs module). The only other code path where SMB_VFS_KERNEL_FLOCK is called, is already protected. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11919 Signed-off-by: Michael Adam Reviewed-by: Christian Ambach Autobuild-User(master): Christian Ambach Autobuild-Date(master): Thu May 19 02:34:36 CEST 2016 on sn-devel-144 (cherry picked from commit 6b232b2720a3d71bc0b4b5603215b3f9d3de5ca6) --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 1cb546055d0..3ab04b7dcaf 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -246,7 +246,6 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp, const struct security_token *del_nt_token = NULL; bool got_tokens = false; bool normal_close; - int ret_flock; /* Ensure any pending write time updates are done. */ if (fsp->update_write_time_event) { @@ -470,12 +469,16 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp, pop_sec_ctx(); } - /* remove filesystem sharemodes */ - ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, 0, 0); - if (ret_flock == -1) { - DEBUG(2, ("close_remove_share_mode: removing kernel flock for " - "%s failed: %s\n", fsp_str_dbg(fsp), - strerror(errno))); + if (fsp->kernel_share_modes_taken) { + int ret_flock; + + /* remove filesystem sharemodes */ + ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, 0, 0); + if (ret_flock == -1) { + DEBUG(2, ("close_remove_share_mode: removing kernel " + "flock for %s failed: %s\n", + fsp_str_dbg(fsp), strerror(errno))); + } } if (!del_share_mode(lck, fsp)) { diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 0d90c99ecd3..61b7145fa75 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -3084,6 +3084,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, return NT_STATUS_SHARING_VIOLATION; } + + fsp->kernel_share_modes_taken = true; } /*