# Welcome to pyzfs’s documentation!

Contents:

# Indices and tables

- Index

- Module Index

- Search Page

## Documentation for the libzfs_core

Python wrappers for libzfs_core library.

libzfs_core is intended to be a stable, committed interface for programmatic administration of ZFS. This wrapper provides one-to-one wrappers for libzfs_core API functions, but the signatures and types are more natural to Python. nvlists are wrapped as dictionaries or lists depending on their usage. Some parameters have default values depending on typical use for increased convenience. Output parameters are not used and return values are directly returned. Enumerations and bit flags become strings and lists of strings in Python. Errors are reported as exceptions rather than integer errno-style error codes. The wrapper takes care to provide one-to-many mapping of the error codes to the exceptions by interpreting a context in which the error code is produced.

To submit an issue or contribute to development of this package please visit its GitHub repository.

libzfs_core.MAXNAMELEN

  Maximum length of any ZFS name.

libzfs_core.lzc_bookmark(bookmarks)

  Create bookmarks.

  Parameters:

    bookmarks (dict of bytes to bytes) – a dict that maps names of wanted bookmarks to names of existing snapshots or bookmarks.

  Raises:

    BookmarkFailure – if any of the bookmarks can not be created for any reason.

  The bookmarks dict maps from name of the bookmark (e.g. `pool/fs#bmark`) to the name of the snapshot (e.g. `pool/fs@snap`) or existint bookmark `pool/fs@snap`. All the bookmarks and snapshots must be in the same pool.

libzfs_core.lzc_change_key(fsname, crypt_cmd, props=None, key=None)

  Change encryption key on the specified dataset.

  Parameters:

    - fsname (bytes) – the name of the dataset.

    - crypt_cmd (str) – the encryption “command” to be executed, currently supported values are “new_key”, “inherit”, “force_new_key” and “force_inherit”.

    - props (dict of bytes:Any) – a dict of encryption-related property name-value pairs; only “keyformat”, “keylocation” and “pbkdf2iters” are supported (empty by default).

    - key (bytes) – dataset encryption key data (empty by default).

  Raises:

    - PropertyInvalid – if `props` contains invalid values.

    - FilesystemNotFound – if the dataset does not exist.

    - UnknownCryptCommand – if `crypt_cmd` is invalid.

    - EncryptionKeyNotLoaded – if the encryption key is not currently loaded and therefore cannot be changed.

libzfs_core.lzc_channel_program(poolname, program, instrlimit=10000000, memlimit=10485760, params=None)

  Executes a script as a ZFS channel program on pool `poolname`.

  Parameters:

    - poolname (bytes) – the name of the pool.

    - program (bytes) – channel program text.

    - instrlimit (int) – execution time limit, in milliseconds.

    - memlimit (int) – execution memory limit, in bytes.

    - params (dict of bytes:Any) – a list of parameters passed to the channel program (empty by default).

  Returns:

    a dictionary of result values procuced by the channel program, if any.

  Return type:

    dict

  Raises:

    - PoolNotFound – if the pool does not exist.

    - ZCPLimitInvalid – if either instruction or memory limit are invalid.

    - ZCPSyntaxError – if the channel program contains syntax errors.

    - ZCPTimeout – if the channel program took too long to execute.

    - ZCPSpaceError – if the channel program exhausted the memory limit.

    - ZCPMemoryError – if the channel program return value was too large.

    - ZCPPermissionError – if the user lacks the permission to run the channel program. Channel programs must be run as root.

    - ZCPRuntimeError – if the channel program encountered a runtime error.

libzfs_core.lzc_channel_program_nosync(poolname, program, instrlimit=10000000, memlimit=10485760, params=None)

  Executes a script as a read-only ZFS channel program on pool `poolname`. A read-only channel program works programmatically the same way as a normal channel program executed with `lzc_channel_program()`. The only difference is it runs exclusively in open-context and therefore can return faster. The downside to that, is that the program cannot change on-disk state by calling functions from the zfs.sync submodule.

  Parameters:

    - poolname (bytes) – the name of the pool.

    - program (bytes) – channel program text.

    - instrlimit (int) – execution time limit, in milliseconds.

    - memlimit (int) – execution memory limit, in bytes.

    - params (dict of bytes:Any) – a list of parameters passed to the channel program (empty by default).

  Returns:

    a dictionary of result values procuced by the channel program, if any.

  Return type:

    dict

  Raises:

    - PoolNotFound – if the pool does not exist.

    - ZCPLimitInvalid – if either instruction or memory limit are invalid.

    - ZCPSyntaxError – if the channel program contains syntax errors.

    - ZCPTimeout – if the channel program took too long to execute.

    - ZCPSpaceError – if the channel program exhausted the memory limit.

    - ZCPMemoryError – if the channel program return value was too large.

    - ZCPPermissionError – if the user lacks the permission to run the channel program. Channel programs must be run as root.

    - ZCPRuntimeError – if the channel program encountered a runtime error.

libzfs_core.lzc_clone(name, origin, props=None)

  Clone a ZFS filesystem or a ZFS volume (“zvol”) from a given snapshot.

  Parameters:

    - name (bytes) – a name of the dataset to be created.

    - origin (bytes) – a name of the origin snapshot.

    - props (dict of bytes:Any) – a dict of ZFS dataset property name-value pairs (empty by default).

  Raises:

    - FilesystemExists – if a dataset with the given name already exists.

    - DatasetNotFound – if either a parent dataset of the requested dataset or the origin snapshot does not exist.

    - PropertyInvalid – if one or more of the specified properties is invalid or has an invalid type or value.

    - FilesystemNameInvalid – if the name is not a valid dataset name.

    - SnapshotNameInvalid – if the origin is not a valid snapshot name.

    - NameTooLong – if the name or the origin name is too long.

    - PoolsDiffer – if the clone and the origin have different pool names.

  Note

  Because of a deficiency of the underlying C interface `DatasetNotFound` can mean that either a parent filesystem of the target or the origin snapshot does not exist. It is currently impossible to distinguish between the cases. `lzc_hold()` can be used to check that the snapshot exists and ensure that it is not destroyed before cloning.

libzfs_core.lzc_create(name, ds_type='zfs', props=None, key=None)

  Create a ZFS filesystem or a ZFS volume (“zvol”).

  Parameters:

    - name (bytes) – a name of the dataset to be created.

    - ds_type (str) – the type of the dataset to be created, currently supported types are “zfs” (the default) for a filesystem and “zvol” for a volume.

    - props (dict of bytes:Any) – a dict of ZFS dataset property name-value pairs (empty by default).

    - key (bytes) – dataset encryption key data (empty by default).

  Raises:

    - FilesystemExists – if a dataset with the given name already exists.

    - ParentNotFound – if a parent dataset of the requested dataset does not exist.

    - PropertyInvalid – if one or more of the specified properties is invalid or has an invalid type or value.

    - NameInvalid – if the name is not a valid dataset name.

    - NameTooLong – if the name is too long.

    - WrongParent – if the parent dataset of the requested dataset is not a filesystem (e.g. ZVOL)

