From: Volker Lendecke Date: Mon, 2 Sep 2019 14:25:28 +0000 (+0200) Subject: smbd: Remove stale share mode entries while walking the array X-Git-Tag: talloc-2.3.1~782 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87e42c73d379738a5f87569ea630c28c9d66c148;p=thirdparty%2Fsamba.git 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 Reviewed-by: Jeremy Allison --- 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; inum_share_modes; i++) { + i = 0; + while (inum_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;