2 * Copyright (c) 1995-2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
35 * The interface for the file-cache.
43 #include <nnpfs/nnpfs_message.h>
44 #include <nnpfs/nnpfs_blocks.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
56 #define NACCESS NNPFS_MAXRIGHTS
63 /* these must match PRSFS_* from rxdef/common.h */
64 enum Access
{ ANONE
= 0x0,
76 struct nnpfs_cache_handle nnpfs_handle
;
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 */
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? */
116 u_int tokens
; /* read/write tokens for the kernel */
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 */
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
;
150 fcache_init (u_long alowvnodes
,
158 fcache_reinit(u_long alowvnodes
,
164 fcache_purge_volume (VenusFid fid
);
167 fcache_purge_host (u_long host
);
170 fcache_purge_cred (nnpfs_pag_t cred
, int32_t cell
);
173 fcache_stale_entry (VenusFid fid
, AFSCallBack callback
);
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
);
188 fcache_throw_block (struct block
*b
);
191 fcache_append_block(FCacheEntry
*entry
, uint64_t offset
);
194 fcache_block_exists(FCacheEntry
*entry
, uint64_t offset
);
197 fcache_block_lru(struct block
*b
);
200 fcache_node_lru(FCacheEntry
*e
);
203 fcache_node_setkernelp(FCacheEntry
*e
, Bool val
);
206 fcache_data_setkernelp(FCacheEntry
*e
, uint64_t offset
, Bool val
, Bool unbusy
);
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
,
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
,
242 create_symlink (FCacheEntry
*dir_entry
,
243 const char *name
, AFSStoreStatus
*store_attr
,
244 VenusFid
*child_fid
, AFSFetchStatus
*fetch_attr
,
245 const char *contents
,
249 create_link (FCacheEntry
*dir_entry
,
251 FCacheEntry
*existing_entry
,
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
,
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
);
279 fcache_release (FCacheEntry
*e
);
282 fcache_find(VenusFid fid
);
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
);
300 fcache_status (void);
303 fcache_store_state (void);
306 getvoltype(int32_t volid
, const VolCacheEntry
*ve
);
309 getacl(VenusFid fid
, CredCacheEntry
*ce
,
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
,
324 setvolstat(VenusFid fid
, CredCacheEntry
*ce
,
325 AFSStoreVolumeStatus
*volstat
,
331 fcache_highbytes(void);
334 fcache_usedbytes(void);
337 fcache_lowbytes(void);
340 fcache_highvnodes(void);
343 fcache_usedvnodes(void);
346 fcache_lowvnodes(void);
349 fcache_getblocksize(void);
352 fcache_setblocksize(uint64_t newsize
);
355 fcache_set_appendquota(void);
358 fcache_update_appendquota(FCacheEntry
*e
);
361 fcache_giveup_all_callbacks (void);
364 fcache_get_status_length(const AFSFetchStatus
*status
);
367 fcache_set_status_length(AFSFetchStatus
*status
, int64_t length
);
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
*);
380 findaccess (nnpfs_pag_t cred
, AccessEntry
*ae
, AccessEntry
**pos
);
383 fcache_unused(FCacheEntry
*entry
);
386 fcache_set_have(FCacheEntry
*entry
, uint64_t offset
, uint64_t length
);
389 fcache_set_have_all(FCacheEntry
*e
, uint64_t len
);
393 init_fs_context (FCacheEntry
*e
,
395 fs_server_context
*context
);
398 find_first_fs (fs_server_context
*context
);
401 find_next_fs (fs_server_context
*context
,
402 ConnCacheEntry
*prev_conn
,
406 free_fs_server_context (fs_server_context
*context
);
409 recon_hashtabadd(FCacheEntry
*entry
);
412 recon_hashtabdel(FCacheEntry
*entry
);
415 fcache_get_fbuf (FCacheEntry
*centry
, fbuf
*fbuf
, int fbuf_flags
);
418 fcache_calculate_usage (void);
421 fcache_realfid (const FCacheEntry
*entry
);
424 fcache_mark_as_mountpoint (FCacheEntry
*entry
);
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
);
442 fcache_check_dirs(void);
445 fcache_check_blocks(void);
448 fcache_cleaner_ref(void);
450 fcache_cleaner_deref(void);
452 #endif /* _FCACHE_H_ */