libzfs_core.lzc_destroy_bookmarks(bookmarks)

  Destroy bookmarks.

  Parameters:

    bookmarks (list of bytes) – a list of the bookmarks to be destroyed. The bookmarks are specified as `fs#bmark`.

  Raises:

    BookmarkDestructionFailure – if any of the bookmarks may not be destroyed.

  The bookmarks must all be in the same pool. Bookmarks that do not exist will be silently ignored. This also includes the case where the filesystem component of the bookmark name does not exist. However, an invalid bookmark name will cause `NameInvalid` error reported in `SnapshotDestructionFailure.errors`.

  Either all bookmarks that existed are destroyed or an exception is raised.

libzfs_core.lzc_destroy_snaps(snaps, defer)

  Destroy snapshots.

  They must all be in the same pool. Snapshots that do not exist will be silently ignored.

  If ‘defer’ is not set, and a snapshot has user holds or clones, the destroy operation will fail and none of the snapshots will be destroyed.

  If ‘defer’ is set, and a snapshot has user holds or clones, it will be marked for deferred destruction, and will be destroyed when the last hold or clone is removed/destroyed.

  The operation succeeds if all snapshots were destroyed (or marked for later destruction if ‘defer’ is set) or didn’t exist to begin with.

  Parameters:

    - snaps (list of bytes) – a list of names of snapshots to be destroyed.

    - defer (bool) – whether to mark busy snapshots for deferred destruction rather than immediately failing.

  Raises:

    SnapshotDestructionFailure – if one or more snapshots could not be created.

  Note

  `SnapshotDestructionFailure` is a compound exception that provides at least one detailed error object in `SnapshotDestructionFailure.errors` list.

  Typical error is `SnapshotIsCloned` if defer is False. The snapshot names are validated quite loosely and invalid names are typically ignored as nonexisting snapshots.

  A snapshot name referring to a filesystem that doesn’t exist is ignored. However, non-existent pool name causes `PoolNotFound`.

libzfs_core.lzc_exists(name)

  Check if a dataset (a filesystem, or a volume, or a snapshot) with the given name exists.

  Parameters:

    name (bytes) – the dataset name to check.

  Returns:

    True if the dataset exists, False otherwise.

  Return type:

    bool

  Note

  `lzc_exists` can not be used to check for existence of bookmarks.

libzfs_core.lzc_get_bookmarks(fsname, props=None)

  Retrieve a listing of bookmarks for the given file system.

  Parameters:

    - fsname (bytes) – a name of the filesystem.

    - props (list of bytes) – a list of properties that will be returned for each bookmark.

  Returns:

    a dict that maps the bookmarks’ short names to their properties.

  Return type:

    dict of bytes:dict

  Raises:

    FilesystemNotFound – if the filesystem is not found.

  The following are valid properties on bookmarks:

  guidinteger

    globally unique identifier of the snapshot the bookmark refers to

  createtxginteger

    txg when the snapshot the bookmark refers to was created

  creationinteger

    timestamp when the snapshot the bookmark refers to was created

  Any other properties passed in `props` are ignored without reporting any error. Values in the returned dictionary map the names of the requested properties to their respective values.

libzfs_core.lzc_get_holds(snapname)

  Retrieve list of user holds on the specified snapshot.

  Parameters:

    snapname (bytes) – the name of the snapshot.

  Returns:

    holds on the snapshot along with their creation times in seconds since the epoch

  Return type:

    dict of bytes : int

libzfs_core.lzc_hold(holds, fd=None)

  Create user holds on snapshots. If there is a hold on a snapshot, the snapshot can not be destroyed. (However, it can be marked for deletion by `lzc_destroy_snaps()` ( `defer` = True ).)

  Parameters:

    - holds (dict of bytes : bytes) – the dictionary of names of the snapshots to hold mapped to the hold names.

    - fd (int or None) – if not None then it must be the result of `os.open()` called as `os.open("/dev/zfs", O_EXCL)`.

  Returns:

    a list of the snapshots that do not exist.

  Return type:

    list of bytes

  Raises:

    - HoldFailure – if a hold was impossible on one or more of the snapshots.

    - BadHoldCleanupFD – if `fd` is not a valid file descriptor associated with `/dev/zfs`.

  The snapshots must all be in the same pool.

  If `fd` is not None, then when the `fd` is closed (including on process termination), the holds will be released. If the system is shut down uncleanly, the holds will be released when the pool is next opened or imported.

  Holds for snapshots which don’t exist will be skipped and have an entry added to the return value, but will not cause an overall failure. No exceptions is raised if all holds, for snapshots that existed, were successfully created. Otherwise `HoldFailure` exception is raised and no holds will be created. `HoldFailure.errors` may contain a single element for an error that is not specific to any hold / snapshot, or it may contain one or more elements detailing specific error per each affected hold.

libzfs_core.lzc_load_key(fsname, noop, key)

  Load or verify encryption key on the specified dataset.

  Parameters:

    - fsname (bytes) – the name of the dataset.

    - noop (bool) – if True the encryption key will only be verified, not loaded.

    - key (bytes) – dataset encryption key data.

  Raises:

    - FilesystemNotFound – if the dataset does not exist.

    - EncryptionKeyAlreadyLoaded – if the encryption key is already loaded.

    - EncryptionKeyInvalid – if the encryption key provided is incorrect.

libzfs_core.lzc_pool_checkpoint(name)

  Creates a checkpoint for the specified pool.

  Parameters:

    name (bytes) – the name of the pool to create a checkpoint for.

  Raises:

    - CheckpointExists – if the pool already has a checkpoint.

    - CheckpointDiscarding – if ZFS is in the middle of discarding a checkpoint for this pool.

    - DeviceRemovalRunning – if a vdev is currently being removed.

    - DeviceTooBig – if one or more top-level vdevs exceed the maximum vdev size.

libzfs_core.lzc_pool_checkpoint_discard(name)

  Discard the checkpoint from the specified pool.

  Parameters:

    name (bytes) – the name of the pool to discard the checkpoint from.

  Raises:

    - CheckpointNotFound – if pool does not have a checkpoint.

    - CheckpointDiscarding – if ZFS is in the middle of discarding a checkpoint for this pool.

libzfs_core.lzc_promote(name)

  Promotes the ZFS dataset.

  Parameters:

    name (bytes) – the name of the dataset to promote.

  Raises:

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

    - NameTooLong – if the dataset’s origin has a snapshot that, if transferred to the dataset, would get a too long name.

    - NotClone – if the dataset is not a clone.

    - FilesystemNotFound – if the dataset does not exist.

    - SnapshotExists – if the dataset already has a snapshot with the same name as one of the origin’s snapshots.

