netatalk  4.6.0
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; the default is DEFAULT_DIRCACHE_SIZE in
26 * atalk/globals.h (included above) */
27#define MIN_DIRCACHE_SIZE 1024 /* 1K minimum (testing/constrained systems) */
28#define MAX_DIRCACHE_SIZE 1048576 /* 1M maximum (high-memory servers) */
29#define DIRCACHE_FREE_QUANTUM 256
30
31/* Batch collect bound per chain scan; iw_can_work re-checked per removal */
32#define DEFERRED_CHAIN_BATCH 16
33
34/* flags for dircache_remove */
35#define DIRCACHE (1 << 0)
36#define DIDNAME_INDEX (1 << 1)
37#define QUEUE_INDEX (1 << 2)
38#define DIRCACHE_NOSHRINK (1 << 3) /* Skip hash table shrink */
39#define DIRCACHE_ALL (DIRCACHE|DIDNAME_INDEX|QUEUE_INDEX)
40
42extern qnode_t *arc_ghost_trim_candidate(q_t *q, const struct dir *skip);
43extern void dircache_purge_vol(const struct vol *vol);
44extern int dircache_init(int reqsize);
45extern int dircache_add(const struct vol *, struct dir *);
46extern void dircache_remove(const struct vol *, struct dir *, int flag);
47extern struct dir *dircache_search_by_did(const struct vol *vol, cnid_t did);
48extern struct dir *dircache_lookup_parent(const struct vol *vol, cnid_t did);
49extern struct dir *dircache_search_by_name(const struct vol *,
50 const struct dir *dir, char *name, size_t len);
51
52extern void dircache_dump(void);
53extern void log_dircache_stat(void);
54extern unsigned int dircache_resolve_size(int reqsize);
55extern void dircache_reset_validation_counter(void);
56extern void dircache_report_invalid_entry(struct dir *dir);
57extern int dircache_remove_children(const struct vol *vol,
58 struct dir *dir);
59extern int dircache_reindex_didname(const struct vol *vol,
60 struct dir *dir);
61extern void dircache_promote(struct dir *dir);
62extern void process_cache_hints(AFPObj *obj);
63extern void dircache_remove_children_defer(const struct vol *vol,
64 struct dir *dir);
65extern void dircache_flush_deferred_for_vol(uint16_t vid);
66extern int dircache_has_deferred_work(void);
67extern int dircache_process_deferred_chain(void);
68extern void dircache_rfork_shutdown(void);
69
70/* Tier 2: Resource Fork data cache */
71extern size_t rfork_cache_used;
72extern size_t rfork_cache_budget;
73extern size_t rfork_max_entry_size;
74extern unsigned int rfork_lru_count;
75extern q_t *rfork_lru;
76
77/* Tier 2: Resource Fork data cache statistics */
78extern unsigned long long rfork_stat_lookups;
79extern unsigned long long rfork_stat_hits;
80extern unsigned long long rfork_stat_misses;
81extern unsigned long long rfork_stat_added;
82extern unsigned long long rfork_stat_evicted;
83extern unsigned long long rfork_stat_invalidated;
84extern size_t rfork_stat_used_max;
85
86#endif /* DIRCACHE_H */
uint32_t cnid_t
Definition adouble.h:157
struct dir * dircache_search_by_name(const struct vol *vol, const struct dir *dir, char *name, size_t len)
Search the cache via did/name hashtable.
Definition dircache.c:1585
void dircache_flush_deferred_for_vol(uint16_t vid)
Process deferred cleanup entries for a closing volume synchronously.
Definition dircache.c:3170
void dircache_purge_vol(const struct vol *vol)
Release every cache entry belonging to a closing volume.
Definition dircache.c:492
struct dir * dircache_search_by_did(const struct vol *vol, cnid_t cnid)
Search the dircache via a CNID for a directory.
Definition dircache.c:1437
unsigned long long rfork_stat_evicted
Definition dircache.c:232
int dircache_process_deferred_chain(void)
Process one unit of deferred cleanup.
Definition dircache.c:3581
void dircache_dump(void)
Dump dircache to /tmp/dircache.PID.
Definition dircache.c:2617
int dircache_remove_children(const struct vol *vol, struct dir *dir)
Remove all child entries of a directory from the dircache.
Definition dircache.c:2051
int dircache_init(int reqsize)
Initialize the dircache and indexes.
Definition dircache.c:2274
struct dir * dircache_lookup_parent(const struct vol *vol, cnid_t did)
Plain index probe for pfd_cache parent resolution.
Definition dircache.c:1393
size_t rfork_cache_budget
Definition dircache.c:243
unsigned int dircache_resolve_size(int reqsize)
Resolve a requested dircache size to the effective maximum.
Definition dircache.c:2230
void dircache_rfork_shutdown(void)
Shutdown the rfork cache — free remaining RFork LRU nodes and sentinel.
Definition dircache.c:2592
size_t rfork_max_entry_size
Definition dircache.c:245
unsigned long long rfork_stat_added
Definition dircache.c:231
void log_dircache_stat(void)
Log dircache statistics.
Definition dircache.c:2375
int dircache_add(const struct vol *vol, struct dir *dir)
create struct dir from struct path
Definition dircache.c:1743
unsigned int rfork_lru_count
Definition dircache.c:247
size_t rfork_stat_used_max
Definition dircache.c:234
unsigned long long rfork_stat_hits
Definition dircache.c:229
unsigned long long rfork_stat_misses
Definition dircache.c:230
void dircache_remove(const struct vol *vol, struct dir *dir, int flags)
Remove an entry from the dircache.
Definition dircache.c:1909
unsigned long long rfork_stat_lookups
Definition dircache.c:228
int dircache_has_deferred_work(void)
Definition dircache.c:3236
q_t * rfork_lru
Definition dircache.c:249
size_t rfork_cache_used
Definition dircache.c:241
void dircache_remove_children_defer(const struct vol *vol, struct dir *dir)
Enqueue a deferred dircache_remove_children operation.
Definition dircache.c:3086
void dircache_reset_validation_counter(void)
Reset validation counter for consistent testing.
Definition dircache.c:2831
qnode_t * arc_ghost_trim_candidate(q_t *q, const struct dir *skip)
Pick the ghost to release from a list at capacity.
Definition dircache.c:571
void process_cache_hints(AFPObj *obj)
Process cross-process dircache invalidation hints.
Definition dircache.c:2862
void dircache_promote(struct dir *dir)
Promote a cache entry to signal recency.
Definition dircache.c:2189
void dircache_report_invalid_entry(struct dir *dir)
Report that a cache entry was invalid when actually used.
Definition dircache.c:3064
unsigned long long rfork_stat_invalidated
Definition dircache.c:233
int dircache_reindex_didname(const struct vol *vol, struct dir *dir)
Re-insert entry into DID/name index after key change.
Definition dircache.c:2141
cnid_t did
Definition nad_cp.c:92
#define flag(x)
Definition netacnv.c:15
qnode_t q_t
Definition queue.h:32
struct qnode qnode_t
Definition globals.h:190
Definition include/atalk/directory.h:72
Definition include/atalk/volume.h:33