1*61145dc2SMartin Matuska.\" SPDX-License-Identifier: CDDL-1.0 216038816SMartin Matuska.\" 3eda14cbcSMatt Macy.\" This file and its contents are supplied under the terms of the 4eda14cbcSMatt Macy.\" Common Development and Distribution License ("CDDL"), version 1.0. 5eda14cbcSMatt Macy.\" You may only use this file in accordance with the terms of version 6eda14cbcSMatt Macy.\" 1.0 of the CDDL. 7eda14cbcSMatt Macy.\" 8eda14cbcSMatt Macy.\" A full copy of the text of the CDDL should have accompanied this 9eda14cbcSMatt Macy.\" source. A copy of the CDDL is also available via the Internet at 10eda14cbcSMatt Macy.\" http://www.illumos.org/license/CDDL. 11eda14cbcSMatt Macy.\" 12eda14cbcSMatt Macy.\" Copyright (c) 2016, 2019 by Delphix. All Rights Reserved. 13eda14cbcSMatt Macy.\" Copyright (c) 2019, 2020 by Christian Schwarz. All Rights Reserved. 14eda14cbcSMatt Macy.\" Copyright 2020 Joyent, Inc. 15eda14cbcSMatt Macy.\" 1616038816SMartin Matuska.Dd May 27, 2021 17eda14cbcSMatt Macy.Dt ZFS-PROGRAM 8 18eda14cbcSMatt Macy.Os 1916038816SMartin Matuska. 20eda14cbcSMatt Macy.Sh NAME 217877fdebSMatt Macy.Nm zfs-program 2216038816SMartin Matuska.Nd execute ZFS channel programs 23eda14cbcSMatt Macy.Sh SYNOPSIS 247877fdebSMatt Macy.Nm zfs 257877fdebSMatt Macy.Cm program 26eda14cbcSMatt Macy.Op Fl jn 27eda14cbcSMatt Macy.Op Fl t Ar instruction-limit 28eda14cbcSMatt Macy.Op Fl m Ar memory-limit 29eda14cbcSMatt Macy.Ar pool 30eda14cbcSMatt Macy.Ar script 3116038816SMartin Matuska.Op Ar script arguments 3216038816SMartin Matuska. 33eda14cbcSMatt Macy.Sh DESCRIPTION 34eda14cbcSMatt MacyThe ZFS channel program interface allows ZFS administrative operations to be 35eda14cbcSMatt Macyrun programmatically as a Lua script. 36eda14cbcSMatt MacyThe entire script is executed atomically, with no other administrative 37eda14cbcSMatt Macyoperations taking effect concurrently. 38eda14cbcSMatt MacyA library of ZFS calls is made available to channel program scripts. 39eda14cbcSMatt MacyChannel programs may only be run with root privileges. 40eda14cbcSMatt Macy.Pp 41eda14cbcSMatt MacyA modified version of the Lua 5.2 interpreter is used to run channel program 42eda14cbcSMatt Macyscripts. 4316038816SMartin MatuskaThe Lua 5.2 manual can be found at 44eda14cbcSMatt Macy.Lk http://www.lua.org/manual/5.2/ 45eda14cbcSMatt Macy.Pp 46eda14cbcSMatt MacyThe channel program given by 47eda14cbcSMatt Macy.Ar script 48eda14cbcSMatt Macywill be run on 49eda14cbcSMatt Macy.Ar pool , 50eda14cbcSMatt Macyand any attempts to access or modify other pools will cause an error. 5116038816SMartin Matuska. 52eda14cbcSMatt Macy.Sh OPTIONS 53eda14cbcSMatt Macy.Bl -tag -width "-t" 5487bf66d4SMartin Matuska.It Fl j , -json 5516038816SMartin MatuskaDisplay channel program output in JSON format. 5616038816SMartin MatuskaWhen this flag is specified and standard output is empty - 5716038816SMartin Matuskachannel program encountered an error. 5816038816SMartin MatuskaThe details of such an error will be printed to standard error in plain text. 59eda14cbcSMatt Macy.It Fl n 60eda14cbcSMatt MacyExecutes a read-only channel program, which runs faster. 61eda14cbcSMatt MacyThe program cannot change on-disk state by calling functions from the 62eda14cbcSMatt Macyzfs.sync submodule. 63eda14cbcSMatt MacyThe program can be used to gather information such as properties and 64eda14cbcSMatt Macydetermining if changes would succeed (zfs.check.*). 65eda14cbcSMatt MacyWithout this flag, all pending changes must be synced to disk before a 66eda14cbcSMatt Macychannel program can complete. 67eda14cbcSMatt Macy.It Fl t Ar instruction-limit 68eda14cbcSMatt MacyLimit the number of Lua instructions to execute. 69eda14cbcSMatt MacyIf a channel program executes more than the specified number of instructions, 70eda14cbcSMatt Macyit will be stopped and an error will be returned. 71eda14cbcSMatt MacyThe default limit is 10 million instructions, and it can be set to a maximum of 72eda14cbcSMatt Macy100 million instructions. 73eda14cbcSMatt Macy.It Fl m Ar memory-limit 74eda14cbcSMatt MacyMemory limit, in bytes. 75eda14cbcSMatt MacyIf a channel program attempts to allocate more memory than the given limit, it 76eda14cbcSMatt Macywill be stopped and an error returned. 77716fd348SMartin MatuskaThe default memory limit is 10 MiB, and can be set to a maximum of 100 MiB. 78eda14cbcSMatt Macy.El 79eda14cbcSMatt Macy.Pp 80eda14cbcSMatt MacyAll remaining argument strings will be passed directly to the Lua script as 81eda14cbcSMatt Macydescribed in the 82eda14cbcSMatt Macy.Sx LUA INTERFACE 83eda14cbcSMatt Macysection below. 8416038816SMartin Matuska. 85eda14cbcSMatt Macy.Sh LUA INTERFACE 86eda14cbcSMatt MacyA channel program can be invoked either from the command line, or via a library 87eda14cbcSMatt Macycall to 88eda14cbcSMatt Macy.Fn lzc_channel_program . 8916038816SMartin Matuska. 90eda14cbcSMatt Macy.Ss Arguments 91eda14cbcSMatt MacyArguments passed to the channel program are converted to a Lua table. 92eda14cbcSMatt MacyIf invoked from the command line, extra arguments to the Lua script will be 93eda14cbcSMatt Macyaccessible as an array stored in the argument table with the key 'argv': 9416038816SMartin Matuska.Bd -literal -compact -offset indent 95eda14cbcSMatt Macyargs = ... 96eda14cbcSMatt Macyargv = args["argv"] 97eda14cbcSMatt Macy-- argv == {1="arg1", 2="arg2", ...} 98eda14cbcSMatt Macy.Ed 99eda14cbcSMatt Macy.Pp 100716fd348SMartin MatuskaIf invoked from the libzfs interface, an arbitrary argument list can be 101eda14cbcSMatt Macypassed to the channel program, which is accessible via the same 102716fd348SMartin Matuska.Qq Li ... 103716fd348SMartin Matuskasyntax in Lua: 10416038816SMartin Matuska.Bd -literal -compact -offset indent 105eda14cbcSMatt Macyargs = ... 106eda14cbcSMatt Macy-- args == {"foo"="bar", "baz"={...}, ...} 107eda14cbcSMatt Macy.Ed 108eda14cbcSMatt Macy.Pp 109eda14cbcSMatt MacyNote that because Lua arrays are 1-indexed, arrays passed to Lua from the 110716fd348SMartin Matuskalibzfs interface will have their indices incremented by 1. 111eda14cbcSMatt MacyThat is, the element 112eda14cbcSMatt Macyin 113eda14cbcSMatt Macy.Va arr[0] 114eda14cbcSMatt Macyin a C array passed to a channel program will be stored in 115eda14cbcSMatt Macy.Va arr[1] 116eda14cbcSMatt Macywhen accessed from Lua. 11716038816SMartin Matuska. 118eda14cbcSMatt Macy.Ss Return Values 119eda14cbcSMatt MacyLua return statements take the form: 12016038816SMartin Matuska.Dl return ret0, ret1, ret2, ... 121eda14cbcSMatt Macy.Pp 122eda14cbcSMatt MacyReturn statements returning multiple values are permitted internally in a 123eda14cbcSMatt Macychannel program script, but attempting to return more than one value from the 124eda14cbcSMatt Macytop level of the channel program is not permitted and will throw an error. 125eda14cbcSMatt MacyHowever, tables containing multiple values can still be returned. 126eda14cbcSMatt MacyIf invoked from the command line, a return statement: 12716038816SMartin Matuska.Bd -literal -compact -offset indent 128eda14cbcSMatt Macya = {foo="bar", baz=2} 129eda14cbcSMatt Macyreturn a 130eda14cbcSMatt Macy.Ed 131eda14cbcSMatt Macy.Pp 132eda14cbcSMatt MacyWill be output formatted as: 13316038816SMartin Matuska.Bd -literal -compact -offset indent 134eda14cbcSMatt MacyChannel program fully executed with return value: 135eda14cbcSMatt Macy return: 136eda14cbcSMatt Macy baz: 2 137eda14cbcSMatt Macy foo: 'bar' 138eda14cbcSMatt Macy.Ed 13916038816SMartin Matuska. 140eda14cbcSMatt Macy.Ss Fatal Errors 141eda14cbcSMatt MacyIf the channel program encounters a fatal error while running, a non-zero exit 142eda14cbcSMatt Macystatus will be returned. 143eda14cbcSMatt MacyIf more information about the error is available, a singleton list will be 144eda14cbcSMatt Macyreturned detailing the error: 14516038816SMartin Matuska.Dl error: \&"error string, including Lua stack trace" 146eda14cbcSMatt Macy.Pp 147eda14cbcSMatt MacyIf a fatal error is returned, the channel program may have not executed at all, 148eda14cbcSMatt Macymay have partially executed, or may have fully executed but failed to pass a 149eda14cbcSMatt Macyreturn value back to userland. 150eda14cbcSMatt Macy.Pp 151eda14cbcSMatt MacyIf the channel program exhausts an instruction or memory limit, a fatal error 152eda14cbcSMatt Macywill be generated and the program will be stopped, leaving the program partially 153eda14cbcSMatt Macyexecuted. 154eda14cbcSMatt MacyNo attempt is made to reverse or undo any operations already performed. 155eda14cbcSMatt MacyNote that because both the instruction count and amount of memory used by a 156eda14cbcSMatt Macychannel program are deterministic when run against the same inputs and 157eda14cbcSMatt Macyfilesystem state, as long as a channel program has run successfully once, you 158eda14cbcSMatt Macycan guarantee that it will finish successfully against a similar size system. 159eda14cbcSMatt Macy.Pp 160eda14cbcSMatt MacyIf a channel program attempts to return too large a value, the program will 161eda14cbcSMatt Macyfully execute but exit with a nonzero status code and no return value. 162eda14cbcSMatt Macy.Pp 163eda14cbcSMatt Macy.Em Note : 164eda14cbcSMatt MacyZFS API functions do not generate Fatal Errors when correctly invoked, they 165eda14cbcSMatt Macyreturn an error code and the channel program continues executing. 166eda14cbcSMatt MacySee the 167eda14cbcSMatt Macy.Sx ZFS API 168eda14cbcSMatt Macysection below for function-specific details on error return codes. 16916038816SMartin Matuska. 170eda14cbcSMatt Macy.Ss Lua to C Value Conversion 171716fd348SMartin MatuskaWhen invoking a channel program via the libzfs interface, it is necessary to 172eda14cbcSMatt Macytranslate arguments and return values from Lua values to their C equivalents, 173eda14cbcSMatt Macyand vice-versa. 174eda14cbcSMatt Macy.Pp 175eda14cbcSMatt MacyThere is a correspondence between nvlist values in C and Lua tables. 176eda14cbcSMatt MacyA Lua table which is returned from the channel program will be recursively 177eda14cbcSMatt Macyconverted to an nvlist, with table values converted to their natural 178eda14cbcSMatt Macyequivalents: 17916038816SMartin Matuska.TS 18016038816SMartin Matuskacw3 l c l . 181eda14cbcSMatt Macy string -> string 182eda14cbcSMatt Macy number -> int64 183eda14cbcSMatt Macy boolean -> boolean_value 184eda14cbcSMatt Macy nil -> boolean (no value) 185eda14cbcSMatt Macy table -> nvlist 18616038816SMartin Matuska.TE 187eda14cbcSMatt Macy.Pp 188eda14cbcSMatt MacyLikewise, table keys are replaced by string equivalents as follows: 18916038816SMartin Matuska.TS 19016038816SMartin Matuskacw3 l c l . 191eda14cbcSMatt Macy string -> no change 192eda14cbcSMatt Macy number -> signed decimal string ("%lld") 193eda14cbcSMatt Macy boolean -> "true" | "false" 19416038816SMartin Matuska.TE 195eda14cbcSMatt Macy.Pp 196eda14cbcSMatt MacyAny collision of table key strings (for example, the string "true" and a 197eda14cbcSMatt Macytrue boolean value) will cause a fatal error. 198eda14cbcSMatt Macy.Pp 199eda14cbcSMatt MacyLua numbers are represented internally as signed 64-bit integers. 20016038816SMartin Matuska. 201eda14cbcSMatt Macy.Sh LUA STANDARD LIBRARY 202eda14cbcSMatt MacyThe following Lua built-in base library functions are available: 20316038816SMartin Matuska.TS 20416038816SMartin Matuskacw3 l l l l . 20516038816SMartin Matuska assert rawlen collectgarbage rawget 20616038816SMartin Matuska error rawset getmetatable select 20716038816SMartin Matuska ipairs setmetatable next tonumber 20816038816SMartin Matuska pairs tostring rawequal type 20916038816SMartin Matuska.TE 210eda14cbcSMatt Macy.Pp 211eda14cbcSMatt MacyAll functions in the 212eda14cbcSMatt Macy.Em coroutine , 213eda14cbcSMatt Macy.Em string , 214eda14cbcSMatt Macyand 215eda14cbcSMatt Macy.Em table 216eda14cbcSMatt Macybuilt-in submodules are also available. 217eda14cbcSMatt MacyA complete list and documentation of these modules is available in the Lua 218eda14cbcSMatt Macymanual. 219eda14cbcSMatt Macy.Pp 220eda14cbcSMatt MacyThe following functions base library functions have been disabled and are 221eda14cbcSMatt Macynot available for use in channel programs: 22216038816SMartin Matuska.TS 22316038816SMartin Matuskacw3 l l l l l l . 22416038816SMartin Matuska dofile loadfile load pcall print xpcall 22516038816SMartin Matuska.TE 22616038816SMartin Matuska. 227eda14cbcSMatt Macy.Sh ZFS API 22816038816SMartin Matuska. 229eda14cbcSMatt Macy.Ss Function Arguments 230eda14cbcSMatt MacyEach API function takes a fixed set of required positional arguments and 231eda14cbcSMatt Macyoptional keyword arguments. 232eda14cbcSMatt MacyFor example, the destroy function takes a single positional string argument 233eda14cbcSMatt Macy(the name of the dataset to destroy) and an optional "defer" keyword boolean 234eda14cbcSMatt Macyargument. 235eda14cbcSMatt MacyWhen using parentheses to specify the arguments to a Lua function, only 236eda14cbcSMatt Macypositional arguments can be used: 23716038816SMartin Matuska.Dl Sy zfs.sync.destroy Ns Pq \&"rpool@snap" 238eda14cbcSMatt Macy.Pp 239eda14cbcSMatt MacyTo use keyword arguments, functions must be called with a single argument that 240eda14cbcSMatt Macyis a Lua table containing entries mapping integers to positional arguments and 241eda14cbcSMatt Macystrings to keyword arguments: 24216038816SMartin Matuska.Dl Sy zfs.sync.destroy Ns Pq {1="rpool@snap", defer=true} 243eda14cbcSMatt Macy.Pp 244eda14cbcSMatt MacyThe Lua language allows curly braces to be used in place of parenthesis as 245eda14cbcSMatt Macysyntactic sugar for this calling convention: 24616038816SMartin Matuska.Dl Sy zfs.sync.snapshot Ns {"rpool@snap", defer=true} 24716038816SMartin Matuska. 248eda14cbcSMatt Macy.Ss Function Return Values 249eda14cbcSMatt MacyIf an API function succeeds, it returns 0. 250eda14cbcSMatt MacyIf it fails, it returns an error code and the channel program continues 251eda14cbcSMatt Macyexecuting. 252eda14cbcSMatt MacyAPI functions do not generate Fatal Errors except in the case of an 253eda14cbcSMatt Macyunrecoverable internal file system error. 254eda14cbcSMatt Macy.Pp 255eda14cbcSMatt MacyIn addition to returning an error code, some functions also return extra 256eda14cbcSMatt Macydetails describing what caused the error. 257eda14cbcSMatt MacyThis extra description is given as a second return value, and will always be a 258eda14cbcSMatt MacyLua table, or Nil if no error details were returned. 259eda14cbcSMatt MacyDifferent keys will exist in the error details table depending on the function 260eda14cbcSMatt Macyand error case. 261eda14cbcSMatt MacyAny such function may be called expecting a single return value: 26216038816SMartin Matuska.Dl errno = Sy zfs.sync.promote Ns Pq dataset 263eda14cbcSMatt Macy.Pp 264eda14cbcSMatt MacyOr, the error details can be retrieved: 26516038816SMartin Matuska.Bd -literal -compact -offset indent 26616038816SMartin Matuska.No errno, details = Sy zfs.sync.promote Ns Pq dataset 267eda14cbcSMatt Macyif (errno == EEXIST) then 268eda14cbcSMatt Macy assert(details ~= Nil) 269eda14cbcSMatt Macy list_of_conflicting_snapshots = details 270eda14cbcSMatt Macyend 271eda14cbcSMatt Macy.Ed 272eda14cbcSMatt Macy.Pp 273eda14cbcSMatt MacyThe following global aliases for API function error return codes are defined 274eda14cbcSMatt Macyfor use in channel programs: 27516038816SMartin Matuska.TS 27616038816SMartin Matuskacw3 l l l l l l l . 27716038816SMartin Matuska EPERM ECHILD ENODEV ENOSPC ENOENT EAGAIN ENOTDIR 27816038816SMartin Matuska ESPIPE ESRCH ENOMEM EISDIR EROFS EINTR EACCES 27916038816SMartin Matuska EINVAL EMLINK EIO EFAULT ENFILE EPIPE ENXIO 28016038816SMartin Matuska ENOTBLK EMFILE EDOM E2BIG EBUSY ENOTTY ERANGE 28116038816SMartin Matuska ENOEXEC EEXIST ETXTBSY EDQUOT EBADF EXDEV EFBIG 28216038816SMartin Matuska.TE 28316038816SMartin Matuska. 284eda14cbcSMatt Macy.Ss API Functions 28516038816SMartin MatuskaFor detailed descriptions of the exact behavior of any ZFS administrative 286eda14cbcSMatt Macyoperations, see the main 287184c1b94SMartin Matuska.Xr zfs 8 288eda14cbcSMatt Macymanual page. 289eda14cbcSMatt Macy.Bl -tag -width "xx" 29016038816SMartin Matuska.It Fn zfs.debug msg 291eda14cbcSMatt MacyRecord a debug message in the zfs_dbgmsg log. 292eda14cbcSMatt MacyA log of these messages can be printed via mdb's "::zfs_dbgmsg" command, or 29316038816SMartin Matuskacan be monitored live by running 29416038816SMartin Matuska.Dl dtrace -n 'zfs-dbgmsg{trace(stringof(arg0))}' 295eda14cbcSMatt Macy.Pp 29616038816SMartin Matuska.Bl -tag -compact -width "property (string)" 29716038816SMartin Matuska.It Ar msg Pq string 298eda14cbcSMatt MacyDebug message to be printed. 29916038816SMartin Matuska.El 30016038816SMartin Matuska.It Fn zfs.exists dataset 301eda14cbcSMatt MacyReturns true if the given dataset exists, or false if it doesn't. 302eda14cbcSMatt MacyA fatal error will be thrown if the dataset is not in the target pool. 303eda14cbcSMatt MacyThat is, in a channel program running on rpool, 30416038816SMartin Matuska.Sy zfs.exists Ns Pq \&"rpool/nonexistent_fs" 30516038816SMartin Matuskareturns false, but 30616038816SMartin Matuska.Sy zfs.exists Ns Pq \&"somepool/fs_that_may_exist" 30716038816SMartin Matuskawill error. 308eda14cbcSMatt Macy.Pp 30916038816SMartin Matuska.Bl -tag -compact -width "property (string)" 31016038816SMartin Matuska.It Ar dataset Pq string 311eda14cbcSMatt MacyDataset to check for existence. 312eda14cbcSMatt MacyMust be in the target pool. 31316038816SMartin Matuska.El 31416038816SMartin Matuska.It Fn zfs.get_prop dataset property 315eda14cbcSMatt MacyReturns two values. 316eda14cbcSMatt MacyFirst, a string, number or table containing the property value for the given 317eda14cbcSMatt Macydataset. 318eda14cbcSMatt MacySecond, a string containing the source of the property (i.e. the name of the 319eda14cbcSMatt Macydataset in which it was set or nil if it is readonly). 320eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid or the property doesn't exist. 321eda14cbcSMatt MacyNote that Lua only supports int64 number types whereas ZFS number properties 322eda14cbcSMatt Macyare uint64. 32316038816SMartin MatuskaThis means very large values (like GUIDs) may wrap around and appear negative. 324eda14cbcSMatt Macy.Pp 32516038816SMartin Matuska.Bl -tag -compact -width "property (string)" 32616038816SMartin Matuska.It Ar dataset Pq string 327eda14cbcSMatt MacyFilesystem or snapshot path to retrieve properties from. 32816038816SMartin Matuska.It Ar property Pq string 329eda14cbcSMatt MacyName of property to retrieve. 33016038816SMartin MatuskaAll filesystem, snapshot and volume properties are supported except for 33116038816SMartin Matuska.Sy mounted 33216038816SMartin Matuskaand 33316038816SMartin Matuska.Sy iscsioptions . 33416038816SMartin MatuskaAlso supports the 33516038816SMartin Matuska.Sy written@ Ns Ar snap 33616038816SMartin Matuskaand 33716038816SMartin Matuska.Sy written# Ns Ar bookmark 33816038816SMartin Matuskaproperties and the 33916038816SMartin Matuska.Ao Sy user Ns | Ns Sy group Ac Ns Ao Sy quota Ns | Ns Sy used Ac Ns Sy @ Ns Ar id 34016038816SMartin Matuskaproperties, though the id must be in numeric form. 34116038816SMartin Matuska.El 342eda14cbcSMatt Macy.El 343eda14cbcSMatt Macy.Bl -tag -width "xx" 344eda14cbcSMatt Macy.It Sy zfs.sync submodule 345eda14cbcSMatt MacyThe sync submodule contains functions that modify the on-disk state. 346eda14cbcSMatt MacyThey are executed in "syncing context". 347eda14cbcSMatt Macy.Pp 348eda14cbcSMatt MacyThe available sync submodule functions are as follows: 349eda14cbcSMatt Macy.Bl -tag -width "xx" 35016038816SMartin Matuska.It Sy zfs.sync.destroy Ns Pq Ar dataset , Op Ar defer Ns = Ns Sy true Ns | Ns Sy false 351eda14cbcSMatt MacyDestroy the given dataset. 352eda14cbcSMatt MacyReturns 0 on successful destroy, or a nonzero error code if the dataset could 353eda14cbcSMatt Macynot be destroyed (for example, if the dataset has any active children or 354eda14cbcSMatt Macyclones). 355eda14cbcSMatt Macy.Pp 35616038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 35716038816SMartin Matuska.It Ar dataset Pq string 358eda14cbcSMatt MacyFilesystem or snapshot to be destroyed. 35916038816SMartin Matuska.It Op Ar defer Pq boolean 360eda14cbcSMatt MacyValid only for destroying snapshots. 361eda14cbcSMatt MacyIf set to true, and the snapshot has holds or clones, allows the snapshot to be 362eda14cbcSMatt Macymarked for deferred deletion rather than failing. 36316038816SMartin Matuska.El 36416038816SMartin Matuska.It Fn zfs.sync.inherit dataset property 365eda14cbcSMatt MacyClears the specified property in the given dataset, causing it to be inherited 366eda14cbcSMatt Macyfrom an ancestor, or restored to the default if no ancestor property is set. 367eda14cbcSMatt MacyThe 36816038816SMartin Matuska.Nm zfs Cm inherit Fl S 369eda14cbcSMatt Macyoption has not been implemented. 370eda14cbcSMatt MacyReturns 0 on success, or a nonzero error code if the property could not be 371eda14cbcSMatt Macycleared. 372eda14cbcSMatt Macy.Pp 37316038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 37416038816SMartin Matuska.It Ar dataset Pq string 375eda14cbcSMatt MacyFilesystem or snapshot containing the property to clear. 37616038816SMartin Matuska.It Ar property Pq string 377eda14cbcSMatt MacyThe property to clear. 378eda14cbcSMatt MacyAllowed properties are the same as those for the 379eda14cbcSMatt Macy.Nm zfs Cm inherit 380eda14cbcSMatt Macycommand. 38116038816SMartin Matuska.El 38216038816SMartin Matuska.It Fn zfs.sync.promote dataset 383eda14cbcSMatt MacyPromote the given clone to a filesystem. 384eda14cbcSMatt MacyReturns 0 on successful promotion, or a nonzero error code otherwise. 385eda14cbcSMatt MacyIf EEXIST is returned, the second return value will be an array of the clone's 386eda14cbcSMatt Macysnapshots whose names collide with snapshots of the parent filesystem. 387eda14cbcSMatt Macy.Pp 38816038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 38916038816SMartin Matuska.It Ar dataset Pq string 390eda14cbcSMatt MacyClone to be promoted. 39116038816SMartin Matuska.El 39216038816SMartin Matuska.It Fn zfs.sync.rollback filesystem 393eda14cbcSMatt MacyRollback to the previous snapshot for a dataset. 394eda14cbcSMatt MacyReturns 0 on successful rollback, or a nonzero error code otherwise. 395eda14cbcSMatt MacyRollbacks can be performed on filesystems or zvols, but not on snapshots 396eda14cbcSMatt Macyor mounted datasets. 397eda14cbcSMatt MacyEBUSY is returned in the case where the filesystem is mounted. 398eda14cbcSMatt Macy.Pp 39916038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 40016038816SMartin Matuska.It Ar filesystem Pq string 401eda14cbcSMatt MacyFilesystem to rollback. 40216038816SMartin Matuska.El 40316038816SMartin Matuska.It Fn zfs.sync.set_prop dataset property value 404eda14cbcSMatt MacySets the given property on a dataset. 405eda14cbcSMatt MacyCurrently only user properties are supported. 406eda14cbcSMatt MacyReturns 0 if the property was set, or a nonzero error code otherwise. 407eda14cbcSMatt Macy.Pp 40816038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 40916038816SMartin Matuska.It Ar dataset Pq string 410eda14cbcSMatt MacyThe dataset where the property will be set. 41116038816SMartin Matuska.It Ar property Pq string 412eda14cbcSMatt MacyThe property to set. 41316038816SMartin Matuska.It Ar value Pq string 414eda14cbcSMatt MacyThe value of the property to be set. 41516038816SMartin Matuska.El 41616038816SMartin Matuska.It Fn zfs.sync.snapshot dataset 417eda14cbcSMatt MacyCreate a snapshot of a filesystem. 418eda14cbcSMatt MacyReturns 0 if the snapshot was successfully created, 419eda14cbcSMatt Macyand a nonzero error code otherwise. 420eda14cbcSMatt Macy.Pp 421eda14cbcSMatt MacyNote: Taking a snapshot will fail on any pool older than legacy version 27. 422eda14cbcSMatt MacyTo enable taking snapshots from ZCP scripts, the pool must be upgraded. 423eda14cbcSMatt Macy.Pp 42416038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 42516038816SMartin Matuska.It Ar dataset Pq string 426eda14cbcSMatt MacyName of snapshot to create. 42716038816SMartin Matuska.El 428c7046f76SMartin Matuska.It Fn zfs.sync.rename_snapshot dataset oldsnapname newsnapname 429c7046f76SMartin MatuskaRename a snapshot of a filesystem or a volume. 430c7046f76SMartin MatuskaReturns 0 if the snapshot was successfully renamed, 431c7046f76SMartin Matuskaand a nonzero error code otherwise. 432c7046f76SMartin Matuska.Pp 433c7046f76SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 434c7046f76SMartin Matuska.It Ar dataset Pq string 435c7046f76SMartin MatuskaName of the snapshot's parent dataset. 436c7046f76SMartin Matuska.It Ar oldsnapname Pq string 437c7046f76SMartin MatuskaOriginal name of the snapshot. 438c7046f76SMartin Matuska.It Ar newsnapname Pq string 439c7046f76SMartin MatuskaNew name of the snapshot. 440c7046f76SMartin Matuska.El 44116038816SMartin Matuska.It Fn zfs.sync.bookmark source newbookmark 442eda14cbcSMatt MacyCreate a bookmark of an existing source snapshot or bookmark. 443eda14cbcSMatt MacyReturns 0 if the new bookmark was successfully created, 444eda14cbcSMatt Macyand a nonzero error code otherwise. 445eda14cbcSMatt Macy.Pp 446eda14cbcSMatt MacyNote: Bookmarking requires the corresponding pool feature to be enabled. 447eda14cbcSMatt Macy.Pp 44816038816SMartin Matuska.Bl -tag -compact -width "newbookmark (string)" 44916038816SMartin Matuska.It Ar source Pq string 450eda14cbcSMatt MacyFull name of the existing snapshot or bookmark. 45116038816SMartin Matuska.It Ar newbookmark Pq string 452eda14cbcSMatt MacyFull name of the new bookmark. 453eda14cbcSMatt Macy.El 45416038816SMartin Matuska.El 455eda14cbcSMatt Macy.It Sy zfs.check submodule 45616038816SMartin MatuskaFor each function in the 45716038816SMartin Matuska.Sy zfs.sync 45816038816SMartin Matuskasubmodule, there is a corresponding 45916038816SMartin Matuska.Sy zfs.check 460eda14cbcSMatt Macyfunction which performs a "dry run" of the same operation. 46116038816SMartin MatuskaEach takes the same arguments as its 46216038816SMartin Matuska.Sy zfs.sync 46316038816SMartin Matuskacounterpart and returns 0 if the operation would succeed, 46416038816SMartin Matuskaor a non-zero error code if it would fail, along with any other error details. 465eda14cbcSMatt MacyThat is, each has the same behavior as the corresponding sync function except 466eda14cbcSMatt Macyfor actually executing the requested change. 467eda14cbcSMatt MacyFor example, 46816038816SMartin Matuska.Fn zfs.check.destroy \&"fs" 469eda14cbcSMatt Macyreturns 0 if 47016038816SMartin Matuska.Fn zfs.sync.destroy \&"fs" 471eda14cbcSMatt Macywould successfully destroy the dataset. 472eda14cbcSMatt Macy.Pp 47316038816SMartin MatuskaThe available 47416038816SMartin Matuska.Sy zfs.check 47516038816SMartin Matuskafunctions are: 47616038816SMartin Matuska.Bl -tag -compact -width "xx" 47716038816SMartin Matuska.It Sy zfs.check.destroy Ns Pq Ar dataset , Op Ar defer Ns = Ns Sy true Ns | Ns Sy false 47816038816SMartin Matuska.It Fn zfs.check.promote dataset 47916038816SMartin Matuska.It Fn zfs.check.rollback filesystem 48016038816SMartin Matuska.It Fn zfs.check.set_property dataset property value 48116038816SMartin Matuska.It Fn zfs.check.snapshot dataset 482eda14cbcSMatt Macy.El 483eda14cbcSMatt Macy.It Sy zfs.list submodule 484eda14cbcSMatt MacyThe zfs.list submodule provides functions for iterating over datasets and 485eda14cbcSMatt Macyproperties. 486eda14cbcSMatt MacyRather than returning tables, these functions act as Lua iterators, and are 487eda14cbcSMatt Macygenerally used as follows: 48816038816SMartin Matuska.Bd -literal -compact -offset indent 48916038816SMartin Matuska.No for child in Fn zfs.list.children \&"rpool" No do 490eda14cbcSMatt Macy ... 491eda14cbcSMatt Macyend 492eda14cbcSMatt Macy.Ed 493eda14cbcSMatt Macy.Pp 49416038816SMartin MatuskaThe available 49516038816SMartin Matuska.Sy zfs.list 49616038816SMartin Matuskafunctions are: 497eda14cbcSMatt Macy.Bl -tag -width "xx" 49816038816SMartin Matuska.It Fn zfs.list.clones snapshot 499eda14cbcSMatt MacyIterate through all clones of the given snapshot. 500eda14cbcSMatt Macy.Pp 50116038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 50216038816SMartin Matuska.It Ar snapshot Pq string 503eda14cbcSMatt MacyMust be a valid snapshot path in the current pool. 50416038816SMartin Matuska.El 50516038816SMartin Matuska.It Fn zfs.list.snapshots dataset 506eda14cbcSMatt MacyIterate through all snapshots of the given dataset. 50716038816SMartin MatuskaEach snapshot is returned as a string containing the full dataset name, 50816038816SMartin Matuskae.g. "pool/fs@snap". 509eda14cbcSMatt Macy.Pp 51016038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 51116038816SMartin Matuska.It Ar dataset Pq string 512eda14cbcSMatt MacyMust be a valid filesystem or volume. 51316038816SMartin Matuska.El 51416038816SMartin Matuska.It Fn zfs.list.children dataset 515eda14cbcSMatt MacyIterate through all direct children of the given dataset. 51616038816SMartin MatuskaEach child is returned as a string containing the full dataset name, 51716038816SMartin Matuskae.g. "pool/fs/child". 518eda14cbcSMatt Macy.Pp 51916038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 52016038816SMartin Matuska.It Ar dataset Pq string 521eda14cbcSMatt MacyMust be a valid filesystem or volume. 52216038816SMartin Matuska.El 52316038816SMartin Matuska.It Fn zfs.list.bookmarks dataset 52416038816SMartin MatuskaIterate through all bookmarks of the given dataset. 52516038816SMartin MatuskaEach bookmark is returned as a string containing the full dataset name, 52616038816SMartin Matuskae.g. "pool/fs#bookmark". 527eda14cbcSMatt Macy.Pp 52816038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 52916038816SMartin Matuska.It Ar dataset Pq string 530eda14cbcSMatt MacyMust be a valid filesystem or volume. 53116038816SMartin Matuska.El 53216038816SMartin Matuska.It Fn zfs.list.holds snapshot 53316038816SMartin MatuskaIterate through all user holds on the given snapshot. 53416038816SMartin MatuskaEach hold is returned 535eda14cbcSMatt Macyas a pair of the hold's tag and the timestamp (in seconds since the epoch) at 536eda14cbcSMatt Macywhich it was created. 537eda14cbcSMatt Macy.Pp 53816038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 53916038816SMartin Matuska.It Ar snapshot Pq string 540eda14cbcSMatt MacyMust be a valid snapshot. 54116038816SMartin Matuska.El 54216038816SMartin Matuska.It Fn zfs.list.properties dataset 543eda14cbcSMatt MacyAn alias for zfs.list.user_properties (see relevant entry). 544eda14cbcSMatt Macy.Pp 54516038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 54616038816SMartin Matuska.It Ar dataset Pq string 547eda14cbcSMatt MacyMust be a valid filesystem, snapshot, or volume. 54816038816SMartin Matuska.El 54916038816SMartin Matuska.It Fn zfs.list.user_properties dataset 55016038816SMartin MatuskaIterate through all user properties for the given dataset. 55116038816SMartin MatuskaFor each step of the iteration, output the property name, its value, 55216038816SMartin Matuskaand its source. 553eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid. 554eda14cbcSMatt Macy.Pp 55516038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 55616038816SMartin Matuska.It Ar dataset Pq string 557eda14cbcSMatt MacyMust be a valid filesystem, snapshot, or volume. 55816038816SMartin Matuska.El 55916038816SMartin Matuska.It Fn zfs.list.system_properties dataset 560eda14cbcSMatt MacyReturns an array of strings, the names of the valid system (non-user defined) 561eda14cbcSMatt Macyproperties for the given dataset. 562eda14cbcSMatt MacyThrows a Lua error if the dataset is invalid. 563eda14cbcSMatt Macy.Pp 56416038816SMartin Matuska.Bl -tag -compact -width "snapshot (string)" 56516038816SMartin Matuska.It Ar dataset Pq string 566eda14cbcSMatt MacyMust be a valid filesystem, snapshot or volume. 567eda14cbcSMatt Macy.El 568eda14cbcSMatt Macy.El 56916038816SMartin Matuska.El 57016038816SMartin Matuska. 571eda14cbcSMatt Macy.Sh EXAMPLES 57216038816SMartin Matuska. 573eda14cbcSMatt Macy.Ss Example 1 574eda14cbcSMatt MacyThe following channel program recursively destroys a filesystem and all its 575eda14cbcSMatt Macysnapshots and children in a naive manner. 576eda14cbcSMatt MacyNote that this does not involve any error handling or reporting. 577eda14cbcSMatt Macy.Bd -literal -offset indent 578eda14cbcSMatt Macyfunction destroy_recursive(root) 579eda14cbcSMatt Macy for child in zfs.list.children(root) do 580eda14cbcSMatt Macy destroy_recursive(child) 581eda14cbcSMatt Macy end 582eda14cbcSMatt Macy for snap in zfs.list.snapshots(root) do 583eda14cbcSMatt Macy zfs.sync.destroy(snap) 584eda14cbcSMatt Macy end 585eda14cbcSMatt Macy zfs.sync.destroy(root) 586eda14cbcSMatt Macyend 587eda14cbcSMatt Macydestroy_recursive("pool/somefs") 588eda14cbcSMatt Macy.Ed 58916038816SMartin Matuska. 590eda14cbcSMatt Macy.Ss Example 2 591eda14cbcSMatt MacyA more verbose and robust version of the same channel program, which 592eda14cbcSMatt Macyproperly detects and reports errors, and also takes the dataset to destroy 593eda14cbcSMatt Macyas a command line argument, would be as follows: 594eda14cbcSMatt Macy.Bd -literal -offset indent 595eda14cbcSMatt Macysucceeded = {} 596eda14cbcSMatt Macyfailed = {} 597eda14cbcSMatt Macy 598eda14cbcSMatt Macyfunction destroy_recursive(root) 599eda14cbcSMatt Macy for child in zfs.list.children(root) do 600eda14cbcSMatt Macy destroy_recursive(child) 601eda14cbcSMatt Macy end 602eda14cbcSMatt Macy for snap in zfs.list.snapshots(root) do 603eda14cbcSMatt Macy err = zfs.sync.destroy(snap) 604eda14cbcSMatt Macy if (err ~= 0) then 605eda14cbcSMatt Macy failed[snap] = err 606eda14cbcSMatt Macy else 607eda14cbcSMatt Macy succeeded[snap] = err 608eda14cbcSMatt Macy end 609eda14cbcSMatt Macy end 610eda14cbcSMatt Macy err = zfs.sync.destroy(root) 611eda14cbcSMatt Macy if (err ~= 0) then 612eda14cbcSMatt Macy failed[root] = err 613eda14cbcSMatt Macy else 614eda14cbcSMatt Macy succeeded[root] = err 615eda14cbcSMatt Macy end 616eda14cbcSMatt Macyend 617eda14cbcSMatt Macy 618eda14cbcSMatt Macyargs = ... 619eda14cbcSMatt Macyargv = args["argv"] 620eda14cbcSMatt Macy 621eda14cbcSMatt Macydestroy_recursive(argv[1]) 622eda14cbcSMatt Macy 623eda14cbcSMatt Macyresults = {} 624eda14cbcSMatt Macyresults["succeeded"] = succeeded 625eda14cbcSMatt Macyresults["failed"] = failed 626eda14cbcSMatt Macyreturn results 627eda14cbcSMatt Macy.Ed 62816038816SMartin Matuska. 629eda14cbcSMatt Macy.Ss Example 3 630eda14cbcSMatt MacyThe following function performs a forced promote operation by attempting to 631eda14cbcSMatt Macypromote the given clone and destroying any conflicting snapshots. 632eda14cbcSMatt Macy.Bd -literal -offset indent 633eda14cbcSMatt Macyfunction force_promote(ds) 634eda14cbcSMatt Macy errno, details = zfs.check.promote(ds) 635eda14cbcSMatt Macy if (errno == EEXIST) then 636eda14cbcSMatt Macy assert(details ~= Nil) 637eda14cbcSMatt Macy for i, snap in ipairs(details) do 638eda14cbcSMatt Macy zfs.sync.destroy(ds .. "@" .. snap) 639eda14cbcSMatt Macy end 640eda14cbcSMatt Macy elseif (errno ~= 0) then 641eda14cbcSMatt Macy return errno 642eda14cbcSMatt Macy end 643eda14cbcSMatt Macy return zfs.sync.promote(ds) 644eda14cbcSMatt Macyend 645eda14cbcSMatt Macy.Ed 646