2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2004
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 this is the open files database. It implements shared storage of
22 what files are open between server instances, and implements the rules
23 of shared access to files.
25 The caller needs to provide a file_key, which specifies what file
26 they are talking about. This needs to be a unique key across all
27 filesystems, and is usually implemented in terms of a device/inode
30 Before any operations can be performed the caller needs to establish
31 a lock on the record associated with file_key. That is done by
32 calling odb_lock(). The caller releases this lock by calling
33 talloc_free() on the returned handle.
35 All other operations on a record are done by passing the odb_lock()
36 handle back to this module. The handle contains internal
37 information about what file_key is being operated on.
41 #include "ntvfs/ntvfs.h"
42 #include "ntvfs/common/ntvfs_common.h"
43 #include "cluster/cluster.h"
44 #include "param/param.h"
46 static const struct opendb_ops *ops;
49 set the odb backend ops
51 void odb_set_ops(const struct opendb_ops *new_ops)
57 Open up the openfiles.tdb database. Close it down using
58 talloc_free(). We need the messaging_ctx to allow for pending open
61 _PUBLIC_ struct odb_context *odb_init(TALLOC_CTX *mem_ctx,
62 struct ntvfs_context *ntvfs_ctx)
65 if (lp_parm_bool(ntvfs_ctx->lp_ctx, NULL, "ctdb", "opendb", false)) {
71 return ops->odb_init(mem_ctx, ntvfs_ctx);
75 get a lock on a entry in the odb. This call returns a lock handle,
76 which the caller should unlock using talloc_free().
78 _PUBLIC_ struct odb_lock *odb_lock(TALLOC_CTX *mem_ctx,
79 struct odb_context *odb, DATA_BLOB *file_key)
81 return ops->odb_lock(mem_ctx, odb, file_key);
84 _PUBLIC_ DATA_BLOB odb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck)
86 return ops->odb_get_key(mem_ctx, lck);
90 register an open file in the open files database. This implements the share_access
93 Note that the path is only used by the delete on close logic, not
94 for comparing with other filenames
96 _PUBLIC_ NTSTATUS odb_open_file(struct odb_lock *lck,
97 void *file_handle, const char *path,
98 uint32_t stream_id, uint32_t share_access,
99 uint32_t access_mask, bool delete_on_close,
100 uint32_t open_disposition, bool break_to_none,
101 uint32_t oplock_level, uint32_t *oplock_granted)
103 return ops->odb_open_file(lck, file_handle, path, stream_id, share_access,
104 access_mask, delete_on_close, open_disposition,
105 break_to_none, oplock_level, oplock_granted);
110 register a pending open file in the open files database
112 _PUBLIC_ NTSTATUS odb_open_file_pending(struct odb_lock *lck, void *private)
114 return ops->odb_open_file_pending(lck, private);
119 remove a opendb entry
121 _PUBLIC_ NTSTATUS odb_close_file(struct odb_lock *lck, void *file_handle)
123 return ops->odb_close_file(lck, file_handle);
128 remove a pending opendb entry
130 _PUBLIC_ NTSTATUS odb_remove_pending(struct odb_lock *lck, void *private)
132 return ops->odb_remove_pending(lck, private);
137 rename the path in a open file
139 _PUBLIC_ NTSTATUS odb_rename(struct odb_lock *lck, const char *path)
141 return ops->odb_rename(lck, path);
145 update delete on close flag on an open file
147 _PUBLIC_ NTSTATUS odb_set_delete_on_close(struct odb_lock *lck, bool del_on_close)
149 return ops->odb_set_delete_on_close(lck, del_on_close);
153 return the current value of the delete_on_close bit, and how many
154 people still have the file open
156 _PUBLIC_ NTSTATUS odb_get_delete_on_close(struct odb_context *odb,
157 DATA_BLOB *key, bool *del_on_close,
158 int *open_count, char **path)
160 return ops->odb_get_delete_on_close(odb, key, del_on_close, open_count, path);
165 determine if a file can be opened with the given share_access,
166 create_options and access_mask
168 _PUBLIC_ NTSTATUS odb_can_open(struct odb_lock *lck,
169 uint32_t share_access, uint32_t create_options,
170 uint32_t access_mask)
172 return ops->odb_can_open(lck, share_access, create_options, access_mask);
175 _PUBLIC_ NTSTATUS odb_update_oplock(struct odb_lock *lck, void *file_handle,
176 uint32_t oplock_level)
178 return ops->odb_update_oplock(lck, file_handle, oplock_level);
181 _PUBLIC_ NTSTATUS odb_break_oplocks(struct odb_lock *lck)
183 return ops->odb_break_oplocks(lck);