Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.
Alex Blewitt edited this page Dec 11, 2010 · 1 revision
  1. summary How the user-land commands interact with the kernel-land commands
  2. labels Developer

Introduction

Most of the ZFS user level commands (zfs, zpool) are merely wrappers around instruction that get handed over to the kernel. These are executed with an `ioctl` call, which passes a number/argument to the appropriate routine in the kernel itself.

For example the zfs_iter_filesystems call invokes an `ioctl` with an argument `ZFS_IOC_DATASET_LIST_NEXT`. This corresponds to the macro ZFS_IOC_CMD(18), which ultimately ends up as `ioctl('Z',18,struct zfs_cmd)`.

In fact, `ioctl` is `#defined` to `app_ioctl` (defined in libzfs_util.c and mapped in libzfs_ioctl.h) so that the error number is appropriately copied across.

Kernel

The kernel receives the `ioctl` in the zfsdev_ioctl() call, which in turn looks up (based on index) the value in the zfs_ioc_vec array, which essentially is a list of function pointers, like zfs_ioc_dataset_list_next().

Ultimately, this function from the table gets invoked by invoking the zvec_func call, which has been bound to the function pointer from the lookup table.

Summary

  * Client invokes an `ioctl(ZFS_IOC_DATASET_LIST_NEXT)`, which is essentially `ioctl('Z',18,&zc)`
  * Gets mapped via the `app_ioctl()` macro to support re-acquisition of error number
  * Kernel receives `zfsdev_ioctl(, 18, &zc)`
  * Kernel looks up `zfs_ioc_vec[18]` to get function pointer `zfs_ioc_dataset_list_next`
  * Kernel invokes `zvec_func` which is the same as the acquired function pointer `zfs_ioc_dataset_list_next` in this case
  * Kernel steps into the `zfs_ios_dataset_list_next()` function

Ultimately, the client's invocation of an `ioctl` ZFS_IOC_FOO_BAR` will translate to a call `zfs_ioc_foo_bar()` in the `zfs_ioctl.c file

Clone this wiki locally