2 Unix SMB/CIFS implementation.
4 generic byte range locking code
6 Copyright (C) Andrew Tridgell 1992-2004
7 Copyright (C) Jeremy Allison 1992-2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /* This module implements a tdb based byte range locking service,
24 replacing the fcntl() based byte range locking previously
25 used. This allows us to provide the same semantics as NT */
28 #include "system/filesys.h"
29 #include "lib/tdb/include/tdb.h"
30 #include "messaging/messaging.h"
32 #include "lib/messaging/irpc.h"
33 #include "libcli/libcli.h"
34 #include "cluster/cluster.h"
35 #include "ntvfs/common/ntvfs_common.h"
37 static const struct brlock_ops *ops;
40 set the brl backend ops
42 void brl_set_ops(const struct brlock_ops *new_ops)
48 Open up the brlock database. Close it down using talloc_free(). We
49 need the messaging_ctx to allow for pending lock notifications.
51 struct brl_context *brl_init(TALLOC_CTX *mem_ctx, struct server_id server,
52 struct messaging_context *messaging_ctx)
55 if (lp_parm_bool(-1, "ctdb", "brlock", False)) {
61 return ops->brl_init(mem_ctx, server, messaging_ctx);
64 struct brl_handle *brl_create_handle(TALLOC_CTX *mem_ctx, struct ntvfs_handle *ntvfs, DATA_BLOB *file_key)
66 return ops->brl_create_handle(mem_ctx, ntvfs, file_key);
70 Lock a range of bytes. The lock_type can be a PENDING_*_LOCK, in
71 which case a real lock is first tried, and if that fails then a
72 pending lock is created. When the pending lock is triggered (by
73 someone else closing an overlapping lock range) a messaging
74 notification is sent, identified by the notify_ptr
76 NTSTATUS brl_lock(struct brl_context *brl,
77 struct brl_handle *brlh,
79 uint64_t start, uint64_t size,
80 enum brl_type lock_type,
83 return ops->brl_lock(brl, brlh, smbpid, start, size, lock_type, notify_ptr);
88 Unlock a range of bytes.
90 NTSTATUS brl_unlock(struct brl_context *brl,
91 struct brl_handle *brlh,
93 uint64_t start, uint64_t size)
95 return ops->brl_unlock(brl, brlh, smbpid, start, size);
99 remove a pending lock. This is called when the caller has either
100 given up trying to establish a lock or when they have succeeded in
101 getting it. In either case they no longer need to be notified.
103 NTSTATUS brl_remove_pending(struct brl_context *brl,
104 struct brl_handle *brlh,
107 return ops->brl_remove_pending(brl, brlh, notify_ptr);
112 Test if we are allowed to perform IO on a region of an open file
114 NTSTATUS brl_locktest(struct brl_context *brl,
115 struct brl_handle *brlh,
117 uint64_t start, uint64_t size,
118 enum brl_type lock_type)
120 return ops->brl_locktest(brl, brlh, smbpid, start, size, lock_type);
125 Remove any locks associated with a open file.
127 NTSTATUS brl_close(struct brl_context *brl,
128 struct brl_handle *brlh)
130 return ops->brl_close(brl, brlh);