libzfs_core.lzc_receive(snapname, fd, force=False, raw=False, origin=None, props=None)

  Receive from the specified `fd`, creating the specified snapshot.

  Parameters:

    - snapname (bytes) – the name of the snapshot to create.

    - fd (int) – the file descriptor from which to read the stream.

    - force (bool) – whether to roll back or destroy the target filesystem if that is required to receive the stream.

    - raw (bool) – whether this is a “raw” stream.

    - origin (bytes or None) – the optional origin snapshot name if the stream is for a clone.

    - props (dict of bytes : Any) – the properties to set on the snapshot as received properties.

  Raises:

    - IOError – if an input / output error occurs while reading from the `fd`.

    - DatasetExists – if the snapshot named `snapname` already exists.

    - DatasetExists – if the stream is a full stream and the destination filesystem already exists.

    - DatasetExists – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot exists and it is an origin of a cloned filesystem.

    - StreamMismatch – if an incremental stream is received and the latest snapshot of the destination filesystem does not match the source snapshot of the stream.

    - StreamMismatch – if a full stream is received and the destination filesystem already exists and it has at least one snapshot, and `force` is False.

    - StreamMismatch – if an incremental clone stream is received but the specified `origin` is not the actual received origin.

    - DestinationModified – if an incremental stream is received and the destination filesystem has been modified since the last snapshot and `force` is False.

    - DestinationModified – if a full stream is received and the destination filesystem already exists and it does not have any snapshots, and `force` is False.

    - DatasetNotFound – if the destination filesystem and its parent do not exist.

    - DatasetNotFound – if the `origin` is not None and does not exist.

    - DatasetBusy – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot is held and could not be destroyed.

    - DatasetBusy – if another receive operation is being performed on the destination filesystem.

    - BadStream – if the stream is corrupt or it is not recognized or it is a compound stream or it is a clone stream, but `origin` is None.

    - BadStream – if a clone stream is received and the destination filesystem already exists.

    - StreamFeatureNotSupported – if the stream has a feature that is not supported on this side.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

    - WrongParent – if the parent dataset of the received destination is not a filesystem (e.g. ZVOL)

  Note

  The `origin` is ignored if the actual stream is an incremental stream that is not a clone stream and the destination filesystem exists. If the stream is a full stream and the destination filesystem does not exist then the `origin` is checked for existence: if it does not exist `DatasetNotFound` is raised, otherwise `StreamMismatch` is raised, because that snapshot can not have any relation to the stream.

  Note

  If `force` is True and the stream is incremental then the destination filesystem is rolled back to a matching source snapshot if necessary. Intermediate snapshots are destroyed in that case.

  However, none of the existing snapshots may have the same name as `snapname` even if such a snapshot were to be destroyed. The existing `snapname` snapshot always causes `SnapshotExists` to be raised.

  If `force` is True and the stream is a full stream then the destination filesystem is replaced with the received filesystem unless the former has any snapshots. This prevents the destination filesystem from being rolled back / replaced.

  Note

  This interface does not work on dedup’d streams (those with `DMU_BACKUP_FEATURE_DEDUP`).

  Note

  `lzc_receive` does not return until all of the stream is read from `fd` and applied to the pool.

  Note

  `lzc_receive` does not close `fd` upon returning.

libzfs_core.lzc_receive_one(snapname, fd, begin_record, force=False, resumable=False, raw=False, origin=None, props=None, cleanup_fd=-1, action_handle=0)

  Like `lzc_receive()`, but allows the caller to pass all supported arguments and retrieve all values returned. The only additional input parameter is ‘cleanup_fd’ which is used to set a cleanup-on-exit file descriptor.

  Parameters:

    - snapname (bytes) – the name of the snapshot to create.

    - fd (int) – the file descriptor from which to read the stream.

    - begin_record (`cffi` CData representing the dmu_replay_record_t structure.) – the stream’s begin record.

    - force (bool) – whether to roll back or destroy the target filesystem if that is required to receive the stream.

    - resumable (bool) – whether this stream should be treated as resumable. If the receive fails due to premature stream termination, the intermediate state will be preserved on disk and may subsequently be resumed with `lzc_send_resume()`.

    - raw (bool) – whether this is a “raw” stream.

    - origin (bytes or None) – the optional origin snapshot name if the stream is for a clone.

    - props (dict of bytes : Any) – the properties to set on the snapshot as received properties.

    - cleanup_fd (int) – file descriptor used to set a cleanup-on-exit file descriptor.

    - action_handle (int) – variable used to pass the handle for guid/ds mapping: this should be set to zero on first call and will contain an updated handle on success, which should be passed in subsequent calls.

  Returns:

    a tuple with two elements where the first one is the number of bytes read from the file descriptor and the second one is the action_handle return value.

  Raises:

    - IOError – if an input / output error occurs while reading from the `fd`.

    - DatasetExists – if the snapshot named `snapname` already exists.

    - DatasetExists – if the stream is a full stream and the destination filesystem already exists.

    - DatasetExists – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot exists and it is an origin of a cloned filesystem.

    - StreamMismatch – if an incremental stream is received and the latest snapshot of the destination filesystem does not match the source snapshot of the stream.

    - StreamMismatch – if a full stream is received and the destination filesystem already exists and it has at least one snapshot, and `force` is False.

    - StreamMismatch – if an incremental clone stream is received but the specified `origin` is not the actual received origin.

    - DestinationModified – if an incremental stream is received and the destination filesystem has been modified since the last snapshot and `force` is False.

    - DestinationModified – if a full stream is received and the destination filesystem already exists and it does not have any snapshots, and `force` is False.

    - DatasetNotFound – if the destination filesystem and its parent do not exist.

    - DatasetNotFound – if the `origin` is not None and does not exist.

    - DatasetBusy – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot is held and could not be destroyed.

    - DatasetBusy – if another receive operation is being performed on the destination filesystem.

    - BadStream – if the stream is corrupt or it is not recognized or it is a compound stream or it is a clone stream, but `origin` is None.

    - BadStream – if a clone stream is received and the destination filesystem already exists.

    - StreamFeatureNotSupported – if the stream has a feature that is not supported on this side.

    - ReceivePropertyFailure – if one or more of the specified properties is invalid or has an invalid type or value.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

libzfs_core.lzc_receive_resumable(snapname, fd, force=False, raw=False, origin=None, props=None)

  Like `lzc_receive()`, but if the receive fails due to premature stream termination, the intermediate state will be preserved on disk. In this case, ECKSUM will be returned. The receive may subsequently be resumed with a resuming send stream generated by lzc_send_resume().

  Parameters:

    - snapname (bytes) – the name of the snapshot to create.

    - fd (int) – the file descriptor from which to read the stream.

    - force (bool) – whether to roll back or destroy the target filesystem if that is required to receive the stream.

    - raw (bool) – whether this is a “raw” stream.

    - origin (bytes or None) – the optional origin snapshot name if the stream is for a clone.

    - props (dict of bytes : Any) – the properties to set on the snapshot as received properties.

  Raises:

    - IOError – if an input / output error occurs while reading from the `fd`.

    - DatasetExists – if the snapshot named `snapname` already exists.

    - DatasetExists – if the stream is a full stream and the destination filesystem already exists.

    - DatasetExists – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot exists and it is an origin of a cloned filesystem.

    - StreamMismatch – if an incremental stream is received and the latest snapshot of the destination filesystem does not match the source snapshot of the stream.

    - StreamMismatch – if a full stream is received and the destination filesystem already exists and it has at least one snapshot, and `force` is False.

    - StreamMismatch – if an incremental clone stream is received but the specified `origin` is not the actual received origin.

    - DestinationModified – if an incremental stream is received and the destination filesystem has been modified since the last snapshot and `force` is False.

    - DestinationModified – if a full stream is received and the destination filesystem already exists and it does not have any snapshots, and `force` is False.

    - DatasetNotFound – if the destination filesystem and its parent do not exist.

    - DatasetNotFound – if the `origin` is not None and does not exist.

    - DatasetBusy – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot is held and could not be destroyed.

    - DatasetBusy – if another receive operation is being performed on the destination filesystem.

    - BadStream – if the stream is corrupt or it is not recognized or it is a compound stream or it is a clone stream, but `origin` is None.

    - BadStream – if a clone stream is received and the destination filesystem already exists.

    - StreamFeatureNotSupported – if the stream has a feature that is not supported on this side.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

