]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Add share_mode_watch_send/recv
authorVolker Lendecke <vl@samba.org>
Mon, 4 Nov 2019 11:57:35 +0000 (12:57 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 22 Nov 2019 23:57:47 +0000 (23:57 +0000)
For now this is a simple wrapper around dbwrap_watched_watch_send()
that will make the direct db_record reference in struct
share_mode_data unnecessary.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/locking/proto.h
source3/locking/share_mode_lock.c

index fc11ef8863c66d5d84bb6f60de4feb7484487ab5..432278e3c3078bc48a7077b977d93eabe4d4353b 100644 (file)
@@ -150,6 +150,14 @@ NTSTATUS share_mode_do_locked(
        void *private_data);
 NTSTATUS share_mode_wakeup_waiters(struct file_id id);
 
+struct tevent_req *share_mode_watch_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct file_id id,
+       struct server_id blocker);
+NTSTATUS share_mode_watch_recv(
+       struct tevent_req *req, bool *blockerdead, struct server_id *blocker);
+
 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
                                                  struct file_id id);
 struct tevent_req *fetch_share_mode_send(TALLOC_CTX *mem_ctx,
index ecc410c6598e462ddffe397ebaf22fee8d805034..fbf8f2b54bbebae2267b5673f545b1c86fb2926b 100644 (file)
@@ -815,6 +815,89 @@ NTSTATUS share_mode_wakeup_waiters(struct file_id id)
        return share_mode_do_locked(id, share_mode_wakeup_waiters_fn, NULL);
 }
 
+struct share_mode_watch_state {
+       struct tevent_context *ev;
+       bool blockerdead;
+       struct server_id blocker;
+       struct tevent_req *subreq;
+};
+
+static void share_mode_watch_fn(
+       TDB_DATA value, bool *modified_dependent, void *private_data)
+{
+       struct share_mode_watch_state *state = talloc_get_type_abort(
+               private_data, struct share_mode_watch_state);
+
+       state->subreq = dbwrap_watched_watch_send(
+               state, state->ev, static_share_mode_record, state->blocker);
+}
+
+static void share_mode_watch_done(struct tevent_req *subreq);
+
+struct tevent_req *share_mode_watch_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct file_id id,
+       struct server_id blocker)
+{
+       struct tevent_req *req = NULL;
+       struct share_mode_watch_state *state = NULL;
+       NTSTATUS status;
+
+       req = tevent_req_create(
+               mem_ctx, &state, struct share_mode_watch_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->ev = ev;
+       state->blocker = blocker;
+
+       status = share_mode_do_locked(id, share_mode_watch_fn, state);
+       if (tevent_req_nterror(req, status)) {
+               return tevent_req_post(req, ev);
+       }
+       if (tevent_req_nomem(state->subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(state->subreq, share_mode_watch_done, req);
+       return req;
+}
+
+static void share_mode_watch_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct share_mode_watch_state *state = tevent_req_data(
+               req, struct share_mode_watch_state);
+       NTSTATUS status;
+
+       status = dbwrap_watched_watch_recv(
+               subreq, &state->blockerdead, &state->blocker);
+       if (tevent_req_nterror(req, status)) {
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS share_mode_watch_recv(
+       struct tevent_req *req, bool *blockerdead, struct server_id *blocker)
+{
+       struct share_mode_watch_state *state = tevent_req_data(
+               req, struct share_mode_watch_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       if (blockerdead != NULL) {
+               *blockerdead = state->blockerdead;
+       }
+       if (blocker != NULL) {
+               *blocker = state->blocker;
+       }
+       return NT_STATUS_OK;
+}
+
 struct fetch_share_mode_unlocked_state {
        TALLOC_CTX *mem_ctx;
        struct share_mode_lock *lck;