xref: /freebsd/sys/contrib/openzfs/man/man8/zfs-program.8 (revision c7046f76c2c027b00c0e6ba57cfd28f1a78f5e23)
116038816SMartin Matuska.\"
2eda14cbcSMatt Macy.\" This file and its contents are supplied under the terms of the
3eda14cbcSMatt Macy.\" Common Development and Distribution License ("CDDL"), version 1.0.
4eda14cbcSMatt Macy.\" You may only use this file in accordance with the terms of version
5eda14cbcSMatt Macy.\" 1.0 of the CDDL.
6eda14cbcSMatt Macy.\"
7eda14cbcSMatt Macy.\" A full copy of the text of the CDDL should have accompanied this
8eda14cbcSMatt Macy.\" source.  A copy of the CDDL is also available via the Internet at
9eda14cbcSMatt Macy.\" http://www.illumos.org/license/CDDL.
10eda14cbcSMatt Macy.\"
11eda14cbcSMatt Macy.\" Copyright (c) 2016, 2019 by Delphix. All Rights Reserved.
12eda14cbcSMatt Macy.\" Copyright (c) 2019, 2020 by Christian Schwarz. All Rights Reserved.
13eda14cbcSMatt Macy.\" Copyright 2020 Joyent, Inc.
14eda14cbcSMatt Macy.\"
1516038816SMartin Matuska.Dd May 27, 2021
16eda14cbcSMatt Macy.Dt ZFS-PROGRAM 8
17eda14cbcSMatt Macy.Os
1816038816SMartin Matuska.
19eda14cbcSMatt Macy.Sh NAME
207877fdebSMatt Macy.Nm zfs-program
2116038816SMartin Matuska.Nd execute ZFS channel programs
22eda14cbcSMatt Macy.Sh SYNOPSIS
237877fdebSMatt Macy.Nm zfs
247877fdebSMatt Macy.Cm program
25eda14cbcSMatt Macy.Op Fl jn
26eda14cbcSMatt Macy.Op Fl t Ar instruction-limit
27eda14cbcSMatt Macy.Op Fl m Ar memory-limit
28eda14cbcSMatt Macy.Ar pool
29eda14cbcSMatt Macy.Ar script
3016038816SMartin Matuska.Op Ar script arguments
3116038816SMartin Matuska.
32eda14cbcSMatt Macy.Sh DESCRIPTION
33eda14cbcSMatt MacyThe ZFS channel program interface allows ZFS administrative operations to be
34eda14cbcSMatt Macyrun programmatically as a Lua script.
35eda14cbcSMatt MacyThe entire script is executed atomically, with no other administrative
36eda14cbcSMatt Macyoperations taking effect concurrently.
37eda14cbcSMatt MacyA library of ZFS calls is made available to channel program scripts.
38eda14cbcSMatt MacyChannel programs may only be run with root privileges.
39eda14cbcSMatt Macy.Pp
40eda14cbcSMatt MacyA modified version of the Lua 5.2 interpreter is used to run channel program
41eda14cbcSMatt Macyscripts.
4216038816SMartin MatuskaThe Lua 5.2 manual can be found at
43eda14cbcSMatt Macy.Lk http://www.lua.org/manual/5.2/
44eda14cbcSMatt Macy.Pp
45eda14cbcSMatt MacyThe channel program given by
46eda14cbcSMatt Macy.Ar script
47eda14cbcSMatt Macywill be run on
48eda14cbcSMatt Macy.Ar pool ,
49eda14cbcSMatt Macyand any attempts to access or modify other pools will cause an error.
5016038816SMartin Matuska.
51eda14cbcSMatt Macy.Sh OPTIONS
52eda14cbcSMatt Macy.Bl -tag -width "-t"
53eda14cbcSMatt Macy.It Fl j
5416038816SMartin MatuskaDisplay channel program output in JSON format.
5516038816SMartin MatuskaWhen this flag is specified and standard output is empty -
5616038816SMartin Matuskachannel program encountered an error.
5716038816SMartin MatuskaThe details of such an error will be printed to standard error in plain text.
58eda14cbcSMatt Macy.It Fl n
59eda14cbcSMatt MacyExecutes a read-only channel program, which runs faster.
60eda14cbcSMatt MacyThe program cannot change on-disk state by calling functions from the
61eda14cbcSMatt Macyzfs.sync submodule.
62eda14cbcSMatt MacyThe program can be used to gather information such as properties and
63eda14cbcSMatt Macydetermining if changes would succeed (zfs.check.*).
64eda14cbcSMatt MacyWithout this flag, all pending changes must be synced to disk before a
65eda14cbcSMatt Macychannel program can complete.
66eda14cbcSMatt Macy.It Fl t Ar instruction-limit
67eda14cbcSMatt MacyLimit the number of Lua instructions to execute.
68eda14cbcSMatt MacyIf a channel program executes more than the specified number of instructions,
69eda14cbcSMatt Macyit will be stopped and an error will be returned.
70eda14cbcSMatt MacyThe default limit is 10 million instructions, and it can be set to a maximum of
71eda14cbcSMatt Macy100 million instructions.
72eda14cbcSMatt Macy.It Fl m Ar memory-limit
73eda14cbcSMatt MacyMemory limit, in bytes.
74eda14cbcSMatt MacyIf a channel program attempts to allocate more memory than the given limit, it
75eda14cbcSMatt Macywill be stopped and an error returned.
76716fd348SMartin MatuskaThe default memory limit is 10 MiB, and can be set to a maximum of 100 MiB.
77eda14cbcSMatt Macy.El
78eda14cbcSMatt Macy.Pp
79eda14cbcSMatt MacyAll remaining argument strings will be passed directly to the Lua script as
80eda14cbcSMatt Macydescribed in the
81eda14cbcSMatt Macy.Sx LUA INTERFACE
82eda14cbcSMatt Macysection below.
8316038816SMartin Matuska.
84eda14cbcSMatt Macy.Sh LUA INTERFACE
85eda14cbcSMatt MacyA channel program can be invoked either from the command line, or via a library
86eda14cbcSMatt Macycall to
87eda14cbcSMatt Macy.Fn lzc_channel_program .
8816038816SMartin Matuska.
89eda14cbcSMatt Macy.Ss Arguments
90eda14cbcSMatt MacyArguments passed to the channel program are converted to a Lua table.
91eda14cbcSMatt MacyIf invoked from the command line, extra arguments to the Lua script will be
92eda14cbcSMatt Macyaccessible as an array stored in the argument table with the key 'argv':
9316038816SMartin Matuska.Bd -literal -compact -offset indent
94eda14cbcSMatt Macyargs = ...
95eda14cbcSMatt Macyargv = args["argv"]
96eda14cbcSMatt Macy-- argv == {1="arg1", 2="arg2", ...}
97eda14cbcSMatt Macy.Ed
98eda14cbcSMatt Macy.Pp
99716fd348SMartin MatuskaIf invoked from the libzfs interface, an arbitrary argument list can be
100eda14cbcSMatt Macypassed to the channel program, which is accessible via the same
101716fd348SMartin Matuska.Qq Li ...
102716fd348SMartin Matuskasyntax in Lua:
10316038816SMartin Matuska.Bd -literal -compact -offset indent
104eda14cbcSMatt Macyargs = ...
105eda14cbcSMatt Macy-- args == {"foo"="bar", "baz"={...}, ...}
106eda14cbcSMatt Macy.Ed
107eda14cbcSMatt Macy.Pp
108eda14cbcSMatt MacyNote that because Lua arrays are 1-indexed, arrays passed to Lua from the
109716fd348SMartin Matuskalibzfs interface will have their indices incremented by 1.
110eda14cbcSMatt MacyThat is, the element
111eda14cbcSMatt Macyin
112eda14cbcSMatt Macy.Va arr[0]
113eda14cbcSMatt Macyin a C array passed to a channel program will be stored in
114eda14cbcSMatt Macy.Va arr[1]
115eda14cbcSMatt Macywhen accessed from Lua.
11616038816SMartin Matuska.
117eda14cbcSMatt Macy.Ss Return Values
118eda14cbcSMatt MacyLua return statements take the form:
11916038816SMartin Matuska.Dl return ret0, ret1, ret2, ...
120eda14cbcSMatt Macy.Pp
121eda14cbcSMatt MacyReturn statements returning multiple values are permitted internally in a
122eda14cbcSMatt Macychannel program script, but attempting to return more than one value from the
123eda14cbcSMatt Macytop level of the channel program is not permitted and will throw an error.
124eda14cbcSMatt MacyHowever, tables containing multiple values can still be returned.
125eda14cbcSMatt MacyIf invoked from the command line, a return statement:
12616038816SMartin Matuska.Bd -literal -compact -offset indent
127eda14cbcSMatt Macya = {foo="bar", baz=2}
128eda14cbcSMatt Macyreturn a
129eda14cbcSMatt Macy.Ed
130eda14cbcSMatt Macy.Pp
131eda14cbcSMatt MacyWill be output formatted as:
13216038816SMartin Matuska.Bd -literal -compact -offset indent
133eda14cbcSMatt MacyChannel program fully executed with return value:
134eda14cbcSMatt Macy    return:
135eda14cbcSMatt Macy        baz: 2
136eda14cbcSMatt Macy        foo: 'bar'
137eda14cbcSMatt Macy.Ed
13816038816SMartin Matuska.
139eda14cbcSMatt Macy.Ss Fatal Errors
140eda14cbcSMatt MacyIf the channel program encounters a fatal error while running, a non-zero exit
141eda14cbcSMatt Macystatus will be returned.
142eda14cbcSMatt MacyIf more information about the error is available, a singleton list will be
143eda14cbcSMatt Macyreturned detailing the error:
14416038816SMartin Matuska.Dl error: \&"error string, including Lua stack trace"
145eda14cbcSMatt Macy.Pp
146eda14cbcSMatt MacyIf a fatal error is returned, the channel program may have not executed at all,
147eda14cbcSMatt Macymay have partially executed, or may have fully executed but failed to pass a
148eda14cbcSMatt Macyreturn value back to userland.
149eda14cbcSMatt Macy.Pp
150eda14cbcSMatt MacyIf the channel program exhausts an instruction or memory limit, a fatal error
151eda14cbcSMatt Macywill be generated and the program will be stopped, leaving the program partially
152eda14cbcSMatt Macyexecuted.
153eda14cbcSMatt MacyNo attempt is made to reverse or undo any operations already performed.
154eda14cbcSMatt MacyNote that because both the instruction count and amount of memory used by a
155eda14cbcSMatt Macychannel program are deterministic when run against the same inputs and
156eda14cbcSMatt Macyfilesystem state, as long as a channel program has run successfully once, you
157eda14cbcSMatt Macycan guarantee that it will finish successfully against a similar size system.
158eda14cbcSMatt Macy.Pp
159eda14cbcSMatt MacyIf a channel program attempts to return too large a value, the program will
160eda14cbcSMatt Macyfully execute but exit with a nonzero status code and no return value.
161eda14cbcSMatt Macy.Pp
162eda14cbcSMatt Macy.Em Note :
163eda14cbcSMatt MacyZFS API functions do not generate Fatal Errors when correctly invoked, they
164eda14cbcSMatt Macyreturn an error code and the channel program continues executing.
165eda14cbcSMatt MacySee the
166eda14cbcSMatt Macy.Sx ZFS API
167eda14cbcSMatt Macysection below for function-specific details on error return codes.
16816038816SMartin Matuska.
169eda14cbcSMatt Macy.Ss Lua to C Value Conversion
170716fd348SMartin MatuskaWhen invoking a channel program via the libzfs interface, it is necessary to
171eda14cbcSMatt Macytranslate arguments and return values from Lua values to their C equivalents,
172eda14cbcSMatt Macyand vice-versa.
173eda14cbcSMatt Macy.Pp
174eda14cbcSMatt MacyThere is a correspondence between nvlist values in C and Lua tables.
175eda14cbcSMatt MacyA Lua table which is returned from the channel program will be recursively
176eda14cbcSMatt Macyconverted to an nvlist, with table values converted to their natural
177eda14cbcSMatt Macyequivalents:
17816038816SMartin Matuska.TS
17916038816SMartin Matuskacw3 l c l .
180eda14cbcSMatt Macy	string	->	string
181eda14cbcSMatt Macy	number	->	int64
182eda14cbcSMatt Macy	boolean	->	boolean_value
183eda14cbcSMatt Macy	nil	->	boolean (no value)
184eda14cbcSMatt Macy	table	->	nvlist
18516038816SMartin Matuska.TE
186eda14cbcSMatt Macy.Pp
187eda14cbcSMatt MacyLikewise, table keys are replaced by string equivalents as follows:
18816038816SMartin Matuska.TS
18916038816SMartin Matuskacw3 l c l .
190eda14cbcSMatt Macy	string	->	no change
191eda14cbcSMatt Macy	number	->	signed decimal string ("%lld")
192eda14cbcSMatt Macy	boolean	->	"true" | "false"
19316038816SMartin Matuska.TE
194eda14cbcSMatt Macy.Pp
195eda14cbcSMatt MacyAny collision of table key strings (for example, the string "true" and a
196eda14cbcSMatt Macytrue boolean value) will cause a fatal error.
197eda14cbcSMatt Macy.Pp
198eda14cbcSMatt MacyLua numbers are represented internally as signed 64-bit integers.
19916038816SMartin Matuska.
200eda14cbcSMatt Macy.Sh LUA STANDARD LIBRARY
201eda14cbcSMatt MacyThe following Lua built-in base library functions are available:
20216038816SMartin Matuska.TS
20316038816SMartin Matuskacw3 l l l l .
20416038816SMartin Matuska	assert	rawlen	collectgarbage	rawget
20516038816SMartin Matuska	error	rawset	getmetatable	select
20616038816SMartin Matuska	ipairs	setmetatable	next	tonumber
20716038816SMartin Matuska	pairs	tostring	rawequal	type
20816038816SMartin Matuska.TE
209eda14cbcSMatt Macy.Pp
210eda14cbcSMatt MacyAll functions in the
211eda14cbcSMatt Macy.Em coroutine ,
212eda14cbcSMatt Macy.Em string ,
213eda14cbcSMatt Macyand
214eda14cbcSMatt Macy.Em table
215eda14cbcSMatt Macybuilt-in submodules are also available.
216eda14cbcSMatt MacyA complete list and documentation of these modules is available in the Lua
217eda14cbcSMatt Macymanual.
218eda14cbcSMatt Macy.Pp
219eda14cbcSMatt MacyThe following functions base library functions have been disabled and are
220eda14cbcSMatt Macynot available for use in channel programs:
22116038816SMartin Matuska.TS
22216038816SMartin Matuskacw3 l l l l l l .
22316038816SMartin Matuska	dofile	loadfile	load	pcall	print	xpcall
22416038816SMartin Matuska.TE
22516038816SMartin Matuska.
226eda14cbcSMatt Macy.Sh ZFS API
22716038816SMartin Matuska.
228eda14cbcSMatt Macy.Ss Function Arguments
229eda14cbcSMatt MacyEach API function takes a fixed set of required positional arguments and
230eda14cbcSMatt Macyoptional keyword arguments.
231eda14cbcSMatt MacyFor example, the destroy function takes a single positional string argument
232eda14cbcSMatt Macy(the name of the dataset to destroy) and an optional "defer" keyword boolean
233eda14cbcSMatt Macyargument.
234eda14cbcSMatt MacyWhen using parentheses to specify the arguments to a Lua function, only
235eda14cbcSMatt Macypositional arguments can be used:
23616038816SMartin Matuska.Dl Sy zfs.sync.destroy Ns Pq \&"rpool@snap"
237eda14cbcSMatt Macy.Pp
238eda14cbcSMatt MacyTo use keyword arguments, functions must be called with a single argument that
239eda14cbcSMatt Macyis a Lua table containing entries mapping integers to positional arguments and
240eda14cbcSMatt Macystrings to keyword arguments:
24116038816SMartin Matuska.Dl Sy zfs.sync.destroy Ns Pq {1="rpool@snap", defer=true}
242eda14cbcSMatt Macy.Pp
243eda14cbcSMatt MacyThe Lua language allows curly braces to be used in place of parenthesis as
244eda14cbcSMatt Macysyntactic sugar for this calling convention:
24516038816SMartin Matuska.Dl Sy zfs.sync.snapshot Ns {"rpool@snap", defer=true}
24616038816SMartin Matuska.
247eda14cbcSMatt Macy.Ss Function Return Values
248eda14cbcSMatt MacyIf an API function succeeds, it returns 0.
249eda14cbcSMatt MacyIf it fails, it returns an error code and the channel program continues
250eda14cbcSMatt Macyexecuting.
251eda14cbcSMatt MacyAPI functions do not generate Fatal Errors except in the case of an
252eda14cbcSMatt Macyunrecoverable internal file system error.
253eda14cbcSMatt Macy.Pp
254eda14cbcSMatt MacyIn addition to returning an error code, some functions also return extra
255eda14cbcSMatt Macydetails describing what caused the error.
256eda14cbcSMatt MacyThis extra description is given as a second return value, and will always be a
257eda14cbcSMatt MacyLua table, or Nil if no error details were returned.
258eda14cbcSMatt MacyDifferent keys will exist in the error details table depending on the function
259eda14cbcSMatt Macyand error case.
260eda14cbcSMatt MacyAny such function may be called expecting a single return value:
26116038816SMartin Matuska.Dl errno = Sy zfs.sync.promote Ns Pq dataset
262eda14cbcSMatt Macy.Pp
263eda14cbcSMatt MacyOr, the error details can be retrieved:
26416038816SMartin Matuska.Bd -literal -compact -offset indent
26516038816SMartin Matuska.No errno, details = Sy zfs.sync.promote Ns Pq dataset
266eda14cbcSMatt Macyif (errno == EEXIST) then
267eda14cbcSMatt Macy    assert(details ~= Nil)
268eda14cbcSMatt Macy    list_of_conflicting_snapshots = details
269eda14cbcSMatt Macyend
270eda14cbcSMatt Macy.Ed
271eda14cbcSMatt Macy.Pp
272eda14cbcSMatt MacyThe following global aliases for API function error return codes are defined
273eda14cbcSMatt Macyfor use in channel programs:
27416038816SMartin Matuska.TS
27516038816SMartin Matuskacw3 l l l l l l l .
27616038816SMartin Matuska	EPERM	ECHILD	ENODEV	ENOSPC	ENOENT	EAGAIN	ENOTDIR
27716038816SMartin Matuska	ESPIPE	ESRCH	ENOMEM	EISDIR	EROFS	EINTR	EACCES
27816038816SMartin Matuska	EINVAL	EMLINK	EIO	EFAULT	ENFILE	EPIPE	ENXIO
27916038816SMartin Matuska	ENOTBLK	EMFILE	EDOM	E2BIG	EBUSY	ENOTTY	ERANGE
28016038816SMartin Matuska	ENOEXEC	EEXIST	ETXTBSY	EDQUOT	EBADF	EXDEV	EFBIG
28116038816SMartin Matuska.TE
28216038816SMartin Matuska.
283eda14cbcSMatt Macy.Ss API Functions
28416038816SMartin MatuskaFor detailed descriptions of the exact behavior of any ZFS administrative
285eda14cbcSMatt Macyoperations, see the main
286184c1b94SMartin Matuska.Xr zfs 8
287eda14cbcSMatt Macymanual page.
288eda14cbcSMatt Macy.Bl -tag -width "xx"
28916038816SMartin Matuska.It Fn zfs.debug msg
290eda14cbcSMatt MacyRecord a debug message in the zfs_dbgmsg log.
291eda14cbcSMatt MacyA log of these messages can be printed via mdb's "::zfs_dbgmsg" command, or
29216038816SMartin Matuskacan be monitored live by running
29316038816SMartin Matuska.Dl dtrace -n 'zfs-dbgmsg{trace(stringof(arg0))}'
294eda14cbcSMatt Macy.Pp
29516038816SMartin Matuska.Bl -tag -compact -width "property (string)"
29616038816SMartin Matuska.It Ar msg Pq string
297eda14cbcSMatt MacyDebug message to be printed.
29816038816SMartin Matuska.El
29916038816SMartin Matuska.It Fn zfs.exists dataset
300eda14cbcSMatt MacyReturns true if the given dataset exists, or false if it doesn't.
301eda14cbcSMatt MacyA fatal error will be thrown if the dataset is not in the target pool.
302eda14cbcSMatt MacyThat is, in a channel program running on rpool,
30316038816SMartin Matuska.Sy zfs.exists Ns Pq \&"rpool/nonexistent_fs"
30416038816SMartin Matuskareturns false, but
30516038816SMartin Matuska.Sy zfs.exists Ns Pq \&"somepool/fs_that_may_exist"
30616038816SMartin Matuskawill error.
307eda14cbcSMatt Macy.Pp
30816038816SMartin Matuska.Bl -tag -compact -width "property (string)"
30916038816SMartin Matuska.It Ar dataset Pq string
310eda14cbcSMatt MacyDataset to check for existence.
311eda14cbcSMatt MacyMust be in the target pool.
31216038816SMartin Matuska.El
31316038816SMartin Matuska.It Fn zfs.get_prop dataset property
314eda14cbcSMatt MacyReturns two values.
315eda14cbcSMatt MacyFirst, a string, number or table containing the property value for the given
316eda14cbcSMatt Macydataset.
317eda14cbcSMatt MacySecond, a string containing the source of the property (i.e. the name of the
318eda14cbcSMatt Macydataset in which it was set or nil if it is readonly).
319eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid or the property doesn't exist.
320eda14cbcSMatt MacyNote that Lua only supports int64 number types whereas ZFS number properties
321eda14cbcSMatt Macyare uint64.
32216038816SMartin MatuskaThis means very large values (like GUIDs) may wrap around and appear negative.
323eda14cbcSMatt Macy.Pp
32416038816SMartin Matuska.Bl -tag -compact -width "property (string)"
32516038816SMartin Matuska.It Ar dataset Pq string
326eda14cbcSMatt MacyFilesystem or snapshot path to retrieve properties from.
32716038816SMartin Matuska.It Ar property Pq string
328eda14cbcSMatt MacyName of property to retrieve.
32916038816SMartin MatuskaAll filesystem, snapshot and volume properties are supported except for
33016038816SMartin Matuska.Sy mounted
33116038816SMartin Matuskaand
33216038816SMartin Matuska.Sy iscsioptions .
33316038816SMartin MatuskaAlso supports the
33416038816SMartin Matuska.Sy written@ Ns Ar snap
33516038816SMartin Matuskaand
33616038816SMartin Matuska.Sy written# Ns Ar bookmark
33716038816SMartin Matuskaproperties and the
33816038816SMartin Matuska.Ao Sy user Ns | Ns Sy group Ac Ns Ao Sy quota Ns | Ns Sy used Ac Ns Sy @ Ns Ar id
33916038816SMartin Matuskaproperties, though the id must be in numeric form.
34016038816SMartin Matuska.El
341eda14cbcSMatt Macy.El
342eda14cbcSMatt Macy.Bl -tag -width "xx"
343eda14cbcSMatt Macy.It Sy zfs.sync submodule
344eda14cbcSMatt MacyThe sync submodule contains functions that modify the on-disk state.
345eda14cbcSMatt MacyThey are executed in "syncing context".
346eda14cbcSMatt Macy.Pp
347eda14cbcSMatt MacyThe available sync submodule functions are as follows:
348eda14cbcSMatt Macy.Bl -tag -width "xx"
34916038816SMartin Matuska.It Sy zfs.sync.destroy Ns Pq Ar dataset , Op Ar defer Ns = Ns Sy true Ns | Ns Sy false
350eda14cbcSMatt MacyDestroy the given dataset.
351eda14cbcSMatt MacyReturns 0 on successful destroy, or a nonzero error code if the dataset could
352eda14cbcSMatt Macynot be destroyed (for example, if the dataset has any active children or
353eda14cbcSMatt Macyclones).
354eda14cbcSMatt Macy.Pp
35516038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
35616038816SMartin Matuska.It Ar dataset Pq string
357eda14cbcSMatt MacyFilesystem or snapshot to be destroyed.
35816038816SMartin Matuska.It Op Ar defer Pq boolean
359eda14cbcSMatt MacyValid only for destroying snapshots.
360eda14cbcSMatt MacyIf set to true, and the snapshot has holds or clones, allows the snapshot to be
361eda14cbcSMatt Macymarked for deferred deletion rather than failing.
36216038816SMartin Matuska.El
36316038816SMartin Matuska.It Fn zfs.sync.inherit dataset property
364eda14cbcSMatt MacyClears the specified property in the given dataset, causing it to be inherited
365eda14cbcSMatt Macyfrom an ancestor, or restored to the default if no ancestor property is set.
366eda14cbcSMatt MacyThe
36716038816SMartin Matuska.Nm zfs Cm inherit Fl S
368eda14cbcSMatt Macyoption has not been implemented.
369eda14cbcSMatt MacyReturns 0 on success, or a nonzero error code if the property could not be
370eda14cbcSMatt Macycleared.
371eda14cbcSMatt Macy.Pp
37216038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
37316038816SMartin Matuska.It Ar dataset Pq string
374eda14cbcSMatt MacyFilesystem or snapshot containing the property to clear.
37516038816SMartin Matuska.It Ar property Pq string
376eda14cbcSMatt MacyThe property to clear.
377eda14cbcSMatt MacyAllowed properties are the same as those for the
378eda14cbcSMatt Macy.Nm zfs Cm inherit
379eda14cbcSMatt Macycommand.
38016038816SMartin Matuska.El
38116038816SMartin Matuska.It Fn zfs.sync.promote dataset
382eda14cbcSMatt MacyPromote the given clone to a filesystem.
383eda14cbcSMatt MacyReturns 0 on successful promotion, or a nonzero error code otherwise.
384eda14cbcSMatt MacyIf EEXIST is returned, the second return value will be an array of the clone's
385eda14cbcSMatt Macysnapshots whose names collide with snapshots of the parent filesystem.
386eda14cbcSMatt Macy.Pp
38716038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
38816038816SMartin Matuska.It Ar dataset Pq string
389eda14cbcSMatt MacyClone to be promoted.
39016038816SMartin Matuska.El
39116038816SMartin Matuska.It Fn zfs.sync.rollback filesystem
392eda14cbcSMatt MacyRollback to the previous snapshot for a dataset.
393eda14cbcSMatt MacyReturns 0 on successful rollback, or a nonzero error code otherwise.
394eda14cbcSMatt MacyRollbacks can be performed on filesystems or zvols, but not on snapshots
395eda14cbcSMatt Macyor mounted datasets.
396eda14cbcSMatt MacyEBUSY is returned in the case where the filesystem is mounted.
397eda14cbcSMatt Macy.Pp
39816038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
39916038816SMartin Matuska.It Ar filesystem Pq string
400eda14cbcSMatt MacyFilesystem to rollback.
40116038816SMartin Matuska.El
40216038816SMartin Matuska.It Fn zfs.sync.set_prop dataset property value
403eda14cbcSMatt MacySets the given property on a dataset.
404eda14cbcSMatt MacyCurrently only user properties are supported.
405eda14cbcSMatt MacyReturns 0 if the property was set, or a nonzero error code otherwise.
406eda14cbcSMatt Macy.Pp
40716038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
40816038816SMartin Matuska.It Ar dataset Pq string
409eda14cbcSMatt MacyThe dataset where the property will be set.
41016038816SMartin Matuska.It Ar property Pq string
411eda14cbcSMatt MacyThe property to set.
41216038816SMartin Matuska.It Ar value Pq string
413eda14cbcSMatt MacyThe value of the property to be set.
41416038816SMartin Matuska.El
41516038816SMartin Matuska.It Fn zfs.sync.snapshot dataset
416eda14cbcSMatt MacyCreate a snapshot of a filesystem.
417eda14cbcSMatt MacyReturns 0 if the snapshot was successfully created,
418eda14cbcSMatt Macyand a nonzero error code otherwise.
419eda14cbcSMatt Macy.Pp
420eda14cbcSMatt MacyNote: Taking a snapshot will fail on any pool older than legacy version 27.
421eda14cbcSMatt MacyTo enable taking snapshots from ZCP scripts, the pool must be upgraded.
422eda14cbcSMatt Macy.Pp
42316038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
42416038816SMartin Matuska.It Ar dataset Pq string
425eda14cbcSMatt MacyName of snapshot to create.
42616038816SMartin Matuska.El
427*c7046f76SMartin Matuska.It Fn zfs.sync.rename_snapshot dataset oldsnapname newsnapname
428*c7046f76SMartin MatuskaRename a snapshot of a filesystem or a volume.
429*c7046f76SMartin MatuskaReturns 0 if the snapshot was successfully renamed,
430*c7046f76SMartin Matuskaand a nonzero error code otherwise.
431*c7046f76SMartin Matuska.Pp
432*c7046f76SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
433*c7046f76SMartin Matuska.It Ar dataset Pq string
434*c7046f76SMartin MatuskaName of the snapshot's parent dataset.
435*c7046f76SMartin Matuska.It Ar oldsnapname Pq string
436*c7046f76SMartin MatuskaOriginal name of the snapshot.
437*c7046f76SMartin Matuska.It Ar newsnapname Pq string
438*c7046f76SMartin MatuskaNew name of the snapshot.
439*c7046f76SMartin Matuska.El
44016038816SMartin Matuska.It Fn zfs.sync.bookmark source newbookmark
441eda14cbcSMatt MacyCreate a bookmark of an existing source snapshot or bookmark.
442eda14cbcSMatt MacyReturns 0 if the new bookmark was successfully created,
443eda14cbcSMatt Macyand a nonzero error code otherwise.
444eda14cbcSMatt Macy.Pp
445eda14cbcSMatt MacyNote: Bookmarking requires the corresponding pool feature to be enabled.
446eda14cbcSMatt Macy.Pp
44716038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)"
44816038816SMartin Matuska.It Ar source Pq string
449eda14cbcSMatt MacyFull name of the existing snapshot or bookmark.
45016038816SMartin Matuska.It Ar newbookmark Pq string
451eda14cbcSMatt MacyFull name of the new bookmark.
452eda14cbcSMatt Macy.El
45316038816SMartin Matuska.El
454eda14cbcSMatt Macy.It Sy zfs.check submodule
45516038816SMartin MatuskaFor each function in the
45616038816SMartin Matuska.Sy zfs.sync
45716038816SMartin Matuskasubmodule, there is a corresponding
45816038816SMartin Matuska.Sy zfs.check
459eda14cbcSMatt Macyfunction which performs a "dry run" of the same operation.
46016038816SMartin MatuskaEach takes the same arguments as its
46116038816SMartin Matuska.Sy zfs.sync
46216038816SMartin Matuskacounterpart and returns 0 if the operation would succeed,
46316038816SMartin Matuskaor a non-zero error code if it would fail, along with any other error details.
464eda14cbcSMatt MacyThat is, each has the same behavior as the corresponding sync function except
465eda14cbcSMatt Macyfor actually executing the requested change.
466eda14cbcSMatt MacyFor example,
46716038816SMartin Matuska.Fn zfs.check.destroy \&"fs"
468eda14cbcSMatt Macyreturns 0 if
46916038816SMartin Matuska.Fn zfs.sync.destroy \&"fs"
470eda14cbcSMatt Macywould successfully destroy the dataset.
471eda14cbcSMatt Macy.Pp
47216038816SMartin MatuskaThe available
47316038816SMartin Matuska.Sy zfs.check
47416038816SMartin Matuskafunctions are:
47516038816SMartin Matuska.Bl -tag -compact -width "xx"
47616038816SMartin Matuska.It Sy zfs.check.destroy Ns Pq Ar dataset , Op Ar defer Ns = Ns Sy true Ns | Ns Sy false
47716038816SMartin Matuska.It Fn zfs.check.promote dataset
47816038816SMartin Matuska.It Fn zfs.check.rollback filesystem
47916038816SMartin Matuska.It Fn zfs.check.set_property dataset property value
48016038816SMartin Matuska.It Fn zfs.check.snapshot dataset
481eda14cbcSMatt Macy.El
482eda14cbcSMatt Macy.It Sy zfs.list submodule
483eda14cbcSMatt MacyThe zfs.list submodule provides functions for iterating over datasets and
484eda14cbcSMatt Macyproperties.
485eda14cbcSMatt MacyRather than returning tables, these functions act as Lua iterators, and are
486eda14cbcSMatt Macygenerally used as follows:
48716038816SMartin Matuska.Bd -literal -compact -offset indent
48816038816SMartin Matuska.No for child in Fn zfs.list.children \&"rpool" No do
489eda14cbcSMatt Macy    ...
490eda14cbcSMatt Macyend
491eda14cbcSMatt Macy.Ed
492eda14cbcSMatt Macy.Pp
49316038816SMartin MatuskaThe available
49416038816SMartin Matuska.Sy zfs.list
49516038816SMartin Matuskafunctions are:
496eda14cbcSMatt Macy.Bl -tag -width "xx"
49716038816SMartin Matuska.It Fn zfs.list.clones snapshot
498eda14cbcSMatt MacyIterate through all clones of the given snapshot.
499eda14cbcSMatt Macy.Pp
50016038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
50116038816SMartin Matuska.It Ar snapshot Pq string
502eda14cbcSMatt MacyMust be a valid snapshot path in the current pool.
50316038816SMartin Matuska.El
50416038816SMartin Matuska.It Fn zfs.list.snapshots dataset
505eda14cbcSMatt MacyIterate through all snapshots of the given dataset.
50616038816SMartin MatuskaEach snapshot is returned as a string containing the full dataset name,
50716038816SMartin Matuskae.g. "pool/fs@snap".
508eda14cbcSMatt Macy.Pp
50916038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
51016038816SMartin Matuska.It Ar dataset Pq string
511eda14cbcSMatt MacyMust be a valid filesystem or volume.
51216038816SMartin Matuska.El
51316038816SMartin Matuska.It Fn zfs.list.children dataset
514eda14cbcSMatt MacyIterate through all direct children of the given dataset.
51516038816SMartin MatuskaEach child is returned as a string containing the full dataset name,
51616038816SMartin Matuskae.g. "pool/fs/child".
517eda14cbcSMatt Macy.Pp
51816038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
51916038816SMartin Matuska.It Ar dataset Pq string
520eda14cbcSMatt MacyMust be a valid filesystem or volume.
52116038816SMartin Matuska.El
52216038816SMartin Matuska.It Fn zfs.list.bookmarks dataset
52316038816SMartin MatuskaIterate through all bookmarks of the given dataset.
52416038816SMartin MatuskaEach bookmark is returned as a string containing the full dataset name,
52516038816SMartin Matuskae.g. "pool/fs#bookmark".
526eda14cbcSMatt Macy.Pp
52716038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
52816038816SMartin Matuska.It Ar dataset Pq string
529eda14cbcSMatt MacyMust be a valid filesystem or volume.
53016038816SMartin Matuska.El
53116038816SMartin Matuska.It Fn zfs.list.holds snapshot
53216038816SMartin MatuskaIterate through all user holds on the given snapshot.
53316038816SMartin MatuskaEach hold is returned
534eda14cbcSMatt Macyas a pair of the hold's tag and the timestamp (in seconds since the epoch) at
535eda14cbcSMatt Macywhich it was created.
536eda14cbcSMatt Macy.Pp
53716038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
53816038816SMartin Matuska.It Ar snapshot Pq string
539eda14cbcSMatt MacyMust be a valid snapshot.
54016038816SMartin Matuska.El
54116038816SMartin Matuska.It Fn zfs.list.properties dataset
542eda14cbcSMatt MacyAn alias for zfs.list.user_properties (see relevant entry).
543eda14cbcSMatt Macy.Pp
54416038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
54516038816SMartin Matuska.It Ar dataset Pq string
546eda14cbcSMatt MacyMust be a valid filesystem, snapshot, or volume.
54716038816SMartin Matuska.El
54816038816SMartin Matuska.It Fn zfs.list.user_properties dataset
54916038816SMartin MatuskaIterate through all user properties for the given dataset.
55016038816SMartin MatuskaFor each step of the iteration, output the property name, its value,
55116038816SMartin Matuskaand its source.
552eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid.
553eda14cbcSMatt Macy.Pp
55416038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
55516038816SMartin Matuska.It Ar dataset Pq string
556eda14cbcSMatt MacyMust be a valid filesystem, snapshot, or volume.
55716038816SMartin Matuska.El
55816038816SMartin Matuska.It Fn zfs.list.system_properties dataset
559eda14cbcSMatt MacyReturns an array of strings, the names of the valid system (non-user defined)
560eda14cbcSMatt Macyproperties for the given dataset.
561eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid.
562eda14cbcSMatt Macy.Pp
56316038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)"
56416038816SMartin Matuska.It Ar dataset Pq string
565eda14cbcSMatt MacyMust be a valid filesystem, snapshot or volume.
566eda14cbcSMatt Macy.El
567eda14cbcSMatt Macy.El
56816038816SMartin Matuska.El
56916038816SMartin Matuska.
570eda14cbcSMatt Macy.Sh EXAMPLES
57116038816SMartin Matuska.
572eda14cbcSMatt Macy.Ss Example 1
573eda14cbcSMatt MacyThe following channel program recursively destroys a filesystem and all its
574eda14cbcSMatt Macysnapshots and children in a naive manner.
575eda14cbcSMatt MacyNote that this does not involve any error handling or reporting.
576eda14cbcSMatt Macy.Bd -literal -offset indent
577eda14cbcSMatt Macyfunction destroy_recursive(root)
578eda14cbcSMatt Macy    for child in zfs.list.children(root) do
579eda14cbcSMatt Macy        destroy_recursive(child)
580eda14cbcSMatt Macy    end
581eda14cbcSMatt Macy    for snap in zfs.list.snapshots(root) do
582eda14cbcSMatt Macy        zfs.sync.destroy(snap)
583eda14cbcSMatt Macy    end
584eda14cbcSMatt Macy    zfs.sync.destroy(root)
585eda14cbcSMatt Macyend
586eda14cbcSMatt Macydestroy_recursive("pool/somefs")
587eda14cbcSMatt Macy.Ed
58816038816SMartin Matuska.
589eda14cbcSMatt Macy.Ss Example 2
590eda14cbcSMatt MacyA more verbose and robust version of the same channel program, which
591eda14cbcSMatt Macyproperly detects and reports errors, and also takes the dataset to destroy
592eda14cbcSMatt Macyas a command line argument, would be as follows:
593eda14cbcSMatt Macy.Bd -literal -offset indent
594eda14cbcSMatt Macysucceeded = {}
595eda14cbcSMatt Macyfailed = {}
596eda14cbcSMatt Macy
597eda14cbcSMatt Macyfunction destroy_recursive(root)
598eda14cbcSMatt Macy    for child in zfs.list.children(root) do
599eda14cbcSMatt Macy        destroy_recursive(child)
600eda14cbcSMatt Macy    end
601eda14cbcSMatt Macy    for snap in zfs.list.snapshots(root) do
602eda14cbcSMatt Macy        err = zfs.sync.destroy(snap)
603eda14cbcSMatt Macy        if (err ~= 0) then
604eda14cbcSMatt Macy            failed[snap] = err
605eda14cbcSMatt Macy        else
606eda14cbcSMatt Macy            succeeded[snap] = err
607eda14cbcSMatt Macy        end
608eda14cbcSMatt Macy    end
609eda14cbcSMatt Macy    err = zfs.sync.destroy(root)
610eda14cbcSMatt Macy    if (err ~= 0) then
611eda14cbcSMatt Macy        failed[root] = err
612eda14cbcSMatt Macy    else
613eda14cbcSMatt Macy        succeeded[root] = err
614eda14cbcSMatt Macy    end
615eda14cbcSMatt Macyend
616eda14cbcSMatt Macy
617eda14cbcSMatt Macyargs = ...
618eda14cbcSMatt Macyargv = args["argv"]
619eda14cbcSMatt Macy
620eda14cbcSMatt Macydestroy_recursive(argv[1])
621eda14cbcSMatt Macy
622eda14cbcSMatt Macyresults = {}
623eda14cbcSMatt Macyresults["succeeded"] = succeeded
624eda14cbcSMatt Macyresults["failed"] = failed
625eda14cbcSMatt Macyreturn results
626eda14cbcSMatt Macy.Ed
62716038816SMartin Matuska.
628eda14cbcSMatt Macy.Ss Example 3
629eda14cbcSMatt MacyThe following function performs a forced promote operation by attempting to
630eda14cbcSMatt Macypromote the given clone and destroying any conflicting snapshots.
631eda14cbcSMatt Macy.Bd -literal -offset indent
632eda14cbcSMatt Macyfunction force_promote(ds)
633eda14cbcSMatt Macy   errno, details = zfs.check.promote(ds)
634eda14cbcSMatt Macy   if (errno == EEXIST) then
635eda14cbcSMatt Macy       assert(details ~= Nil)
636eda14cbcSMatt Macy       for i, snap in ipairs(details) do
637eda14cbcSMatt Macy           zfs.sync.destroy(ds .. "@" .. snap)
638eda14cbcSMatt Macy       end
639eda14cbcSMatt Macy   elseif (errno ~= 0) then
640eda14cbcSMatt Macy       return errno
641eda14cbcSMatt Macy   end
642eda14cbcSMatt Macy   return zfs.sync.promote(ds)
643eda14cbcSMatt Macyend
644eda14cbcSMatt Macy.Ed
645