smbd: Return "blocker_pid" from do_lock()
[Samba.git] / source3 / locking / proto.h
blob273d3666d370a1d68f73642d7dd6f5723a3582e1
1 /*
2 * Unix SMB/CIFS implementation.
3 * Locking functions
5 * Copyright (C) Andrew Tridgell 1992-2000
6 * Copyright (C) Jeremy Allison 1992-2006
7 * Copyright (C) Volker Lendecke 2005
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _LOCKING_PROTO_H_
24 #define _LOCKING_PROTO_H_
26 /* The following definitions come from locking/brlock.c */
28 void brl_init(bool read_only);
29 void brl_shutdown(void);
31 unsigned int brl_num_locks(const struct byte_range_lock *brl);
32 struct files_struct *brl_fsp(struct byte_range_lock *brl);
33 uint32_t brl_num_read_oplocks(const struct byte_range_lock *brl);
34 void brl_set_num_read_oplocks(struct byte_range_lock *brl,
35 uint32_t num_read_oplocks);
37 NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
38 struct lock_struct *plock,
39 bool blocking_lock);
41 NTSTATUS brl_lock(struct messaging_context *msg_ctx,
42 struct byte_range_lock *br_lck,
43 uint64_t smblctx,
44 struct server_id pid,
45 br_off start,
46 br_off size,
47 enum brl_type lock_type,
48 enum brl_flavour lock_flav,
49 bool blocking_lock,
50 struct server_id *blocker_pid,
51 uint64_t *psmblctx);
52 bool brl_unlock(struct messaging_context *msg_ctx,
53 struct byte_range_lock *br_lck,
54 uint64_t smblctx,
55 struct server_id pid,
56 br_off start,
57 br_off size,
58 enum brl_flavour lock_flav);
59 bool brl_unlock_windows_default(struct messaging_context *msg_ctx,
60 struct byte_range_lock *br_lck,
61 const struct lock_struct *plock);
62 bool brl_locktest(struct byte_range_lock *br_lck,
63 const struct lock_struct *rw_probe);
64 NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
65 uint64_t *psmblctx,
66 struct server_id pid,
67 br_off *pstart,
68 br_off *psize,
69 enum brl_type *plock_type,
70 enum brl_flavour lock_flav);
71 bool brl_lock_cancel(struct byte_range_lock *br_lck,
72 uint64_t smblctx,
73 struct server_id pid,
74 br_off start,
75 br_off size,
76 enum brl_flavour lock_flav);
77 bool brl_lock_cancel_default(struct byte_range_lock *br_lck,
78 struct lock_struct *plock);
79 bool brl_mark_disconnected(struct files_struct *fsp);
80 bool brl_reconnect_disconnected(struct files_struct *fsp);
81 void brl_close_fnum(struct messaging_context *msg_ctx,
82 struct byte_range_lock *br_lck);
83 int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
84 enum brl_type lock_type,
85 enum brl_flavour lock_flav,
86 br_off start, br_off size,
87 void *private_data),
88 void *private_data);
89 struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
90 files_struct *fsp);
91 struct byte_range_lock *brl_get_locks_readonly(files_struct *fsp);
92 void brl_revalidate(struct messaging_context *msg_ctx,
93 void *private_data,
94 uint32_t msg_type,
95 struct server_id server_id,
96 DATA_BLOB *data);
97 bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id);
99 /* The following definitions come from locking/locking.c */
101 const char *lock_type_name(enum brl_type lock_type);
102 const char *lock_flav_name(enum brl_flavour lock_flav);
103 void init_strict_lock_struct(files_struct *fsp,
104 uint64_t smblctx,
105 br_off start,
106 br_off size,
107 enum brl_type lock_type,
108 struct lock_struct *plock);
109 bool strict_lock_check_default(files_struct *fsp,
110 struct lock_struct *plock);
111 NTSTATUS query_lock(files_struct *fsp,
112 uint64_t *psmblctx,
113 uint64_t *pcount,
114 uint64_t *poffset,
115 enum brl_type *plock_type,
116 enum brl_flavour lock_flav);
117 struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
118 files_struct *fsp,
119 uint64_t smblctx,
120 uint64_t count,
121 uint64_t offset,
122 enum brl_type lock_type,
123 enum brl_flavour lock_flav,
124 bool blocking_lock,
125 NTSTATUS *perr,
126 struct server_id *pblocker_pid,
127 uint64_t *psmblctx);
128 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
129 files_struct *fsp,
130 uint64_t smblctx,
131 uint64_t count,
132 uint64_t offset,
133 enum brl_flavour lock_flav);
134 NTSTATUS do_lock_cancel(files_struct *fsp,
135 uint64_t smblctx,
136 uint64_t count,
137 uint64_t offset,
138 enum brl_flavour lock_flav);
139 void locking_close_file(struct messaging_context *msg_ctx,
140 files_struct *fsp,
141 enum file_close_type close_type);
142 bool locking_init(void);
143 bool locking_init_readonly(void);
144 bool locking_end(void);
145 char *share_mode_str(TALLOC_CTX *ctx, int num,
146 const struct file_id *id,
147 const struct share_mode_entry *e);
148 struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
149 struct file_id id);
150 struct share_mode_lock *get_share_mode_lock(
151 TALLOC_CTX *mem_ctx,
152 struct file_id id,
153 const char *servicepath,
154 const struct smb_filename *smb_fname,
155 const struct timespec *old_write_time);
156 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
157 struct file_id id);
158 struct tevent_req *fetch_share_mode_send(TALLOC_CTX *mem_ctx,
159 struct tevent_context *ev,
160 struct file_id id,
161 bool *queued);
162 NTSTATUS fetch_share_mode_recv(struct tevent_req *req,
163 TALLOC_CTX *mem_ctx,
164 struct share_mode_lock **_lck);
165 bool rename_share_filename(struct messaging_context *msg_ctx,
166 struct share_mode_lock *lck,
167 struct file_id id,
168 const char *servicepath,
169 uint32_t orig_name_hash,
170 uint32_t new_name_hash,
171 const struct smb_filename *smb_fname);
172 void get_file_infos(struct file_id id,
173 uint32_t name_hash,
174 bool *delete_on_close,
175 struct timespec *write_time);
176 bool is_valid_share_mode_entry(const struct share_mode_entry *e);
177 bool share_mode_stale_pid(struct share_mode_data *d, uint32_t idx);
178 bool set_share_mode(struct share_mode_lock *lck,
179 struct files_struct *fsp,
180 uid_t uid,
181 uint64_t mid,
182 uint16_t op_type,
183 const struct GUID *client_guid,
184 const struct smb2_lease_key *lease_key);
185 struct share_mode_entry *find_share_mode_entry(struct share_mode_lock *lck,
186 files_struct *fsp);
187 void remove_stale_share_mode_entries(struct share_mode_data *d);
188 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp);
189 bool mark_share_mode_disconnected(struct share_mode_lock *lck,
190 struct files_struct *fsp);
191 bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
192 bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
193 bool get_delete_on_close_token(struct share_mode_lock *lck,
194 uint32_t name_hash,
195 const struct security_token **pp_nt_tok,
196 const struct security_unix_token **pp_tok);
197 void reset_delete_on_close_lck(files_struct *fsp,
198 struct share_mode_lock *lck);
199 void set_delete_on_close_lck(files_struct *fsp,
200 struct share_mode_lock *lck,
201 const struct security_token *nt_tok,
202 const struct security_unix_token *tok);
203 bool set_delete_on_close(files_struct *fsp, bool delete_on_close,
204 const struct security_token *nt_tok,
205 const struct security_unix_token *tok);
206 bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash);
207 bool set_sticky_write_time(struct file_id fileid, struct timespec write_time);
208 bool set_write_time(struct file_id fileid, struct timespec write_time);
209 struct timespec get_share_mode_write_time(struct share_mode_lock *lck);
210 bool file_has_open_streams(files_struct *fsp);
211 int share_mode_forall(int (*fn)(struct file_id fid,
212 const struct share_mode_data *data,
213 void *private_data),
214 void *private_data);
215 int share_entry_forall(int (*fn)(struct file_id fid,
216 const struct share_mode_data *data,
217 const struct share_mode_entry *entry,
218 void *private_data),
219 void *private_data);
220 bool share_mode_cleanup_disconnected(struct file_id id,
221 uint64_t open_persistent_id);
222 bool share_mode_forall_leases(
223 struct share_mode_lock *lck,
224 bool (*fn)(struct share_mode_lock *lck,
225 struct share_mode_entry *e,
226 void *private_data),
227 void *private_data);
230 /* The following definitions come from locking/posix.c */
232 bool is_posix_locked(files_struct *fsp,
233 uint64_t *pu_offset,
234 uint64_t *pu_count,
235 enum brl_type *plock_type,
236 enum brl_flavour lock_flav);
237 bool posix_locking_init(bool read_only);
238 bool posix_locking_end(void);
239 int fd_close_posix(const struct files_struct *fsp);
240 bool set_posix_lock_windows_flavour(files_struct *fsp,
241 uint64_t u_offset,
242 uint64_t u_count,
243 enum brl_type lock_type,
244 const struct lock_context *lock_ctx,
245 const struct lock_struct *plocks,
246 int num_locks,
247 int *errno_ret);
248 bool release_posix_lock_windows_flavour(files_struct *fsp,
249 uint64_t u_offset,
250 uint64_t u_count,
251 enum brl_type deleted_lock_type,
252 const struct lock_context *lock_ctx,
253 const struct lock_struct *plocks,
254 int num_locks);
255 bool set_posix_lock_posix_flavour(files_struct *fsp,
256 uint64_t u_offset,
257 uint64_t u_count,
258 enum brl_type lock_type,
259 const struct lock_context *lock_ctx,
260 int *errno_ret);
261 bool release_posix_lock_posix_flavour(files_struct *fsp,
262 uint64_t u_offset,
263 uint64_t u_count,
264 const struct lock_context *lock_ctx,
265 const struct lock_struct *plocks,
266 int num_locks);
268 /* The following definitions come from locking/leases_util.c */
269 uint32_t map_oplock_to_lease_type(uint16_t op_type);
270 uint32_t fsp_lease_type(const struct files_struct *fsp);
271 uint32_t lease_type_is_exclusive(uint32_t lease_type);
272 bool fsp_lease_type_is_exclusive(const struct files_struct *fsp);
274 #endif /* _LOCKING_PROTO_H_ */