netatalk: cnid_dbd.c File Reference

netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
cnid_dbd.c File Reference
`#include <arpa/inet.h>`
`#include <errno.h>`
`#include <stdbool.h>`
`#include <stdint.h>`
`#include <net/if.h>`
`#include <netdb.h>`
`#include <netinet/in.h>`
`#include <netinet/tcp.h>`
`#include <stdlib.h>`
`#include <sys/param.h>`
`#include <sys/socket.h>`
`#include <sys/stat.h>`
`#include <sys/time.h>`
`#include <sys/uio.h>`
`#include <sys/un.h>`
`#include <signal.h>`
`#include <time.h>`
`#include <atalk/adouble.h>`
`#include <atalk/cnid_bdb_private.h>`
`#include <atalk/cnid.h>`
`#include <atalk/logger.h>`
`#include <atalk/util.h>`
`#include <atalk/volume.h>`
`#include "cnid_dbd.h"`

## Macros
#define | SOL_TCP IPPROTO_TCP
#define | MAX_DELAY 20
#define | ONE_DELAY 5

## Functions
static void | sig_handler (int signo)
static void | RQST_RESET (struct cnid_dbd_rqst *r)
static void | delay (int sec)
static int | tsock_getfd (const char *host, const char *port)
static int | write_vec (int fd, struct iovec *iov, ssize_t towrite, int vecs)
| Write "towrite" bytes using writev on non-blocking fd.
static int | init_tsock (CNID_bdb_private *db)
static int | send_packet (CNID_bdb_private *db, struct cnid_dbd_rqst *rqst)
static void | dbd_initstamp (struct cnid_dbd_rqst *rqst)
static int | dbd_reply_stamp (struct cnid_dbd_rply *rply)
static int | dbd_rpc (CNID_bdb_private *db, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
| send a request and get reply
static int | transmit_locked (CNID_bdb_private *db, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
| Inner transmit body, signal handlers must already be installed.
static int | transmit (CNID_bdb_private *db, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
static struct _cnid_db * | cnid_dbd_new (struct vol *vol)
struct _cnid_db * | cnid_dbd_open (struct cnid_open_args *args)
void | cnid_dbd_close (struct _cnid_db *cdb)
static int | cnid_dbd_stamp (CNID_bdb_private *db)
cnid_t | cnid_dbd_add (struct _cnid_db *cdb, const struct stat *st, cnid_t did, const char *name, size_t len, cnid_t hint)
cnid_t | cnid_dbd_get (struct _cnid_db *cdb, cnid_t did, const char *name, size_t len)
char * | cnid_dbd_resolve (struct _cnid_db *cdb, cnid_t *id, void *buffer, size_t len)
int | cnid_dbd_getstamp (struct _cnid_db *cdb, void *buffer, const size_t len)
cnid_t | cnid_dbd_lookup (struct _cnid_db *cdb, const struct stat *st, cnid_t did, const char *name, size_t len)
int | cnid_dbd_find (struct _cnid_db *cdb, const char *name, size_t namelen, void *buffer, size_t buflen, bool *more_available)
| Backend implementation of cnid_find() for the DBD daemon backend.
int | cnid_dbd_update (struct _cnid_db *cdb, cnid_t id, const struct stat *st, cnid_t did, const char *name, size_t len)
cnid_t | cnid_dbd_rebuild_add (struct _cnid_db *cdb, const struct stat *st, cnid_t did, const char *name, size_t len, cnid_t hint)
int | cnid_dbd_delete (struct _cnid_db *cdb, const cnid_t id)
int | cnid_dbd_wipe (struct _cnid_db *cdb)

## Variables
static volatile sig_atomic_t | stop_signal = 0
struct _cnid_module | cnid_dbd_module

## Macro Definition Documentation

## ◆ MAX_DELAY

#define MAX_DELAY 20

Wait MAX_DELAY seconds before a request to the CNID server times out

## ◆ ONE_DELAY

#define ONE_DELAY 5

## ◆ SOL_TCP

#define SOL_TCP IPPROTO_TCP

## Function Documentation

## ◆ cnid_dbd_add()

cnid_t cnid_dbd_add | ( | struct _cnid_db * | cdb,
|  | const struct stat * | st,
|  | cnid_t | did,
|  | const char * | name,
|  | size_t | len,
|  | cnid_t | hint )

## ◆ cnid_dbd_close()

void cnid_dbd_close | ( | struct _cnid_db * | cdb | ) |

## ◆ cnid_dbd_delete()

int cnid_dbd_delete | ( | struct _cnid_db * | cdb,
|  | const cnid_t | id )

## ◆ cnid_dbd_find()

int cnid_dbd_find | ( | struct _cnid_db * | cdb,
|  | const char * | name,
|  | size_t | namelen,
|  | void * | buffer,
|  | size_t | buflen,
|  | bool * | more_available )

Backend implementation of cnid_find() for the DBD daemon backend.

Parameter validation is performed once in the wrapper at libatalk/cnid/cnid.c. This function trusts that cdb, name, namelen, buffer and buflen are sane and focuses on driving the paginated SEARCH RPC to cnid_dbd.

The single cleanup path (goto out) ensures signal-handler restoration and more_available write-back happen in exactly one place — every error arm goes through it. *more_available is set to true if the result set was truncated by the daemon offset cap, the wall-clock deadline, signal-induced abort, or the buffer-fit guard; written only on success (the wrapper has already pre-zeroed it for error paths).

## ◆ cnid_dbd_get()

cnid_t cnid_dbd_get | ( | struct _cnid_db * | cdb,
|  | cnid_t | did,
|  | const char * | name,
|  | size_t | len )

## ◆ cnid_dbd_getstamp()

int cnid_dbd_getstamp | ( | struct _cnid_db * | cdb,
|  | void * | buffer,
|  | const size_t | len )

Caller passes buffer where we will store the db stamp

## ◆ cnid_dbd_lookup()

cnid_t cnid_dbd_lookup | ( | struct _cnid_db * | cdb,
|  | const struct stat * | st,
|  | cnid_t | did,
|  | const char * | name,
|  | size_t | len )

## ◆ cnid_dbd_new()

struct _cnid_db * cnid_dbd_new | ( | struct vol * | vol | ) |
| static

## ◆ cnid_dbd_open()

struct _cnid_db * cnid_dbd_open | ( | struct cnid_open_args * | args | ) |

## ◆ cnid_dbd_rebuild_add()

cnid_t cnid_dbd_rebuild_add | ( | struct _cnid_db * | cdb,
|  | const struct stat * | st,
|  | cnid_t | did,
|  | const char * | name,
|  | size_t | len,
|  | cnid_t | hint )

## ◆ cnid_dbd_resolve()

char * cnid_dbd_resolve | ( | struct _cnid_db * | cdb,
|  | cnid_t * | id,
|  | void * | buffer,
|  | size_t | len )

## ◆ cnid_dbd_stamp()

int cnid_dbd_stamp | ( | CNID_bdb_private * | db | ) |
| static

Get the db stamp

## ◆ cnid_dbd_update()

int cnid_dbd_update | ( | struct _cnid_db * | cdb,
|  | cnid_t | id,
|  | const struct stat * | st,
|  | cnid_t | did,
|  | const char * | name,
|  | size_t | len )

## ◆ cnid_dbd_wipe()

int cnid_dbd_wipe | ( | struct _cnid_db * | cdb | ) |

## ◆ dbd_initstamp()

void dbd_initstamp | ( | struct cnid_dbd_rqst * | rqst | ) |
| static

## ◆ dbd_reply_stamp()

int dbd_reply_stamp | ( | struct cnid_dbd_rply * | rply | ) |
| static

## ◆ dbd_rpc()

int dbd_rpc | ( | CNID_bdb_private * | db,
|  | struct cnid_dbd_rqst * | rqst,
|  | struct cnid_dbd_rply * | rply )
| static

send a request and get reply

Note
  assume send is non blocking
  if no answer after sometime (at least MAX_DELAY secondes) return an error

## ◆ delay()

void delay | ( | int | sec | ) |
| static

## ◆ init_tsock()

int init_tsock | ( | CNID_bdb_private * | db | ) |
| static

## ◆ RQST_RESET()

void RQST_RESET | ( | struct cnid_dbd_rqst * | r | ) |
| static

## ◆ send_packet()

int send_packet | ( | CNID_bdb_private * | db,
|  | struct cnid_dbd_rqst * | rqst )
| static

## ◆ sig_handler()

void sig_handler | ( | int | signo | ) |
| static

## ◆ transmit()

int transmit | ( | CNID_bdb_private * | db,
|  | struct cnid_dbd_rqst * | rqst,
|  | struct cnid_dbd_rply * | rply )
| static

## ◆ transmit_locked()

int transmit_locked | ( | CNID_bdb_private * | db,
|  | struct cnid_dbd_rqst * | rqst,
|  | struct cnid_dbd_rply * | rply )
| static

Inner transmit body, signal handlers must already be installed.

Caller must have installed sig_handler for SIGTERM/SIGINT and reset stop_signal to 0; otherwise the first loop iteration breaks immediately and returns -1 (which the caller would misread as an I/O failure).

Used directly by cnid_dbd_find()'s pagination loop, which installs sigaction once across all batches.

## ◆ tsock_getfd()

int tsock_getfd | ( | const char * | host,
|  | const char * | port )
| static

## ◆ write_vec()

int write_vec | ( | int | fd,
|  | struct iovec * | iov,
|  | ssize_t | towrite,
|  | int | vecs )
| static

Write "towrite" bytes using writev on non-blocking fd.

Every short write is considered an error, transmit can handle that.

Parameters

  [in] | fd | socket fd which must be non-blocking
  [in] | iov | iovec for writev
  [in] | towrite | number of bytes in all iovec elements
  [in] | vecs | number of iovecs in array

Returns
  "towrite" bytes written or -1 on error

## Variable Documentation

## ◆ cnid_dbd_module

struct _cnid_module cnid_dbd_module

Initial value:
= {
"dbd",
{NULL, NULL},
cnid_dbd_open,
0
}
cnid_dbd_open
struct _cnid_db * cnid_dbd_open(struct cnid_open_args *args)
Definition cnid_dbd.c:533
NULL
#define NULL
Definition utf8util.c:47

## ◆ stop_signal

volatile sig_atomic_t stop_signal = 0
| static