libzfs_core.lzc_receive_with_cmdprops(snapname, fd, begin_record, force=False, resumable=False, raw=False, origin=None, props=None, cmdprops=None, key=None, cleanup_fd=-1, action_handle=0)

  Like `lzc_receive_one()`, but allows the caller to pass an additional ‘cmdprops’ argument. The ‘cmdprops’ nvlist contains both override (‘zfs receive -o’) and exclude (‘zfs receive -x’) properties.

  Parameters:

    - snapname (bytes) – the name of the snapshot to create.

    - fd (int) – the file descriptor from which to read the stream.

    - begin_record (`cffi` CData representing the dmu_replay_record_t structure.) – the stream’s begin record.

    - force (bool) – whether to roll back or destroy the target filesystem if that is required to receive the stream.

    - resumable (bool) – whether this stream should be treated as resumable. If the receive fails due to premature stream termination, the intermediate state will be preserved on disk and may subsequently be resumed with `lzc_send_resume()`.

    - raw (bool) – whether this is a “raw” stream.

    - origin (bytes or None) – the optional origin snapshot name if the stream is for a clone.

    - props (dict of bytes : Any) – the properties to set on the snapshot as received properties.

    - cmdprops (dict of bytes : Any) – the properties to set on the snapshot as local overrides to received properties. bool values are forcefully inherited while every other value is set locally as if the command “zfs set” was invoked immediately before the receive.

    - key (bytes) – raw bytes representing user’s wrapping key

    - cleanup_fd (int) – file descriptor used to set a cleanup-on-exit file descriptor.

    - action_handle (int) – variable used to pass the handle for guid/ds mapping: this should be set to zero on first call and will contain an updated handle on success, it should be passed in subsequent calls.

  Returns:

    a tuple with two elements where the first one is the number of bytes read from the file descriptor and the second one is the action_handle return value.

  Raises:

    - IOError – if an input / output error occurs while reading from the `fd`.

    - DatasetExists – if the snapshot named `snapname` already exists.

    - DatasetExists – if the stream is a full stream and the destination filesystem already exists.

    - DatasetExists – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot exists and it is an origin of a cloned filesystem.

    - StreamMismatch – if an incremental stream is received and the latest snapshot of the destination filesystem does not match the source snapshot of the stream.

    - StreamMismatch – if a full stream is received and the destination filesystem already exists and it has at least one snapshot, and `force` is False.

    - StreamMismatch – if an incremental clone stream is received but the specified `origin` is not the actual received origin.

    - DestinationModified – if an incremental stream is received and the destination filesystem has been modified since the last snapshot and `force` is False.

    - DestinationModified – if a full stream is received and the destination filesystem already exists and it does not have any snapshots, and `force` is False.

    - DatasetNotFound – if the destination filesystem and its parent do not exist.

    - DatasetNotFound – if the `origin` is not None and does not exist.

    - DatasetBusy – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot is held and could not be destroyed.

    - DatasetBusy – if another receive operation is being performed on the destination filesystem.

    - BadStream – if the stream is corrupt or it is not recognized or it is a compound stream or it is a clone stream, but `origin` is None.

    - BadStream – if a clone stream is received and the destination filesystem already exists.

    - StreamFeatureNotSupported – if the stream has a feature that is not supported on this side.

    - ReceivePropertyFailure – if one or more of the specified properties is invalid or has an invalid type or value.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

libzfs_core.lzc_receive_with_header(snapname, fd, begin_record, force=False, resumable=False, raw=False, origin=None, props=None)

  Like `lzc_receive()`, but allows the caller to read the begin record and then to pass it in.

  That could be useful if the caller wants to derive, for example, the snapname or the origin parameters based on the information contained in the begin record. `receive_header()` can be used to receive the begin record from the file descriptor.

  Parameters:

    - snapname (bytes) – the name of the snapshot to create.

    - fd (int) – the file descriptor from which to read the stream.

    - begin_record (`cffi` CData representing the dmu_replay_record_t structure.) – the stream’s begin record.

    - force (bool) – whether to roll back or destroy the target filesystem if that is required to receive the stream.

    - resumable (bool) – whether this stream should be treated as resumable. If the receive fails due to premature stream termination, the intermediate state will be preserved on disk and may subsequently be resumed with `lzc_send_resume()`.

    - raw (bool) – whether this is a “raw” stream.

    - origin (bytes or None) – the optional origin snapshot name if the stream is for a clone.

    - props (dict of bytes : Any) – the properties to set on the snapshot as received properties.

  Raises:

    - IOError – if an input / output error occurs while reading from the `fd`.

    - DatasetExists – if the snapshot named `snapname` already exists.

    - DatasetExists – if the stream is a full stream and the destination filesystem already exists.

    - DatasetExists – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot exists and it is an origin of a cloned filesystem.

    - StreamMismatch – if an incremental stream is received and the latest snapshot of the destination filesystem does not match the source snapshot of the stream.

    - StreamMismatch – if a full stream is received and the destination filesystem already exists and it has at least one snapshot, and `force` is False.

    - StreamMismatch – if an incremental clone stream is received but the specified `origin` is not the actual received origin.

    - DestinationModified – if an incremental stream is received and the destination filesystem has been modified since the last snapshot and `force` is False.

    - DestinationModified – if a full stream is received and the destination filesystem already exists and it does not have any snapshots, and `force` is False.

    - DatasetNotFound – if the destination filesystem and its parent do not exist.

    - DatasetNotFound – if the `origin` is not None and does not exist.

    - DatasetBusy – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot is held and could not be destroyed.

    - DatasetBusy – if another receive operation is being performed on the destination filesystem.

    - BadStream – if the stream is corrupt or it is not recognized or it is a compound stream or it is a clone stream, but `origin` is None.

    - BadStream – if a clone stream is received and the destination filesystem already exists.

    - StreamFeatureNotSupported – if the stream has a feature that is not supported on this side.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

