netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
server_ipc.h File Reference
`#include <stdint.h>`
`#include <atalk/cnid.h>`
`#include <atalk/globals.h>`
`#include <atalk/server_child.h>`

Go to the source code of this file.

## Data Structures
struct | ipc_cache_hint_payload

## Macros
#define | IPC_HEADERLEN 14
#define | IPC_MAXMSGSIZE 90
#define | IPC_DISCOLDSESSION 0
#define | IPC_GETSESSION 1
#define | IPC_STATE 2
#define | IPC_VOLUMES 3
#define | IPC_LOGINDONE 4
#define | IPC_CACHE_HINT 5
#define | IPC_SESSIONTOKEN 6
#define | CACHE_HINT_REFRESH 0
#define | CACHE_HINT_DELETE 1
#define | CACHE_HINT_DELETE_CHILDREN 2
#define | HINT_BUF_SIZE 128
#define | HINT_FLUSH_INTERVAL_MS 50

## Functions
int | ipc_server_read (server_child_t *children, int fd)
| Read a IPC message from a child.
int | ipc_child_write (AFPObj *obj, uint16_t command, size_t len, void *token)
int | ipc_child_state (AFPObj *obj, uint16_t state)
int | ipc_send_cache_hint (const AFPObj *obj, uint16_t vid, cnid_t cnid, uint8_t event)
| Send a dircache invalidation hint from child to parent.
unsigned long long | ipc_get_hints_sent (void)
unsigned long long | ipc_get_hints_dropped (void)
void | hint_flush_pending (server_child_t *children)
| Flush all buffered hints to sibling children.
int | hint_buf_count (void)
| Return current number of buffered hints.

## Macro Definition Documentation

## ◆ CACHE_HINT_DELETE

#define CACHE_HINT_DELETE 1

direct dir_remove() by CNID

## ◆ CACHE_HINT_DELETE_CHILDREN

#define CACHE_HINT_DELETE_CHILDREN 2

dircache_remove_children() + remove/refresh parent

## ◆ CACHE_HINT_REFRESH

#define CACHE_HINT_REFRESH 0

ostat + dir_modify(DCMOD_STAT)

## ◆ HINT_BUF_SIZE

#define HINT_BUF_SIZE 128

## ◆ HINT_FLUSH_INTERVAL_MS

#define HINT_FLUSH_INTERVAL_MS 50

## ◆ IPC_CACHE_HINT

#define IPC_CACHE_HINT 5

Cross-process dircache invalidation hint

## ◆ IPC_DISCOLDSESSION

#define IPC_DISCOLDSESSION 0

## ◆ IPC_GETSESSION

#define IPC_GETSESSION 1

## ◆ IPC_HEADERLEN

#define IPC_HEADERLEN 14

## ◆ IPC_LOGINDONE

#define IPC_LOGINDONE 4

## ◆ IPC_MAXMSGSIZE

#define IPC_MAXMSGSIZE 90

## ◆ IPC_SESSIONTOKEN

#define IPC_SESSIONTOKEN 6

pass opaque reconnect token

## ◆ IPC_STATE

#define IPC_STATE 2

pass AFP session state

## ◆ IPC_VOLUMES

#define IPC_VOLUMES 3

pass list of open volumes

## Function Documentation

## ◆ hint_buf_count()

int hint_buf_count | ( | void |  | ) |
| extern

Return current number of buffered hints.

Used by main event loop to decide poll timeout:

- count > 0: use HINT_FLUSH_INTERVAL_MS timeout
- count == 0: use -1 (infinite, block until event)

## ◆ hint_flush_pending()

void hint_flush_pending | ( | server_child_t * | children | ) |
| extern

Flush all buffered hints to sibling children.

Called from the parent main event loop when:

1. The 50ms poll timeout expires and hint_buf.count > 0
2. hint_buf.count reaches HINT_BUF_SIZE after ipc_server_read

Iterates the child table directly:

- Signals are blocked (no SIGCHLD can modify table)
- SIGCHLD already processed before flush (dead children removed)
- No other thread modifies the table

Performs priority sorting, PIPE_BUF-safe chunked writes.

While this function writes to child pipes, new IPC messages from children accumulate in the kernel socket buffer and are read on the next poll() iteration.

## ◆ ipc_child_state()

int ipc_child_state | ( | AFPObj * | obj,
|  | uint16_t | state )
| extern

## ◆ ipc_child_write()

int ipc_child_write | ( | AFPObj * | obj,
|  | uint16_t | command,
|  | size_t | len,
|  | void * | token )
| extern

## ◆ ipc_get_hints_dropped()

unsigned long long ipc_get_hints_dropped | ( | void |  | ) |
| extern

## ◆ ipc_get_hints_sent()

unsigned long long ipc_get_hints_sent | ( | void |  | ) |
| extern

## ◆ ipc_send_cache_hint()

int ipc_send_cache_hint | ( | const AFPObj * | obj,
|  | uint16_t | vid,
|  | cnid_t | cnid,
|  | uint8_t | event )
| extern

Send a dircache invalidation hint from child to parent.

Called directly from AFP command handlers that modify dircache state. Independent of the external FCE system — always active when IPC is available.

Uses a direct non-blocking write() to the IPC socketpair instead of ipc_child_write()/writet() — this ensures the AFP command handler is never blocked waiting for IPC buffer space. If the kernel socket buffer is full (parent not draining fast enough), the hint is silently dropped. Hints are best-effort optimizations, and the dircache validation mechanism & graceful fail-on-use detection makes drops safe.

The 22-byte message (14-byte IPC header + 8-byte payload) is well under the kernel socket buffer size, so partial writes cannot occur when space is available.

Parameters

  [in] | obj | AFPObj with ipc_fd
  [in] | vid | Volume ID (network byte order, matches vol->v_vid)
  [in] | cnid | CNID of affected file/dir (network byte order)
  [in] | event | Hint type: CACHE_HINT_REFRESH, CACHE_HINT_DELETE, or CACHE_HINT_DELETE_CHILDREN

Returns
  0 on success (or graceful drop), -1 on fatal error

## ◆ ipc_server_read()

int ipc_server_read | ( | server_child_t * | children,
|  | int | fd )
| extern

Read a IPC message from a child.

This is using an fd with non-blocking IO, so EAGAIN is not an error

Parameters

  [in,out] | children | pointer to our structure with all childs
  [in] | fd | IPC socket with child

Returns
  -1 on error, 0 on success