s3/locking: Revert "s3:locking: Remove dead code"
[bbaumbach/samba-autobuild/.git] / source3 / locking / share_mode_lock.h
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.
6  *
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.
11  *
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/>.
14  */
15
16 #ifndef __LOCKING_SHARE_MODE_LOCK_H__
17 #define __LOCKING_SHARE_MODE_LOCK_H__
18
19 #include "replace.h"
20 #include <tevent.h>
21 #include "librpc/gen_ndr/file_id.h"
22 #include "lib/util/time.h"
23
24 struct share_mode_data;
25 struct share_mode_lock;
26 struct share_mode_entry;
27 struct smb_filename;
28 struct files_struct;
29 struct smb2_lease_key;
30
31 bool locking_init(void);
32 bool locking_init_readonly(void);
33 bool locking_end(void);
34
35 struct file_id share_mode_lock_file_id(const struct share_mode_lock *lck);
36
37 struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
38                                                      struct file_id id);
39
40 bool del_share_mode(struct share_mode_lock *lck,
41                     struct files_struct *fsp);
42 bool downgrade_share_oplock(struct share_mode_lock *lck,
43                             struct files_struct *fsp);
44 bool remove_share_oplock(struct share_mode_lock *lck,
45                          struct files_struct *fsp);
46 bool file_has_read_lease(struct files_struct *fsp);
47
48 bool set_share_mode(
49         struct share_mode_lock *lck,
50         struct files_struct *fsp,
51         uid_t uid,
52         uint64_t mid,
53         uint16_t op_type,
54         const struct smb2_lease_key *lease_key,
55         uint32_t share_access,
56         uint32_t access_mask);
57 bool reset_share_mode_entry(
58         struct share_mode_lock *lck,
59         struct server_id old_pid,
60         uint64_t old_share_file_id,
61         struct server_id new_pid,
62         uint64_t new_mid,
63         uint64_t new_share_file_id);
64
65 bool mark_share_mode_disconnected(
66         struct share_mode_lock *lck, struct files_struct *fsp);
67
68 struct share_mode_lock *fetch_share_mode_unlocked(
69         TALLOC_CTX *mem_ctx,
70         struct file_id id);
71
72 struct tevent_req *fetch_share_mode_send(
73         TALLOC_CTX *mem_ctx,
74         struct tevent_context *ev,
75         struct file_id id,
76         bool *queued);
77 NTSTATUS fetch_share_mode_recv(
78         struct tevent_req *req,
79         TALLOC_CTX *mem_ctx,
80         struct share_mode_lock **_lck);
81
82 int share_entry_forall(
83         int (*fn)(struct file_id fid,
84                   const struct share_mode_data *data,
85                   const struct share_mode_entry *entry,
86                   void *private_data),
87         void *private_data);
88
89 NTSTATUS share_mode_count_entries(struct file_id fid, size_t *num_share_modes);
90 int share_mode_forall(
91         int (*fn)(struct file_id fid,
92                   const struct share_mode_data *data,
93                   void *private_data),
94         void *private_data);
95 bool share_mode_forall_entries(
96         struct share_mode_lock *lck,
97         bool (*fn)(struct share_mode_entry *e,
98                    bool *modified,
99                    void *private_data),
100         void *private_data);
101
102 NTTIME share_mode_changed_write_time(struct share_mode_lock *lck);
103 void share_mode_set_changed_write_time(struct share_mode_lock *lck, struct timespec write_time);
104 void share_mode_set_old_write_time(struct share_mode_lock *lck, struct timespec write_time);
105 const char *share_mode_servicepath(struct share_mode_lock *lck);
106 char *share_mode_filename(TALLOC_CTX *mem_ctx, struct share_mode_lock *lck);
107 char *share_mode_data_dump(
108         TALLOC_CTX *mem_ctx, struct share_mode_lock *lck);
109
110 void share_mode_flags_get(
111         struct share_mode_lock *lck,
112         uint32_t *access_mask,
113         uint32_t *share_mode,
114         uint32_t *lease_type);
115 void share_mode_flags_set(
116         struct share_mode_lock *lck,
117         uint32_t access_mask,
118         uint32_t share_mode,
119         uint32_t lease_type,
120         bool *modified);
121
122 struct tevent_req *share_mode_watch_send(
123         TALLOC_CTX *mem_ctx,
124         struct tevent_context *ev,
125         struct share_mode_lock *lck,
126         struct server_id blocker);
127 NTSTATUS share_mode_watch_recv(
128         struct tevent_req *req, bool *blockerdead, struct server_id *blocker);
129 NTSTATUS share_mode_wakeup_waiters(struct file_id id);
130
131 typedef void (*share_mode_do_locked_vfs_fn_t)(
132                 struct share_mode_lock *lck,
133                 void *private_data);
134 NTSTATUS _share_mode_do_locked_vfs_denied(
135         struct file_id id,
136         share_mode_do_locked_vfs_fn_t fn,
137         void *private_data,
138         const char *location);
139 #define share_mode_do_locked_vfs_denied(__id, __fn, __private_data) \
140         _share_mode_do_locked_vfs_denied(__id, __fn, __private_data, __location__)
141 NTSTATUS _share_mode_do_locked_vfs_allowed(
142         struct file_id id,
143         share_mode_do_locked_vfs_fn_t fn,
144         void *private_data,
145         const char *location);
146 #define share_mode_do_locked_vfs_allowed(__id, __fn, __private_data) \
147         _share_mode_do_locked_vfs_allowed(__id, __fn, __private_data, __location__)
148
149 struct share_mode_entry_prepare_state {
150         struct file_id __fid;
151         struct share_mode_lock *__lck_ptr;
152         union {
153 #define __SHARE_MODE_LOCK_SPACE 32
154                 uint8_t __u8_space[__SHARE_MODE_LOCK_SPACE];
155 #ifdef SHARE_MODE_ENTRY_PREPARE_STATE_LCK_SPACE
156                 struct share_mode_lock __lck_space;
157 #endif
158         };
159 };
160
161 typedef void (*share_mode_entry_prepare_lock_fn_t)(
162                 struct share_mode_lock *lck,
163                 bool *keep_locked,
164                 void *private_data);
165 NTSTATUS _share_mode_entry_prepare_lock(
166         struct share_mode_entry_prepare_state *prepare_state,
167         struct file_id id,
168         const char *servicepath,
169         const struct smb_filename *smb_fname,
170         const struct timespec *old_write_time,
171         share_mode_entry_prepare_lock_fn_t fn,
172         void *private_data,
173         const char *location);
174 #define share_mode_entry_prepare_lock_add(__prepare_state, __id, \
175                 __servicepath, __smb_fname, __old_write_time, \
176                 __fn, __private_data) \
177         _share_mode_entry_prepare_lock(__prepare_state, __id, \
178                 __servicepath, __smb_fname, __old_write_time, \
179                 __fn, __private_data, __location__);
180 #define share_mode_entry_prepare_lock_del(__prepare_state, __id, \
181                 __fn, __private_data) \
182         _share_mode_entry_prepare_lock(__prepare_state, __id, \
183                 NULL, NULL, NULL, \
184                 __fn, __private_data, __location__);
185
186 typedef void (*share_mode_entry_prepare_unlock_fn_t)(
187                 struct share_mode_lock *lck,
188                 void *private_data);
189 NTSTATUS _share_mode_entry_prepare_unlock(
190         struct share_mode_entry_prepare_state *prepare_state,
191         share_mode_entry_prepare_unlock_fn_t fn,
192         void *private_data,
193         const char *location);
194 #define share_mode_entry_prepare_unlock(__prepare_state, \
195                 __fn, __private_data) \
196         _share_mode_entry_prepare_unlock(__prepare_state, \
197                 __fn, __private_data, __location__);
198
199 #endif