2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 abstract the various kernel interfaces to leases (oplocks) into a
22 single Samba friendly interface
26 #include "system/filesys.h"
27 #include "ntvfs/sysdep/sys_lease.h"
28 #include "lib/events/events.h"
29 #include "lib/util/dlinklist.h"
30 #include "param/param.h"
33 /* list of registered backends */
34 static struct sys_lease_ops *backends;
35 static uint32_t num_backends;
37 #define LEASE_BACKEND "lease:backend"
40 initialise a system change notify backend
42 _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config *scfg,
44 struct event_context *ev,
45 struct messaging_context *msg,
46 sys_lease_send_break_fn break_send)
48 struct sys_lease_context *ctx;
53 if (num_backends == 0) {
58 ev = event_context_find(mem_ctx);
61 ctx = talloc_zero(mem_ctx, struct sys_lease_context);
68 ctx->break_send = break_send;
70 bname = share_string_option(scfg, LEASE_BACKEND, NULL);
76 for (i=0;i<num_backends;i++) {
77 if (strcasecmp(backends[i].name, bname) == 0) {
78 ctx->ops = &backends[i];
88 status = ctx->ops->init(ctx);
89 if (!NT_STATUS_IS_OK(status)) {
98 register a lease backend
100 _PUBLIC_ NTSTATUS sys_lease_register(const struct sys_lease_ops *backend)
102 struct sys_lease_ops *b;
103 b = talloc_realloc(talloc_autofree_context(), backends,
104 struct sys_lease_ops, num_backends+1);
105 NT_STATUS_HAVE_NO_MEMORY(b);
107 backends[num_backends] = *backend;
112 _PUBLIC_ NTSTATUS sys_lease_init(void)
114 static bool initialized = false;
116 init_module_fn static_init[] = { STATIC_sys_lease_MODULES };
118 if (initialized) return NT_STATUS_OK;
121 run_init_functions(static_init);
126 NTSTATUS sys_lease_setup(struct sys_lease_context *ctx,
127 struct opendb_entry *e)
129 return ctx->ops->setup(ctx, e);
132 NTSTATUS sys_lease_update(struct sys_lease_context *ctx,
133 struct opendb_entry *e)
135 return ctx->ops->update(ctx, e);
138 NTSTATUS sys_lease_remove(struct sys_lease_context *ctx,
139 struct opendb_entry *e)
141 return ctx->ops->remove(ctx, e);