FreeBSD ZFS
The Zettabyte File System
Functions

zfs_onexit.c File Reference

ZFS callback routines on process exit. More...

#include <sys/types.h>
#include <sys/param.h>
#include <sys/errno.h>
#include <sys/kmem.h>
#include <sys/conf.h>
#include <sys/sunddi.h>
#include <sys/zfs_ioctl.h>
#include <sys/zfs_onexit.h>
#include <sys/zvol.h>
Include dependency graph for zfs_onexit.c:

Go to the source code of this file.

Functions

void zfs_onexit_init (zfs_onexit_t **zop)
void zfs_onexit_destroy (zfs_onexit_t *zo)
static int zfs_onexit_minor_to_state (minor_t minor, zfs_onexit_t **zo)
int zfs_onexit_fd_hold (int fd, minor_t *minorp)
 Consumers might need to operate by minor number instead of fd, since they might be running in another thread (e.g.
void zfs_onexit_fd_rele (int fd)
int zfs_onexit_add_cb (minor_t minor, void(*func)(void *), void *data, uint64_t *action_handle)
 Add a callback to be invoked when the calling process exits.
static zfs_onexit_action_node_tzfs_onexit_find_cb (zfs_onexit_t *zo, uint64_t action_handle)
int zfs_onexit_del_cb (minor_t minor, uint64_t action_handle, boolean_t fire)
 Delete the callback.
int zfs_onexit_cb_data (minor_t minor, uint64_t action_handle, void **data)
 Return the data associated with this callback.

Detailed Description

ZFS callback routines on process exit.

ZFS kernel routines may add/delete callback routines to be invoked upon process exit (triggered via the close operation from the /dev/zfs driver).

These cleanup callbacks are intended to allow for the accumulation of kernel state across multiple ioctls. User processes participate by opening ZFS_DEV with O_EXCL. This causes the ZFS driver to do a clone-open, generating a unique minor number. The process then passes along that file descriptor to each ioctl that might have a cleanup operation.

Consumers of the onexit routines should call zfs_onexit_fd_hold() early on to validate the given fd and add a reference to its file table entry. This allows the consumer to do its work and then add a callback, knowing that zfs_onexit_add_cb() won't fail with EBADF. When finished, consumers should call zfs_onexit_fd_rele().

A simple example is zfs_ioc_recv(), where we might create an AVL tree with dataset/GUID mappings and then reuse that tree on subsequent zfs_ioc_recv() calls.

On the first zfs_ioc_recv() call, dmu_recv_stream() will kmem_alloc() the AVL tree and pass it along with a callback function to zfs_onexit_add_cb(). The zfs_onexit_add_cb() routine will register the callback and return an action handle.

The action handle is then passed from user space to subsequent zfs_ioc_recv() calls, so that dmu_recv_stream() can fetch its AVL tree by calling zfs_onexit_cb_data() with the device minor number and action handle.

If the user process exits abnormally, the callback is invoked implicitly as part of the driver close operation. Once the user space process is finished with the accumulated kernel state, it can also just call close(2) on the cleanup fd to trigger the cleanup callback.

Definition in file zfs_onexit.c.


Function Documentation

int zfs_onexit_add_cb ( minor_t  minor,
void(*)(void *)  func,
void *  data,
uint64_t *  action_handle 
)

Add a callback to be invoked when the calling process exits.

Definition at line 155 of file zfs_onexit.c.

int zfs_onexit_cb_data ( minor_t  minor,
uint64_t  action_handle,
void **  data 
)

Return the data associated with this callback.

This allows consumers of the cleanup-on-exit interfaces to stash kernel data across system calls, knowing that it will be cleaned up if the calling process exits.

Definition at line 236 of file zfs_onexit.c.

int zfs_onexit_del_cb ( minor_t  minor,
uint64_t  action_handle,
boolean_t  fire 
)

Delete the callback.

Parameters:
[in]firetrigger the callback if set

Definition at line 204 of file zfs_onexit.c.

void zfs_onexit_destroy ( zfs_onexit_t zo)

Definition at line 87 of file zfs_onexit.c.

int zfs_onexit_fd_hold ( int  fd,
minor_t *  minorp 
)

Consumers might need to operate by minor number instead of fd, since they might be running in another thread (e.g.

txg_sync_thread). Callers of this function must call zfs_onexit_fd_rele() when they're finished using the minor number.

Definition at line 123 of file zfs_onexit.c.

void zfs_onexit_fd_rele ( int  fd)

Definition at line 146 of file zfs_onexit.c.

static zfs_onexit_action_node_t* zfs_onexit_find_cb ( zfs_onexit_t zo,
uint64_t  action_handle 
) [static]

Definition at line 181 of file zfs_onexit.c.

void zfs_onexit_init ( zfs_onexit_t **  zop)

Definition at line 76 of file zfs_onexit.c.

static int zfs_onexit_minor_to_state ( minor_t  minor,
zfs_onexit_t **  zo 
) [static]

Definition at line 107 of file zfs_onexit.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines