s3:blocking: split smbd_smb1_do_locks_retry() into _try() and _retry()
authorStefan Metzmacher <metze@samba.org>
Tue, 13 Aug 2019 16:34:36 +0000 (18:34 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 9 Sep 2019 14:23:39 +0000 (14:23 +0000)
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 <vl@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/blocking.c

index 91438fe44860d21f0d145fd3943021c454582e3f..0fa39ae58ab909d0bcf25dca99d9cc8fc9e651ba 100644 (file)
@@ -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(