smbd: Remove share_mode_lease and the leases array from share_mode_entry
authorVolker Lendecke <vl@samba.org>
Wed, 19 Sep 2018 15:42:51 +0000 (17:42 +0200)
committerChristof Schmitt <cs@samba.org>
Sun, 14 Apr 2019 05:18:14 +0000 (05:18 +0000)
This also removes the temporary functions introduced during the patchset.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
Autobuild-User(master): Christof Schmitt <cs@samba.org>
Autobuild-Date(master): Sun Apr 14 05:18:14 UTC 2019 on sn-devel-144

source3/librpc/idl/open_files.idl
source3/locking/locking.c
source3/locking/share_mode_lock.c
source3/smbd/open.c
source3/smbd/oplock.c
source3/smbd/proto.h

index a474da1..2f6f861 100644 (file)
@@ -12,41 +12,10 @@ import "misc.idl";
 
 interface open_files
 {
-       typedef [public,flag(NDR_PAHEX)] struct {
-               GUID                    client_guid;
-               smb2_lease_key          lease_key;
-               smb2_lease_state        current_state;
-               /*
-                * 'breaking' indicates that we're waiting
-                * for a lease break ack from the client
-                * and breaking_to_requested and breaking_to_required
-                * have a meaning.
-                *
-                * breaking_to_requested is the value already sent to
-                * the client, the client needs to ack to this (or less).
-                *
-                * breaking_to_required is the internal value that needs to
-                * be reached before we can reset breaking = false, this
-                * may requires multiple roundtrips to the client, e.g.
-                * when the lease broken to a more reduced value, while
-                * the lease break is still in progress.
-                *
-                * The following can be assumed (if breaking == true):
-                *
-                * current_state > breaking_to_requested >= breaking_to_required
-                */
-               boolean8                breaking;
-               smb2_lease_state        breaking_to_requested;
-               smb2_lease_state        breaking_to_required;
-               uint16                  lease_version;
-               uint16                  epoch;
-       } share_mode_lease;
-
        typedef [public] struct {
                server_id       pid;
                hyper           op_mid;
                uint16          op_type;
-               uint32          lease_idx;
                GUID            client_guid;
                smb2_lease_key  lease_key;
                uint32          access_mask;
@@ -78,8 +47,6 @@ interface open_files
                [string,charset(UTF8)] char *stream_name;
                uint32 num_share_modes;
                [size_is(num_share_modes)] share_mode_entry share_modes[];
-               uint32 num_leases;
-               [size_is(num_leases)] share_mode_lease leases[];
                uint32 num_delete_tokens;
                [size_is(num_delete_tokens)] delete_token delete_tokens[];
                timespec old_write_time;
index 7a70c33..10e9606 100644 (file)
@@ -672,7 +672,6 @@ static void remove_share_mode_lease(struct share_mode_data *d,
                                    struct share_mode_entry *e)
 {
        uint16_t op_type;
-       uint32_t lease_idx;
        uint32_t i;
 
        op_type = e->op_type;
@@ -689,9 +688,6 @@ static void remove_share_mode_lease(struct share_mode_data *d,
         * it, remove it.
         */
 
-       lease_idx = e->lease_idx;
-       e->lease_idx = UINT32_MAX;
-
        for (i=0; i<d->num_share_modes; i++) {
                struct share_mode_entry *e2 = &d->share_modes[i];
 
@@ -716,18 +712,6 @@ static void remove_share_mode_lease(struct share_mode_data *d,
                return;
        }
 
-       d->num_leases -= 1;
-       d->leases[lease_idx] = d->leases[d->num_leases];
-
-       /*
-        * We changed the lease array. Fix all references to it.
-        */
-       for (i=0; i<d->num_share_modes; i++) {
-               if (d->share_modes[i].lease_idx == d->num_leases) {
-                       d->share_modes[i].lease_idx = lease_idx;
-               }
-       }
-
        {
                NTSTATUS status;
 
@@ -853,37 +837,8 @@ bool set_share_mode(struct share_mode_lock *lck,
        e->op_type = op_type;
 
        if (op_type == LEASE_OPLOCK) {
-               uint32_t i;
-
                e->client_guid = *client_guid;
                e->lease_key = *lease_key;
-
-               /*
-                * Need to set lease_idx. This is essentially
-                * find_share_mode_lease(), but that will go away
-                * soon. So don't add the dependency here.
-                */
-
-               for (i=0; i<d->num_leases; i++) {
-                       struct share_mode_lease *l = &d->leases[i];
-
-                       if (smb2_lease_equal(client_guid,
-                                            lease_key,
-                                            &l->client_guid,
-                                            &l->lease_key)) {
-                               break;
-                       }
-               }
-
-               if (i == d->num_leases) {
-                       DBG_WARNING("lease not found\n");
-                       d->num_share_modes -= 1;
-                       return false;
-               }
-
-               e->lease_idx = i;
-       } else {
-               e->lease_idx = UINT32_MAX;
        }
 
        e->time.tv_sec = fsp->open_time.tv_sec;
index 5d0abfe..a20de67 100644 (file)
@@ -1011,7 +1011,6 @@ bool share_mode_cleanup_disconnected(struct file_id fid,
                  open_persistent_id);
 
        data->num_share_modes = 0;
-       data->num_leases = 0;
        data->modified = true;
 
        ret = true;
index 837af05..d23e896 100644 (file)
@@ -1971,81 +1971,6 @@ static bool file_has_brlocks(files_struct *fsp)
        return (brl_num_locks(br_lck) > 0);
 }
 
-static int find_share_mode_lease(struct share_mode_data *d,
-                                const struct GUID *client_guid,
-                                const struct smb2_lease_key *key)
-{
-       uint32_t i;
-
-       for (i=0; i<d->num_leases; i++) {
-               struct share_mode_lease *l = &d->leases[i];
-
-               if (smb2_lease_equal(client_guid,
-                                    key,
-                                    &l->client_guid,
-                                    &l->lease_key)) {
-                       return i;
-               }
-       }
-
-       return -1;
-}
-
-NTSTATUS update_share_mode_lease_from_db(
-       struct share_mode_data *d,
-       const struct GUID *client_guid,
-       const struct smb2_lease_key *lease_key)
-{
-       int idx;
-       struct share_mode_lease *l;
-       uint32_t current_state, breaking_to_requested, breaking_to_required;
-       bool breaking;
-       uint16_t lease_version, epoch;
-       NTSTATUS status;
-
-       idx = find_share_mode_lease(d, client_guid, lease_key);
-       if (idx == -1) {
-               DBG_WARNING("find_share_mode_lease failed\n");
-               return NT_STATUS_NOT_FOUND;
-       }
-       l = &d->leases[idx];
-
-       status = leases_db_get(client_guid,
-                              lease_key,
-                              &d->id,
-                              &current_state,
-                              &breaking,
-                              &breaking_to_requested,
-                              &breaking_to_required,
-                              &lease_version,
-                              &epoch);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_WARNING("leases_db_get returned %s\n",
-                           nt_errstr(status));
-               return status;
-       }
-
-       if ((l->current_state == current_state) &&
-           (l->breaking == breaking) &&
-           (l->breaking_to_requested == breaking_to_requested) &&
-           (l->breaking_to_required == breaking_to_required) &&
-           (l->lease_version == lease_version) &&
-           (l->epoch == epoch)) {
-               return NT_STATUS_OK;
-       }
-
-       l->current_state = current_state;
-       l->breaking = breaking;
-       l->breaking_to_requested = breaking_to_requested;
-       l->breaking_to_required = breaking_to_required;
-       l->lease_version = lease_version;
-       l->epoch = epoch;
-
-       d->modified = true;
-
-       return NT_STATUS_OK;
-}
-
 struct fsp_lease *find_fsp_lease(struct files_struct *new_fsp,
                                 const struct smb2_lease_key *key,
                                 uint32_t current_state,
@@ -2100,7 +2025,6 @@ static NTSTATUS try_lease_upgrade(struct files_struct *fsp,
                                  const struct smb2_lease *lease,
                                  uint32_t granted)
 {
-       struct share_mode_data *d = lck->data;
        bool do_upgrade;
        uint32_t current_state, breaking_to_requested, breaking_to_required;
        bool breaking;
@@ -2189,14 +2113,6 @@ static NTSTATUS try_lease_upgrade(struct files_struct *fsp,
                }
        }
 
-       status = update_share_mode_lease_from_db(
-               d, client_guid, &lease->lease_key);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_WARNING("update_share_mode_lease_from_db failed: %s\n",
-                           nt_errstr(status));
-               return status;
-       }
-
        fsp_lease_update(lck, fsp_client_guid(fsp), fsp->lease);
 
        return NT_STATUS_OK;
@@ -2209,19 +2125,8 @@ static NTSTATUS grant_new_fsp_lease(struct files_struct *fsp,
                                    uint32_t granted)
 {
        struct share_mode_data *d = lck->data;
-       struct share_mode_lease *tmp;
        NTSTATUS status;
 
-       tmp = talloc_realloc(d, d->leases, struct share_mode_lease,
-                            d->num_leases+1);
-       if (tmp == NULL) {
-               /*
-                * See [MS-SMB2]
-                */
-               return NT_STATUS_INSUFFICIENT_RESOURCES;
-       }
-       d->leases = tmp;
-
        fsp->lease = talloc_zero(fsp->conn->sconn, struct fsp_lease);
        if (fsp->lease == NULL) {
                return NT_STATUS_INSUFFICIENT_RESOURCES;
@@ -2233,14 +2138,6 @@ static NTSTATUS grant_new_fsp_lease(struct files_struct *fsp,
        fsp->lease->lease.lease_state = granted;
        fsp->lease->lease.lease_epoch = lease->lease_epoch + 1;
 
-       d->leases[d->num_leases] = (struct share_mode_lease) {
-               .client_guid = *client_guid,
-               .lease_key = fsp->lease->lease.lease_key,
-               .current_state = fsp->lease->lease.lease_state,
-               .lease_version = fsp->lease->lease.lease_version,
-               .epoch = fsp->lease->lease.lease_epoch,
-       };
-
        status = leases_db_add(client_guid,
                               &lease->lease_key,
                               &fsp->file_id,
@@ -2257,7 +2154,6 @@ static NTSTATUS grant_new_fsp_lease(struct files_struct *fsp,
                return NT_STATUS_INSUFFICIENT_RESOURCES;
        }
 
-       d->num_leases += 1;
        d->modified = true;
 
        return NT_STATUS_OK;
index 02ecd53..22277ab 100644 (file)
@@ -737,17 +737,17 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
                }
        }
 
-       status = update_share_mode_lease_from_db(lck->data, client_guid, key);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_WARNING("update_share_mode_lease_from_db failed: %s\n",
-                           nt_errstr(status));
-               TALLOC_FREE(lck);
-               return status;
-       }
-
        DEBUG(10, ("%s: Downgrading %s to %x => %s\n", __func__,
                   file_id_string_tos(&id), (unsigned)lease_state, nt_errstr(status)));
 
+       /*
+        * No, we did not modify the share mode array. We did modify
+        * the leases_db. But without this we don't notify a lease
+        * break waiter via dbwrap_watch_record. We need to make
+        * leases_db watched too.
+        */
+       lck->data->modified = true;
+
        {
                struct downgrade_lease_fsps_state state = {
                        .id = id, .lck = lck, .key = key,
@@ -1102,17 +1102,6 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
                        }
                }
 
-               status = update_share_mode_lease_from_db(
-                       lck->data,
-                       client_guid,
-                       &fsp->lease->lease.lease_key);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DBG_WARNING("update_share_mode_lease_from_db "
-                                   "failed: %s\n", nt_errstr(status));
-                       TALLOC_FREE(lck);
-                       return;
-               }
-
                /* Ensure we're in sync with current lease state. */
                fsp_lease_update(lck, fsp_client_guid(fsp), fsp->lease);
 
index a5c55c6..68568e1 100644 (file)
@@ -691,11 +691,6 @@ void msg_file_was_renamed(struct messaging_context *msg,
                          uint32_t msg_type,
                          struct server_id server_id,
                          DATA_BLOB *data);
-struct share_mode_lease;
-NTSTATUS update_share_mode_lease_from_db(
-       struct share_mode_data *d,
-       const struct GUID *client_guid,
-       const struct smb2_lease_key *lease_key);
 struct fsp_lease *find_fsp_lease(struct files_struct *new_fsp,
                                 const struct smb2_lease_key *key,
                                 uint32_t current_state,