diff options
author | Volker Lendecke <vl@samba.org> | 2012-10-31 13:02:19 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2013-03-26 11:22:16 +0100 |
commit | 032da72e2b81685f292622cfd2ced14af257849d (patch) | |
tree | 9e8333fd1f5fdae8058dff4984a09dfa82e2606b /source3 | |
parent | c2b26a43ffae22c9dff7929c48531fec9e6ed922 (diff) | |
download | samba-032da72e2b81685f292622cfd2ced14af257849d.tar.gz samba-032da72e2b81685f292622cfd2ced14af257849d.tar.bz2 samba-032da72e2b81685f292622cfd2ced14af257849d.zip |
smbd: Avoid some talloc_realloc in notify_internal
For the nonclustered case we will only ever have one vnn in notify_index.tdb.
For this case, without this patch we did talloc_realloc when collecting vnns to
be able to do the memcpy instead of explicit copy with a for-loop. This new
code will partition the new vnns we see when parsing a notify_index.tdb record
into ourselves and all foreign vnns, only really collecting the foreign ones in
an array.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/smbd/notify_internal.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c index f5a8584b2e..af838d6097 100644 --- a/source3/smbd/notify_internal.c +++ b/source3/smbd/notify_internal.c @@ -484,7 +484,7 @@ static void notify_trigger_index_parser(TDB_DATA key, TDB_DATA data, struct notify_trigger_index_state *state = (struct notify_trigger_index_state *)private_data; uint32_t *new_vnns; - size_t i, num_vnns, num_new_vnns; + size_t i, num_vnns, num_new_vnns, num_remote_vnns; if ((data.dsize % sizeof(uint32_t)) != 0) { DEBUG(1, ("Invalid record size in notify index db: %u\n", @@ -493,22 +493,32 @@ static void notify_trigger_index_parser(TDB_DATA key, TDB_DATA data, } new_vnns = (uint32_t *)data.dptr; num_new_vnns = data.dsize / sizeof(uint32_t); - - num_vnns = talloc_array_length(state->vnns); + num_remote_vnns = num_new_vnns; for (i=0; i<num_new_vnns; i++) { if (new_vnns[i] == state->my_vnn) { state->found_my_vnn = true; + num_remote_vnns -= 1; } } + if (num_remote_vnns == 0) { + return; + } + num_vnns = talloc_array_length(state->vnns); state->vnns = talloc_realloc(state->mem_ctx, state->vnns, uint32_t, - num_vnns + num_new_vnns); - if ((num_vnns + num_new_vnns != 0) && (state->vnns == NULL)) { + num_vnns + num_remote_vnns); + if (state->vnns == NULL) { DEBUG(1, ("talloc_realloc failed\n")); return; } - memcpy(&state->vnns[num_vnns], data.dptr, data.dsize); + + for (i=0; i<num_new_vnns; i++) { + if (new_vnns[i] != state->my_vnn) { + state->vnns[num_vnns] = new_vnns[i]; + num_vnns += 1; + } + } } static int vnn_cmp(const void *p1, const void *p2) |