ctdb-tests: Update statd-callout tests to handle both modes
[samba4-gss.git] / source3 / locking / share_mode_lock.h
blob97a7a847f541e290c538f32fee4d01342a25adc3
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #ifndef __LOCKING_SHARE_MODE_LOCK_H__
17 #define __LOCKING_SHARE_MODE_LOCK_H__
19 #include "replace.h"
20 #include <tevent.h>
21 #include "librpc/gen_ndr/file_id.h"
22 #include "lib/util/time.h"
23 #include "libcli/util/ntstatus.h"
25 struct share_mode_data;
26 struct share_mode_lock;
27 struct share_mode_entry;
28 struct smb_filename;
29 struct files_struct;
30 struct smb2_lease_key;
32 bool locking_init(void);
33 bool locking_init_readonly(void);
34 bool locking_end(void);
36 struct file_id share_mode_lock_file_id(const struct share_mode_lock *lck);
38 struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
39 struct file_id id);
41 bool del_share_mode_open_id(struct share_mode_lock *lck,
42 struct server_id open_pid,
43 uint64_t open_file_id);
44 bool del_share_mode(struct share_mode_lock *lck,
45 struct files_struct *fsp);
46 bool downgrade_share_oplock(struct share_mode_lock *lck,
47 struct files_struct *fsp);
48 bool remove_share_oplock(struct share_mode_lock *lck,
49 struct files_struct *fsp);
50 bool file_has_read_lease(struct files_struct *fsp);
52 bool set_share_mode(
53 struct share_mode_lock *lck,
54 struct files_struct *fsp,
55 uid_t uid,
56 uint64_t mid,
57 uint16_t op_type,
58 const struct smb2_lease_key *lease_key,
59 uint32_t share_access,
60 uint32_t access_mask);
61 bool reset_share_mode_entry(
62 struct share_mode_lock *lck,
63 struct server_id old_pid,
64 uint64_t old_share_file_id,
65 struct server_id new_pid,
66 uint64_t new_mid,
67 uint64_t new_share_file_id);
69 bool mark_share_mode_disconnected(
70 struct share_mode_lock *lck, struct files_struct *fsp);
72 struct share_mode_lock *fetch_share_mode_unlocked(
73 TALLOC_CTX *mem_ctx,
74 struct file_id id);
76 struct tevent_req *fetch_share_mode_send(
77 TALLOC_CTX *mem_ctx,
78 struct tevent_context *ev,
79 struct file_id id,
80 bool *queued);
81 NTSTATUS fetch_share_mode_recv(
82 struct tevent_req *req,
83 TALLOC_CTX *mem_ctx,
84 struct share_mode_lock **_lck);
86 int share_entry_forall_read(int (*ro_fn)(struct file_id fid,
87 const struct share_mode_data *data,
88 const struct share_mode_entry *entry,
89 void *private_data),
90 void *private_data);
91 int share_entry_forall(int (*fn)(struct file_id fid,
92 struct share_mode_data *data,
93 struct share_mode_entry *entry,
94 void *private_data),
95 void *private_data);
97 NTSTATUS share_mode_count_entries(struct file_id fid, size_t *num_share_modes);
98 int share_mode_forall(
99 int (*fn)(struct file_id fid,
100 struct share_mode_data *data,
101 void *private_data),
102 void *private_data);
103 int share_mode_forall_read(int (*fn)(struct file_id fid,
104 const struct share_mode_data *data,
105 void *private_data),
106 void *private_data);
107 bool share_mode_forall_entries(
108 struct share_mode_lock *lck,
109 bool (*fn)(struct share_mode_entry *e,
110 bool *modified,
111 void *private_data),
112 void *private_data);
114 NTTIME share_mode_changed_write_time(struct share_mode_lock *lck);
115 void share_mode_set_changed_write_time(struct share_mode_lock *lck, struct timespec write_time);
116 void share_mode_set_old_write_time(struct share_mode_lock *lck, struct timespec write_time);
117 const char *share_mode_servicepath(struct share_mode_lock *lck);
118 char *share_mode_filename(TALLOC_CTX *mem_ctx, struct share_mode_lock *lck);
119 char *share_mode_data_dump(
120 TALLOC_CTX *mem_ctx, struct share_mode_lock *lck);
122 void share_mode_flags_get(
123 struct share_mode_lock *lck,
124 uint32_t *access_mask,
125 uint32_t *share_mode,
126 uint32_t *lease_type);
127 void share_mode_flags_set(
128 struct share_mode_lock *lck,
129 uint32_t access_mask,
130 uint32_t share_mode,
131 uint32_t lease_type,
132 bool *modified);
134 struct tevent_req *share_mode_watch_send(
135 TALLOC_CTX *mem_ctx,
136 struct tevent_context *ev,
137 struct file_id *id,
138 struct server_id blocker);
139 NTSTATUS share_mode_watch_recv(
140 struct tevent_req *req, bool *blockerdead, struct server_id *blocker);
141 NTSTATUS share_mode_wakeup_waiters(struct file_id id);
143 typedef void (*share_mode_do_locked_vfs_fn_t)(
144 struct share_mode_lock *lck,
145 void *private_data);
146 NTSTATUS _share_mode_do_locked_vfs_denied(
147 struct file_id id,
148 share_mode_do_locked_vfs_fn_t fn,
149 void *private_data,
150 const char *location);
151 #define share_mode_do_locked_vfs_denied(__id, __fn, __private_data) \
152 _share_mode_do_locked_vfs_denied(__id, __fn, __private_data, __location__)
153 NTSTATUS _share_mode_do_locked_vfs_allowed(
154 struct file_id id,
155 share_mode_do_locked_vfs_fn_t fn,
156 void *private_data,
157 const char *location);
158 #define share_mode_do_locked_vfs_allowed(__id, __fn, __private_data) \
159 _share_mode_do_locked_vfs_allowed(__id, __fn, __private_data, __location__)
161 struct share_mode_entry_prepare_state {
162 struct file_id __fid;
163 struct share_mode_lock *__lck_ptr;
164 union {
165 #define __SHARE_MODE_LOCK_SPACE 32
166 uint8_t __u8_space[__SHARE_MODE_LOCK_SPACE];
167 #ifdef SHARE_MODE_ENTRY_PREPARE_STATE_LCK_SPACE
168 struct share_mode_lock __lck_space;
169 #endif
173 typedef void (*share_mode_entry_prepare_lock_fn_t)(
174 struct share_mode_lock *lck,
175 bool *keep_locked,
176 void *private_data);
177 NTSTATUS _share_mode_entry_prepare_lock(
178 struct share_mode_entry_prepare_state *prepare_state,
179 struct file_id id,
180 const char *servicepath,
181 const struct smb_filename *smb_fname,
182 const struct timespec *old_write_time,
183 share_mode_entry_prepare_lock_fn_t fn,
184 void *private_data,
185 const char *location);
186 #define share_mode_entry_prepare_lock_add(__prepare_state, __id, \
187 __servicepath, __smb_fname, __old_write_time, \
188 __fn, __private_data) \
189 _share_mode_entry_prepare_lock(__prepare_state, __id, \
190 __servicepath, __smb_fname, __old_write_time, \
191 __fn, __private_data, __location__);
192 #define share_mode_entry_prepare_lock_del(__prepare_state, __id, \
193 __fn, __private_data) \
194 _share_mode_entry_prepare_lock(__prepare_state, __id, \
195 NULL, NULL, NULL, \
196 __fn, __private_data, __location__);
198 typedef void (*share_mode_entry_prepare_unlock_fn_t)(
199 struct share_mode_lock *lck,
200 void *private_data);
201 NTSTATUS _share_mode_entry_prepare_unlock(
202 struct share_mode_entry_prepare_state *prepare_state,
203 share_mode_entry_prepare_unlock_fn_t fn,
204 void *private_data,
205 const char *location);
206 #define share_mode_entry_prepare_unlock(__prepare_state, \
207 __fn, __private_data) \
208 _share_mode_entry_prepare_unlock(__prepare_state, \
209 __fn, __private_data, __location__);
211 #endif