clean up headers, obsd socket.h needs types.h
[arla.git] / arlad / fcache.h
blob7f16fadf6950bc61317d9ceb73a7305725ee8e84
1 /*
2 * Copyright (c) 1995-2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
35 * The interface for the file-cache.
38 /* $Id$ */
40 #ifndef _FCACHE_H_
41 #define _FCACHE_H_
43 #include <nnpfs/nnpfs_message.h>
44 #include <nnpfs/nnpfs_blocks.h>
45 #include <fcntl.h>
46 #include <cred.h>
47 #include <heap.h>
50 * For each entry in the filecache we save the rights of NACCESS users.
51 * The value should be the same as NNPFS_MAXRIGHTS from nnpfs_message.h
52 * If it isn't you can get some very strange behavior from nnpfs, so don't
53 * even try. XXX
54 */
56 #define NACCESS NNPFS_MAXRIGHTS
58 typedef struct {
59 nnpfs_pag_t cred;
60 u_long access;
61 } AccessEntry;
63 /* these must match PRSFS_* from rxdef/common.h */
64 enum Access { ANONE = 0x0,
65 AREAD = 0x01,
66 AWRITE = 0x02,
67 AINSERT = 0x04,
68 ALIST = 0x08,
69 ADELETE = 0x10,
70 ALOCK = 0x20,
71 AADMIN = 0x40 };
73 typedef struct {
74 Bool valid;
75 #if 0
76 struct nnpfs_cache_handle nnpfs_handle;
77 #endif
78 } fcache_cache_handle;
80 struct block; /* fwd */
82 typedef struct FCacheEntry {
83 struct Lock lock; /* locking information for this entry */
84 VenusFid fid; /* The fid of the file for this entry */
85 unsigned refcount; /* reference count */
86 uint32_t host; /* the source of this entry */
87 int64_t usage; /* the cache usage size */
88 AFSFetchStatus status; /* Removed unused stuff later */
89 AFSCallBack callback; /* Callback to the AFS-server */
90 AFSVolSync volsync; /* Sync info for ro-volumes */
91 AccessEntry acccache[NACCESS]; /* cache for the access rights */
92 uint32_t anonaccess; /* the access mask for system:anyuser */
93 uint32_t index; /* this is V%u */
94 /*x*/ fcache_cache_handle handle; /* handle */
95 List *blocks;
96 struct {
97 unsigned usedp : 1; /* Is this entry used? */
98 unsigned attrp : 1; /* Are the attributes in status valid? */
99 unsigned attrusedp : 1; /* Attr is used in the kernel */
100 /*x*/ unsigned datausedp : 1; /* Data is used in the kernel */
101 unsigned extradirp : 1; /* Has this directory been "converted"? */
102 unsigned mountp : 1; /* Is this an AFS mount point? */
103 unsigned kernelp : 1; /* Does this entry exist in the kernel? */
104 unsigned sentenced : 1; /* This entry should die */
105 unsigned dirtied : 1; /* Putdata failed. */
106 unsigned stale : 1; /* Data isn't valid. */
107 unsigned silly : 1; /* Instead of silly-rename */
108 unsigned fake_mp : 1; /* a `fake' mount point */
109 unsigned vol_root : 1; /* root of a volume */
110 unsigned waiters : 1; /* Are threads waiting for I/O to complete? */
111 unsigned gcp : 1; /* Allow gc of blocks while node is locked? */
112 unsigned locked : 1; /* Is this node locked? */
113 unsigned lockwait : 1; /* Are threads waiting to lock? */
114 unsigned appended : 1; /* Has kernel sent 'appenddata' for node? */
115 } flags;
116 u_int tokens; /* read/write tokens for the kernel */
117 VenusFid parent;
118 Listitem *lru_le; /* lru */
119 heap_ptr invalid_ptr; /* pointer into the heap */
120 VolCacheEntry *volume; /* pointer to the volume entry */
121 Bool priority; /* is the file worth keeping */
122 int hits; /* number of lookups */
123 PollerEntry *poll; /* poller entry */
124 uint32_t disco_id; /* id in disconncted log */
125 } FCacheEntry;
128 * The fileservers to ask for a particular volume.
131 struct fs_server_context {
132 int i; /* current number being probed */
133 int num_conns; /* number in `conns' */
134 VolCacheEntry *ve; /* */
135 struct fs_server_entry {
136 ConnCacheEntry *conn; /* rx connection to server */
137 int ve_ent; /* entry in `ve' */
138 } conns[NMAXNSERVERS];
141 typedef struct fs_server_context fs_server_context;
144 * How far the cleaner will go went cleaning things up.
147 extern Bool fprioritylevel;
149 void
150 fcache_init (u_long alowvnodes,
151 u_long ahighvnodes,
152 int64_t alowbytes,
153 int64_t ahighbytes,
154 uint64_t blocksize,
155 Bool recover);
158 fcache_reinit(u_long alowvnodes,
159 u_long ahighvnodes,
160 int64_t alowbytes,
161 int64_t ahighbytes);
163 void
164 fcache_purge_volume (VenusFid fid);
166 void
167 fcache_purge_host (u_long host);
169 void
170 fcache_purge_cred (nnpfs_pag_t cred, int32_t cell);
172 void
173 fcache_stale_entry (VenusFid fid, AFSCallBack callback);
175 void
176 fcache_invalidate_mp (void);
179 fcache_dir_name (FCacheEntry *entry, char *s, size_t len);
182 fcache_extra_file_name (FCacheEntry *entry, char *s, size_t len);
185 fcache_open_block (FCacheEntry *entry, uint64_t offset, Bool writep);
187 void
188 fcache_throw_block (struct block *b);
191 fcache_append_block(FCacheEntry *entry, uint64_t offset);
193 Bool
194 fcache_block_exists(FCacheEntry *entry, uint64_t offset);
196 void
197 fcache_block_lru(struct block *b);
199 void
200 fcache_node_lru(FCacheEntry *e);
202 void
203 fcache_node_setkernelp(FCacheEntry *e, Bool val);
205 void
206 fcache_data_setkernelp(FCacheEntry *e, uint64_t offset, Bool val, Bool unbusy);
208 void
209 fcache_data_setbusy(FCacheEntry *e, uint64_t offset, uint64_t end, Bool val);
212 fcache_open_extra_dir (FCacheEntry *entry, int flag, mode_t mode);
215 fcache_fhget (char *filename, fcache_cache_handle *handle);
218 write_data(FCacheEntry *entry, FCacheEntry *data_entry,
219 uint64_t offset, uint64_t length,
220 AFSStoreStatus *storestatus, CredCacheEntry *ce);
223 truncate_file (FCacheEntry *entry, uint64_t size,
224 AFSStoreStatus *status, CredCacheEntry *ce);
227 write_attr (FCacheEntry *entry, const AFSStoreStatus *status,
228 CredCacheEntry *ce);
231 create_file (FCacheEntry *dir_entry,
232 const char *name, AFSStoreStatus *store_attr,
233 FCacheEntry **ret_entry, CredCacheEntry *ce);
236 create_directory (FCacheEntry *dir_entry,
237 const char *name, AFSStoreStatus *store_attr,
238 VenusFid *child_fid, AFSFetchStatus *fetch_attr,
239 CredCacheEntry *ce);
242 create_symlink (FCacheEntry *dir_entry,
243 const char *name, AFSStoreStatus *store_attr,
244 VenusFid *child_fid, AFSFetchStatus *fetch_attr,
245 const char *contents,
246 CredCacheEntry *ce);
249 create_link (FCacheEntry *dir_entry,
250 const char *name,
251 FCacheEntry *existing_entry,
252 CredCacheEntry *ce);
255 remove_file(FCacheEntry *dir_entry, const char *name,
256 FCacheEntry *child_entry, CredCacheEntry *ce);
259 remove_directory(FCacheEntry *dir_entry, const char *name,
260 FCacheEntry *child_entry, CredCacheEntry *ce);
263 rename_file (FCacheEntry *old_dir,
264 const char *old_name,
265 FCacheEntry *new_dir,
266 const char *new_name,
267 CredCacheEntry *ce);
270 getroot (VenusFid *res, CredCacheEntry *ce);
273 fcache_get (FCacheEntry **res, VenusFid fid, CredCacheEntry *ce);
276 fcache_get_gc (FCacheEntry **res, VenusFid fid, CredCacheEntry *ce);
278 void
279 fcache_release (FCacheEntry *e);
281 FCacheEntry *
282 fcache_find(VenusFid fid);
284 FCacheEntry *
285 fcache_find_gcp(VenusFid fid, Bool gcp);
288 fcache_get_data (FCacheEntry **e, CredCacheEntry **ce,
289 uint64_t wanted_offset, uint64_t wanted_end);
292 fcache_verify_attr (FCacheEntry *entry, FCacheEntry *parent_entry,
293 const char *prefered_name, CredCacheEntry* ce);
296 followmountpoint (VenusFid *fid, const VenusFid *parent, FCacheEntry *parent_e,
297 CredCacheEntry **ce);
299 void
300 fcache_status (void);
303 fcache_store_state (void);
305 long
306 getvoltype(int32_t volid, const VolCacheEntry *ve);
309 getacl(VenusFid fid, CredCacheEntry *ce,
310 AFSOpaque *opaque);
313 setacl(VenusFid fid, CredCacheEntry *ce,
314 AFSOpaque *opaque, FCacheEntry **ret);
317 getvolstat(VenusFid fid, CredCacheEntry *ce,
318 AFSFetchVolumeStatus *volstat,
319 char *volumename, size_t volumenamesz,
320 char *offlinemsg,
321 char *motd);
324 setvolstat(VenusFid fid, CredCacheEntry *ce,
325 AFSStoreVolumeStatus *volstat,
326 char *volumename,
327 char *offlinemsg,
328 char *motd);
330 int64_t
331 fcache_highbytes(void);
333 int64_t
334 fcache_usedbytes(void);
336 int64_t
337 fcache_lowbytes(void);
339 u_long
340 fcache_highvnodes(void);
342 u_long
343 fcache_usedvnodes(void);
345 u_long
346 fcache_lowvnodes(void);
348 uint64_t
349 fcache_getblocksize(void);
351 void
352 fcache_setblocksize(uint64_t newsize);
354 int64_t
355 fcache_set_appendquota(void);
358 fcache_update_appendquota(FCacheEntry *e);
361 fcache_giveup_all_callbacks (void);
363 uint64_t
364 fcache_get_status_length(const AFSFetchStatus *status);
366 void
367 fcache_set_status_length(AFSFetchStatus *status, int64_t length);
369 void
370 fcache_discard_attrs(void);
373 fcache_reobtain_callbacks (struct nnpfs_cred *cred);
375 /* XXX - this shouldn't be public, but getrights in inter.c needs it */
377 read_attr (FCacheEntry *, CredCacheEntry *);
379 Bool
380 findaccess (nnpfs_pag_t cred, AccessEntry *ae, AccessEntry **pos);
382 void
383 fcache_unused(FCacheEntry *entry);
386 fcache_set_have(FCacheEntry *entry, uint64_t offset, uint64_t length);
388 void
389 fcache_set_have_all(FCacheEntry *e, uint64_t len);
393 init_fs_context (FCacheEntry *e,
394 CredCacheEntry *ce,
395 fs_server_context *context);
397 ConnCacheEntry *
398 find_first_fs (fs_server_context *context);
400 ConnCacheEntry *
401 find_next_fs (fs_server_context *context,
402 ConnCacheEntry *prev_conn,
403 int mark_as_dead);
405 void
406 free_fs_server_context (fs_server_context *context);
408 void
409 recon_hashtabadd(FCacheEntry *entry);
411 void
412 recon_hashtabdel(FCacheEntry *entry);
415 fcache_get_fbuf (FCacheEntry *centry, fbuf *fbuf, int fbuf_flags);
417 int64_t
418 fcache_calculate_usage (void);
420 const VenusFid *
421 fcache_realfid (const FCacheEntry *entry);
423 void
424 fcache_mark_as_mountpoint (FCacheEntry *entry);
426 const char *
427 fcache_getdefsysname (void);
430 fcache_addsysname (const char *sysname);
433 fcache_removesysname (const char *sysname);
436 fcache_setdefsysname (const char *sysname);
439 fs_probe (struct rx_connection *conn);
441 void
442 fcache_check_dirs(void);
444 void
445 fcache_check_blocks(void);
447 void
448 fcache_cleaner_ref(void);
449 void
450 fcache_cleaner_deref(void);
452 #endif /* _FCACHE_H_ */