Documentation/Administrative Commands

This webpage describes the code flow when doing zfs administrative commands (/sbin/zfs subcommands that change state). We will look at the example of  and examine what each layer of code is responsible for. This is intended as an introduction to the many layers of ZFS, so we won't go into detail on how snapshots are implemented. You can read more about snapshots in an old blog post.

/sbin/zfs infrastructure
The generic (subcommand agnostic) infrastructure of the zfs command does the following:
 * Create a libzfs handle (libzfs_init).
 * Determine which subcommand should be executed and run it.
 * Each zfs subcommand has a callback, typically named.
 * Call a libzfs function (zpool_log_history) to log the command (see below for details)

snapshot subcommand
The snapshot subcommand's callback is. It does the following:
 * Parse the command line arguments.
 * Create a list of the snapshots that need to be created.
 * Call a libzfs function (zfs_iter_filesystems) to iterate over the descendent filesystems, adding the snapshot of that filesystem to the list
 * Call a libzfs function (zfs_snapshot_nvl) to create the snapshots and handle any errors.

libzfs
We saw two uses of libzfs: iterating over the descendent filesystems, and creating the snapshots.