netatalk  4.4.0dev
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
dircache.h File Reference
#include <sys/types.h>
#include <atalk/directory.h>
#include <atalk/volume.h>

Go to the source code of this file.

Macros

#define MAX_POSSIBLE_DIRCACHE_SIZE   131072
#define DIRCACHE_FREE_QUANTUM   256
#define DIRCACHE   (1 << 0)
#define DIDNAME_INDEX   (1 << 1)
#define QUEUE_INDEX   (1 << 2)
#define DIRCACHE_ALL   (DIRCACHE|DIDNAME_INDEX|QUEUE_INDEX)

Functions

int dircache_init (int reqsize)
 Initialize the dircache and indexes.
int dircache_add (const struct vol *, struct dir *)
 create struct dir from struct path
void dircache_remove (const struct vol *, struct dir *, int flag)
struct dirdircache_search_by_did (const struct vol *vol, cnid_t did)
 Search the dircache via a CNID for a directory.
struct dirdircache_search_by_name (const struct vol *, const struct dir *dir, char *name, int len)
 Search the cache via did/name hashtable.
void dircache_dump (void)
 Dump dircache to /tmp/dircache.PID.
void log_dircache_stat (void)
 Log dircache statistics.
int dircache_set_validation_params (unsigned int freq, unsigned int meta_win, unsigned int meta_thresh)
 Set directory cache validation parameters.
void dircache_reset_validation_counter (void)
 Reset validation counter for consistent testing.
void dircache_report_invalid_entry (struct dir *dir)
 Report that a cache entry was invalid when actually used.
void dircache_remove_children (const struct vol *vol, struct dir *dir)
 Remove all child entries of a directory from the dircache.

Macro Definition Documentation

◆ DIDNAME_INDEX

#define DIDNAME_INDEX   (1 << 1)

◆ DIRCACHE

#define DIRCACHE   (1 << 0)

◆ DIRCACHE_ALL

#define DIRCACHE_ALL   (DIRCACHE|DIDNAME_INDEX|QUEUE_INDEX)

◆ DIRCACHE_FREE_QUANTUM

#define DIRCACHE_FREE_QUANTUM   256

◆ MAX_POSSIBLE_DIRCACHE_SIZE

#define MAX_POSSIBLE_DIRCACHE_SIZE   131072

◆ QUEUE_INDEX

#define QUEUE_INDEX   (1 << 2)

Function Documentation

◆ dircache_add()

int dircache_add ( const struct vol * vol,
struct dir * dir )
extern

create struct dir from struct path

Add a struct dir to the cache and its indexes.

Parameters
vol(r) pointer to volume
dir(r) pointer to parent directory
Returns
0 on success, -1 on error which should result in an abort

◆ dircache_dump()

void dircache_dump ( void )
extern

Dump dircache to /tmp/dircache.PID.

◆ dircache_init()

int dircache_init ( int reqsize)
extern

Initialize the dircache and indexes.

This is called in child afpd initialization. The maximum cache size will be max(DEFAULT_MAX_DIRCACHE_SIZE, min(size, MAX_POSSIBLE_DIRCACHE_SIZE)). It initializes a hashtable which we use to store a directory cache in. It also initializes two indexes:

  • a DID/name index on the main dircache
  • a queue index on the dircache
Parameters
reqsize(r) requested maximum size from afp.conf
Returns
0 on success, -1 on error

◆ dircache_remove()

void dircache_remove ( const struct vol * ,
struct dir * ,
int flag )
extern

◆ dircache_remove_children()

void dircache_remove_children ( const struct vol * vol,
struct dir * dir )
extern

Remove all child entries of a directory from the dircache.

When a directory is renamed or moved, the full paths stored in the dircache become invalid for all child entries of the renamed dir. This function prunes orphaned child dircache entries of given dir. CNID entries use parent DIDs and name, and requre recursion to get the full path, therefore parent changes do not invalidate the CNIDs.

Parameters
vol(r) volume
dir(r) parent directory whose children should be removed

◆ dircache_report_invalid_entry()

void dircache_report_invalid_entry ( struct dir * dir)
extern

Report that a cache entry was invalid when actually used.

This function should be called when a cached directory entry that was returned without validation (for performance) turns out to be invalid when actually accessed (e.g., file doesn't exist, has been modified, etc). This helps track the effectiveness of the validation frequency setting.

Parameters
dir(r) The directory entry that was found to be invalid

◆ dircache_reset_validation_counter()

void dircache_reset_validation_counter ( void )
extern

Reset validation counter for consistent testing.

Resets the global validation counter to ensure predictable validation patterns between test runs or configuration changes.

◆ dircache_search_by_did()

struct dir * dircache_search_by_did ( const struct vol * vol,
cnid_t cnid )
extern

Search the dircache via a CNID for a directory.

Found cache entries are expunged if both the parent directory st_ctime and the objects st_ctime are modified. This func builds on the fact, that all our code only ever needs to and does search the dircache by CNID expecting directories to be returned, but not files. Thus (1) if we find a file for a given CNID we (1a) remove it from the cache (1b) return NULL indicating nothing found (2) we can then use d_fullpath to stat the directory

Parameters
vol(r) pointer to struct vol
cnid(r) CNID of the directory to search
Returns
Pointer to struct dir if found, else NULL

◆ dircache_search_by_name()

struct dir * dircache_search_by_name ( const struct vol * vol,
const struct dir * dir,
char * name,
int len )
extern

Search the cache via did/name hashtable.

Found cache entries are expunged if both the parent directory st_ctime and the objects st_ctime are modified.

Parameters
vol(r) volume
dir(r) directory
name(r) name (server side encoding)
len(r) strlen of name
Returns
pointer to struct dir if found in cache, else NULL

◆ dircache_set_validation_params()

int dircache_set_validation_params ( unsigned int freq,
unsigned int meta_win,
unsigned int meta_thresh )
extern

Set directory cache validation parameters.

Allows runtime configuration of cache validation behavior for performance tuning. Lower validation frequency improves performance but may delay detection of external filesystem changes.

Parameters
freq(r) validation frequency (1 = validate every access, 5 = every 5th access)
meta_win(r) metadata change time window in seconds
meta_thresh(r) metadata change threshold in seconds
Returns
0 on success, -1 on invalid parameters

◆ log_dircache_stat()

void log_dircache_stat ( void )
extern

Log dircache statistics.

Includes hit ratio percentage for monitoring cache effectiveness, validation-specific metrics to monitor performance impact of the optimization changes, and username for tracking per-user stats. Shows both expunged (caught by validation) and invalid_on_use (missed by validation).