netatalk: dircache.h Source File

netatalk 4.5.1
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
dircache.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
3 * Copyright (c) 2025-2026 Andy Lemin (@andylemin)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14*/
15
16#ifndef DIRCACHE_H
17#define DIRCACHE_H
18
19#include <sys/types.h>
20
21#include <atalk/directory.h>
22#include <atalk/globals.h>
23#include <atalk/volume.h>
24
25/* Dircache size bounds */
26#define MIN_DIRCACHE_SIZE 1024 /* 1K minimum (testing/constrained systems) */
27#define DEFAULT_DIRCACHE_SIZE 65536 /* 64K default (production) */
28#define MAX_DIRCACHE_SIZE 1048576 /* 1M maximum (high-memory servers) */
29#define DIRCACHE_FREE_QUANTUM 256
30
31/* Max dircache entries removed per hash chain per idle worker iteration.
32 * 16 is compromise between latency (~1μs per dir_free × 16 = ~16μs per batch)
33 * and is_idle polling frequency (instant yield to AFP commands) */
34#define DEFERRED_CHAIN_BATCH 16
35
36/* flags for dircache_remove */
37#define DIRCACHE (1 << 0)
38#define DIDNAME_INDEX (1 << 1)
39#define QUEUE_INDEX (1 << 2)
40#define DIRCACHE_NOSHRINK (1 << 3) /* Skip hash table shrink */
41#define DIRCACHE_ALL (DIRCACHE|DIDNAME_INDEX|QUEUE_INDEX)
42
43extern int dircache_init(int reqsize);
44extern int dircache_add(const struct vol *, struct dir *);
45extern void dircache_remove(const struct vol *, struct dir *, int flag);
46extern struct dir *dircache_search_by_did(const struct vol *vol, cnid_t did);
47extern struct dir *dircache_search_by_name(const struct vol *,
48 const struct dir *dir, char *name, size_t len);
49extern void dircache_dump(void);
50extern void log_dircache_stat(void);
51extern int dircache_set_validation_params(unsigned int freq);
52extern void dircache_reset_validation_counter(void);
53extern void dircache_report_invalid_entry(struct dir *dir);
54extern int dircache_remove_children(const struct vol *vol,
55 struct dir *dir);
56extern int dircache_reindex_didname(const struct vol *vol,
57 struct dir *dir);
58extern void dircache_promote(struct dir *dir);
59extern void process_cache_hints(AFPObj *obj);
60extern void dircache_remove_children_defer(const struct vol *vol,
61 struct dir *dir);
62extern void dircache_flush_deferred_for_vol(uint16_t vid);
63extern int dircache_has_deferred_work(void);
64extern int dircache_process_deferred_chain(void);
65extern void dircache_rfork_shutdown(void);
66
67/* Tier 2: Resource Fork data cache */
68extern size_t rfork_cache_used;
69extern size_t rfork_cache_budget;
70extern size_t rfork_max_entry_size;
71extern unsigned int rfork_lru_count;
72extern q_t *rfork_lru;
73
74/* Tier 2: Resource Fork data cache statistics */
75extern unsigned long long rfork_stat_lookups;
76extern unsigned long long rfork_stat_hits;
77extern unsigned long long rfork_stat_misses;
78extern unsigned long long rfork_stat_added;
79extern unsigned long long rfork_stat_evicted;
80extern unsigned long long rfork_stat_invalidated;
81extern size_t rfork_stat_used_max;
82
83#endif /* DIRCACHE_H */
cnid_t
uint32_t cnid_t
Definition adouble.h:156
rfork_stat_evicted
unsigned long long rfork_stat_evicted
Definition dircache.c:182
rfork_cache_budget
size_t rfork_cache_budget
Definition dircache.c:193
rfork_max_entry_size
size_t rfork_max_entry_size
Definition dircache.c:195
rfork_stat_added
unsigned long long rfork_stat_added
Definition dircache.c:181
rfork_lru_count
unsigned int rfork_lru_count
Definition dircache.c:197
rfork_stat_used_max
size_t rfork_stat_used_max
Definition dircache.c:184
rfork_stat_hits
unsigned long long rfork_stat_hits
Definition dircache.c:179
rfork_stat_misses
unsigned long long rfork_stat_misses
Definition dircache.c:180
rfork_stat_lookups
unsigned long long rfork_stat_lookups
Definition dircache.c:178
rfork_lru
q_t * rfork_lru
Definition dircache.c:199
rfork_cache_used
size_t rfork_cache_used
Definition dircache.c:191
rfork_stat_invalidated
unsigned long long rfork_stat_invalidated
Definition dircache.c:183
dircache_flush_deferred_for_vol
void dircache_flush_deferred_for_vol(uint16_t vid)
Process deferred cleanup entries for a closing volume synchronously.
Definition dircache.c:2744
dircache_search_by_did
struct dir * dircache_search_by_did(const struct vol *vol, cnid_t did)
Search the dircache via a CNID for a directory.
Definition dircache.c:1137
dircache_process_deferred_chain
int dircache_process_deferred_chain(void)
Process one hash chain from the current deferred cleanup job.
Definition dircache.c:2823
dircache_dump
void dircache_dump(void)
Dump dircache to /tmp/dircache.PID.
Definition dircache.c:2252
dircache_remove_children
int dircache_remove_children(const struct vol *vol, struct dir *dir)
Remove all child entries of a directory from the dircache.
Definition dircache.c:1681
dircache_init
int dircache_init(int reqsize)
Initialize the dircache and indexes.
Definition dircache.c:1879
dircache_rfork_shutdown
void dircache_rfork_shutdown(void)
Shutdown the rfork cache — free remaining RFork LRU nodes and sentinel.
Definition dircache.c:2227
log_dircache_stat
void log_dircache_stat(void)
Log dircache statistics.
Definition dircache.c:2012
dircache_set_validation_params
int dircache_set_validation_params(unsigned int freq)
Set directory cache validation frequency.
Definition dircache.c:2469
dircache_has_deferred_work
int dircache_has_deferred_work(void)
Definition dircache.c:2809
dircache_search_by_name
struct dir * dircache_search_by_name(const struct vol *, const struct dir *dir, char *name, size_t len)
Search the cache via did/name hashtable.
Definition dircache.c:1299
dircache_remove_children_defer
void dircache_remove_children_defer(const struct vol *vol, struct dir *dir)
Enqueue a deferred dircache_remove_children operation.
Definition dircache.c:2699
dircache_reset_validation_counter
void dircache_reset_validation_counter(void)
Reset validation counter for consistent testing.
Definition dircache.c:2491
dircache_remove
void dircache_remove(const struct vol *, struct dir *, int flag)
Remove an entry from the dircache.
Definition dircache.c:1572
process_cache_hints
void process_cache_hints(AFPObj *obj)
Process cross-process dircache invalidation hints.
Definition dircache.c:2522
dircache_promote
void dircache_promote(struct dir *dir)
Promote a cache entry to signal recency.
Definition dircache.c:1835
dircache_report_invalid_entry
void dircache_report_invalid_entry(struct dir *dir)
Report that a cache entry was invalid when actually used.
Definition dircache.c:2677
dircache_add
int dircache_add(const struct vol *, struct dir *)
create struct dir from struct path
Definition dircache.c:1441
dircache_reindex_didname
int dircache_reindex_didname(const struct vol *vol, struct dir *dir)
Re-insert entry into DID/name index after key change.
Definition dircache.c:1803
vid
static uint16_t vid
Definition fuzz.c:51
globals.h
directory.h
volume.h
did
cnid_t did
Definition nad_cp.c:93
flag
#define flag(x)
Definition netacnv.c:15
obj
static AFPObj obj
Definition netatalk.c:69
q_t
qnode_t q_t
Definition queue.h:32
AFPObj
Definition globals.h:166
dir
Definition include/atalk/directory.h:56
vol
Definition include/atalk/volume.h:33