diff options
author | Volker Lendecke <vl@samba.org> | 2018-09-14 16:41:25 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2018-10-02 18:13:20 +0200 |
commit | a93aa1511fe71a7d43facb79cca7e89aed289075 (patch) | |
tree | 58c091a02a8043a5ed938e53e6dc519b229b3d8a /source3/smbd/oplock.c | |
parent | 56139b8ec621d47d542042e7aa512aa07fd53fd0 (diff) | |
download | samba-a93aa1511fe71a7d43facb79cca7e89aed289075.tar.gz |
smbd: Move downgrade_share_lease into downgrade_lease
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>
Diffstat (limited to 'source3/smbd/oplock.c')
-rw-r--r-- | source3/smbd/oplock.c | 104 |
1 files changed, 49 insertions, 55 deletions
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index 7ed223ddcfe..d2dc4077bbe 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -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; } { |