1*eda14cbcSMatt Macy.\" This file and its contents are supplied under the terms of the 2*eda14cbcSMatt Macy.\" Common Development and Distribution License ("CDDL"), version 1.0. 3*eda14cbcSMatt Macy.\" You may only use this file in accordance with the terms of version 4*eda14cbcSMatt Macy.\" 1.0 of the CDDL. 5*eda14cbcSMatt Macy.\" 6*eda14cbcSMatt Macy.\" A full copy of the text of the CDDL should have accompanied this 7*eda14cbcSMatt Macy.\" source. A copy of the CDDL is also available via the Internet at 8*eda14cbcSMatt Macy.\" http://www.illumos.org/license/CDDL. 9*eda14cbcSMatt Macy.\" 10*eda14cbcSMatt Macy.\" 11*eda14cbcSMatt Macy.\" Copyright (c) 2016, 2019 by Delphix. All Rights Reserved. 12*eda14cbcSMatt Macy.\" Copyright (c) 2019, 2020 by Christian Schwarz. All Rights Reserved. 13*eda14cbcSMatt Macy.\" Copyright 2020 Joyent, Inc. 14*eda14cbcSMatt Macy.\" 15*eda14cbcSMatt Macy.Dd February 3, 2020 16*eda14cbcSMatt Macy.Dt ZFS-PROGRAM 8 17*eda14cbcSMatt Macy.Os 18*eda14cbcSMatt Macy.Sh NAME 19*eda14cbcSMatt Macy.Nm zfs program 20*eda14cbcSMatt Macy.Nd executes ZFS channel programs 21*eda14cbcSMatt Macy.Sh SYNOPSIS 22*eda14cbcSMatt Macy.Cm "zfs program" 23*eda14cbcSMatt Macy.Op Fl jn 24*eda14cbcSMatt Macy.Op Fl t Ar instruction-limit 25*eda14cbcSMatt Macy.Op Fl m Ar memory-limit 26*eda14cbcSMatt Macy.Ar pool 27*eda14cbcSMatt Macy.Ar script 28*eda14cbcSMatt Macy.\".Op Ar optional arguments to channel program 29*eda14cbcSMatt Macy.Sh DESCRIPTION 30*eda14cbcSMatt MacyThe ZFS channel program interface allows ZFS administrative operations to be 31*eda14cbcSMatt Macyrun programmatically as a Lua script. 32*eda14cbcSMatt MacyThe entire script is executed atomically, with no other administrative 33*eda14cbcSMatt Macyoperations taking effect concurrently. 34*eda14cbcSMatt MacyA library of ZFS calls is made available to channel program scripts. 35*eda14cbcSMatt MacyChannel programs may only be run with root privileges. 36*eda14cbcSMatt Macy.Pp 37*eda14cbcSMatt MacyA modified version of the Lua 5.2 interpreter is used to run channel program 38*eda14cbcSMatt Macyscripts. 39*eda14cbcSMatt MacyThe Lua 5.2 manual can be found at: 40*eda14cbcSMatt Macy.Bd -centered -offset indent 41*eda14cbcSMatt Macy.Lk http://www.lua.org/manual/5.2/ 42*eda14cbcSMatt Macy.Ed 43*eda14cbcSMatt Macy.Pp 44*eda14cbcSMatt MacyThe channel program given by 45*eda14cbcSMatt Macy.Ar script 46*eda14cbcSMatt Macywill be run on 47*eda14cbcSMatt Macy.Ar pool , 48*eda14cbcSMatt Macyand any attempts to access or modify other pools will cause an error. 49*eda14cbcSMatt Macy.Sh OPTIONS 50*eda14cbcSMatt Macy.Bl -tag -width "-t" 51*eda14cbcSMatt Macy.It Fl j 52*eda14cbcSMatt MacyDisplay channel program output in JSON format. When this flag is specified and 53*eda14cbcSMatt Macystandard output is empty - channel program encountered an error. The details of 54*eda14cbcSMatt Macysuch an error will be printed to standard error in plain text. 55*eda14cbcSMatt Macy.It Fl n 56*eda14cbcSMatt MacyExecutes a read-only channel program, which runs faster. 57*eda14cbcSMatt MacyThe program cannot change on-disk state by calling functions from the 58*eda14cbcSMatt Macyzfs.sync submodule. 59*eda14cbcSMatt MacyThe program can be used to gather information such as properties and 60*eda14cbcSMatt Macydetermining if changes would succeed (zfs.check.*). 61*eda14cbcSMatt MacyWithout this flag, all pending changes must be synced to disk before a 62*eda14cbcSMatt Macychannel program can complete. 63*eda14cbcSMatt Macy.It Fl t Ar instruction-limit 64*eda14cbcSMatt MacyLimit the number of Lua instructions to execute. 65*eda14cbcSMatt MacyIf a channel program executes more than the specified number of instructions, 66*eda14cbcSMatt Macyit will be stopped and an error will be returned. 67*eda14cbcSMatt MacyThe default limit is 10 million instructions, and it can be set to a maximum of 68*eda14cbcSMatt Macy100 million instructions. 69*eda14cbcSMatt Macy.It Fl m Ar memory-limit 70*eda14cbcSMatt MacyMemory limit, in bytes. 71*eda14cbcSMatt MacyIf a channel program attempts to allocate more memory than the given limit, it 72*eda14cbcSMatt Macywill be stopped and an error returned. 73*eda14cbcSMatt MacyThe default memory limit is 10 MB, and can be set to a maximum of 100 MB. 74*eda14cbcSMatt Macy.El 75*eda14cbcSMatt Macy.Pp 76*eda14cbcSMatt MacyAll remaining argument strings will be passed directly to the Lua script as 77*eda14cbcSMatt Macydescribed in the 78*eda14cbcSMatt Macy.Sx LUA INTERFACE 79*eda14cbcSMatt Macysection below. 80*eda14cbcSMatt Macy.Sh LUA INTERFACE 81*eda14cbcSMatt MacyA channel program can be invoked either from the command line, or via a library 82*eda14cbcSMatt Macycall to 83*eda14cbcSMatt Macy.Fn lzc_channel_program . 84*eda14cbcSMatt Macy.Ss Arguments 85*eda14cbcSMatt MacyArguments passed to the channel program are converted to a Lua table. 86*eda14cbcSMatt MacyIf invoked from the command line, extra arguments to the Lua script will be 87*eda14cbcSMatt Macyaccessible as an array stored in the argument table with the key 'argv': 88*eda14cbcSMatt Macy.Bd -literal -offset indent 89*eda14cbcSMatt Macyargs = ... 90*eda14cbcSMatt Macyargv = args["argv"] 91*eda14cbcSMatt Macy-- argv == {1="arg1", 2="arg2", ...} 92*eda14cbcSMatt Macy.Ed 93*eda14cbcSMatt Macy.Pp 94*eda14cbcSMatt MacyIf invoked from the libZFS interface, an arbitrary argument list can be 95*eda14cbcSMatt Macypassed to the channel program, which is accessible via the same 96*eda14cbcSMatt Macy"..." syntax in Lua: 97*eda14cbcSMatt Macy.Bd -literal -offset indent 98*eda14cbcSMatt Macyargs = ... 99*eda14cbcSMatt Macy-- args == {"foo"="bar", "baz"={...}, ...} 100*eda14cbcSMatt Macy.Ed 101*eda14cbcSMatt Macy.Pp 102*eda14cbcSMatt MacyNote that because Lua arrays are 1-indexed, arrays passed to Lua from the 103*eda14cbcSMatt MacylibZFS interface will have their indices incremented by 1. 104*eda14cbcSMatt MacyThat is, the element 105*eda14cbcSMatt Macyin 106*eda14cbcSMatt Macy.Va arr[0] 107*eda14cbcSMatt Macyin a C array passed to a channel program will be stored in 108*eda14cbcSMatt Macy.Va arr[1] 109*eda14cbcSMatt Macywhen accessed from Lua. 110*eda14cbcSMatt Macy.Ss Return Values 111*eda14cbcSMatt MacyLua return statements take the form: 112*eda14cbcSMatt Macy.Bd -literal -offset indent 113*eda14cbcSMatt Macyreturn ret0, ret1, ret2, ... 114*eda14cbcSMatt Macy.Ed 115*eda14cbcSMatt Macy.Pp 116*eda14cbcSMatt MacyReturn statements returning multiple values are permitted internally in a 117*eda14cbcSMatt Macychannel program script, but attempting to return more than one value from the 118*eda14cbcSMatt Macytop level of the channel program is not permitted and will throw an error. 119*eda14cbcSMatt MacyHowever, tables containing multiple values can still be returned. 120*eda14cbcSMatt MacyIf invoked from the command line, a return statement: 121*eda14cbcSMatt Macy.Bd -literal -offset indent 122*eda14cbcSMatt Macya = {foo="bar", baz=2} 123*eda14cbcSMatt Macyreturn a 124*eda14cbcSMatt Macy.Ed 125*eda14cbcSMatt Macy.Pp 126*eda14cbcSMatt MacyWill be output formatted as: 127*eda14cbcSMatt Macy.Bd -literal -offset indent 128*eda14cbcSMatt MacyChannel program fully executed with return value: 129*eda14cbcSMatt Macy return: 130*eda14cbcSMatt Macy baz: 2 131*eda14cbcSMatt Macy foo: 'bar' 132*eda14cbcSMatt Macy.Ed 133*eda14cbcSMatt Macy.Ss Fatal Errors 134*eda14cbcSMatt MacyIf the channel program encounters a fatal error while running, a non-zero exit 135*eda14cbcSMatt Macystatus will be returned. 136*eda14cbcSMatt MacyIf more information about the error is available, a singleton list will be 137*eda14cbcSMatt Macyreturned detailing the error: 138*eda14cbcSMatt Macy.Bd -literal -offset indent 139*eda14cbcSMatt Macyerror: "error string, including Lua stack trace" 140*eda14cbcSMatt Macy.Ed 141*eda14cbcSMatt Macy.Pp 142*eda14cbcSMatt MacyIf a fatal error is returned, the channel program may have not executed at all, 143*eda14cbcSMatt Macymay have partially executed, or may have fully executed but failed to pass a 144*eda14cbcSMatt Macyreturn value back to userland. 145*eda14cbcSMatt Macy.Pp 146*eda14cbcSMatt MacyIf the channel program exhausts an instruction or memory limit, a fatal error 147*eda14cbcSMatt Macywill be generated and the program will be stopped, leaving the program partially 148*eda14cbcSMatt Macyexecuted. 149*eda14cbcSMatt MacyNo attempt is made to reverse or undo any operations already performed. 150*eda14cbcSMatt MacyNote that because both the instruction count and amount of memory used by a 151*eda14cbcSMatt Macychannel program are deterministic when run against the same inputs and 152*eda14cbcSMatt Macyfilesystem state, as long as a channel program has run successfully once, you 153*eda14cbcSMatt Macycan guarantee that it will finish successfully against a similar size system. 154*eda14cbcSMatt Macy.Pp 155*eda14cbcSMatt MacyIf a channel program attempts to return too large a value, the program will 156*eda14cbcSMatt Macyfully execute but exit with a nonzero status code and no return value. 157*eda14cbcSMatt Macy.Pp 158*eda14cbcSMatt Macy.Em Note : 159*eda14cbcSMatt MacyZFS API functions do not generate Fatal Errors when correctly invoked, they 160*eda14cbcSMatt Macyreturn an error code and the channel program continues executing. 161*eda14cbcSMatt MacySee the 162*eda14cbcSMatt Macy.Sx ZFS API 163*eda14cbcSMatt Macysection below for function-specific details on error return codes. 164*eda14cbcSMatt Macy.Ss Lua to C Value Conversion 165*eda14cbcSMatt MacyWhen invoking a channel program via the libZFS interface, it is necessary to 166*eda14cbcSMatt Macytranslate arguments and return values from Lua values to their C equivalents, 167*eda14cbcSMatt Macyand vice-versa. 168*eda14cbcSMatt Macy.Pp 169*eda14cbcSMatt MacyThere is a correspondence between nvlist values in C and Lua tables. 170*eda14cbcSMatt MacyA Lua table which is returned from the channel program will be recursively 171*eda14cbcSMatt Macyconverted to an nvlist, with table values converted to their natural 172*eda14cbcSMatt Macyequivalents: 173*eda14cbcSMatt Macy.Bd -literal -offset indent 174*eda14cbcSMatt Macystring -> string 175*eda14cbcSMatt Macynumber -> int64 176*eda14cbcSMatt Macyboolean -> boolean_value 177*eda14cbcSMatt Macynil -> boolean (no value) 178*eda14cbcSMatt Macytable -> nvlist 179*eda14cbcSMatt Macy.Ed 180*eda14cbcSMatt Macy.Pp 181*eda14cbcSMatt MacyLikewise, table keys are replaced by string equivalents as follows: 182*eda14cbcSMatt Macy.Bd -literal -offset indent 183*eda14cbcSMatt Macystring -> no change 184*eda14cbcSMatt Macynumber -> signed decimal string ("%lld") 185*eda14cbcSMatt Macyboolean -> "true" | "false" 186*eda14cbcSMatt Macy.Ed 187*eda14cbcSMatt Macy.Pp 188*eda14cbcSMatt MacyAny collision of table key strings (for example, the string "true" and a 189*eda14cbcSMatt Macytrue boolean value) will cause a fatal error. 190*eda14cbcSMatt Macy.Pp 191*eda14cbcSMatt MacyLua numbers are represented internally as signed 64-bit integers. 192*eda14cbcSMatt Macy.Sh LUA STANDARD LIBRARY 193*eda14cbcSMatt MacyThe following Lua built-in base library functions are available: 194*eda14cbcSMatt Macy.Bd -literal -offset indent 195*eda14cbcSMatt Macyassert rawlen 196*eda14cbcSMatt Macycollectgarbage rawget 197*eda14cbcSMatt Macyerror rawset 198*eda14cbcSMatt Macygetmetatable select 199*eda14cbcSMatt Macyipairs setmetatable 200*eda14cbcSMatt Macynext tonumber 201*eda14cbcSMatt Macypairs tostring 202*eda14cbcSMatt Macyrawequal type 203*eda14cbcSMatt Macy.Ed 204*eda14cbcSMatt Macy.Pp 205*eda14cbcSMatt MacyAll functions in the 206*eda14cbcSMatt Macy.Em coroutine , 207*eda14cbcSMatt Macy.Em string , 208*eda14cbcSMatt Macyand 209*eda14cbcSMatt Macy.Em table 210*eda14cbcSMatt Macybuilt-in submodules are also available. 211*eda14cbcSMatt MacyA complete list and documentation of these modules is available in the Lua 212*eda14cbcSMatt Macymanual. 213*eda14cbcSMatt Macy.Pp 214*eda14cbcSMatt MacyThe following functions base library functions have been disabled and are 215*eda14cbcSMatt Macynot available for use in channel programs: 216*eda14cbcSMatt Macy.Bd -literal -offset indent 217*eda14cbcSMatt Macydofile 218*eda14cbcSMatt Macyloadfile 219*eda14cbcSMatt Macyload 220*eda14cbcSMatt Macypcall 221*eda14cbcSMatt Macyprint 222*eda14cbcSMatt Macyxpcall 223*eda14cbcSMatt Macy.Ed 224*eda14cbcSMatt Macy.Sh ZFS API 225*eda14cbcSMatt Macy.Ss Function Arguments 226*eda14cbcSMatt MacyEach API function takes a fixed set of required positional arguments and 227*eda14cbcSMatt Macyoptional keyword arguments. 228*eda14cbcSMatt MacyFor example, the destroy function takes a single positional string argument 229*eda14cbcSMatt Macy(the name of the dataset to destroy) and an optional "defer" keyword boolean 230*eda14cbcSMatt Macyargument. 231*eda14cbcSMatt MacyWhen using parentheses to specify the arguments to a Lua function, only 232*eda14cbcSMatt Macypositional arguments can be used: 233*eda14cbcSMatt Macy.Bd -literal -offset indent 234*eda14cbcSMatt Macyzfs.sync.destroy("rpool@snap") 235*eda14cbcSMatt Macy.Ed 236*eda14cbcSMatt Macy.Pp 237*eda14cbcSMatt MacyTo use keyword arguments, functions must be called with a single argument that 238*eda14cbcSMatt Macyis a Lua table containing entries mapping integers to positional arguments and 239*eda14cbcSMatt Macystrings to keyword arguments: 240*eda14cbcSMatt Macy.Bd -literal -offset indent 241*eda14cbcSMatt Macyzfs.sync.destroy({1="rpool@snap", defer=true}) 242*eda14cbcSMatt Macy.Ed 243*eda14cbcSMatt Macy.Pp 244*eda14cbcSMatt MacyThe Lua language allows curly braces to be used in place of parenthesis as 245*eda14cbcSMatt Macysyntactic sugar for this calling convention: 246*eda14cbcSMatt Macy.Bd -literal -offset indent 247*eda14cbcSMatt Macyzfs.sync.snapshot{"rpool@snap", defer=true} 248*eda14cbcSMatt Macy.Ed 249*eda14cbcSMatt Macy.Ss Function Return Values 250*eda14cbcSMatt MacyIf an API function succeeds, it returns 0. 251*eda14cbcSMatt MacyIf it fails, it returns an error code and the channel program continues 252*eda14cbcSMatt Macyexecuting. 253*eda14cbcSMatt MacyAPI functions do not generate Fatal Errors except in the case of an 254*eda14cbcSMatt Macyunrecoverable internal file system error. 255*eda14cbcSMatt Macy.Pp 256*eda14cbcSMatt MacyIn addition to returning an error code, some functions also return extra 257*eda14cbcSMatt Macydetails describing what caused the error. 258*eda14cbcSMatt MacyThis extra description is given as a second return value, and will always be a 259*eda14cbcSMatt MacyLua table, or Nil if no error details were returned. 260*eda14cbcSMatt MacyDifferent keys will exist in the error details table depending on the function 261*eda14cbcSMatt Macyand error case. 262*eda14cbcSMatt MacyAny such function may be called expecting a single return value: 263*eda14cbcSMatt Macy.Bd -literal -offset indent 264*eda14cbcSMatt Macyerrno = zfs.sync.promote(dataset) 265*eda14cbcSMatt Macy.Ed 266*eda14cbcSMatt Macy.Pp 267*eda14cbcSMatt MacyOr, the error details can be retrieved: 268*eda14cbcSMatt Macy.Bd -literal -offset indent 269*eda14cbcSMatt Macyerrno, details = zfs.sync.promote(dataset) 270*eda14cbcSMatt Macyif (errno == EEXIST) then 271*eda14cbcSMatt Macy assert(details ~= Nil) 272*eda14cbcSMatt Macy list_of_conflicting_snapshots = details 273*eda14cbcSMatt Macyend 274*eda14cbcSMatt Macy.Ed 275*eda14cbcSMatt Macy.Pp 276*eda14cbcSMatt MacyThe following global aliases for API function error return codes are defined 277*eda14cbcSMatt Macyfor use in channel programs: 278*eda14cbcSMatt Macy.Bd -literal -offset indent 279*eda14cbcSMatt MacyEPERM ECHILD ENODEV ENOSPC 280*eda14cbcSMatt MacyENOENT EAGAIN ENOTDIR ESPIPE 281*eda14cbcSMatt MacyESRCH ENOMEM EISDIR EROFS 282*eda14cbcSMatt MacyEINTR EACCES EINVAL EMLINK 283*eda14cbcSMatt MacyEIO EFAULT ENFILE EPIPE 284*eda14cbcSMatt MacyENXIO ENOTBLK EMFILE EDOM 285*eda14cbcSMatt MacyE2BIG EBUSY ENOTTY ERANGE 286*eda14cbcSMatt MacyENOEXEC EEXIST ETXTBSY EDQUOT 287*eda14cbcSMatt MacyEBADF EXDEV EFBIG 288*eda14cbcSMatt Macy.Ed 289*eda14cbcSMatt Macy.Ss API Functions 290*eda14cbcSMatt MacyFor detailed descriptions of the exact behavior of any zfs administrative 291*eda14cbcSMatt Macyoperations, see the main 292*eda14cbcSMatt Macy.Xr zfs 1 293*eda14cbcSMatt Macymanual page. 294*eda14cbcSMatt Macy.Bl -tag -width "xx" 295*eda14cbcSMatt Macy.It Em zfs.debug(msg) 296*eda14cbcSMatt MacyRecord a debug message in the zfs_dbgmsg log. 297*eda14cbcSMatt MacyA log of these messages can be printed via mdb's "::zfs_dbgmsg" command, or 298*eda14cbcSMatt Macycan be monitored live by running: 299*eda14cbcSMatt Macy.Bd -literal -offset indent 300*eda14cbcSMatt Macy dtrace -n 'zfs-dbgmsg{trace(stringof(arg0))}' 301*eda14cbcSMatt Macy.Ed 302*eda14cbcSMatt Macy.Pp 303*eda14cbcSMatt Macymsg (string) 304*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 305*eda14cbcSMatt MacyDebug message to be printed. 306*eda14cbcSMatt Macy.Ed 307*eda14cbcSMatt Macy.It Em zfs.exists(dataset) 308*eda14cbcSMatt MacyReturns true if the given dataset exists, or false if it doesn't. 309*eda14cbcSMatt MacyA fatal error will be thrown if the dataset is not in the target pool. 310*eda14cbcSMatt MacyThat is, in a channel program running on rpool, 311*eda14cbcSMatt Macyzfs.exists("rpool/nonexistent_fs") returns false, but 312*eda14cbcSMatt Macyzfs.exists("somepool/fs_that_may_exist") will error. 313*eda14cbcSMatt Macy.Pp 314*eda14cbcSMatt Macydataset (string) 315*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 316*eda14cbcSMatt MacyDataset to check for existence. 317*eda14cbcSMatt MacyMust be in the target pool. 318*eda14cbcSMatt Macy.Ed 319*eda14cbcSMatt Macy.It Em zfs.get_prop(dataset, property) 320*eda14cbcSMatt MacyReturns two values. 321*eda14cbcSMatt MacyFirst, a string, number or table containing the property value for the given 322*eda14cbcSMatt Macydataset. 323*eda14cbcSMatt MacySecond, a string containing the source of the property (i.e. the name of the 324*eda14cbcSMatt Macydataset in which it was set or nil if it is readonly). 325*eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid or the property doesn't exist. 326*eda14cbcSMatt MacyNote that Lua only supports int64 number types whereas ZFS number properties 327*eda14cbcSMatt Macyare uint64. 328*eda14cbcSMatt MacyThis means very large values (like guid) may wrap around and appear negative. 329*eda14cbcSMatt Macy.Pp 330*eda14cbcSMatt Macydataset (string) 331*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 332*eda14cbcSMatt MacyFilesystem or snapshot path to retrieve properties from. 333*eda14cbcSMatt Macy.Ed 334*eda14cbcSMatt Macy.Pp 335*eda14cbcSMatt Macyproperty (string) 336*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 337*eda14cbcSMatt MacyName of property to retrieve. 338*eda14cbcSMatt MacyAll filesystem, snapshot and volume properties are supported except 339*eda14cbcSMatt Macyfor 'mounted' and 'iscsioptions.' 340*eda14cbcSMatt MacyAlso supports the 'written@snap' and 'written#bookmark' properties and 341*eda14cbcSMatt Macythe '<user|group><quota|used>@id' properties, though the id must be in numeric 342*eda14cbcSMatt Macyform. 343*eda14cbcSMatt Macy.Ed 344*eda14cbcSMatt Macy.El 345*eda14cbcSMatt Macy.Bl -tag -width "xx" 346*eda14cbcSMatt Macy.It Sy zfs.sync submodule 347*eda14cbcSMatt MacyThe sync submodule contains functions that modify the on-disk state. 348*eda14cbcSMatt MacyThey are executed in "syncing context". 349*eda14cbcSMatt Macy.Pp 350*eda14cbcSMatt MacyThe available sync submodule functions are as follows: 351*eda14cbcSMatt Macy.Bl -tag -width "xx" 352*eda14cbcSMatt Macy.It Em zfs.sync.destroy(dataset, [defer=true|false]) 353*eda14cbcSMatt MacyDestroy the given dataset. 354*eda14cbcSMatt MacyReturns 0 on successful destroy, or a nonzero error code if the dataset could 355*eda14cbcSMatt Macynot be destroyed (for example, if the dataset has any active children or 356*eda14cbcSMatt Macyclones). 357*eda14cbcSMatt Macy.Pp 358*eda14cbcSMatt Macydataset (string) 359*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 360*eda14cbcSMatt MacyFilesystem or snapshot to be destroyed. 361*eda14cbcSMatt Macy.Ed 362*eda14cbcSMatt Macy.Pp 363*eda14cbcSMatt Macy[optional] defer (boolean) 364*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 365*eda14cbcSMatt MacyValid only for destroying snapshots. 366*eda14cbcSMatt MacyIf set to true, and the snapshot has holds or clones, allows the snapshot to be 367*eda14cbcSMatt Macymarked for deferred deletion rather than failing. 368*eda14cbcSMatt Macy.Ed 369*eda14cbcSMatt Macy.It Em zfs.sync.inherit(dataset, property) 370*eda14cbcSMatt MacyClears the specified property in the given dataset, causing it to be inherited 371*eda14cbcSMatt Macyfrom an ancestor, or restored to the default if no ancestor property is set. 372*eda14cbcSMatt MacyThe 373*eda14cbcSMatt Macy.Ql zfs inherit -S 374*eda14cbcSMatt Macyoption has not been implemented. 375*eda14cbcSMatt MacyReturns 0 on success, or a nonzero error code if the property could not be 376*eda14cbcSMatt Macycleared. 377*eda14cbcSMatt Macy.Pp 378*eda14cbcSMatt Macydataset (string) 379*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 380*eda14cbcSMatt MacyFilesystem or snapshot containing the property to clear. 381*eda14cbcSMatt Macy.Ed 382*eda14cbcSMatt Macy.Pp 383*eda14cbcSMatt Macyproperty (string) 384*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 385*eda14cbcSMatt MacyThe property to clear. 386*eda14cbcSMatt MacyAllowed properties are the same as those for the 387*eda14cbcSMatt Macy.Nm zfs Cm inherit 388*eda14cbcSMatt Macycommand. 389*eda14cbcSMatt Macy.Ed 390*eda14cbcSMatt Macy.It Em zfs.sync.promote(dataset) 391*eda14cbcSMatt MacyPromote the given clone to a filesystem. 392*eda14cbcSMatt MacyReturns 0 on successful promotion, or a nonzero error code otherwise. 393*eda14cbcSMatt MacyIf EEXIST is returned, the second return value will be an array of the clone's 394*eda14cbcSMatt Macysnapshots whose names collide with snapshots of the parent filesystem. 395*eda14cbcSMatt Macy.Pp 396*eda14cbcSMatt Macydataset (string) 397*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 398*eda14cbcSMatt MacyClone to be promoted. 399*eda14cbcSMatt Macy.Ed 400*eda14cbcSMatt Macy.It Em zfs.sync.rollback(filesystem) 401*eda14cbcSMatt MacyRollback to the previous snapshot for a dataset. 402*eda14cbcSMatt MacyReturns 0 on successful rollback, or a nonzero error code otherwise. 403*eda14cbcSMatt MacyRollbacks can be performed on filesystems or zvols, but not on snapshots 404*eda14cbcSMatt Macyor mounted datasets. 405*eda14cbcSMatt MacyEBUSY is returned in the case where the filesystem is mounted. 406*eda14cbcSMatt Macy.Pp 407*eda14cbcSMatt Macyfilesystem (string) 408*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 409*eda14cbcSMatt MacyFilesystem to rollback. 410*eda14cbcSMatt Macy.Ed 411*eda14cbcSMatt Macy.It Em zfs.sync.set_prop(dataset, property, value) 412*eda14cbcSMatt MacySets the given property on a dataset. 413*eda14cbcSMatt MacyCurrently only user properties are supported. 414*eda14cbcSMatt MacyReturns 0 if the property was set, or a nonzero error code otherwise. 415*eda14cbcSMatt Macy.Pp 416*eda14cbcSMatt Macydataset (string) 417*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 418*eda14cbcSMatt MacyThe dataset where the property will be set. 419*eda14cbcSMatt Macy.Ed 420*eda14cbcSMatt Macy.Pp 421*eda14cbcSMatt Macyproperty (string) 422*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 423*eda14cbcSMatt MacyThe property to set. 424*eda14cbcSMatt MacyOnly user properties are supported. 425*eda14cbcSMatt Macy.Ed 426*eda14cbcSMatt Macy.Pp 427*eda14cbcSMatt Macyvalue (string) 428*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 429*eda14cbcSMatt MacyThe value of the property to be set. 430*eda14cbcSMatt Macy.Ed 431*eda14cbcSMatt Macy.It Em zfs.sync.snapshot(dataset) 432*eda14cbcSMatt MacyCreate a snapshot of a filesystem. 433*eda14cbcSMatt MacyReturns 0 if the snapshot was successfully created, 434*eda14cbcSMatt Macyand a nonzero error code otherwise. 435*eda14cbcSMatt Macy.Pp 436*eda14cbcSMatt MacyNote: Taking a snapshot will fail on any pool older than legacy version 27. 437*eda14cbcSMatt MacyTo enable taking snapshots from ZCP scripts, the pool must be upgraded. 438*eda14cbcSMatt Macy.Pp 439*eda14cbcSMatt Macydataset (string) 440*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 441*eda14cbcSMatt MacyName of snapshot to create. 442*eda14cbcSMatt Macy.Ed 443*eda14cbcSMatt Macy.It Em zfs.sync.bookmark(source, newbookmark) 444*eda14cbcSMatt MacyCreate a bookmark of an existing source snapshot or bookmark. 445*eda14cbcSMatt MacyReturns 0 if the new bookmark was successfully created, 446*eda14cbcSMatt Macyand a nonzero error code otherwise. 447*eda14cbcSMatt Macy.Pp 448*eda14cbcSMatt MacyNote: Bookmarking requires the corresponding pool feature to be enabled. 449*eda14cbcSMatt Macy.Pp 450*eda14cbcSMatt Macysource (string) 451*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 452*eda14cbcSMatt MacyFull name of the existing snapshot or bookmark. 453*eda14cbcSMatt Macy.Ed 454*eda14cbcSMatt Macy.Pp 455*eda14cbcSMatt Macynewbookmark (string) 456*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 457*eda14cbcSMatt MacyFull name of the new bookmark. 458*eda14cbcSMatt Macy.El 459*eda14cbcSMatt Macy.It Sy zfs.check submodule 460*eda14cbcSMatt MacyFor each function in the zfs.sync submodule, there is a corresponding zfs.check 461*eda14cbcSMatt Macyfunction which performs a "dry run" of the same operation. 462*eda14cbcSMatt MacyEach takes the same arguments as its zfs.sync counterpart and returns 0 if the 463*eda14cbcSMatt Macyoperation would succeed, or a non-zero error code if it would fail, along with 464*eda14cbcSMatt Macyany other error details. 465*eda14cbcSMatt MacyThat is, each has the same behavior as the corresponding sync function except 466*eda14cbcSMatt Macyfor actually executing the requested change. 467*eda14cbcSMatt MacyFor example, 468*eda14cbcSMatt Macy.Em zfs.check.destroy("fs") 469*eda14cbcSMatt Macyreturns 0 if 470*eda14cbcSMatt Macy.Em zfs.sync.destroy("fs") 471*eda14cbcSMatt Macywould successfully destroy the dataset. 472*eda14cbcSMatt Macy.Pp 473*eda14cbcSMatt MacyThe available zfs.check functions are: 474*eda14cbcSMatt Macy.Bl -tag -width "xx" 475*eda14cbcSMatt Macy.It Em zfs.check.destroy(dataset, [defer=true|false]) 476*eda14cbcSMatt Macy.It Em zfs.check.promote(dataset) 477*eda14cbcSMatt Macy.It Em zfs.check.rollback(filesystem) 478*eda14cbcSMatt Macy.It Em zfs.check.set_property(dataset, property, value) 479*eda14cbcSMatt Macy.It Em zfs.check.snapshot(dataset) 480*eda14cbcSMatt Macy.El 481*eda14cbcSMatt Macy.It Sy zfs.list submodule 482*eda14cbcSMatt MacyThe zfs.list submodule provides functions for iterating over datasets and 483*eda14cbcSMatt Macyproperties. 484*eda14cbcSMatt MacyRather than returning tables, these functions act as Lua iterators, and are 485*eda14cbcSMatt Macygenerally used as follows: 486*eda14cbcSMatt Macy.Bd -literal -offset indent 487*eda14cbcSMatt Macyfor child in zfs.list.children("rpool") do 488*eda14cbcSMatt Macy ... 489*eda14cbcSMatt Macyend 490*eda14cbcSMatt Macy.Ed 491*eda14cbcSMatt Macy.Pp 492*eda14cbcSMatt MacyThe available zfs.list functions are: 493*eda14cbcSMatt Macy.Bl -tag -width "xx" 494*eda14cbcSMatt Macy.It Em zfs.list.clones(snapshot) 495*eda14cbcSMatt MacyIterate through all clones of the given snapshot. 496*eda14cbcSMatt Macy.Pp 497*eda14cbcSMatt Macysnapshot (string) 498*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 499*eda14cbcSMatt MacyMust be a valid snapshot path in the current pool. 500*eda14cbcSMatt Macy.Ed 501*eda14cbcSMatt Macy.It Em zfs.list.snapshots(dataset) 502*eda14cbcSMatt MacyIterate through all snapshots of the given dataset. 503*eda14cbcSMatt MacyEach snapshot is returned as a string containing the full dataset name, e.g. 504*eda14cbcSMatt Macy"pool/fs@snap". 505*eda14cbcSMatt Macy.Pp 506*eda14cbcSMatt Macydataset (string) 507*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 508*eda14cbcSMatt MacyMust be a valid filesystem or volume. 509*eda14cbcSMatt Macy.Ed 510*eda14cbcSMatt Macy.It Em zfs.list.children(dataset) 511*eda14cbcSMatt MacyIterate through all direct children of the given dataset. 512*eda14cbcSMatt MacyEach child is returned as a string containing the full dataset name, e.g. 513*eda14cbcSMatt Macy"pool/fs/child". 514*eda14cbcSMatt Macy.Pp 515*eda14cbcSMatt Macydataset (string) 516*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 517*eda14cbcSMatt MacyMust be a valid filesystem or volume. 518*eda14cbcSMatt Macy.Ed 519*eda14cbcSMatt Macy.It Em zfs.list.bookmarks(dataset) 520*eda14cbcSMatt MacyIterate through all bookmarks of the given dataset. Each bookmark is returned 521*eda14cbcSMatt Macyas a string containing the full dataset name, e.g. "pool/fs#bookmark". 522*eda14cbcSMatt Macy.Pp 523*eda14cbcSMatt Macydataset (string) 524*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 525*eda14cbcSMatt MacyMust be a valid filesystem or volume. 526*eda14cbcSMatt Macy.Ed 527*eda14cbcSMatt Macy.It Em zfs.list.holds(snapshot) 528*eda14cbcSMatt MacyIterate through all user holds on the given snapshot. Each hold is returned 529*eda14cbcSMatt Macyas a pair of the hold's tag and the timestamp (in seconds since the epoch) at 530*eda14cbcSMatt Macywhich it was created. 531*eda14cbcSMatt Macy.Pp 532*eda14cbcSMatt Macysnapshot (string) 533*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 534*eda14cbcSMatt MacyMust be a valid snapshot. 535*eda14cbcSMatt Macy.Ed 536*eda14cbcSMatt Macy.It Em zfs.list.properties(dataset) 537*eda14cbcSMatt MacyAn alias for zfs.list.user_properties (see relevant entry). 538*eda14cbcSMatt Macy.Pp 539*eda14cbcSMatt Macydataset (string) 540*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 541*eda14cbcSMatt MacyMust be a valid filesystem, snapshot, or volume. 542*eda14cbcSMatt Macy.Ed 543*eda14cbcSMatt Macy.It Em zfs.list.user_properties(dataset) 544*eda14cbcSMatt MacyIterate through all user properties for the given dataset. For each 545*eda14cbcSMatt Macystep of the iteration, output the property name, its value, and its source. 546*eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid. 547*eda14cbcSMatt Macy.Pp 548*eda14cbcSMatt Macydataset (string) 549*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 550*eda14cbcSMatt MacyMust be a valid filesystem, snapshot, or volume. 551*eda14cbcSMatt Macy.Ed 552*eda14cbcSMatt Macy.It Em zfs.list.system_properties(dataset) 553*eda14cbcSMatt MacyReturns an array of strings, the names of the valid system (non-user defined) 554*eda14cbcSMatt Macyproperties for the given dataset. 555*eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid. 556*eda14cbcSMatt Macy.Pp 557*eda14cbcSMatt Macydataset (string) 558*eda14cbcSMatt Macy.Bd -ragged -compact -offset "xxxx" 559*eda14cbcSMatt MacyMust be a valid filesystem, snapshot or volume. 560*eda14cbcSMatt Macy.Ed 561*eda14cbcSMatt Macy.El 562*eda14cbcSMatt Macy.El 563*eda14cbcSMatt Macy.Sh EXAMPLES 564*eda14cbcSMatt Macy.Ss Example 1 565*eda14cbcSMatt MacyThe following channel program recursively destroys a filesystem and all its 566*eda14cbcSMatt Macysnapshots and children in a naive manner. 567*eda14cbcSMatt MacyNote that this does not involve any error handling or reporting. 568*eda14cbcSMatt Macy.Bd -literal -offset indent 569*eda14cbcSMatt Macyfunction destroy_recursive(root) 570*eda14cbcSMatt Macy for child in zfs.list.children(root) do 571*eda14cbcSMatt Macy destroy_recursive(child) 572*eda14cbcSMatt Macy end 573*eda14cbcSMatt Macy for snap in zfs.list.snapshots(root) do 574*eda14cbcSMatt Macy zfs.sync.destroy(snap) 575*eda14cbcSMatt Macy end 576*eda14cbcSMatt Macy zfs.sync.destroy(root) 577*eda14cbcSMatt Macyend 578*eda14cbcSMatt Macydestroy_recursive("pool/somefs") 579*eda14cbcSMatt Macy.Ed 580*eda14cbcSMatt Macy.Ss Example 2 581*eda14cbcSMatt MacyA more verbose and robust version of the same channel program, which 582*eda14cbcSMatt Macyproperly detects and reports errors, and also takes the dataset to destroy 583*eda14cbcSMatt Macyas a command line argument, would be as follows: 584*eda14cbcSMatt Macy.Bd -literal -offset indent 585*eda14cbcSMatt Macysucceeded = {} 586*eda14cbcSMatt Macyfailed = {} 587*eda14cbcSMatt Macy 588*eda14cbcSMatt Macyfunction destroy_recursive(root) 589*eda14cbcSMatt Macy for child in zfs.list.children(root) do 590*eda14cbcSMatt Macy destroy_recursive(child) 591*eda14cbcSMatt Macy end 592*eda14cbcSMatt Macy for snap in zfs.list.snapshots(root) do 593*eda14cbcSMatt Macy err = zfs.sync.destroy(snap) 594*eda14cbcSMatt Macy if (err ~= 0) then 595*eda14cbcSMatt Macy failed[snap] = err 596*eda14cbcSMatt Macy else 597*eda14cbcSMatt Macy succeeded[snap] = err 598*eda14cbcSMatt Macy end 599*eda14cbcSMatt Macy end 600*eda14cbcSMatt Macy err = zfs.sync.destroy(root) 601*eda14cbcSMatt Macy if (err ~= 0) then 602*eda14cbcSMatt Macy failed[root] = err 603*eda14cbcSMatt Macy else 604*eda14cbcSMatt Macy succeeded[root] = err 605*eda14cbcSMatt Macy end 606*eda14cbcSMatt Macyend 607*eda14cbcSMatt Macy 608*eda14cbcSMatt Macyargs = ... 609*eda14cbcSMatt Macyargv = args["argv"] 610*eda14cbcSMatt Macy 611*eda14cbcSMatt Macydestroy_recursive(argv[1]) 612*eda14cbcSMatt Macy 613*eda14cbcSMatt Macyresults = {} 614*eda14cbcSMatt Macyresults["succeeded"] = succeeded 615*eda14cbcSMatt Macyresults["failed"] = failed 616*eda14cbcSMatt Macyreturn results 617*eda14cbcSMatt Macy.Ed 618*eda14cbcSMatt Macy.Ss Example 3 619*eda14cbcSMatt MacyThe following function performs a forced promote operation by attempting to 620*eda14cbcSMatt Macypromote the given clone and destroying any conflicting snapshots. 621*eda14cbcSMatt Macy.Bd -literal -offset indent 622*eda14cbcSMatt Macyfunction force_promote(ds) 623*eda14cbcSMatt Macy errno, details = zfs.check.promote(ds) 624*eda14cbcSMatt Macy if (errno == EEXIST) then 625*eda14cbcSMatt Macy assert(details ~= Nil) 626*eda14cbcSMatt Macy for i, snap in ipairs(details) do 627*eda14cbcSMatt Macy zfs.sync.destroy(ds .. "@" .. snap) 628*eda14cbcSMatt Macy end 629*eda14cbcSMatt Macy elseif (errno ~= 0) then 630*eda14cbcSMatt Macy return errno 631*eda14cbcSMatt Macy end 632*eda14cbcSMatt Macy return zfs.sync.promote(ds) 633*eda14cbcSMatt Macyend 634*eda14cbcSMatt Macy.Ed 635