libzfs_core.lzc_receive_with_heal(snapname, fd, begin_record, force=False, corrective=True, resumable=False, raw=False, origin=None, props=None, cmdprops=None, key=None, cleanup_fd=-1, action_handle=0)

  Like `lzc_receive_cmdprops()`, but allows the caller to pass an additional ‘corrective’ argument. The ‘corrective’ boolean set to true indicates that a corruption healing receive should be performed.

  Parameters:

    - snapname (bytes) – the name of the snapshot to create.

    - fd (int) – the file descriptor from which to read the stream.

    - begin_record (`cffi` CData representing the dmu_replay_record_t structure.) – the stream’s begin record.

    - force (bool) – whether to roll back or destroy the target filesystem if that is required to receive the stream.

    - corrective (bool) – whether this stream should be used to heal data.

    - resumable (bool) – whether this stream should be treated as resumable. If the receive fails due to premature stream termination, the intermediate state will be preserved on disk and may subsequently be resumed with `lzc_send_resume()`.

    - raw (bool) – whether this is a “raw” stream.

    - origin (bytes or None) – the optional origin snapshot name if the stream is for a clone.

    - props (dict of bytes : Any) – the properties to set on the snapshot as received properties.

    - cmdprops (dict of bytes : Any) – the properties to set on the snapshot as local overrides to received properties. bool values are forcefully inherited while every other value is set locally as if the command “zfs set” was invoked immediately before the receive.

    - key (bytes) – raw bytes representing user’s wrapping key

    - cleanup_fd (int) – file descriptor used to set a cleanup-on-exit file descriptor.

    - action_handle (int) – variable used to pass the handle for guid/ds mapping: this should be set to zero on first call and will contain an updated handle on success, it should be passed in subsequent calls.

  Returns:

    a tuple with two elements where the first one is the number of bytes read from the file descriptor and the second one is the action_handle return value.

  Raises:

    - IOError – if an input / output error occurs while reading from the `fd`.

    - DatasetExists – if the snapshot named `snapname` already exists.

    - DatasetExists – if the stream is a full stream and the destination filesystem already exists.

    - DatasetExists – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot exists and it is an origin of a cloned filesystem.

    - StreamMismatch – if an incremental stream is received and the latest snapshot of the destination filesystem does not match the source snapshot of the stream.

    - StreamMismatch – if a full stream is received and the destination filesystem already exists and it has at least one snapshot, and `force` is False.

    - StreamMismatch – if an incremental clone stream is received but the specified `origin` is not the actual received origin.

    - DestinationModified – if an incremental stream is received and the destination filesystem has been modified since the last snapshot and `force` is False.

    - DestinationModified – if a full stream is received and the destination filesystem already exists and it does not have any snapshots, and `force` is False.

    - DatasetNotFound – if the destination filesystem and its parent do not exist.

    - DatasetNotFound – if the `origin` is not None and does not exist.

    - DatasetBusy – if `force` is True but the destination filesystem could not be rolled back to a matching snapshot because a newer snapshot is held and could not be destroyed.

    - DatasetBusy – if another receive operation is being performed on the destination filesystem.

    - EncryptionKeyNotLoaded – if corrective is set to true indicates the key must be loaded to do a non-raw corrective recv on an encrypted dataset.

    - BadStream – if corrective is set to true indicates that corrective recv was not able to reconstruct a corrupted block.

    - BadStream – if the stream is corrupt or it is not recognized or it is a compound stream or it is a clone stream, but `origin` is None.

    - BadStream – if a clone stream is received and the destination filesystem already exists.

    - StreamFeatureNotSupported – if corrective is set to true indicates stream is not compatible with the data in the pool.

    - StreamFeatureNotSupported – if the stream has a feature that is not supported on this side.

    - ReceivePropertyFailure – if one or more of the specified properties is invalid or has an invalid type or value.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

libzfs_core.lzc_release(holds)

  Release user holds on snapshots.

  If the snapshot has been marked for deferred destroy (by lzc_destroy_snaps(defer=B_TRUE)), it does not have any clones, and all the user holds are removed, then the snapshot will be destroyed.

  The snapshots must all be in the same pool.

  Parameters:

    holds (dict of bytes : list of bytes) – a `dict` where keys are snapshot names and values are lists of hold tags to remove.

  Returns:

    a list of any snapshots that do not exist and of any tags that do not exist for existing snapshots. Such tags are qualified with a corresponding snapshot name using the following format `pool/fs@snap#tag`

  Return type:

    list of bytes

  Raises:

    HoldReleaseFailure – if one or more existing holds could not be released.

  Holds which failed to release because they didn’t exist will have an entry added to errlist, but will not cause an overall failure.

  This call is success if `holds` was empty or all holds that existed, were successfully removed. Otherwise an exception will be raised.

libzfs_core.lzc_reopen(poolname, restart=True)

  Reopen a pool

  Parameters:

    - poolname (bytes) – the name of the pool.

    - restart (bool) – whether to restart an in-progress scrub operation.

  Raises:

    PoolNotFound – if the pool does not exist.

libzfs_core.lzc_rollback(name)

  Roll back a filesystem or volume to its most recent snapshot.

  Note that the latest snapshot may change if a new one is concurrently created or the current one is destroyed. lzc_rollback_to can be used to roll back to a specific latest snapshot.

  Parameters:

    name (bytes) – a name of the dataset to be rolled back.

  Returns:

    a name of the most recent snapshot.

  Return type:

    bytes

  Raises:

    - FilesystemNotFound – if the dataset does not exist.

    - SnapshotNotFound – if the dataset does not have any snapshots.

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

libzfs_core.lzc_rollback_to(name, snap)

  Roll back this filesystem or volume to the specified snapshot, if possible.

  Parameters:

    - name (bytes) – a name of the dataset to be rolled back.

    - snap (bytes) – a name of the snapshot to be rolled back.

  Raises:

    - FilesystemNotFound – if the dataset does not exist.

    - SnapshotNotFound – if the dataset does not have any snapshots.

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

    - SnapshotNotLatest – if the snapshot is not the latest.

libzfs_core.lzc_send(snapname, fromsnap, fd, flags=None)

  Generate a zfs send stream for the specified snapshot and write it to the specified file descriptor.

  Parameters:

    - snapname (bytes) – the name of the snapshot to send.

    - fromsnap (bytes or None) – if not None the name of the starting snapshot for the incremental stream.

    - fd (int) – the file descriptor to write the send stream to.

    - flags (list of bytes) – the flags that control what enhanced features can be used in the stream.

  Raises:

    - SnapshotNotFound – if either the starting snapshot is not None and does not exist, or if the ending snapshot does not exist.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

    - SnapshotMismatch – if `fromsnap` is not an ancestor snapshot of `snapname`.

    - PoolsDiffer – if the snapshots belong to different pools.

    - IOError – if an input / output error occurs while writing to `fd`.

    - UnknownStreamFeature – if the `flags` contain an unknown flag name.

  If `fromsnap` is None, a full (non-incremental) stream will be sent. If `fromsnap` is not None, it must be the full name of a snapshot or bookmark to send an incremental from, e.g. `pool/fs@earlier_snap` or `pool/fs#earlier_bmark`.

  The specified snapshot or bookmark must represent an earlier point in the history of `snapname`. It can be an earlier snapshot in the same filesystem or zvol as `snapname`, or it can be the origin of `snapname`’s filesystem, or an earlier snapshot in the origin, etc. `fromsnap` must be strictly an earlier snapshot, specifying the same snapshot as both `fromsnap` and `snapname` is an error.

  If `flags` contains “large_blocks”, the stream is permitted to contain `DRR_WRITE` records with `drr_length` > 128K, and `DRR_OBJECT` records with `drr_blksz` > 128K.

  If `flags` contains “embedded_data”, the stream is permitted to contain `DRR_WRITE_EMBEDDED` records with `drr_etype` == `BP_EMBEDDED_TYPE_DATA`, which the receiving system must support (as indicated by support for the embedded_data feature).

  If `flags` contains “compress”, the stream is generated by using compressed WRITE records for blocks which are compressed on disk and in memory. If the lz4_compress feature is active on the sending system, then the receiving system must have that feature enabled as well.

  If `flags` contains “raw”, the stream is generated, for encrypted datasets, by sending data exactly as it exists on disk. This allows backups to be taken even if encryption keys are not currently loaded.

  Note

  `lzc_send` can actually accept a filesystem name as the `snapname`. In that case `lzc_send` acts as if a temporary snapshot was created after the start of the call and before the stream starts being produced.

  Note

  `lzc_send` does not return until all of the stream is written to `fd`.

  Note

  `lzc_send` does not close `fd` upon returning.

