Line data Source code
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 : #include "lib/util/samba_modules.h" 31 : 32 : #undef strcasecmp 33 : 34 : /* list of registered backends */ 35 : static struct sys_lease_ops *backends; 36 : static uint32_t num_backends; 37 : 38 : #define LEASE_BACKEND "lease:backend" 39 : 40 : /* 41 : initialise a system change notify backend 42 : */ 43 1328 : _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config *scfg, 44 : TALLOC_CTX *mem_ctx, 45 : struct tevent_context *ev, 46 : struct imessaging_context *msg, 47 : sys_lease_send_break_fn break_send) 48 : { 49 0 : struct sys_lease_context *ctx; 50 0 : const char *bname; 51 0 : int i; 52 0 : NTSTATUS status; 53 0 : TALLOC_CTX * tmp_ctx; 54 : 55 1328 : if (num_backends == 0) { 56 0 : return NULL; 57 : } 58 : 59 1328 : if (ev == NULL) { 60 0 : return NULL; 61 : } 62 : 63 1328 : ctx = talloc_zero(mem_ctx, struct sys_lease_context); 64 1328 : if (ctx == NULL) { 65 0 : return NULL; 66 : } 67 : 68 1328 : tmp_ctx = talloc_new(ctx); 69 1328 : if (tmp_ctx == NULL) { 70 0 : return NULL; 71 : } 72 : 73 1328 : ctx->event_ctx = ev; 74 1328 : ctx->msg_ctx = msg; 75 1328 : ctx->break_send = break_send; 76 : 77 1328 : bname = share_string_option(tmp_ctx, scfg, LEASE_BACKEND, NULL); 78 1328 : if (!bname) { 79 1328 : talloc_free(ctx); 80 1328 : return NULL; 81 : } 82 : 83 0 : for (i=0;i<num_backends;i++) { 84 0 : if (strcasecmp(backends[i].name, bname) == 0) { 85 0 : ctx->ops = &backends[i]; 86 0 : break; 87 : } 88 : } 89 : 90 0 : if (!ctx->ops) { 91 0 : talloc_free(ctx); 92 0 : return NULL; 93 : } 94 : 95 0 : status = ctx->ops->init(ctx); 96 0 : if (!NT_STATUS_IS_OK(status)) { 97 0 : talloc_free(ctx); 98 0 : return NULL; 99 : } 100 : 101 0 : TALLOC_FREE(tmp_ctx); 102 0 : return ctx; 103 : } 104 : 105 : /* 106 : register a lease backend 107 : */ 108 4 : _PUBLIC_ NTSTATUS sys_lease_register(TALLOC_CTX *ctx, 109 : const struct sys_lease_ops *backend) 110 : { 111 0 : struct sys_lease_ops *b; 112 4 : b = talloc_realloc(ctx, backends, 113 : struct sys_lease_ops, num_backends+1); 114 4 : NT_STATUS_HAVE_NO_MEMORY(b); 115 4 : backends = b; 116 4 : backends[num_backends] = *backend; 117 4 : num_backends++; 118 4 : return NT_STATUS_OK; 119 : } 120 : 121 4 : _PUBLIC_ NTSTATUS sys_lease_init(void) 122 : { 123 0 : static bool initialized = false; 124 : #define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *); 125 0 : STATIC_sys_lease_MODULES_PROTO; 126 4 : init_module_fn static_init[] = { STATIC_sys_lease_MODULES }; 127 : 128 4 : if (initialized) return NT_STATUS_OK; 129 4 : initialized = true; 130 : 131 4 : run_init_functions(NULL, static_init); 132 : 133 4 : return NT_STATUS_OK; 134 : } 135 : 136 0 : NTSTATUS sys_lease_setup(struct sys_lease_context *ctx, 137 : struct opendb_entry *e) 138 : { 139 0 : return ctx->ops->setup(ctx, e); 140 : } 141 : 142 0 : NTSTATUS sys_lease_update(struct sys_lease_context *ctx, 143 : struct opendb_entry *e) 144 : { 145 0 : return ctx->ops->update(ctx, e); 146 : } 147 : 148 0 : NTSTATUS sys_lease_remove(struct sys_lease_context *ctx, 149 : struct opendb_entry *e) 150 : { 151 0 : return ctx->ops->remove(ctx, e); 152 : }