From 94e7cbcc32b73e4d56e7209e04d22d4270a6eb5b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 6 Jan 2025 15:59:27 +0100 Subject: [PATCH] s3/brlock: split out brl_get_locks_readonly_parse() BUG: https://bugzilla.samba.org/show_bug.cgi?id=15767 Pair-Programmed-With: Ralph Boehme Signed-off-by: Ralph Boehme Signed-off-by: Stefan Metzmacher --- source3/locking/brlock.c | 43 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index 0c5dab19389..47103d9b8a0 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -1770,29 +1770,18 @@ static void brl_get_locks_readonly_parser(TDB_DATA key, TDB_DATA data, *state->br_lock = br_lck; } -struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp) +static struct byte_range_lock *brl_get_locks_readonly_parse(TALLOC_CTX *mem_ctx, + files_struct *fsp) { struct byte_range_lock *br_lock = NULL; struct brl_get_locks_readonly_state state; NTSTATUS status; - DEBUG(10, ("seqnum=%d, fsp->brlock_seqnum=%d\n", - dbwrap_get_seqnum(brlock_db), fsp->brlock_seqnum)); - - if ((fsp->brlock_rec != NULL) - && (dbwrap_get_seqnum(brlock_db) == fsp->brlock_seqnum)) { - /* - * We have cached the brlock_rec and the database did not - * change. - */ - return fsp->brlock_rec; - } - /* * Parse the record fresh from the database */ - state.mem_ctx = fsp; + state.mem_ctx = mem_ctx; state.br_lock = &br_lock; status = dbwrap_parse_record( @@ -1805,7 +1794,7 @@ struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp) /* * No locks on this file. Return an empty br_lock. */ - br_lock = talloc_zero(fsp, struct byte_range_lock); + br_lock = talloc_zero(mem_ctx, struct byte_range_lock); if (br_lock == NULL) { return NULL; } @@ -1823,6 +1812,30 @@ struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp) br_lock->modified = false; br_lock->record = NULL; + return br_lock; +} + +struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp) +{ + struct byte_range_lock *br_lock = NULL; + + DEBUG(10, ("seqnum=%d, fsp->brlock_seqnum=%d\n", + dbwrap_get_seqnum(brlock_db), fsp->brlock_seqnum)); + + if ((fsp->brlock_rec != NULL) + && (dbwrap_get_seqnum(brlock_db) == fsp->brlock_seqnum)) { + /* + * We have cached the brlock_rec and the database did not + * change. + */ + return fsp->brlock_rec; + } + + br_lock = brl_get_locks_readonly_parse(fsp, fsp); + if (br_lock == NULL) { + return NULL; + } + /* * Cache the brlock struct, invalidated when the dbwrap_seqnum * changes. See beginning of this routine. -- 2.47.2