]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3/brlock: split out brl_get_locks_readonly_parse()
authorStefan Metzmacher <metze@samba.org>
Mon, 6 Jan 2025 14:59:27 +0000 (15:59 +0100)
committerJule Anger <janger@samba.org>
Thu, 17 Apr 2025 11:31:14 +0000 (11:31 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15767

Pair-Programmed-With: Ralph Boehme <slow@samba.org>
Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit 94e7cbcc32b73e4d56e7209e04d22d4270a6eb5b)

source3/locking/brlock.c

index b0295174954b08c409434aa18e80c99b70904327..c75b83c048d147d83e0d5304c8c9828935eb6fc3 100644 (file)
@@ -1768,29 +1768,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(
@@ -1803,7 +1792,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;
                }
@@ -1821,6 +1810,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.