2021-05-27 00:46:40 +00:00
|
|
|
.\"
|
2018-02-08 16:16:23 +00:00
|
|
|
.\" This file and its contents are supplied under the terms of the
|
|
|
|
.\" Common Development and Distribution License ("CDDL"), version 1.0.
|
|
|
|
.\" You may only use this file in accordance with the terms of version
|
|
|
|
.\" 1.0 of the CDDL.
|
|
|
|
.\"
|
|
|
|
.\" A full copy of the text of the CDDL should have accompanied this
|
|
|
|
.\" source. A copy of the CDDL is also available via the Internet at
|
|
|
|
.\" http://www.illumos.org/license/CDDL.
|
|
|
|
.\"
|
2019-02-26 19:15:28 +00:00
|
|
|
.\" Copyright (c) 2016, 2019 by Delphix. All Rights Reserved.
|
2020-01-16 01:15:05 +00:00
|
|
|
.\" Copyright (c) 2019, 2020 by Christian Schwarz. All Rights Reserved.
|
2020-01-23 01:03:17 +00:00
|
|
|
.\" Copyright 2020 Joyent, Inc.
|
2018-02-08 16:16:23 +00:00
|
|
|
.\"
|
2021-05-27 00:46:40 +00:00
|
|
|
.Dd May 27, 2021
|
2018-02-08 16:16:23 +00:00
|
|
|
.Dt ZFS-PROGRAM 8
|
|
|
|
.Os
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh NAME
|
2020-10-22 18:28:10 +00:00
|
|
|
.Nm zfs-program
|
2021-05-27 00:46:40 +00:00
|
|
|
.Nd execute ZFS channel programs
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh SYNOPSIS
|
2020-10-22 18:28:10 +00:00
|
|
|
.Nm zfs
|
|
|
|
.Cm program
|
2018-03-19 19:40:58 +00:00
|
|
|
.Op Fl jn
|
2018-02-08 16:16:23 +00:00
|
|
|
.Op Fl t Ar instruction-limit
|
|
|
|
.Op Fl m Ar memory-limit
|
|
|
|
.Ar pool
|
|
|
|
.Ar script
|
2021-05-27 00:46:40 +00:00
|
|
|
.Op Ar script arguments
|
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The ZFS channel program interface allows ZFS administrative operations to be
|
|
|
|
run programmatically as a Lua script.
|
|
|
|
The entire script is executed atomically, with no other administrative
|
|
|
|
operations taking effect concurrently.
|
|
|
|
A library of ZFS calls is made available to channel program scripts.
|
|
|
|
Channel programs may only be run with root privileges.
|
|
|
|
.Pp
|
|
|
|
A modified version of the Lua 5.2 interpreter is used to run channel program
|
|
|
|
scripts.
|
2021-05-27 00:46:40 +00:00
|
|
|
The Lua 5.2 manual can be found at
|
2018-02-08 16:16:23 +00:00
|
|
|
.Lk http://www.lua.org/manual/5.2/
|
|
|
|
.Pp
|
|
|
|
The channel program given by
|
|
|
|
.Ar script
|
|
|
|
will be run on
|
|
|
|
.Ar pool ,
|
|
|
|
and any attempts to access or modify other pools will cause an error.
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh OPTIONS
|
|
|
|
.Bl -tag -width "-t"
|
2018-03-19 19:40:58 +00:00
|
|
|
.It Fl j
|
2021-05-27 00:46:40 +00:00
|
|
|
Display channel program output in JSON format.
|
|
|
|
When this flag is specified and standard output is empty -
|
|
|
|
channel program encountered an error.
|
|
|
|
The details of such an error will be printed to standard error in plain text.
|
2018-02-08 16:35:09 +00:00
|
|
|
.It Fl n
|
|
|
|
Executes a read-only channel program, which runs faster.
|
|
|
|
The program cannot change on-disk state by calling functions from the
|
|
|
|
zfs.sync submodule.
|
|
|
|
The program can be used to gather information such as properties and
|
|
|
|
determining if changes would succeed (zfs.check.*).
|
|
|
|
Without this flag, all pending changes must be synced to disk before a
|
|
|
|
channel program can complete.
|
2018-02-08 16:16:23 +00:00
|
|
|
.It Fl t Ar instruction-limit
|
2019-02-26 19:15:28 +00:00
|
|
|
Limit the number of Lua instructions to execute.
|
2018-02-08 16:16:23 +00:00
|
|
|
If a channel program executes more than the specified number of instructions,
|
|
|
|
it will be stopped and an error will be returned.
|
|
|
|
The default limit is 10 million instructions, and it can be set to a maximum of
|
|
|
|
100 million instructions.
|
|
|
|
.It Fl m Ar memory-limit
|
|
|
|
Memory limit, in bytes.
|
|
|
|
If a channel program attempts to allocate more memory than the given limit, it
|
|
|
|
will be stopped and an error returned.
|
2022-05-03 12:07:04 +00:00
|
|
|
The default memory limit is 10 MiB, and can be set to a maximum of 100 MiB.
|
2018-02-08 16:16:23 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
All remaining argument strings will be passed directly to the Lua script as
|
|
|
|
described in the
|
|
|
|
.Sx LUA INTERFACE
|
|
|
|
section below.
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh LUA INTERFACE
|
|
|
|
A channel program can be invoked either from the command line, or via a library
|
|
|
|
call to
|
|
|
|
.Fn lzc_channel_program .
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Arguments
|
|
|
|
Arguments passed to the channel program are converted to a Lua table.
|
|
|
|
If invoked from the command line, extra arguments to the Lua script will be
|
|
|
|
accessible as an array stored in the argument table with the key 'argv':
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bd -literal -compact -offset indent
|
2018-02-08 16:16:23 +00:00
|
|
|
args = ...
|
|
|
|
argv = args["argv"]
|
|
|
|
-- argv == {1="arg1", 2="arg2", ...}
|
|
|
|
.Ed
|
|
|
|
.Pp
|
2022-03-24 19:14:25 +00:00
|
|
|
If invoked from the libzfs interface, an arbitrary argument list can be
|
2018-02-08 16:16:23 +00:00
|
|
|
passed to the channel program, which is accessible via the same
|
2022-03-24 19:14:25 +00:00
|
|
|
.Qq Li ...
|
|
|
|
syntax in Lua:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bd -literal -compact -offset indent
|
2018-02-08 16:16:23 +00:00
|
|
|
args = ...
|
|
|
|
-- args == {"foo"="bar", "baz"={...}, ...}
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Note that because Lua arrays are 1-indexed, arrays passed to Lua from the
|
2022-03-24 19:14:25 +00:00
|
|
|
libzfs interface will have their indices incremented by 1.
|
2018-02-08 16:16:23 +00:00
|
|
|
That is, the element
|
|
|
|
in
|
|
|
|
.Va arr[0]
|
|
|
|
in a C array passed to a channel program will be stored in
|
|
|
|
.Va arr[1]
|
|
|
|
when accessed from Lua.
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Return Values
|
|
|
|
Lua return statements take the form:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Dl return ret0, ret1, ret2, ...
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
Return statements returning multiple values are permitted internally in a
|
|
|
|
channel program script, but attempting to return more than one value from the
|
|
|
|
top level of the channel program is not permitted and will throw an error.
|
|
|
|
However, tables containing multiple values can still be returned.
|
|
|
|
If invoked from the command line, a return statement:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bd -literal -compact -offset indent
|
2018-02-08 16:16:23 +00:00
|
|
|
a = {foo="bar", baz=2}
|
|
|
|
return a
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Will be output formatted as:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bd -literal -compact -offset indent
|
2018-02-08 16:16:23 +00:00
|
|
|
Channel program fully executed with return value:
|
|
|
|
return:
|
|
|
|
baz: 2
|
|
|
|
foo: 'bar'
|
|
|
|
.Ed
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Fatal Errors
|
|
|
|
If the channel program encounters a fatal error while running, a non-zero exit
|
|
|
|
status will be returned.
|
|
|
|
If more information about the error is available, a singleton list will be
|
|
|
|
returned detailing the error:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Dl error: \&"error string, including Lua stack trace"
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
If a fatal error is returned, the channel program may have not executed at all,
|
|
|
|
may have partially executed, or may have fully executed but failed to pass a
|
|
|
|
return value back to userland.
|
|
|
|
.Pp
|
|
|
|
If the channel program exhausts an instruction or memory limit, a fatal error
|
|
|
|
will be generated and the program will be stopped, leaving the program partially
|
|
|
|
executed.
|
|
|
|
No attempt is made to reverse or undo any operations already performed.
|
|
|
|
Note that because both the instruction count and amount of memory used by a
|
|
|
|
channel program are deterministic when run against the same inputs and
|
|
|
|
filesystem state, as long as a channel program has run successfully once, you
|
|
|
|
can guarantee that it will finish successfully against a similar size system.
|
|
|
|
.Pp
|
|
|
|
If a channel program attempts to return too large a value, the program will
|
|
|
|
fully execute but exit with a nonzero status code and no return value.
|
|
|
|
.Pp
|
2020-02-14 21:41:42 +00:00
|
|
|
.Em Note :
|
2018-02-08 16:16:23 +00:00
|
|
|
ZFS API functions do not generate Fatal Errors when correctly invoked, they
|
|
|
|
return an error code and the channel program continues executing.
|
|
|
|
See the
|
|
|
|
.Sx ZFS API
|
|
|
|
section below for function-specific details on error return codes.
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Lua to C Value Conversion
|
2022-03-24 19:14:25 +00:00
|
|
|
When invoking a channel program via the libzfs interface, it is necessary to
|
2018-02-08 16:16:23 +00:00
|
|
|
translate arguments and return values from Lua values to their C equivalents,
|
|
|
|
and vice-versa.
|
|
|
|
.Pp
|
|
|
|
There is a correspondence between nvlist values in C and Lua tables.
|
|
|
|
A Lua table which is returned from the channel program will be recursively
|
|
|
|
converted to an nvlist, with table values converted to their natural
|
|
|
|
equivalents:
|
2021-05-27 00:46:40 +00:00
|
|
|
.TS
|
|
|
|
cw3 l c l .
|
|
|
|
string -> string
|
|
|
|
number -> int64
|
|
|
|
boolean -> boolean_value
|
|
|
|
nil -> boolean (no value)
|
|
|
|
table -> nvlist
|
|
|
|
.TE
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
Likewise, table keys are replaced by string equivalents as follows:
|
2021-05-27 00:46:40 +00:00
|
|
|
.TS
|
|
|
|
cw3 l c l .
|
|
|
|
string -> no change
|
|
|
|
number -> signed decimal string ("%lld")
|
|
|
|
boolean -> "true" | "false"
|
|
|
|
.TE
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
Any collision of table key strings (for example, the string "true" and a
|
|
|
|
true boolean value) will cause a fatal error.
|
|
|
|
.Pp
|
|
|
|
Lua numbers are represented internally as signed 64-bit integers.
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh LUA STANDARD LIBRARY
|
|
|
|
The following Lua built-in base library functions are available:
|
2021-05-27 00:46:40 +00:00
|
|
|
.TS
|
|
|
|
cw3 l l l l .
|
|
|
|
assert rawlen collectgarbage rawget
|
|
|
|
error rawset getmetatable select
|
|
|
|
ipairs setmetatable next tonumber
|
|
|
|
pairs tostring rawequal type
|
|
|
|
.TE
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
All functions in the
|
|
|
|
.Em coroutine ,
|
|
|
|
.Em string ,
|
|
|
|
and
|
|
|
|
.Em table
|
|
|
|
built-in submodules are also available.
|
|
|
|
A complete list and documentation of these modules is available in the Lua
|
|
|
|
manual.
|
|
|
|
.Pp
|
|
|
|
The following functions base library functions have been disabled and are
|
|
|
|
not available for use in channel programs:
|
2021-05-27 00:46:40 +00:00
|
|
|
.TS
|
|
|
|
cw3 l l l l l l .
|
|
|
|
dofile loadfile load pcall print xpcall
|
|
|
|
.TE
|
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh ZFS API
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Function Arguments
|
|
|
|
Each API function takes a fixed set of required positional arguments and
|
|
|
|
optional keyword arguments.
|
|
|
|
For example, the destroy function takes a single positional string argument
|
|
|
|
(the name of the dataset to destroy) and an optional "defer" keyword boolean
|
|
|
|
argument.
|
|
|
|
When using parentheses to specify the arguments to a Lua function, only
|
|
|
|
positional arguments can be used:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Dl Sy zfs.sync.destroy Ns Pq \&"rpool@snap"
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
To use keyword arguments, functions must be called with a single argument that
|
|
|
|
is a Lua table containing entries mapping integers to positional arguments and
|
|
|
|
strings to keyword arguments:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Dl Sy zfs.sync.destroy Ns Pq {1="rpool@snap", defer=true}
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
The Lua language allows curly braces to be used in place of parenthesis as
|
|
|
|
syntactic sugar for this calling convention:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Dl Sy zfs.sync.snapshot Ns {"rpool@snap", defer=true}
|
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Function Return Values
|
|
|
|
If an API function succeeds, it returns 0.
|
|
|
|
If it fails, it returns an error code and the channel program continues
|
|
|
|
executing.
|
|
|
|
API functions do not generate Fatal Errors except in the case of an
|
|
|
|
unrecoverable internal file system error.
|
|
|
|
.Pp
|
|
|
|
In addition to returning an error code, some functions also return extra
|
|
|
|
details describing what caused the error.
|
|
|
|
This extra description is given as a second return value, and will always be a
|
|
|
|
Lua table, or Nil if no error details were returned.
|
|
|
|
Different keys will exist in the error details table depending on the function
|
|
|
|
and error case.
|
|
|
|
Any such function may be called expecting a single return value:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Dl errno = Sy zfs.sync.promote Ns Pq dataset
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
|
|
|
Or, the error details can be retrieved:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bd -literal -compact -offset indent
|
|
|
|
.No errno, details = Sy zfs.sync.promote Ns Pq dataset
|
2018-02-08 16:16:23 +00:00
|
|
|
if (errno == EEXIST) then
|
|
|
|
assert(details ~= Nil)
|
|
|
|
list_of_conflicting_snapshots = details
|
|
|
|
end
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The following global aliases for API function error return codes are defined
|
|
|
|
for use in channel programs:
|
2021-05-27 00:46:40 +00:00
|
|
|
.TS
|
|
|
|
cw3 l l l l l l l .
|
|
|
|
EPERM ECHILD ENODEV ENOSPC ENOENT EAGAIN ENOTDIR
|
|
|
|
ESPIPE ESRCH ENOMEM EISDIR EROFS EINTR EACCES
|
|
|
|
EINVAL EMLINK EIO EFAULT ENFILE EPIPE ENXIO
|
|
|
|
ENOTBLK EMFILE EDOM E2BIG EBUSY ENOTTY ERANGE
|
|
|
|
ENOEXEC EEXIST ETXTBSY EDQUOT EBADF EXDEV EFBIG
|
|
|
|
.TE
|
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss API Functions
|
2021-05-27 00:46:40 +00:00
|
|
|
For detailed descriptions of the exact behavior of any ZFS administrative
|
2018-02-08 16:16:23 +00:00
|
|
|
operations, see the main
|
2021-01-27 00:17:11 +00:00
|
|
|
.Xr zfs 8
|
2018-02-08 16:16:23 +00:00
|
|
|
manual page.
|
|
|
|
.Bl -tag -width "xx"
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Fn zfs.debug msg
|
2018-02-08 16:16:23 +00:00
|
|
|
Record a debug message in the zfs_dbgmsg log.
|
|
|
|
A log of these messages can be printed via mdb's "::zfs_dbgmsg" command, or
|
2021-05-27 00:46:40 +00:00
|
|
|
can be monitored live by running
|
|
|
|
.Dl dtrace -n 'zfs-dbgmsg{trace(stringof(arg0))}'
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "property (string)"
|
|
|
|
.It Ar msg Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Debug message to be printed.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.exists dataset
|
2018-02-08 16:17:52 +00:00
|
|
|
Returns true if the given dataset exists, or false if it doesn't.
|
|
|
|
A fatal error will be thrown if the dataset is not in the target pool.
|
|
|
|
That is, in a channel program running on rpool,
|
2021-05-27 00:46:40 +00:00
|
|
|
.Sy zfs.exists Ns Pq \&"rpool/nonexistent_fs"
|
|
|
|
returns false, but
|
|
|
|
.Sy zfs.exists Ns Pq \&"somepool/fs_that_may_exist"
|
|
|
|
will error.
|
2018-02-08 16:17:52 +00:00
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "property (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:17:52 +00:00
|
|
|
Dataset to check for existence.
|
|
|
|
Must be in the target pool.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.get_prop dataset property
|
2018-02-08 16:16:23 +00:00
|
|
|
Returns two values.
|
|
|
|
First, a string, number or table containing the property value for the given
|
|
|
|
dataset.
|
|
|
|
Second, a string containing the source of the property (i.e. the name of the
|
|
|
|
dataset in which it was set or nil if it is readonly).
|
|
|
|
Throws a Lua error if the dataset is invalid or the property doesn't exist.
|
|
|
|
Note that Lua only supports int64 number types whereas ZFS number properties
|
|
|
|
are uint64.
|
2021-05-27 00:46:40 +00:00
|
|
|
This means very large values (like GUIDs) may wrap around and appear negative.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "property (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Filesystem or snapshot path to retrieve properties from.
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Ar property Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Name of property to retrieve.
|
2021-05-27 00:46:40 +00:00
|
|
|
All filesystem, snapshot and volume properties are supported except for
|
|
|
|
.Sy mounted
|
|
|
|
and
|
|
|
|
.Sy iscsioptions .
|
|
|
|
Also supports the
|
|
|
|
.Sy written@ Ns Ar snap
|
|
|
|
and
|
|
|
|
.Sy written# Ns Ar bookmark
|
|
|
|
properties and the
|
|
|
|
.Ao Sy user Ns | Ns Sy group Ac Ns Ao Sy quota Ns | Ns Sy used Ac Ns Sy @ Ns Ar id
|
|
|
|
properties, though the id must be in numeric form.
|
|
|
|
.El
|
2018-02-08 16:16:23 +00:00
|
|
|
.El
|
|
|
|
.Bl -tag -width "xx"
|
|
|
|
.It Sy zfs.sync submodule
|
|
|
|
The sync submodule contains functions that modify the on-disk state.
|
|
|
|
They are executed in "syncing context".
|
|
|
|
.Pp
|
|
|
|
The available sync submodule functions are as follows:
|
|
|
|
.Bl -tag -width "xx"
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Sy zfs.sync.destroy Ns Pq Ar dataset , Op Ar defer Ns = Ns Sy true Ns | Ns Sy false
|
2018-02-08 16:16:23 +00:00
|
|
|
Destroy the given dataset.
|
|
|
|
Returns 0 on successful destroy, or a nonzero error code if the dataset could
|
|
|
|
not be destroyed (for example, if the dataset has any active children or
|
|
|
|
clones).
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Filesystem or snapshot to be destroyed.
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Op Ar defer Pq boolean
|
2018-02-08 16:16:23 +00:00
|
|
|
Valid only for destroying snapshots.
|
|
|
|
If set to true, and the snapshot has holds or clones, allows the snapshot to be
|
|
|
|
marked for deferred deletion rather than failing.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.sync.inherit dataset property
|
2020-01-23 01:03:17 +00:00
|
|
|
Clears the specified property in the given dataset, causing it to be inherited
|
|
|
|
from an ancestor, or restored to the default if no ancestor property is set.
|
|
|
|
The
|
2021-05-27 00:46:40 +00:00
|
|
|
.Nm zfs Cm inherit Fl S
|
2020-01-23 01:03:17 +00:00
|
|
|
option has not been implemented.
|
|
|
|
Returns 0 on success, or a nonzero error code if the property could not be
|
|
|
|
cleared.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar dataset Pq string
|
2020-01-23 01:03:17 +00:00
|
|
|
Filesystem or snapshot containing the property to clear.
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Ar property Pq string
|
2020-01-23 01:03:17 +00:00
|
|
|
The property to clear.
|
|
|
|
Allowed properties are the same as those for the
|
|
|
|
.Nm zfs Cm inherit
|
|
|
|
command.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.sync.promote dataset
|
2018-02-08 16:16:23 +00:00
|
|
|
Promote the given clone to a filesystem.
|
|
|
|
Returns 0 on successful promotion, or a nonzero error code otherwise.
|
|
|
|
If EEXIST is returned, the second return value will be an array of the clone's
|
|
|
|
snapshots whose names collide with snapshots of the parent filesystem.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Clone to be promoted.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.sync.rollback filesystem
|
2018-02-08 16:20:33 +00:00
|
|
|
Rollback to the previous snapshot for a dataset.
|
|
|
|
Returns 0 on successful rollback, or a nonzero error code otherwise.
|
|
|
|
Rollbacks can be performed on filesystems or zvols, but not on snapshots
|
|
|
|
or mounted datasets.
|
|
|
|
EBUSY is returned in the case where the filesystem is mounted.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar filesystem Pq string
|
2018-02-08 16:20:33 +00:00
|
|
|
Filesystem to rollback.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.sync.set_prop dataset property value
|
2020-02-14 21:41:42 +00:00
|
|
|
Sets the given property on a dataset.
|
|
|
|
Currently only user properties are supported.
|
|
|
|
Returns 0 if the property was set, or a nonzero error code otherwise.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar dataset Pq string
|
2020-02-14 21:41:42 +00:00
|
|
|
The dataset where the property will be set.
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Ar property Pq string
|
2020-02-14 21:41:42 +00:00
|
|
|
The property to set.
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Ar value Pq string
|
2020-02-14 21:41:42 +00:00
|
|
|
The value of the property to be set.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.sync.snapshot dataset
|
2018-02-08 16:24:39 +00:00
|
|
|
Create a snapshot of a filesystem.
|
|
|
|
Returns 0 if the snapshot was successfully created,
|
|
|
|
and a nonzero error code otherwise.
|
|
|
|
.Pp
|
|
|
|
Note: Taking a snapshot will fail on any pool older than legacy version 27.
|
|
|
|
To enable taking snapshots from ZCP scripts, the pool must be upgraded.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:24:39 +00:00
|
|
|
Name of snapshot to create.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
2022-09-02 20:31:19 +00:00
|
|
|
.It Fn zfs.sync.rename_snapshot dataset oldsnapname newsnapname
|
|
|
|
Rename a snapshot of a filesystem or a volume.
|
|
|
|
Returns 0 if the snapshot was successfully renamed,
|
|
|
|
and a nonzero error code otherwise.
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar dataset Pq string
|
|
|
|
Name of the snapshot's parent dataset.
|
|
|
|
.It Ar oldsnapname Pq string
|
|
|
|
Original name of the snapshot.
|
|
|
|
.It Ar newsnapname Pq string
|
|
|
|
New name of the snapshot.
|
|
|
|
.El
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Fn zfs.sync.bookmark source newbookmark
|
2020-01-16 01:15:05 +00:00
|
|
|
Create a bookmark of an existing source snapshot or bookmark.
|
|
|
|
Returns 0 if the new bookmark was successfully created,
|
|
|
|
and a nonzero error code otherwise.
|
|
|
|
.Pp
|
|
|
|
Note: Bookmarking requires the corresponding pool feature to be enabled.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "newbookmark (string)"
|
|
|
|
.It Ar source Pq string
|
2020-01-16 01:15:05 +00:00
|
|
|
Full name of the existing snapshot or bookmark.
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Ar newbookmark Pq string
|
2020-01-16 01:15:05 +00:00
|
|
|
Full name of the new bookmark.
|
2018-02-08 16:16:23 +00:00
|
|
|
.El
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
2018-02-08 16:16:23 +00:00
|
|
|
.It Sy zfs.check submodule
|
2021-05-27 00:46:40 +00:00
|
|
|
For each function in the
|
|
|
|
.Sy zfs.sync
|
|
|
|
submodule, there is a corresponding
|
|
|
|
.Sy zfs.check
|
2018-02-08 16:16:23 +00:00
|
|
|
function which performs a "dry run" of the same operation.
|
2021-05-27 00:46:40 +00:00
|
|
|
Each takes the same arguments as its
|
|
|
|
.Sy zfs.sync
|
|
|
|
counterpart and returns 0 if the operation would succeed,
|
|
|
|
or a non-zero error code if it would fail, along with any other error details.
|
2018-02-08 16:16:23 +00:00
|
|
|
That is, each has the same behavior as the corresponding sync function except
|
|
|
|
for actually executing the requested change.
|
|
|
|
For example,
|
2021-05-27 00:46:40 +00:00
|
|
|
.Fn zfs.check.destroy \&"fs"
|
2018-02-08 16:16:23 +00:00
|
|
|
returns 0 if
|
2021-05-27 00:46:40 +00:00
|
|
|
.Fn zfs.sync.destroy \&"fs"
|
2018-02-08 16:16:23 +00:00
|
|
|
would successfully destroy the dataset.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
The available
|
|
|
|
.Sy zfs.check
|
|
|
|
functions are:
|
|
|
|
.Bl -tag -compact -width "xx"
|
|
|
|
.It Sy zfs.check.destroy Ns Pq Ar dataset , Op Ar defer Ns = Ns Sy true Ns | Ns Sy false
|
|
|
|
.It Fn zfs.check.promote dataset
|
|
|
|
.It Fn zfs.check.rollback filesystem
|
|
|
|
.It Fn zfs.check.set_property dataset property value
|
|
|
|
.It Fn zfs.check.snapshot dataset
|
2018-02-08 16:16:23 +00:00
|
|
|
.El
|
|
|
|
.It Sy zfs.list submodule
|
|
|
|
The zfs.list submodule provides functions for iterating over datasets and
|
|
|
|
properties.
|
|
|
|
Rather than returning tables, these functions act as Lua iterators, and are
|
|
|
|
generally used as follows:
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bd -literal -compact -offset indent
|
|
|
|
.No for child in Fn zfs.list.children \&"rpool" No do
|
2018-02-08 16:16:23 +00:00
|
|
|
...
|
|
|
|
end
|
|
|
|
.Ed
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
The available
|
|
|
|
.Sy zfs.list
|
|
|
|
functions are:
|
2018-02-08 16:16:23 +00:00
|
|
|
.Bl -tag -width "xx"
|
2021-05-27 00:46:40 +00:00
|
|
|
.It Fn zfs.list.clones snapshot
|
2018-02-08 16:16:23 +00:00
|
|
|
Iterate through all clones of the given snapshot.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar snapshot Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Must be a valid snapshot path in the current pool.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.list.snapshots dataset
|
2018-02-08 16:16:23 +00:00
|
|
|
Iterate through all snapshots of the given dataset.
|
2021-05-27 00:46:40 +00:00
|
|
|
Each snapshot is returned as a string containing the full dataset name,
|
|
|
|
e.g. "pool/fs@snap".
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Must be a valid filesystem or volume.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.list.children dataset
|
2018-02-08 16:16:23 +00:00
|
|
|
Iterate through all direct children of the given dataset.
|
2021-05-27 00:46:40 +00:00
|
|
|
Each child is returned as a string containing the full dataset name,
|
|
|
|
e.g. "pool/fs/child".
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Must be a valid filesystem or volume.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.list.bookmarks dataset
|
|
|
|
Iterate through all bookmarks of the given dataset.
|
|
|
|
Each bookmark is returned as a string containing the full dataset name,
|
|
|
|
e.g. "pool/fs#bookmark".
|
2019-08-12 17:02:34 +00:00
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar dataset Pq string
|
2019-08-12 17:02:34 +00:00
|
|
|
Must be a valid filesystem or volume.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.list.holds snapshot
|
|
|
|
Iterate through all user holds on the given snapshot.
|
|
|
|
Each hold is returned
|
2019-08-12 17:02:34 +00:00
|
|
|
as a pair of the hold's tag and the timestamp (in seconds since the epoch) at
|
|
|
|
which it was created.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar snapshot Pq string
|
2019-08-12 17:02:34 +00:00
|
|
|
Must be a valid snapshot.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.list.properties dataset
|
2019-08-12 17:02:34 +00:00
|
|
|
An alias for zfs.list.user_properties (see relevant entry).
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar dataset Pq string
|
2019-08-12 17:02:34 +00:00
|
|
|
Must be a valid filesystem, snapshot, or volume.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.list.user_properties dataset
|
|
|
|
Iterate through all user properties for the given dataset.
|
|
|
|
For each step of the iteration, output the property name, its value,
|
|
|
|
and its source.
|
2019-08-12 17:02:34 +00:00
|
|
|
Throws a Lua error if the dataset is invalid.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Must be a valid filesystem, snapshot, or volume.
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.It Fn zfs.list.system_properties dataset
|
2018-02-08 16:16:23 +00:00
|
|
|
Returns an array of strings, the names of the valid system (non-user defined)
|
|
|
|
properties for the given dataset.
|
|
|
|
Throws a Lua error if the dataset is invalid.
|
|
|
|
.Pp
|
2021-05-27 00:46:40 +00:00
|
|
|
.Bl -tag -compact -width "snapshot (string)"
|
|
|
|
.It Ar dataset Pq string
|
2018-02-08 16:16:23 +00:00
|
|
|
Must be a valid filesystem, snapshot or volume.
|
|
|
|
.El
|
|
|
|
.El
|
2021-05-27 00:46:40 +00:00
|
|
|
.El
|
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Sh EXAMPLES
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Example 1
|
|
|
|
The following channel program recursively destroys a filesystem and all its
|
|
|
|
snapshots and children in a naive manner.
|
|
|
|
Note that this does not involve any error handling or reporting.
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
function destroy_recursive(root)
|
|
|
|
for child in zfs.list.children(root) do
|
|
|
|
destroy_recursive(child)
|
|
|
|
end
|
|
|
|
for snap in zfs.list.snapshots(root) do
|
|
|
|
zfs.sync.destroy(snap)
|
|
|
|
end
|
|
|
|
zfs.sync.destroy(root)
|
|
|
|
end
|
|
|
|
destroy_recursive("pool/somefs")
|
|
|
|
.Ed
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Example 2
|
|
|
|
A more verbose and robust version of the same channel program, which
|
|
|
|
properly detects and reports errors, and also takes the dataset to destroy
|
|
|
|
as a command line argument, would be as follows:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
succeeded = {}
|
|
|
|
failed = {}
|
|
|
|
|
|
|
|
function destroy_recursive(root)
|
|
|
|
for child in zfs.list.children(root) do
|
|
|
|
destroy_recursive(child)
|
|
|
|
end
|
|
|
|
for snap in zfs.list.snapshots(root) do
|
|
|
|
err = zfs.sync.destroy(snap)
|
|
|
|
if (err ~= 0) then
|
|
|
|
failed[snap] = err
|
|
|
|
else
|
|
|
|
succeeded[snap] = err
|
|
|
|
end
|
|
|
|
end
|
|
|
|
err = zfs.sync.destroy(root)
|
|
|
|
if (err ~= 0) then
|
|
|
|
failed[root] = err
|
|
|
|
else
|
|
|
|
succeeded[root] = err
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
args = ...
|
|
|
|
argv = args["argv"]
|
|
|
|
|
|
|
|
destroy_recursive(argv[1])
|
|
|
|
|
|
|
|
results = {}
|
|
|
|
results["succeeded"] = succeeded
|
|
|
|
results["failed"] = failed
|
|
|
|
return results
|
|
|
|
.Ed
|
2021-05-27 00:46:40 +00:00
|
|
|
.
|
2018-02-08 16:16:23 +00:00
|
|
|
.Ss Example 3
|
|
|
|
The following function performs a forced promote operation by attempting to
|
|
|
|
promote the given clone and destroying any conflicting snapshots.
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
function force_promote(ds)
|
|
|
|
errno, details = zfs.check.promote(ds)
|
|
|
|
if (errno == EEXIST) then
|
|
|
|
assert(details ~= Nil)
|
|
|
|
for i, snap in ipairs(details) do
|
|
|
|
zfs.sync.destroy(ds .. "@" .. snap)
|
|
|
|
end
|
|
|
|
elseif (errno ~= 0) then
|
|
|
|
return errno
|
|
|
|
end
|
|
|
|
return zfs.sync.promote(ds)
|
|
|
|
end
|
|
|
|
.Ed
|