1*bbf21555SRichard Lowe.\" This file and its contents are supplied under the terms of the 2*bbf21555SRichard Lowe.\" Common Development and Distribution License ("CDDL"), version 1.0. 3*bbf21555SRichard Lowe.\" You may only use this file in accordance with the terms of version 4*bbf21555SRichard Lowe.\" 1.0 of the CDDL. 5*bbf21555SRichard Lowe.\" 6*bbf21555SRichard Lowe.\" A full copy of the text of the CDDL should have accompanied this 7*bbf21555SRichard Lowe.\" source. A copy of the CDDL is also available via the Internet at 8*bbf21555SRichard Lowe.\" http://www.illumos.org/license/CDDL. 9*bbf21555SRichard Lowe.\" 10*bbf21555SRichard Lowe.\" 11*bbf21555SRichard Lowe.\" Copyright (c) 2016, 2017 by Delphix. All rights reserved. 12*bbf21555SRichard Lowe.\" Copyright (c) 2018 Datto Inc. 13*bbf21555SRichard Lowe.\" Copyright 2020 Joyent, Inc. 14*bbf21555SRichard Lowe.\" Copyright 2021 Jason King 15*bbf21555SRichard Lowe.\" 16*bbf21555SRichard Lowe.Dd November 8, 2021 17*bbf21555SRichard Lowe.Dt ZFS-PROGRAM 8 18*bbf21555SRichard Lowe.Os 19*bbf21555SRichard Lowe.Sh NAME 20*bbf21555SRichard Lowe.Nm "zfs program" 21*bbf21555SRichard Lowe.Nd executes ZFS channel programs 22*bbf21555SRichard Lowe.Sh SYNOPSIS 23*bbf21555SRichard Lowe.Cm "zfs program" 24*bbf21555SRichard Lowe.Op Fl jn 25*bbf21555SRichard Lowe.Op Fl t Ar instruction-limit 26*bbf21555SRichard Lowe.Op Fl m Ar memory-limit 27*bbf21555SRichard Lowe.Ar pool 28*bbf21555SRichard Lowe.Ar script 29*bbf21555SRichard Lowe.\".Op Ar optional arguments to channel program 30*bbf21555SRichard Lowe.Sh DESCRIPTION 31*bbf21555SRichard LoweThe ZFS channel program interface allows ZFS administrative operations to be 32*bbf21555SRichard Lowerun programmatically as a Lua script. 33*bbf21555SRichard LoweThe entire script is executed atomically, with no other administrative 34*bbf21555SRichard Loweoperations taking effect concurrently. 35*bbf21555SRichard LoweA library of ZFS calls is made available to channel program scripts. 36*bbf21555SRichard LoweChannel programs may only be run with root privileges. 37*bbf21555SRichard Lowe.Pp 38*bbf21555SRichard LoweA modified version of the Lua 5.2 interpreter is used to run channel program 39*bbf21555SRichard Lowescripts. 40*bbf21555SRichard LoweThe Lua 5.2 manual can be found at: 41*bbf21555SRichard Lowe.Bd -centered -offset indent 42*bbf21555SRichard Lowe.Lk http://www.lua.org/manual/5.2/ 43*bbf21555SRichard Lowe.Ed 44*bbf21555SRichard Lowe.Pp 45*bbf21555SRichard LoweThe channel program given by 46*bbf21555SRichard Lowe.Ar script 47*bbf21555SRichard Lowewill be run on 48*bbf21555SRichard Lowe.Ar pool , 49*bbf21555SRichard Loweand any attempts to access or modify other pools will cause an error. 50*bbf21555SRichard Lowe.Sh OPTIONS 51*bbf21555SRichard Lowe.Bl -tag -width "-t" 52*bbf21555SRichard Lowe.It Fl j 53*bbf21555SRichard LoweDisplay channel program output in JSON format. 54*bbf21555SRichard LoweWhen this flag is specified and standard output is empty - 55*bbf21555SRichard Lowechannel program encountered an error. 56*bbf21555SRichard LoweThe details of such an error will be printed to standard error in plain text. 57*bbf21555SRichard Lowe.It Fl n 58*bbf21555SRichard LoweExecutes a read-only channel program, which runs faster. 59*bbf21555SRichard LoweThe program cannot change on-disk state by calling functions from the 60*bbf21555SRichard Lowezfs.sync submodule. 61*bbf21555SRichard LoweThe program can be used to gather information such as properties and 62*bbf21555SRichard Lowedetermining if changes would succeed (zfs.check.*). 63*bbf21555SRichard LoweWithout this flag, all pending changes must be synced to disk before a 64*bbf21555SRichard Lowechannel program can complete. 65*bbf21555SRichard Lowe.It Fl t Ar instruction-limit 66*bbf21555SRichard LoweExecution time limit, in number of Lua instructions to execute. 67*bbf21555SRichard LoweIf a channel program executes more than the specified number of instructions, 68*bbf21555SRichard Loweit will be stopped and an error will be returned. 69*bbf21555SRichard LoweThe default limit is 10 million instructions, and it can be set to a maximum of 70*bbf21555SRichard Lowe100 million instructions. 71*bbf21555SRichard Lowe.It Fl m Ar memory-limit 72*bbf21555SRichard LoweMemory limit, in bytes. 73*bbf21555SRichard LoweIf a channel program attempts to allocate more memory than the given limit, it 74*bbf21555SRichard Lowewill be stopped and an error returned. 75*bbf21555SRichard LoweThe default memory limit is 10 MB, and can be set to a maximum of 100 MB. 76*bbf21555SRichard Lowe.El 77*bbf21555SRichard Lowe.Pp 78*bbf21555SRichard LoweAll remaining argument strings will be passed directly to the Lua script as 79*bbf21555SRichard Lowedescribed in the 80*bbf21555SRichard Lowe.Sx LUA INTERFACE 81*bbf21555SRichard Lowesection below. 82*bbf21555SRichard Lowe.Sh LUA INTERFACE 83*bbf21555SRichard LoweA channel program can be invoked either from the command line, or via a library 84*bbf21555SRichard Lowecall to 85*bbf21555SRichard Lowe.Fn lzc_channel_program . 86*bbf21555SRichard Lowe.Ss Arguments 87*bbf21555SRichard LoweArguments passed to the channel program are converted to a Lua table. 88*bbf21555SRichard LoweIf invoked from the command line, extra arguments to the Lua script will be 89*bbf21555SRichard Loweaccessible as an array stored in the argument table with the key 'argv': 90*bbf21555SRichard Lowe.Bd -literal -offset indent 91*bbf21555SRichard Loweargs = ... 92*bbf21555SRichard Loweargv = args["argv"] 93*bbf21555SRichard Lowe-- argv == {1="arg1", 2="arg2", ...} 94*bbf21555SRichard Lowe.Ed 95*bbf21555SRichard Lowe.Pp 96*bbf21555SRichard LoweIf invoked from the libZFS interface, an arbitrary argument list can be 97*bbf21555SRichard Lowepassed to the channel program, which is accessible via the same 98*bbf21555SRichard Lowe"..." syntax in Lua: 99*bbf21555SRichard Lowe.Bd -literal -offset indent 100*bbf21555SRichard Loweargs = ... 101*bbf21555SRichard Lowe-- args == {"foo"="bar", "baz"={...}, ...} 102*bbf21555SRichard Lowe.Ed 103*bbf21555SRichard Lowe.Pp 104*bbf21555SRichard LoweNote that because Lua arrays are 1-indexed, arrays passed to Lua from the 105*bbf21555SRichard LowelibZFS interface will have their indices incremented by 1. 106*bbf21555SRichard LoweThat is, the element 107*bbf21555SRichard Lowein 108*bbf21555SRichard Lowe.Va arr[0] 109*bbf21555SRichard Lowein a C array passed to a channel program will be stored in 110*bbf21555SRichard Lowe.Va arr[1] 111*bbf21555SRichard Lowewhen accessed from Lua. 112*bbf21555SRichard Lowe.Ss Return Values 113*bbf21555SRichard LoweLua return statements take the form: 114*bbf21555SRichard Lowe.Bd -literal -offset indent 115*bbf21555SRichard Lowereturn ret0, ret1, ret2, ... 116*bbf21555SRichard Lowe.Ed 117*bbf21555SRichard Lowe.Pp 118*bbf21555SRichard LoweReturn statements returning multiple values are permitted internally in a 119*bbf21555SRichard Lowechannel program script, but attempting to return more than one value from the 120*bbf21555SRichard Lowetop level of the channel program is not permitted and will throw an error. 121*bbf21555SRichard LoweHowever, tables containing multiple values can still be returned. 122*bbf21555SRichard LoweIf invoked from the command line, a return statement: 123*bbf21555SRichard Lowe.Bd -literal -offset indent 124*bbf21555SRichard Lowea = {foo="bar", baz=2} 125*bbf21555SRichard Lowereturn a 126*bbf21555SRichard Lowe.Ed 127*bbf21555SRichard Lowe.Pp 128*bbf21555SRichard LoweWill be output formatted as: 129*bbf21555SRichard Lowe.Bd -literal -offset indent 130*bbf21555SRichard LoweChannel program fully executed with return value: 131*bbf21555SRichard Lowe return: 132*bbf21555SRichard Lowe baz: 2 133*bbf21555SRichard Lowe foo: 'bar' 134*bbf21555SRichard Lowe.Ed 135*bbf21555SRichard Lowe.Ss Fatal Errors 136*bbf21555SRichard LoweIf the channel program encounters a fatal error while running, a non-zero exit 137*bbf21555SRichard Lowestatus will be returned. 138*bbf21555SRichard LoweIf more information about the error is available, a singleton list will be 139*bbf21555SRichard Lowereturned detailing the error: 140*bbf21555SRichard Lowe.Bd -literal -offset indent 141*bbf21555SRichard Loweerror: "error string, including Lua stack trace" 142*bbf21555SRichard Lowe.Ed 143*bbf21555SRichard Lowe.Pp 144*bbf21555SRichard LoweIf a fatal error is returned, the channel program may have not executed at all, 145*bbf21555SRichard Lowemay have partially executed, or may have fully executed but failed to pass a 146*bbf21555SRichard Lowereturn value back to userland. 147*bbf21555SRichard Lowe.Pp 148*bbf21555SRichard LoweIf the channel program exhausts an instruction or memory limit, a fatal error 149*bbf21555SRichard Lowewill be generated and the program will be stopped, leaving the program partially 150*bbf21555SRichard Loweexecuted. 151*bbf21555SRichard LoweNo attempt is made to reverse or undo any operations already performed. 152*bbf21555SRichard LoweNote that because both the instruction count and amount of memory used by a 153*bbf21555SRichard Lowechannel program are deterministic when run against the same inputs and 154*bbf21555SRichard Lowefilesystem state, as long as a channel program has run successfully once, you 155*bbf21555SRichard Lowecan guarantee that it will finish successfully against a similar size system. 156*bbf21555SRichard Lowe.Pp 157*bbf21555SRichard LoweIf a channel program attempts to return too large a value, the program will 158*bbf21555SRichard Lowefully execute but exit with a nonzero status code and no return value. 159*bbf21555SRichard Lowe.Pp 160*bbf21555SRichard Lowe.Em Note : 161*bbf21555SRichard LoweZFS API functions do not generate Fatal Errors when correctly invoked, they 162*bbf21555SRichard Lowereturn an error code and the channel program continues executing. 163*bbf21555SRichard LoweSee the 164*bbf21555SRichard Lowe.Sx ZFS API 165*bbf21555SRichard Lowesection below for function-specific details on error return codes. 166*bbf21555SRichard Lowe.Ss Lua to C Value Conversion 167*bbf21555SRichard LoweWhen invoking a channel program via the libZFS interface, it is necessary to 168*bbf21555SRichard Lowetranslate arguments and return values from Lua values to their C equivalents, 169*bbf21555SRichard Loweand vice-versa. 170*bbf21555SRichard Lowe.Pp 171*bbf21555SRichard LoweThere is a correspondence between nvlist values in C and Lua tables. 172*bbf21555SRichard LoweA Lua table which is returned from the channel program will be recursively 173*bbf21555SRichard Loweconverted to an nvlist, with table values converted to their natural 174*bbf21555SRichard Loweequivalents: 175*bbf21555SRichard Lowe.Bd -literal -offset indent 176*bbf21555SRichard Lowestring -> string 177*bbf21555SRichard Lowenumber -> int64 178*bbf21555SRichard Loweboolean -> boolean_value 179*bbf21555SRichard Lowenil -> boolean (no value) 180*bbf21555SRichard Lowetable -> nvlist 181*bbf21555SRichard Lowe.Ed 182*bbf21555SRichard Lowe.Pp 183*bbf21555SRichard LoweLikewise, table keys are replaced by string equivalents as follows: 184*bbf21555SRichard Lowe.Bd -literal -offset indent 185*bbf21555SRichard Lowestring -> no change 186*bbf21555SRichard Lowenumber -> signed decimal string ("%lld") 187*bbf21555SRichard Loweboolean -> "true" | "false" 188*bbf21555SRichard Lowe.Ed 189*bbf21555SRichard Lowe.Pp 190*bbf21555SRichard LoweAny collision of table key strings (for example, the string "true" and a 191*bbf21555SRichard Lowetrue boolean value) will cause a fatal error. 192*bbf21555SRichard Lowe.Pp 193*bbf21555SRichard LoweLua numbers are represented internally as signed 64-bit integers. 194*bbf21555SRichard Lowe.Sh LUA STANDARD LIBRARY 195*bbf21555SRichard LoweThe following Lua built-in base library functions are available: 196*bbf21555SRichard Lowe.Bd -literal -offset indent 197*bbf21555SRichard Loweassert rawlen 198*bbf21555SRichard Lowecollectgarbage rawget 199*bbf21555SRichard Loweerror rawset 200*bbf21555SRichard Lowegetmetatable select 201*bbf21555SRichard Loweipairs setmetatable 202*bbf21555SRichard Lowenext tonumber 203*bbf21555SRichard Lowepairs tostring 204*bbf21555SRichard Lowerawequal type 205*bbf21555SRichard Lowe.Ed 206*bbf21555SRichard Lowe.Pp 207*bbf21555SRichard LoweAll functions in the 208*bbf21555SRichard Lowe.Em coroutine , 209*bbf21555SRichard Lowe.Em string , 210*bbf21555SRichard Loweand 211*bbf21555SRichard Lowe.Em table 212*bbf21555SRichard Lowebuilt-in submodules are also available. 213*bbf21555SRichard LoweA complete list and documentation of these modules is available in the Lua 214*bbf21555SRichard Lowemanual. 215*bbf21555SRichard Lowe.Pp 216*bbf21555SRichard LoweThe following functions base library functions have been disabled and are 217*bbf21555SRichard Lowenot available for use in channel programs: 218*bbf21555SRichard Lowe.Bd -literal -offset indent 219*bbf21555SRichard Lowedofile 220*bbf21555SRichard Loweloadfile 221*bbf21555SRichard Loweload 222*bbf21555SRichard Lowepcall 223*bbf21555SRichard Loweprint 224*bbf21555SRichard Lowexpcall 225*bbf21555SRichard Lowe.Ed 226*bbf21555SRichard Lowe.Sh ZFS API 227*bbf21555SRichard Lowe.Ss Function Arguments 228*bbf21555SRichard LoweEach API function takes a fixed set of required positional arguments and 229*bbf21555SRichard Loweoptional keyword arguments. 230*bbf21555SRichard LoweFor example, the destroy function takes a single positional string argument 231*bbf21555SRichard Lowe(the name of the dataset to destroy) and an optional "defer" keyword boolean 232*bbf21555SRichard Loweargument. 233*bbf21555SRichard LoweWhen using parentheses to specify the arguments to a Lua function, only 234*bbf21555SRichard Lowepositional arguments can be used: 235*bbf21555SRichard Lowe.Bd -literal -offset indent 236*bbf21555SRichard Lowezfs.sync.destroy("rpool@snap") 237*bbf21555SRichard Lowe.Ed 238*bbf21555SRichard Lowe.Pp 239*bbf21555SRichard LoweTo use keyword arguments, functions must be called with a single argument that 240*bbf21555SRichard Loweis a Lua table containing entries mapping integers to positional arguments and 241*bbf21555SRichard Lowestrings to keyword arguments: 242*bbf21555SRichard Lowe.Bd -literal -offset indent 243*bbf21555SRichard Lowezfs.sync.destroy({1="rpool@snap", defer=true}) 244*bbf21555SRichard Lowe.Ed 245*bbf21555SRichard Lowe.Pp 246*bbf21555SRichard LoweThe Lua language allows curly braces to be used in place of parenthesis as 247*bbf21555SRichard Lowesyntactic sugar for this calling convention: 248*bbf21555SRichard Lowe.Bd -literal -offset indent 249*bbf21555SRichard Lowezfs.sync.snapshot{"rpool@snap", defer=true} 250*bbf21555SRichard Lowe.Ed 251*bbf21555SRichard Lowe.Ss Function Return Values 252*bbf21555SRichard LoweIf an API function succeeds, it returns 0. 253*bbf21555SRichard LoweIf it fails, it returns an error code and the channel program continues 254*bbf21555SRichard Loweexecuting. 255*bbf21555SRichard LoweAPI functions do not generate Fatal Errors except in the case of an 256*bbf21555SRichard Loweunrecoverable internal file system error. 257*bbf21555SRichard Lowe.Pp 258*bbf21555SRichard LoweIn addition to returning an error code, some functions also return extra 259*bbf21555SRichard Lowedetails describing what caused the error. 260*bbf21555SRichard LoweThis extra description is given as a second return value, and will always be a 261*bbf21555SRichard LoweLua table, or Nil if no error details were returned. 262*bbf21555SRichard LoweDifferent keys will exist in the error details table depending on the function 263*bbf21555SRichard Loweand error case. 264*bbf21555SRichard LoweAny such function may be called expecting a single return value: 265*bbf21555SRichard Lowe.Bd -literal -offset indent 266*bbf21555SRichard Loweerrno = zfs.sync.promote(dataset) 267*bbf21555SRichard Lowe.Ed 268*bbf21555SRichard Lowe.Pp 269*bbf21555SRichard LoweOr, the error details can be retrieved: 270*bbf21555SRichard Lowe.Bd -literal -offset indent 271*bbf21555SRichard Loweerrno, details = zfs.sync.promote(dataset) 272*bbf21555SRichard Loweif (errno == EEXIST) then 273*bbf21555SRichard Lowe assert(details ~= Nil) 274*bbf21555SRichard Lowe list_of_conflicting_snapshots = details 275*bbf21555SRichard Loweend 276*bbf21555SRichard Lowe.Ed 277*bbf21555SRichard Lowe.Pp 278*bbf21555SRichard LoweThe following global aliases for API function error return codes are defined 279*bbf21555SRichard Lowefor use in channel programs: 280*bbf21555SRichard Lowe.Bd -literal -offset indent 281*bbf21555SRichard LoweEPERM ECHILD ENODEV ENOSPC 282*bbf21555SRichard LoweENOENT EAGAIN ENOTDIR ESPIPE 283*bbf21555SRichard LoweESRCH ENOMEM EISDIR EROFS 284*bbf21555SRichard LoweEINTR EACCES EINVAL EMLINK 285*bbf21555SRichard LoweEIO EFAULT ENFILE EPIPE 286*bbf21555SRichard LoweENXIO ENOTBLK EMFILE EDOM 287*bbf21555SRichard LoweE2BIG EBUSY ENOTTY ERANGE 288*bbf21555SRichard LoweENOEXEC EEXIST ETXTBSY EDQUOT 289*bbf21555SRichard LoweEBADF EXDEV EFBIG 290*bbf21555SRichard Lowe.Ed 291*bbf21555SRichard Lowe.Ss API Functions 292*bbf21555SRichard LoweFor detailed descriptions of the exact behavior of any zfs administrative 293*bbf21555SRichard Loweoperations, see the main 294*bbf21555SRichard Lowe.Xr zfs 8 295*bbf21555SRichard Lowemanual page. 296*bbf21555SRichard Lowe.Bl -tag -width "xx" 297*bbf21555SRichard Lowe.It Em zfs.debug(msg) 298*bbf21555SRichard LoweRecord a debug message in the zfs_dbgmsg log. 299*bbf21555SRichard LoweA log of these messages can be printed via mdb's "::zfs_dbgmsg" command, or 300*bbf21555SRichard Lowecan be monitored live by running: 301*bbf21555SRichard Lowe.Bd -literal -offset indent 302*bbf21555SRichard Lowe dtrace -n 'zfs-dbgmsg{trace(stringof(arg0))}' 303*bbf21555SRichard Lowe.Ed 304*bbf21555SRichard Lowe.Pp 305*bbf21555SRichard Lowemsg (string) 306*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 307*bbf21555SRichard LoweDebug message to be printed. 308*bbf21555SRichard Lowe.Ed 309*bbf21555SRichard Lowe.It Em zfs.exists(dataset) 310*bbf21555SRichard LoweReturns true if the given dataset exists, or false if it doesn't. 311*bbf21555SRichard LoweA fatal error will be thrown if the dataset is not in the target pool. 312*bbf21555SRichard LoweThat is, in a channel program running on rpool, 313*bbf21555SRichard Lowezfs.exists("rpool/nonexistent_fs") returns false, but 314*bbf21555SRichard Lowezfs.exists("somepool/fs_that_may_exist") will error. 315*bbf21555SRichard Lowe.Pp 316*bbf21555SRichard Lowedataset (string) 317*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 318*bbf21555SRichard LoweDataset to check for existence. 319*bbf21555SRichard LoweMust be in the target pool. 320*bbf21555SRichard Lowe.Ed 321*bbf21555SRichard Lowe.It Em zfs.get_prop(dataset, property) 322*bbf21555SRichard LoweReturns two values. 323*bbf21555SRichard LoweFirst, a string, number or table containing the property value for the given 324*bbf21555SRichard Lowedataset. 325*bbf21555SRichard LoweSecond, a string containing the source of the property (i.e. the name of the 326*bbf21555SRichard Lowedataset in which it was set or nil if it is readonly). 327*bbf21555SRichard LoweThrows a Lua error if the dataset is invalid or the property doesn't exist. 328*bbf21555SRichard LoweNote that Lua only supports int64 number types whereas ZFS number properties 329*bbf21555SRichard Loweare uint64. 330*bbf21555SRichard LoweThis means very large values (like guid) may wrap around and appear negative. 331*bbf21555SRichard Lowe.Pp 332*bbf21555SRichard Lowedataset (string) 333*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 334*bbf21555SRichard LoweFilesystem or snapshot path to retrieve properties from. 335*bbf21555SRichard Lowe.Ed 336*bbf21555SRichard Lowe.Pp 337*bbf21555SRichard Loweproperty (string) 338*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 339*bbf21555SRichard LoweName of property to retrieve. 340*bbf21555SRichard LoweAll filesystem, snapshot and volume properties are supported except 341*bbf21555SRichard Lowefor 'mounted' and 'iscsioptions.' 342*bbf21555SRichard LoweAlso supports the 'written@snap' and 'written#bookmark' properties and 343*bbf21555SRichard Lowethe '<user|group><quota|used>@id' properties, though the id must be in numeric 344*bbf21555SRichard Loweform. 345*bbf21555SRichard Lowe.Ed 346*bbf21555SRichard Lowe.El 347*bbf21555SRichard Lowe.Bl -tag -width "xx" 348*bbf21555SRichard Lowe.It Sy zfs.sync submodule 349*bbf21555SRichard LoweThe sync submodule contains functions that modify the on-disk state. 350*bbf21555SRichard LoweThey are executed in "syncing context". 351*bbf21555SRichard Lowe.Pp 352*bbf21555SRichard LoweThe available sync submodule functions are as follows: 353*bbf21555SRichard Lowe.Bl -tag -width "xx" 354*bbf21555SRichard Lowe.It Em zfs.sync.change_key(dataset, key) 355*bbf21555SRichard LoweChange the dataset encryption key. 356*bbf21555SRichard Lowe.Fa key 357*bbf21555SRichard Lowemust be in the format (raw or hex) specified by the dataset 358*bbf21555SRichard Lowe.Sy keyformat 359*bbf21555SRichard Loweproperty. 360*bbf21555SRichard Lowe.It Em zfs.sync.destroy(dataset, [defer=true|false]) 361*bbf21555SRichard LoweDestroy the given dataset. 362*bbf21555SRichard LoweReturns 0 on successful destroy, or a nonzero error code if the dataset could 363*bbf21555SRichard Lowenot be destroyed (for example, if the dataset has any active children or 364*bbf21555SRichard Loweclones). 365*bbf21555SRichard Lowe.Pp 366*bbf21555SRichard Lowedataset (string) 367*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 368*bbf21555SRichard LoweFilesystem or snapshot to be destroyed. 369*bbf21555SRichard Lowe.Ed 370*bbf21555SRichard Lowe.Pp 371*bbf21555SRichard Lowe[optional] defer (boolean) 372*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 373*bbf21555SRichard LoweValid only for destroying snapshots. 374*bbf21555SRichard LoweIf set to true, and the snapshot has holds or clones, allows the snapshot to be 375*bbf21555SRichard Lowemarked for deferred deletion rather than failing. 376*bbf21555SRichard Lowe.Ed 377*bbf21555SRichard Lowe.It Em zfs.sync.inherit(dataset, property) 378*bbf21555SRichard LoweClears the specified property in the given dataset, causing it to be inherited 379*bbf21555SRichard Lowefrom an ancestor, or restored to the default if no ancestor property is set. 380*bbf21555SRichard LoweThe 381*bbf21555SRichard Lowe.Ql zfs inherit -S 382*bbf21555SRichard Loweoption has not been implemented. 383*bbf21555SRichard LoweReturns 0 on success, or a nonzero error code if the property could not be 384*bbf21555SRichard Lowecleared. 385*bbf21555SRichard Lowe.Pp 386*bbf21555SRichard Lowedataset (string) 387*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 388*bbf21555SRichard LoweFilesystem or snapshot containing the property to clear. 389*bbf21555SRichard Lowe.Ed 390*bbf21555SRichard Lowe.Pp 391*bbf21555SRichard Loweproperty (string) 392*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 393*bbf21555SRichard LoweThe property to clear. 394*bbf21555SRichard LoweAllowed properties are the same as those for the 395*bbf21555SRichard Lowe.Nm zfs Cm inherit 396*bbf21555SRichard Lowecommand. 397*bbf21555SRichard Lowe.Ed 398*bbf21555SRichard Lowe.It Em zfs.sync.promote(dataset) 399*bbf21555SRichard LowePromote the given clone to a filesystem. 400*bbf21555SRichard LoweReturns 0 on successful promotion, or a nonzero error code otherwise. 401*bbf21555SRichard LoweIf EEXIST is returned, the second return value will be an array of the clone's 402*bbf21555SRichard Lowesnapshots whose names collide with snapshots of the parent filesystem. 403*bbf21555SRichard Lowe.Pp 404*bbf21555SRichard Lowedataset (string) 405*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 406*bbf21555SRichard LoweClone to be promoted. 407*bbf21555SRichard Lowe.Ed 408*bbf21555SRichard Lowe.It Em zfs.sync.rollback(filesystem) 409*bbf21555SRichard LoweRollback to the previous snapshot for a dataset. 410*bbf21555SRichard LoweReturns 0 on successful rollback, or a nonzero error code otherwise. 411*bbf21555SRichard LoweRollbacks can be performed on filesystems or zvols, but not on snapshots 412*bbf21555SRichard Loweor mounted datasets. 413*bbf21555SRichard LoweEBUSY is returned in the case where the filesystem is mounted. 414*bbf21555SRichard Lowe.Pp 415*bbf21555SRichard Lowefilesystem (string) 416*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 417*bbf21555SRichard LoweFilesystem to rollback. 418*bbf21555SRichard Lowe.Ed 419*bbf21555SRichard Lowe.It Em zfs.sync.set_prop(dataset, property, value) 420*bbf21555SRichard LoweSets the given property on a dataset. 421*bbf21555SRichard LoweCurrently only user properties are supported. 422*bbf21555SRichard LoweReturns 0 if the property was set, or a nonzero error code otherwise. 423*bbf21555SRichard Lowe.Pp 424*bbf21555SRichard Lowedataset (string) 425*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 426*bbf21555SRichard LoweThe dataset where the property will be set. 427*bbf21555SRichard Lowe.Ed 428*bbf21555SRichard Lowe.Pp 429*bbf21555SRichard Loweproperty (string) 430*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 431*bbf21555SRichard LoweThe property to set. 432*bbf21555SRichard LoweOnly user properties are supported. 433*bbf21555SRichard Lowe.Ed 434*bbf21555SRichard Lowe.Pp 435*bbf21555SRichard Lowevalue (string) 436*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 437*bbf21555SRichard LoweThe value of the property to be set. 438*bbf21555SRichard Lowe.Ed 439*bbf21555SRichard Lowe.It Em zfs.sync.snapshot(dataset) 440*bbf21555SRichard LoweCreate a snapshot of a filesystem. 441*bbf21555SRichard LoweReturns 0 if the snapshot was successfully created, 442*bbf21555SRichard Loweand a nonzero error code otherwise. 443*bbf21555SRichard Lowe.Pp 444*bbf21555SRichard LoweNote: Taking a snapshot will fail on any pool older than legacy version 27. 445*bbf21555SRichard LoweTo enable taking snapshots from ZCP scripts, the pool must be upgraded. 446*bbf21555SRichard Lowe.Pp 447*bbf21555SRichard Lowedataset (string) 448*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 449*bbf21555SRichard LoweName of snapshot to create. 450*bbf21555SRichard Lowe.Ed 451*bbf21555SRichard Lowe.El 452*bbf21555SRichard Lowe.It Sy zfs.check submodule 453*bbf21555SRichard LoweFor each function in the zfs.sync submodule, there is a corresponding zfs.check 454*bbf21555SRichard Lowefunction which performs a "dry run" of the same operation. 455*bbf21555SRichard LoweEach takes the same arguments as its zfs.sync counterpart and returns 0 if the 456*bbf21555SRichard Loweoperation would succeed, or a non-zero error code if it would fail, along with 457*bbf21555SRichard Loweany other error details. 458*bbf21555SRichard LoweThat is, each has the same behavior as the corresponding sync function except 459*bbf21555SRichard Lowefor actually executing the requested change. 460*bbf21555SRichard LoweFor example, 461*bbf21555SRichard Lowe.Em zfs.check.destroy("fs") 462*bbf21555SRichard Lowereturns 0 if 463*bbf21555SRichard Lowe.Em zfs.sync.destroy("fs") 464*bbf21555SRichard Lowewould successfully destroy the dataset. 465*bbf21555SRichard Lowe.Pp 466*bbf21555SRichard LoweThe available zfs.check functions are: 467*bbf21555SRichard Lowe.Bl -tag -width "xx" 468*bbf21555SRichard Lowe.It Em zfs.check.change_key(dataset, key) 469*bbf21555SRichard Lowe.It Em zfs.check.destroy(dataset, [defer=true|false]) 470*bbf21555SRichard Lowe.It Em zfs.check.promote(dataset) 471*bbf21555SRichard Lowe.It Em zfs.check.rollback(filesystem) 472*bbf21555SRichard Lowe.It Em zfs.check.set_property(dataset, property, value) 473*bbf21555SRichard Lowe.It Em zfs.check.snapshot(dataset) 474*bbf21555SRichard Lowe.El 475*bbf21555SRichard Lowe.It Sy zfs.list submodule 476*bbf21555SRichard LoweThe zfs.list submodule provides functions for iterating over datasets and 477*bbf21555SRichard Loweproperties. 478*bbf21555SRichard LoweRather than returning tables, these functions act as Lua iterators, and are 479*bbf21555SRichard Lowegenerally used as follows: 480*bbf21555SRichard Lowe.Bd -literal -offset indent 481*bbf21555SRichard Lowefor child in zfs.list.children("rpool") do 482*bbf21555SRichard Lowe ... 483*bbf21555SRichard Loweend 484*bbf21555SRichard Lowe.Ed 485*bbf21555SRichard Lowe.Pp 486*bbf21555SRichard LoweThe available zfs.list functions are: 487*bbf21555SRichard Lowe.Bl -tag -width "xx" 488*bbf21555SRichard Lowe.It Em zfs.list.clones(snapshot) 489*bbf21555SRichard LoweIterate through all clones of the given snapshot. 490*bbf21555SRichard Lowe.Pp 491*bbf21555SRichard Lowesnapshot (string) 492*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 493*bbf21555SRichard LoweMust be a valid snapshot path in the current pool. 494*bbf21555SRichard Lowe.Ed 495*bbf21555SRichard Lowe.It Em zfs.list.snapshots(dataset) 496*bbf21555SRichard LoweIterate through all snapshots of the given dataset. 497*bbf21555SRichard LoweEach snapshot is returned as a string containing the full dataset name, e.g. 498*bbf21555SRichard Lowe"pool/fs@snap". 499*bbf21555SRichard Lowe.Pp 500*bbf21555SRichard Lowedataset (string) 501*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 502*bbf21555SRichard LoweMust be a valid filesystem or volume. 503*bbf21555SRichard Lowe.Ed 504*bbf21555SRichard Lowe.It Em zfs.list.children(dataset) 505*bbf21555SRichard LoweIterate through all direct children of the given dataset. 506*bbf21555SRichard LoweEach child is returned as a string containing the full dataset name, e.g. 507*bbf21555SRichard Lowe"pool/fs/child". 508*bbf21555SRichard Lowe.Pp 509*bbf21555SRichard Lowedataset (string) 510*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 511*bbf21555SRichard LoweMust be a valid filesystem or volume. 512*bbf21555SRichard Lowe.Ed 513*bbf21555SRichard Lowe.It Em zfs.list.properties(dataset) 514*bbf21555SRichard LoweIterate through all user properties for the given dataset. 515*bbf21555SRichard Lowe.Pp 516*bbf21555SRichard Lowedataset (string) 517*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 518*bbf21555SRichard LoweMust be a valid filesystem, snapshot, or volume. 519*bbf21555SRichard Lowe.Ed 520*bbf21555SRichard Lowe.It Em zfs.list.system_properties(dataset) 521*bbf21555SRichard LoweReturns an array of strings, the names of the valid system (non-user defined) 522*bbf21555SRichard Loweproperties for the given dataset. 523*bbf21555SRichard LoweThrows a Lua error if the dataset is invalid. 524*bbf21555SRichard Lowe.Pp 525*bbf21555SRichard Lowedataset (string) 526*bbf21555SRichard Lowe.Bd -ragged -compact -offset "xxxx" 527*bbf21555SRichard LoweMust be a valid filesystem, snapshot or volume. 528*bbf21555SRichard Lowe.Ed 529*bbf21555SRichard Lowe.El 530*bbf21555SRichard Lowe.El 531*bbf21555SRichard Lowe.Sh EXAMPLES 532*bbf21555SRichard Lowe.Ss Example 1 533*bbf21555SRichard LoweThe following channel program recursively destroys a filesystem and all its 534*bbf21555SRichard Lowesnapshots and children in a naive manner. 535*bbf21555SRichard LoweNote that this does not involve any error handling or reporting. 536*bbf21555SRichard Lowe.Bd -literal -offset indent 537*bbf21555SRichard Lowefunction destroy_recursive(root) 538*bbf21555SRichard Lowe for child in zfs.list.children(root) do 539*bbf21555SRichard Lowe destroy_recursive(child) 540*bbf21555SRichard Lowe end 541*bbf21555SRichard Lowe for snap in zfs.list.snapshots(root) do 542*bbf21555SRichard Lowe zfs.sync.destroy(snap) 543*bbf21555SRichard Lowe end 544*bbf21555SRichard Lowe zfs.sync.destroy(root) 545*bbf21555SRichard Loweend 546*bbf21555SRichard Lowedestroy_recursive("pool/somefs") 547*bbf21555SRichard Lowe.Ed 548*bbf21555SRichard Lowe.Ss Example 2 549*bbf21555SRichard LoweA more verbose and robust version of the same channel program, which 550*bbf21555SRichard Loweproperly detects and reports errors, and also takes the dataset to destroy 551*bbf21555SRichard Loweas a command line argument, would be as follows: 552*bbf21555SRichard Lowe.Bd -literal -offset indent 553*bbf21555SRichard Lowesucceeded = {} 554*bbf21555SRichard Lowefailed = {} 555*bbf21555SRichard Lowe 556*bbf21555SRichard Lowefunction destroy_recursive(root) 557*bbf21555SRichard Lowe for child in zfs.list.children(root) do 558*bbf21555SRichard Lowe destroy_recursive(child) 559*bbf21555SRichard Lowe end 560*bbf21555SRichard Lowe for snap in zfs.list.snapshots(root) do 561*bbf21555SRichard Lowe err = zfs.sync.destroy(snap) 562*bbf21555SRichard Lowe if (err ~= 0) then 563*bbf21555SRichard Lowe failed[snap] = err 564*bbf21555SRichard Lowe else 565*bbf21555SRichard Lowe succeeded[snap] = err 566*bbf21555SRichard Lowe end 567*bbf21555SRichard Lowe end 568*bbf21555SRichard Lowe err = zfs.sync.destroy(root) 569*bbf21555SRichard Lowe if (err ~= 0) then 570*bbf21555SRichard Lowe failed[root] = err 571*bbf21555SRichard Lowe else 572*bbf21555SRichard Lowe succeeded[root] = err 573*bbf21555SRichard Lowe end 574*bbf21555SRichard Loweend 575*bbf21555SRichard Lowe 576*bbf21555SRichard Loweargs = ... 577*bbf21555SRichard Loweargv = args["argv"] 578*bbf21555SRichard Lowe 579*bbf21555SRichard Lowedestroy_recursive(argv[1]) 580*bbf21555SRichard Lowe 581*bbf21555SRichard Loweresults = {} 582*bbf21555SRichard Loweresults["succeeded"] = succeeded 583*bbf21555SRichard Loweresults["failed"] = failed 584*bbf21555SRichard Lowereturn results 585*bbf21555SRichard Lowe.Ed 586*bbf21555SRichard Lowe.Ss Example 3 587*bbf21555SRichard LoweThe following function performs a forced promote operation by attempting to 588*bbf21555SRichard Lowepromote the given clone and destroying any conflicting snapshots. 589*bbf21555SRichard Lowe.Bd -literal -offset indent 590*bbf21555SRichard Lowefunction force_promote(ds) 591*bbf21555SRichard Lowe errno, details = zfs.check.promote(ds) 592*bbf21555SRichard Lowe if (errno == EEXIST) then 593*bbf21555SRichard Lowe assert(details ~= Nil) 594*bbf21555SRichard Lowe for i, snap in ipairs(details) do 595*bbf21555SRichard Lowe zfs.sync.destroy(ds .. "@" .. snap) 596*bbf21555SRichard Lowe end 597*bbf21555SRichard Lowe elseif (errno ~= 0) then 598*bbf21555SRichard Lowe return errno 599*bbf21555SRichard Lowe end 600*bbf21555SRichard Lowe return zfs.sync.promote(ds) 601*bbf21555SRichard Loweend 602*bbf21555SRichard Lowe.Ed 603