Documentation/Administrative Commands

From OpenZFS
Revision as of 00:59, 13 September 2013 by Mahrens (talk | contribs) (Created page with "This webpage describes the code flow when doing zfs administrative commands (/sbin/zfs subcommands that change state). We will look at the example of <code>zfs snapshot -r</c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This webpage describes the code flow when doing zfs administrative commands (/sbin/zfs subcommands that change state). We will look at the example of zfs snapshot -r 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 zfs_do_subcommand-name.
  • Call a libzfs function (zpool_log_history()) to log the command (see below for details)

snapshot subcommand

The snapshot subcommand's callback is zfs_do_snapshot. 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.

filesystem iteration

snapshot creation

libzfs_core

ioctl infrastructure

snapshot ioctl

DSL

synctask infrastructure

snapshot synctask

MOS sync

CLI history logging