summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2019-09-02 16:25:28 +0200
committerJeremy Allison <jra@samba.org>2019-09-17 22:49:39 +0000
commit87e42c73d379738a5f87569ea630c28c9d66c148 (patch)
treef384ed3b9f19f0b818aa94998288bfbc87325cf3 /source3/locking
parentf96aa7063e846021b69403cc9caa091c8e09b578 (diff)
downloadsamba-87e42c73d379738a5f87569ea630c28c9d66c148.tar.gz
smbd: Remove stale share mode entries while walking the array
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>
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/locking.c10
-rw-r--r--source3/locking/share_mode_lock.c25
2 files changed, 12 insertions, 23 deletions
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index e3fc354a5fa..32bdea1a16a 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -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;
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index 54c82234f94..0fbb788c533 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -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;