libzfs_core.lzc_send_resume(snapname, fromsnap, fd, flags=None, resumeobj=0, resumeoff=0)

  Resume a previously interrupted send operation generating a zfs send stream for the specified snapshot and writing it to the specified file descriptor.

  Parameters:

    - snapname (bytes) – the name of the snapshot to send.

    - fromsnap (bytes or None) – if not None the name of the starting snapshot for the incremental stream.

    - fd (int) – the file descriptor to write the send stream to.

    - flags (list of bytes) – the flags that control what enhanced features can be used in the stream.

    - resumeobj (int) – the object number where this send stream should resume from.

    - resumeoff (int) – the offset where this send stream should resume from.

  Raises:

    - SnapshotNotFound – if either the starting snapshot is not None and does not exist, or if the ending snapshot does not exist.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

    - SnapshotMismatch – if `fromsnap` is not an ancestor snapshot of `snapname`.

    - PoolsDiffer – if the snapshots belong to different pools.

    - IOError – if an input / output error occurs while writing to `fd`.

    - UnknownStreamFeature – if the `flags` contain an unknown flag name.

  Note

  See `lzc_send()` for more information.

libzfs_core.lzc_send_space(snapname, fromsnap=None, flags=None)

  Estimate size of a full or incremental backup stream given the optional starting snapshot and the ending snapshot.

  Parameters:

    - snapname (bytes) – the name of the snapshot for which the estimate should be done.

    - fromsnap (bytes or None) – the optional starting snapshot name. If not None then an incremental stream size is estimated, otherwise a full stream is estimated.

    - flags (list of bytes) – the flags that control what enhanced features can be used in the stream.

  Returns:

    the estimated stream size, in bytes.

  Return type:

    int or long

  Raises:

    - SnapshotNotFound – if either the starting snapshot is not None and does not exist, or if the ending snapshot does not exist.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

    - SnapshotMismatch – if `fromsnap` is not an ancestor snapshot of `snapname`.

    - PoolsDiffer – if the snapshots belong to different pools.

  `fromsnap`, if not `None`, must be strictly an earlier snapshot, specifying the same snapshot as both `fromsnap` and `snapname` is an error.

libzfs_core.lzc_snaprange_space(firstsnap, lastsnap)

  Calculate a size of data referenced by snapshots in the inclusive range between the `firstsnap` and the `lastsnap` and not shared with any other datasets.

  Parameters:

    - firstsnap (bytes) – the name of the first snapshot in the range.

    - lastsnap (bytes) – the name of the last snapshot in the range.

  Returns:

    the calculated stream size, in bytes.

  Return type:

    int or long

  Raises:

    - SnapshotNotFound – if either of the snapshots does not exist.

    - NameInvalid – if the name of either snapshot is invalid.

    - NameTooLong – if the name of either snapshot is too long.

    - SnapshotMismatch – if `fromsnap` is not an ancestor snapshot of `snapname`.

    - PoolsDiffer – if the snapshots belong to different pools.

  `lzc_snaprange_space` calculates total size of blocks that exist because they are referenced only by one or more snapshots in the given range but no other dataset. In other words, this is the set of blocks that were born after the snap before firstsnap, and died before the snap after the last snap. Yet another interpretation is that the result of `lzc_snaprange_space` is the size of the space that would be freed if the snapshots in the range are destroyed.

  If the same snapshot is given as both the `firstsnap` and the `lastsnap`. In that case `lzc_snaprange_space` calculates space used by the snapshot.

libzfs_core.lzc_snapshot(snaps, props=None)

  Create snapshots.

  All snapshots must be in the same pool.

  Optionally snapshot properties can be set on all snapshots. Currently only user properties (prefixed with “user:”) are supported.

  Either all snapshots are successfully created or none are created if an exception is raised.

  Parameters:

    - snaps (list of bytes) – a list of names of snapshots to be created.

    - props (dict of bytes:bytes) – a dict of ZFS dataset property name-value pairs (empty by default).

  Raises:

    SnapshotFailure – if one or more snapshots could not be created.

  Note

  `SnapshotFailure` is a compound exception that provides at least one detailed error object in `SnapshotFailure.errors` list.

  Warning

  The underlying implementation reports an individual, per-snapshot error only for `SnapshotExists` condition and sometimes for `NameTooLong`. In all other cases a single error is reported without connection to any specific snapshot name(s).

  This has the following implications:

  - if multiple error conditions are encountered only one of them is reported

  - unless only one snapshot is requested then it is impossible to tell how many snapshots are problematic and what they are

  - only if there are no other error conditions `SnapshotExists` is reported for all affected snapshots

  - `NameTooLong` can behave either in the same way as `SnapshotExists` or as all other exceptions. The former is the case where the full snapshot name exceeds the maximum allowed length but the short snapshot name (after ‘@’) is within the limit. The latter is the case when the short name alone exceeds the maximum allowed length.

libzfs_core.lzc_sync(poolname, force=False)

  Forces all in-core dirty data to be written to the primary pool storage and not the ZIL.

  Parameters:

    - poolname (bytes) – the name of the pool.

    - force (bool) – whether to force uberblock update even if there is no dirty data.

  Raises:

    PoolNotFound – if the pool does not exist.

  Note

  This method signature is different from its C libzfs_core counterpart: innvl has been replaced by the force boolean and outnvl has been conveniently removed since it’s not used.

libzfs_core.lzc_unload_key(fsname)

  Unload encryption key from the specified dataset.

  Parameters:

    fsname (bytes) – the name of the dataset.

  Raises:

    - FilesystemNotFound – if the dataset does not exist.

    - DatasetBusy – if the encryption key is still being used. This usually occurs when the dataset is mounted.

    - EncryptionKeyNotLoaded – if the encryption key is not currently loaded.

libzfs_core.is_supported(func)

  Check whether C libzfs_core provides implementation required for the given Python wrapper.

  If is_supported returns `False` for the function, then calling the function would result in `NotImplementedError`.

  Parameters:

    func (function) – the function to check.

  Return bool:

    whether the function can be used.

