]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Move downgrade_share_lease into downgrade_lease
authorVolker Lendecke <vl@samba.org>
Fri, 14 Sep 2018 14:41:25 +0000 (16:41 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 2 Oct 2018 16:13:20 +0000 (18:13 +0200)
The next step will simplify the logic of the code.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/oplock.c

index 7ed223ddcfe8bb6f449669d5ba938687287d8efc..d2dc4077bbe84bc2e1109106a3596a60861772e6 100644 (file)
@@ -517,17 +517,29 @@ static struct files_struct *downgrade_lease_fsps(struct files_struct *fsp,
        return NULL;
 }
 
-static NTSTATUS downgrade_share_lease(struct smbd_server_connection *sconn,
-                                     struct share_mode_lock *lck,
-                                     const struct smb2_lease_key *key,
-                                     uint32_t new_lease_state,
-                                     struct share_mode_lease **_l)
+NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
+                        uint32_t num_file_ids,
+                        const struct file_id *ids,
+                        const struct smb2_lease_key *key,
+                        uint32_t lease_state)
 {
-       struct share_mode_data *d = lck->data;
-       struct share_mode_lease *l;
+       struct smbd_server_connection *sconn = xconn->client->sconn;
+       struct share_mode_lock *lck;
+       struct share_mode_data *d = NULL;
+       struct share_mode_lease *l = NULL;
+       const struct file_id id = ids[0];
        int idx;
+       uint32_t i;
+       NTSTATUS status;
 
-       *_l = NULL;
+       DEBUG(10, ("%s: Downgrading %s to %x\n", __func__,
+                  file_id_string_tos(&id), (unsigned)lease_state));
+
+       lck = get_existing_share_mode_lock(talloc_tos(), id);
+       if (lck == NULL) {
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
+       d = lck->data;
 
        idx = find_share_mode_lease(
                d, &sconn->client->connections->smb2.client.guid, key);
@@ -535,13 +547,13 @@ static NTSTATUS downgrade_share_lease(struct smbd_server_connection *sconn,
                DEBUG(10, ("lease not found\n"));
                return NT_STATUS_INVALID_PARAMETER;
        }
-
        l = &d->leases[idx];
 
        if (!l->breaking) {
                DBG_WARNING("Attempt to break from %"PRIu32" to %"PRIu32" - "
                            "but we're not in breaking state\n",
-                           l->current_state, new_lease_state);
+                           l->current_state, lease_state);
+               TALLOC_FREE(lck);
                return NT_STATUS_UNSUCCESSFUL;
        }
 
@@ -549,26 +561,34 @@ static NTSTATUS downgrade_share_lease(struct smbd_server_connection *sconn,
         * Can't upgrade anything: l->breaking_to_requested (and l->current_state)
         * must be a strict bitwise superset of new_lease_state
         */
-       if ((new_lease_state & l->breaking_to_requested) != new_lease_state) {
+       if ((lease_state & l->breaking_to_requested) != lease_state) {
                DBG_WARNING("Attempt to upgrade from %"PRIu32" to %"PRIu32" "
                            "- expected %"PRIu32"\n",
-                           l->current_state, new_lease_state,
+                           l->current_state, lease_state,
                            l->breaking_to_requested);
+               TALLOC_FREE(lck);
                return NT_STATUS_REQUEST_NOT_ACCEPTED;
        }
 
-       if (l->current_state != new_lease_state) {
-               l->current_state = new_lease_state;
+       if (l->current_state != lease_state) {
+               l->current_state = lease_state;
                d->modified = true;
        }
 
-       if ((new_lease_state & ~l->breaking_to_required) != 0) {
+       status = NT_STATUS_OK;
+
+       d->modified = true;
+
+       if ((lease_state & ~l->breaking_to_required) != 0) {
+
                DBG_INFO("lease state %"PRIu32" not fully broken from "
                         "%"PRIu32" to %"PRIu32"\n",
-                        new_lease_state,
+                        lease_state,
                         l->current_state,
                         l->breaking_to_required);
+
                l->breaking_to_requested = l->breaking_to_required;
+
                if (l->current_state & (SMB2_LEASE_WRITE|SMB2_LEASE_HANDLE)) {
                        /*
                         * Here we break in steps, as windows does
@@ -576,47 +596,9 @@ static NTSTATUS downgrade_share_lease(struct smbd_server_connection *sconn,
                         */
                        l->breaking_to_requested |= SMB2_LEASE_READ;
                }
-               d->modified = true;
-               *_l = l;
-               return NT_STATUS_OPLOCK_BREAK_IN_PROGRESS;
-       }
 
-       DBG_DEBUG("breaking from %"PRIu32" to %"PRIu32" - "
-                 "expected %"PRIu32"\n",
-                 l->current_state,
-                 new_lease_state,
-                 l->breaking_to_requested);
-
-       l->breaking_to_requested = 0;
-       l->breaking_to_required = 0;
-       l->breaking = false;
-
-       d->modified = true;
-
-       return NT_STATUS_OK;
-}
-
-NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
-                        uint32_t num_file_ids,
-                        const struct file_id *ids,
-                        const struct smb2_lease_key *key,
-                        uint32_t lease_state)
-{
-       struct smbd_server_connection *sconn = xconn->client->sconn;
-       struct share_mode_lock *lck;
-       struct share_mode_lease *l = NULL;
-       const struct file_id id = ids[0];
-       uint32_t i;
-       NTSTATUS status;
-
-       DEBUG(10, ("%s: Downgrading %s to %x\n", __func__,
-                  file_id_string_tos(&id), (unsigned)lease_state));
-
-       lck = get_existing_share_mode_lock(talloc_tos(), id);
-       if (lck == NULL) {
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               status = NT_STATUS_OPLOCK_BREAK_IN_PROGRESS;
        }
-       status = downgrade_share_lease(sconn, lck, key, lease_state, &l);
 
        DEBUG(10, ("%s: Downgrading %s to %x => %s\n", __func__,
                   file_id_string_tos(&id), (unsigned)lease_state, nt_errstr(status)));
@@ -669,6 +651,18 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
                                          xconn->client->raw_ev_ctx,
                                          downgrade_lease_additional_trigger,
                                          state);
+       } else {
+               DBG_DEBUG("breaking from %"PRIu32" to %"PRIu32" - "
+                         "expected %"PRIu32"\n",
+                         l->current_state,
+                         lease_state,
+                         l->breaking_to_requested);
+
+               l->breaking_to_requested = 0;
+               l->breaking_to_required = 0;
+               l->breaking = false;
+
+               d->modified = true;
        }
 
        {