From e79fcfaaf2ecfca6c3747f6fe4be51f332ebf10d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 13 Aug 2019 18:34:36 +0200 Subject: [PATCH] s3:blocking: split smbd_smb1_do_locks_retry() into _try() and _retry() This will make it possible to have just one caller to smbd_do_locks_try() later and use smbd_smb1_do_locks_try() from within smbd_smb1_do_locks_send(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=14113 Reviewed-by: Volker Lendecke Signed-off-by: Stefan Metzmacher --- source3/smbd/blocking.c | 72 ++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c index 91438fe4486..0fa39ae58ab 100644 --- a/source3/smbd/blocking.c +++ b/source3/smbd/blocking.c @@ -109,6 +109,7 @@ struct smbd_smb1_do_locks_state { uint16_t blocker; }; +static void smbd_smb1_do_locks_try(struct tevent_req *req); static void smbd_smb1_do_locks_retry(struct tevent_req *subreq); static void smbd_smb1_blocked_locks_cleanup( struct tevent_req *req, enum tevent_req_state req_state); @@ -300,10 +301,8 @@ static void smbd_smb1_blocked_locks_cleanup( fsp, blocked, struct tevent_req *, num_blocked-1); } -static void smbd_smb1_do_locks_retry(struct tevent_req *subreq) +static void smbd_smb1_do_locks_try(struct tevent_req *req) { - struct tevent_req *req = tevent_req_callback_data( - subreq, struct tevent_req); struct smbd_smb1_do_locks_state *state = tevent_req_data( req, struct smbd_smb1_do_locks_state); struct files_struct *fsp = state->fsp; @@ -315,36 +314,10 @@ static void smbd_smb1_do_locks_retry(struct tevent_req *subreq) struct timeval endtime; struct server_id blocking_pid = { 0 }; uint64_t blocking_smblctx = 0; + struct tevent_req *subreq = NULL; NTSTATUS status; bool ok; - /* - * Make sure we run as the user again - */ - ok = change_to_user_by_fsp(state->fsp); - if (!ok) { - tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED); - return; - } - - status = dbwrap_watched_watch_recv(subreq, NULL, NULL); - TALLOC_FREE(subreq); - - DBG_DEBUG("dbwrap_watched_watch_recv returned %s\n", - nt_errstr(status)); - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - double elapsed = timeval_elapsed(&state->endtime); - if (elapsed > 0) { - smbd_smb1_brl_finish_by_req( - req, NT_STATUS_FILE_LOCK_CONFLICT); - return; - } - /* - * This is a posix lock retry. Just retry. - */ - } - lck = get_existing_share_mode_lock(state, fsp->file_id); if (tevent_req_nomem(lck, req)) { DBG_DEBUG("Could not get share mode lock\n"); @@ -396,6 +369,45 @@ done: smbd_smb1_brl_finish_by_req(req, status); } +static void smbd_smb1_do_locks_retry(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct smbd_smb1_do_locks_state *state = tevent_req_data( + req, struct smbd_smb1_do_locks_state); + NTSTATUS status; + bool ok; + + /* + * Make sure we run as the user again + */ + ok = change_to_user_by_fsp(state->fsp); + if (!ok) { + tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED); + return; + } + + status = dbwrap_watched_watch_recv(subreq, NULL, NULL); + TALLOC_FREE(subreq); + + DBG_DEBUG("dbwrap_watched_watch_recv returned %s\n", + nt_errstr(status)); + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + double elapsed = timeval_elapsed(&state->endtime); + if (elapsed > 0) { + smbd_smb1_brl_finish_by_req( + req, NT_STATUS_FILE_LOCK_CONFLICT); + return; + } + /* + * This is a posix lock retry. Just retry. + */ + } + + smbd_smb1_do_locks_try(req); +} + NTSTATUS smbd_smb1_do_locks_recv(struct tevent_req *req) { struct smbd_smb1_do_locks_state *state = tevent_req_data( -- 2.11.4.GIT