libzfs_core.lzc_rename(source, target)

  Rename the ZFS dataset.

  Parameters:

    - name (target) – the current name of the dataset to rename.

    - name – the new name of the dataset.

  Raises:

    - NameInvalid – if either the source or target name is invalid.

    - NameTooLong – if either the source or target name is too long.

    - NameTooLong – if a snapshot of the source would get a too long name after renaming.

    - FilesystemNotFound – if the source does not exist.

    - FilesystemNotFound – if the target’s parent does not exist.

    - FilesystemExists – if the target already exists.

    - PoolsDiffer – if the source and target belong to different pools.

    - WrongParent – if the “new” parent dataset is not a filesystem (e.g. ZVOL)

libzfs_core.lzc_destroy(name)

  Destroy the ZFS dataset.

  Parameters:

    name (bytes) – the name of the dataset to destroy.

  Raises:

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

    - FilesystemNotFound – if the dataset does not exist.

libzfs_core.lzc_inherit_prop(name, prop)

  Inherit properties from a parent dataset of the given ZFS dataset.

  Parameters:

    - name (bytes) – the name of the dataset.

    - prop (bytes) – the name of the property to inherit.

  Raises:

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

    - DatasetNotFound – if the dataset does not exist.

    - PropertyInvalid – if one or more of the specified properties is invalid or has an invalid type or value.

  Inheriting a property actually resets it to its default value or removes it if it’s a user property, so that the property could be inherited if it’s inheritable. If the property is not inheritable then it would just have its default value.

  This function can be used on snapshots to inherit user defined properties.

libzfs_core.lzc_get_props(name)

  Get properties of the ZFS dataset.

  Parameters:

    name (bytes) – the name of the dataset.

  Raises:

    - DatasetNotFound – if the dataset does not exist.

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

  Returns:

    a dictionary mapping the property names to their values.

  Return type:

    dict of bytes:Any

  Note

  The value of `clones` property is a list of clone names as byte strings.

  Warning

  The returned dictionary does not contain entries for properties with default values. One exception is the `mountpoint` property for which the default value is derived from the dataset name.

libzfs_core.lzc_list_children(name)

  List the children of the ZFS dataset.

  Parameters:

    name (bytes) – the name of the dataset.

  Returns:

    an iterator that produces the names of the children.

  Raises:

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

    - DatasetNotFound – if the dataset does not exist.

  Warning

  If the dataset does not exist, then the returned iterator would produce no results and no error is reported. That case is indistinguishable from the dataset having no children.

  An attempt to list children of a snapshot is silently ignored as well.

libzfs_core.lzc_list_snaps(name)

  List the snapshots of the ZFS dataset.

  Parameters:

    name (bytes) – the name of the dataset.

  Returns:

    an iterator that produces the names of the snapshots.

  Raises:

    - NameInvalid – if the dataset name is invalid.

    - NameTooLong – if the dataset name is too long.

    - DatasetNotFound – if the dataset does not exist.

  Warning

  If the dataset does not exist, then the returned iterator would produce no results and no error is reported. That case is indistinguishable from the dataset having no snapshots.

  An attempt to list snapshots of a snapshot is silently ignored as well.

libzfs_core.receive_header(fd)

  Read the begin record of the ZFS backup stream from the given file descriptor.

  This is a helper function for `lzc_receive_with_header()`.

  Parameters:

    fd (int) – the file descriptor from which to read the stream.

  Returns:

    a tuple with two elements where the first one is a Python dict representing the fields of the begin record and the second one is an opaque object suitable for passing to `lzc_receive_with_header()`.

  Raises:

    IOError – if an input / output error occurs while reading from the `fd`.

  At present the following fields can be of interest in the header:

  drr_tonamebytes

    the name of the snapshot for which the stream has been created

  drr_toguidinteger

    the GUID of the snapshot for which the stream has been created

  drr_fromguidinteger

    the GUID of the starting snapshot in the case the stream is incremental, zero otherwise

  drr_flagsinteger

    the flags describing the stream’s properties

  drr_typeinteger

    the type of the dataset for which the stream has been created (volume, filesystem)

## Documentation for the libzfs_core exceptions

Exceptions that can be raised by libzfs_core operations.

exception libzfs_core.exceptions.ZFSError
  errno = None
  message = None
  name = None

exception libzfs_core.exceptions.ZFSGenericError(errno, name, message)

exception libzfs_core.exceptions.ZFSInitializationFailed(errno)
  message = 'Failed to initialize libzfs_core'

exception libzfs_core.exceptions.MultipleOperationsFailure(errors, suppressed_count)

exception libzfs_core.exceptions.DatasetNotFound(name)

  This exception is raised when an operation failure can be caused by a missing snapshot or a missing filesystem and it is impossible to distinguish between the causes.

  errno = 2
  message = 'Dataset not found'

exception libzfs_core.exceptions.DatasetExists(name)

  This exception is raised when an operation failure can be caused by an existing snapshot or filesystem and it is impossible to distinguish between the causes.

  errno = 17
  message = 'Dataset already exists'

exception libzfs_core.exceptions.NotClone(name)
  errno = 22
  message = 'Filesystem is not a clone, can not promote'

exception libzfs_core.exceptions.FilesystemExists(name)
  message = 'Filesystem already exists'

exception libzfs_core.exceptions.FilesystemNotFound(name)
  message = 'Filesystem not found'

exception libzfs_core.exceptions.ParentNotFound(name)
  errno = 2
  message = 'Parent not found'

exception libzfs_core.exceptions.WrongParent(name)
  errno = 1033
  message = 'Parent dataset is not a filesystem'

exception libzfs_core.exceptions.SnapshotExists(name)
  message = 'Snapshot already exists'

exception libzfs_core.exceptions.SnapshotNotFound(name)
  message = 'Snapshot not found'

exception libzfs_core.exceptions.SnapshotNotLatest(name)
  errno = 17
  message = 'Snapshot is not the latest'

exception libzfs_core.exceptions.SnapshotIsCloned(name)
  errno = 17
  message = 'Snapshot is cloned'

exception libzfs_core.exceptions.SnapshotIsHeld(name)
  errno = 16
  message = 'Snapshot is held'

exception libzfs_core.exceptions.DuplicateSnapshots(name)
  errno = 18
  message = 'Requested multiple snapshots of the same filesystem'

exception libzfs_core.exceptions.SnapshotFailure(errors, suppressed_count)
  message = 'Creation of snapshot(s) failed for one or more reasons'

exception libzfs_core.exceptions.SnapshotDestructionFailure(errors, suppressed_count)
  message = 'Destruction of snapshot(s) failed for one or more reasons'

exception libzfs_core.exceptions.BookmarkExists(name)
  errno = 17
  message = 'Bookmark already exists'

exception libzfs_core.exceptions.BookmarkNotFound(name)
  errno = 2
  message = 'Bookmark not found'

exception libzfs_core.exceptions.BookmarkMismatch(name)
  errno = 22
  message = "source is not an ancestor of the new bookmark's dataset"

exception libzfs_core.exceptions.BookmarkSourceInvalid(name)
  errno = 22
  message = 'Bookmark source is not a valid snapshot or existing bookmark'

exception libzfs_core.exceptions.BookmarkNotSupported(name)
  errno = 95
  message = 'Bookmark feature is not supported'

exception libzfs_core.exceptions.BookmarkFailure(errors, suppressed_count)
  message = 'Creation of bookmark(s) failed for one or more reasons'

