smbd: Remove stale share mode entries while walking the array
authorVolker Lendecke <vl@samba.org>
Mon, 2 Sep 2019 14:25:28 +0000 (16:25 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 17 Sep 2019 22:49:39 +0000 (22:49 +0000)
Previously, we did this only when writing out the locking.tdb
record. That was because we had places where the index of a particular
share mode entry mattered while operating on the array. This is no
longer the case, so we can remove stale entries early.

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

index e3fc354a5fa08552c6a3a404fd5d961ece4cb1d9..32bdea1a16a578b754331eaea2d24665b73902a7 100644 (file)
@@ -1316,7 +1316,8 @@ bool share_mode_forall_entries(
        struct share_mode_data *d = lck->data;
        uint32_t i;
 
-       for (i=0; i<d->num_share_modes; i++) {
+       i = 0;
+       while (i<d->num_share_modes) {
                struct share_mode_entry *e = &d->share_modes[i];
                struct server_id pid = e->pid;
                uint64_t share_file_id = e->share_file_id;
@@ -1348,6 +1349,13 @@ bool share_mode_forall_entries(
                if (stop) {
                        return true;
                }
+
+               if (e->stale) {
+                       *e = d->share_modes[d->num_share_modes-1];
+                       d->num_share_modes -= 1;
+               } else {
+                       i += 1;
+               }
        }
 
        return true;
index 54c82234f94ed9539b17ffabe447162f83087f00..0fbb788c533263aa6c56696095ef80698c2ee3ff 100644 (file)
@@ -386,27 +386,6 @@ fail:
        return NULL;
 }
 
-static void remove_stale_share_mode_entries(struct share_mode_data *d)
-{
-       uint32_t i;
-
-       i = 0;
-       while (i < d->num_share_modes) {
-               if (d->share_modes[i].stale) {
-                       struct share_mode_entry *m = d->share_modes;
-                       m[i] = m[d->num_share_modes-1];
-                       d->num_share_modes -= 1;
-                       continue;
-               }
-               i += 1;
-       }
-
-       if (d->num_share_modes == 0) {
-               TALLOC_FREE(d->delete_tokens);
-               d->num_delete_tokens = 0;
-       }
-}
-
 /*******************************************************************
  If modified, store the share_mode_data back into the database.
 ********************************************************************/
@@ -428,9 +407,11 @@ static NTSTATUS share_mode_data_store(struct share_mode_data *d)
        }
 
        d->sequence_number += 1;
-       remove_stale_share_mode_entries(d);
 
        if (d->num_share_modes == 0) {
+               TALLOC_FREE(d->delete_tokens);
+               d->num_delete_tokens = 0;
+
                if (d->fresh) {
                        DBG_DEBUG("Ignoring fresh empty record\n");
                        return NT_STATUS_OK;