source: trunk/server/source4/ntvfs/sysdep/sys_lease.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 3.3 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 Copyright (C) Stefan Metzmacher 2008
5
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.
10
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.
15
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/>.
18*/
19
20/*
21 abstract the various kernel interfaces to leases (oplocks) into a
22 single Samba friendly interface
23*/
24
25#include "includes.h"
26#include "system/filesys.h"
27#include "ntvfs/sysdep/sys_lease.h"
28#include "../lib/util/dlinklist.h"
29#include "param/param.h"
30
31/* list of registered backends */
32static struct sys_lease_ops *backends;
33static uint32_t num_backends;
34
35#define LEASE_BACKEND "lease:backend"
36
37/*
38 initialise a system change notify backend
39*/
40_PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config *scfg,
41 TALLOC_CTX *mem_ctx,
42 struct tevent_context *ev,
43 struct messaging_context *msg,
44 sys_lease_send_break_fn break_send)
45{
46 struct sys_lease_context *ctx;
47 const char *bname;
48 int i;
49 NTSTATUS status;
50
51 if (num_backends == 0) {
52 return NULL;
53 }
54
55 if (ev == NULL) {
56 return NULL;
57 }
58
59 ctx = talloc_zero(mem_ctx, struct sys_lease_context);
60 if (ctx == NULL) {
61 return NULL;
62 }
63
64 ctx->event_ctx = ev;
65 ctx->msg_ctx = msg;
66 ctx->break_send = break_send;
67
68 bname = share_string_option(scfg, LEASE_BACKEND, NULL);
69 if (!bname) {
70 talloc_free(ctx);
71 return NULL;
72 }
73
74 for (i=0;i<num_backends;i++) {
75 if (strcasecmp(backends[i].name, bname) == 0) {
76 ctx->ops = &backends[i];
77 break;
78 }
79 }
80
81 if (!ctx->ops) {
82 talloc_free(ctx);
83 return NULL;
84 }
85
86 status = ctx->ops->init(ctx);
87 if (!NT_STATUS_IS_OK(status)) {
88 talloc_free(ctx);
89 return NULL;
90 }
91
92 return ctx;
93}
94
95/*
96 register a lease backend
97*/
98_PUBLIC_ NTSTATUS sys_lease_register(const struct sys_lease_ops *backend)
99{
100 struct sys_lease_ops *b;
101 b = talloc_realloc(talloc_autofree_context(), backends,
102 struct sys_lease_ops, num_backends+1);
103 NT_STATUS_HAVE_NO_MEMORY(b);
104 backends = b;
105 backends[num_backends] = *backend;
106 num_backends++;
107 return NT_STATUS_OK;
108}
109
110_PUBLIC_ NTSTATUS sys_lease_init(void)
111{
112 static bool initialized = false;
113#define _MODULE_PROTO(init) extern NTSTATUS init(void);
114 STATIC_sys_lease_MODULES_PROTO;
115 init_module_fn static_init[] = { STATIC_sys_lease_MODULES };
116
117 if (initialized) return NT_STATUS_OK;
118 initialized = true;
119
120 run_init_functions(static_init);
121
122 return NT_STATUS_OK;
123}
124
125NTSTATUS sys_lease_setup(struct sys_lease_context *ctx,
126 struct opendb_entry *e)
127{
128 return ctx->ops->setup(ctx, e);
129}
130
131NTSTATUS sys_lease_update(struct sys_lease_context *ctx,
132 struct opendb_entry *e)
133{
134 return ctx->ops->update(ctx, e);
135}
136
137NTSTATUS sys_lease_remove(struct sys_lease_context *ctx,
138 struct opendb_entry *e)
139{
140 return ctx->ops->remove(ctx, e);
141}
Note: See TracBrowser for help on using the repository browser.