exception libzfs_core.exceptions.BookmarkDestructionFailure(errors, suppressed_count)
  message = 'Destruction of bookmark(s) failed for one or more reasons'

exception libzfs_core.exceptions.BadHoldCleanupFD
  errno = 9
  message = 'Bad file descriptor as cleanup file descriptor'

exception libzfs_core.exceptions.HoldExists(name)
  errno = 17
  message = 'Hold with a given tag already exists on snapshot'

exception libzfs_core.exceptions.HoldNotFound(name)
  errno = 2
  message = 'Hold with a given tag does not exist on snapshot'

exception libzfs_core.exceptions.HoldFailure(errors, suppressed_count)
  message = 'Placement of hold(s) failed for one or more reasons'

exception libzfs_core.exceptions.HoldReleaseFailure(errors, suppressed_count)
  message = 'Release of hold(s) failed for one or more reasons'

exception libzfs_core.exceptions.SnapshotMismatch(name)
  errno = 19
  message = 'Snapshot is not descendant of source snapshot'

exception libzfs_core.exceptions.StreamMismatch(name)
  errno = 19
  message = 'Stream is not applicable to destination dataset'

exception libzfs_core.exceptions.DestinationModified(name)
  errno = 26
  message = 'Destination dataset has modifications that can not be undone'

exception libzfs_core.exceptions.BadStream
  errno = 52
  message = 'Bad backup stream'

exception libzfs_core.exceptions.StreamFeatureNotSupported
  errno = 95
  message = 'Stream contains unsupported feature'

exception libzfs_core.exceptions.UnknownStreamFeature
  errno = 95
  message = 'Unknown feature requested for stream'

exception libzfs_core.exceptions.StreamFeatureInvalid
  errno = 22
  message = 'Kernel modules must be upgraded to receive this stream'

exception libzfs_core.exceptions.StreamFeatureIncompatible
  errno = 22
  message = 'Incompatible embedded feature with encrypted receive'

exception libzfs_core.exceptions.StreamTruncated
  errno = 1040
  message = 'incomplete stream'

exception libzfs_core.exceptions.ReceivePropertyFailure(errors, suppressed_count)
  message = 'Receiving of properties failed for one or more reasons'

exception libzfs_core.exceptions.StreamIOError(errno)
  message = 'I/O error while writing or reading stream'

exception libzfs_core.exceptions.ZIOError(name)
  errno = 5
  message = 'I/O error'

exception libzfs_core.exceptions.NoSpace(name)
  errno = 28
  message = 'No space left'

exception libzfs_core.exceptions.QuotaExceeded(name)
  errno = 122
  message = 'Quota exceeded'

exception libzfs_core.exceptions.DatasetBusy(name)
  errno = 16
  message = 'Dataset is busy'

exception libzfs_core.exceptions.NameTooLong(name)
  errno = 36
  message = 'Dataset name is too long'

exception libzfs_core.exceptions.NameInvalid(name)
  errno = 22
  message = 'Invalid name'

exception libzfs_core.exceptions.SnapshotNameInvalid(name)
  message = 'Invalid name for snapshot'

exception libzfs_core.exceptions.FilesystemNameInvalid(name)
  message = 'Invalid name for filesystem or volume'

exception libzfs_core.exceptions.BookmarkNameInvalid(name)
  message = 'Invalid name for bookmark'

exception libzfs_core.exceptions.ReadOnlyPool(name)
  errno = 30
  message = 'Pool is read-only'

exception libzfs_core.exceptions.SuspendedPool(name)
  errno = 11
  message = 'Pool is suspended'

exception libzfs_core.exceptions.PoolNotFound(name)
  errno = 18
  message = 'No such pool'

exception libzfs_core.exceptions.PoolsDiffer(name)
  errno = 18
  message = 'Source and target belong to different pools'

exception libzfs_core.exceptions.FeatureNotSupported(name)
  errno = 95
  message = 'Feature is not supported in this version'

exception libzfs_core.exceptions.PropertyNotSupported(name)
  errno = 95
  message = 'Property is not supported in this version'

exception libzfs_core.exceptions.PropertyInvalid(name)
  errno = 22
  message = 'Invalid property or property value'

exception libzfs_core.exceptions.DatasetTypeInvalid(name)
  errno = 22
  message = 'Specified dataset type is unknown'

exception libzfs_core.exceptions.UnknownCryptCommand(name)
  errno = 22
  message = 'Specified crypt command is invalid'

exception libzfs_core.exceptions.EncryptionKeyNotLoaded
  errno = 13
  message = 'Encryption key is not currently loaded'

exception libzfs_core.exceptions.EncryptionKeyAlreadyLoaded
  errno = 17
  message = 'Encryption key is already loaded'

exception libzfs_core.exceptions.EncryptionKeyInvalid
  errno = 13
  message = 'Incorrect encryption key provided'

exception libzfs_core.exceptions.ZCPError
  errno = None
  message = None

exception libzfs_core.exceptions.ZCPSyntaxError(details)
  errno = 22
  message = 'Channel program contains syntax errors'

exception libzfs_core.exceptions.ZCPRuntimeError(details)
  errno = 44
  message = 'Channel programs encountered a runtime error'

exception libzfs_core.exceptions.ZCPLimitInvalid
  errno = 22
  message = 'Channel program called with invalid limits'

exception libzfs_core.exceptions.ZCPTimeout
  errno = 62
  message = 'Channel program timed out'

exception libzfs_core.exceptions.ZCPSpaceError
  errno = 28
  message = 'Channel program exhausted the memory limit'

exception libzfs_core.exceptions.ZCPMemoryError
  errno = 12
  message = 'Channel program return value too large'

exception libzfs_core.exceptions.ZCPPermissionError
  errno = 1
  message = 'Channel programs must be run as root'

exception libzfs_core.exceptions.CheckpointExists
  errno = 1024
  message = 'Pool already has a checkpoint'

exception libzfs_core.exceptions.CheckpointNotFound
  errno = 1026
  message = 'Pool does not have a checkpoint'

exception libzfs_core.exceptions.CheckpointDiscarding
  errno = 1025
  message = 'Pool checkpoint is being discarded'

exception libzfs_core.exceptions.DeviceRemovalRunning
  errno = 1027
  message = 'A vdev is currently being removed'

exception libzfs_core.exceptions.DeviceTooBig
  errno = 1028
  message = 'One or more top-level vdevs exceed the maximum vdev size'

exception libzfs_core.exceptions.RaidzExpansionRunning
  errno = 1049
  message = 'A raidz device is currently expanding'

## Documentation for the miscellaneous types that correspond to specific width C types

Utility functions for casting to a specific C type.

libzfs_core.ctypes.uint8_t(value)

libzfs_core.ctypes.int8_t(value)

libzfs_core.ctypes.uint16_t(value)

libzfs_core.ctypes.int16_t(value)

libzfs_core.ctypes.uint32_t(value)

libzfs_core.ctypes.int32_t(value)

libzfs_core.ctypes.uint64_t(value)

libzfs_core.ctypes.int64_t(value)

libzfs_core.ctypes.boolean_t(value)

libzfs_core.ctypes.uchar_t(value)