Returning multiple values: they can instead be returned as a newly allocated array. Neko's method prevents possible stack corruption by the C programmer, which, in Lua, is possible by passing erroneous values to the stack manipulation functions. (Defining luaassert will catch such attempts as runtime errors).
Section: Maintenance Commands (8)
When a Lua function called from C returns ends it puts its return values on the stack. When a return value is a table, retrieving the table's elements isn't obvious. Assuming the Lua function returned only one thing and that thing is a table, then that table is at the stack's top when it comes back to C. In Lua function can return multiple values. When a function with multiple results is called, multiple assignment is used to store results.
The ZFS channel program interface allows ZFS administrative operations to berun programmatically as a Lua script.The entire script is executed atomically, with no other administrativeoperations taking effect concurrently.A library of ZFS calls is made available to channel program scripts.Channel programs may only be run with root privileges.
A modified version of the Lua 5.2 interpreter is used to run channel programscripts.The Lua 5.2 manual can be found at:
Lk http://www.lua.org/manual/5.2/
The channel program given byscriptwill be run onpool and any attempts to access or modify other pools will cause an error.
OPTIONS
If invoked from the libZFS interface, an arbitrary argument list can bepassed to the channel program, which is accessible via the same'..' syntax in Lua:
Note that because Lua arrays are 1-indexed, arrays passed to Lua from thelibZFS interface will have their indices incremented by 1.That is, the elementinarr[0]in a C array passed to a channel program will be stored inarr[1]when accessed from Lua.
Return Values
Lua return statements take the form:
Return statements returning multiple values are permitted internally in achannel program script, but attempting to return more than one value from thetop level of the channel program is not permitted and will throw an error.However, tables containing multiple values can still be returned.If invoked from the command line, a return statement:
Will be output formatted as:
Fatal Errors
If the channel program encounters a fatal error while running, a non-zero exitstatus will be returned.If more information about the error is available, a singleton list will bereturned detailing the error:
If a fatal error is returned, the channel program may have not executed at all,may have partially executed, or may have fully executed but failed to pass areturn value back to userland.
If the channel program exhausts an instruction or memory limit, a fatal errorwill be generated and the program will be stopped, leaving the program partiallyexecuted.No attempt is made to reverse or undo any operations already performed.Note that because both the instruction count and amount of memory used by achannel program are deterministic when run against the same inputs andfilesystem state, as long as a channel program has run successfully once, youcan guarantee that it will finish successfully against a similar size system.
If a channel program attempts to return too large a value, the program willfully execute but exit with a nonzero status code and no return value.
Note:ZFS API functions do not generate Fatal Errors when correctly invoked, theyreturn an error code and the channel program continues executing.See theSx ZFS APIsection below for function-specific details on error return codes.
Lua to C Value Conversion
When invoking a channel program via the libZFS interface, it is necessary totranslate arguments and return values from Lua values to their C equivalents,and vice-versa.
There is a correspondence between nvlist values in C and Lua tables.A Lua table which is returned from the channel program will be recursivelyconverted to an nvlist, with table values converted to their naturalequivalents:
Likewise, table keys are replaced by string equivalents as follows:
Any collision of table key strings (for example, the string 'true' and atrue boolean value) will cause a fatal error.
Lua numbers are represented internally as signed 64-bit integers.
LUA STANDARD LIBRARY
The following Lua built-in base library functions are available:
All functions in thecoroutinestring andtablebuilt-in submodules are also available.A complete list and documentation of these modules is available in the Luamanual. Clash of clans date and time hack.
The following functions base library functions have been disabled and arenot available for use in channel programs:
ZFS API
Function Arguments
Each API function takes a fixed set of required positional arguments andoptional keyword arguments.For example, the destroy function takes a single positional string argument(the name of the dataset to destroy) and an optional 'defer' keyword booleanargument.When using parentheses to specify the arguments to a Lua function, onlypositional arguments can be used:
To use keyword arguments, functions must be called with a single argument thatis a Lua table containing entries mapping integers to positional arguments andstrings to keyword arguments:
The Lua language allows curly braces to be used in place of parenthesis assyntactic sugar for this calling convention:
Function Return Values
If an API function succeeds, it returns 0.If it fails, it returns an error code and the channel program continuesexecuting.API functions do not generate Fatal Errors except in the case of anunrecoverable internal file system error.
In addition to returning an error code, some functions also return extradetails describing what caused the error.This extra description is given as a second return value, and will always be aLua table, or Nil if no error details were returned.Different keys will exist in the error details table depending on the functionand error case.Any such function may be called expecting a single return value:
Or, the error details can be retrieved:
The following global aliases for API function error return codes are definedfor use in channel programs:
API Functions
For detailed descriptions of the exact behavior of any zfs administrativeoperations, see the mainzfs(1)manual page.
zfs.debug(msg)
Record a debug message in the zfs_dbgmsg log.A log of these messages can be printed via mdb's '::zfs_dbgmsg' command, orcan be monitored live by running:
msg (string)Debug message to be printed.
zfs.exists(dataset)
Returns true if the given dataset exists, or false if it doesn't.A fatal error will be thrown if the dataset is not in the target pool.That is, in a channel program running on rpool,zfs.exists('rpool/nonexistent_fs') returns false, butzfs.exists('somepool/fs_that_may_exist') will error.
dataset (string)Dataset to check for existence.Must be in the target pool.
zfs.get_prop(dataset, property)
Returns two values.First, a string, number or table containing the property value for the givendataset.Second, a string containing the source of the property (i.e. the name of thedataset in which it was set or nil if it is readonly).Throws a Lua error if the dataset is invalid or the property doesn't exist.Note that Lua only supports int64 number types whereas ZFS number propertiesare uint64.This means very large values (like guid) may wrap around and appear negative.
dataset (string)Filesystem or snapshot path to retrieve properties from.
property (string)Name of property to retrieve.All filesystem, snapshot and volume properties are supported exceptfor 'mounted' and 'iscsioptions.'Also supports the 'written@snap' and 'written#bookmark' properties andthe '<user|group><quota|used>@id' properties, though the id must be in numericform.
zfs.sync submodule
The sync submodule contains functions that modify the on-disk state.They are executed in 'syncing context'.
The available sync submodule functions are as follows:
zfs.sync.destroy(dataset, [defer=true|false])
Destroy the given dataset.Returns 0 on successful destroy, or a nonzero error code if the dataset couldnot be destroyed (for example, if the dataset has any active children orclones).
dataset (string)Filesystem or snapshot to be destroyed.
[optional] defer (boolean)Valid only for destroying snapshots.If set to true, and the snapshot has holds or clones, allows the snapshot to bemarked for deferred deletion rather than failing.
zfs.sync.promote(dataset)
Promote the given clone to a filesystem.Returns 0 on successful promotion, or a nonzero error code otherwise.If EEXIST is returned, the second return value will be an array of the clone'ssnapshots whose names collide with snapshots of the parent filesystem.
dataset (string)Clone to be promoted.
zfs.sync.rollback(filesystem)
Rollback to the previous snapshot for a dataset.Returns 0 on successful rollback, or a nonzero error code otherwise.Rollbacks can be performed on filesystems or zvols, but not on snapshotsor mounted datasets.EBUSY is returned in the case where the filesystem is mounted.
filesystem (string)Filesystem to rollback.
zfs.sync.snapshot(dataset)
Create a snapshot of a filesystem.Returns 0 if the snapshot was successfully created,and a nonzero error code otherwise.
Note: Taking a snapshot will fail on any pool older than legacy version 27.To enable taking snapshots from ZCP scripts, the pool must be upgraded.
dataset (string)Name of snapshot to create.
zfs.check submodule
For each function in the zfs.sync submodule, there is a corresponding zfs.checkfunction which performs a 'dry run' of the same operation.Each takes the same arguments as its zfs.sync counterpart and returns 0 if theoperation would succeed, or a non-zero error code if it would fail, along withany other error details.That is, each has the same behavior as the corresponding sync function exceptfor actually executing the requested change.For example,zfs.check.destroy(fs)returns 0 ifzfs.sync.destroy(fs)would successfully destroy the dataset.
The available zfs.check functions are:
dataset (string)Must be a valid filesystem or volume.
zfs.list.children(dataset)
Iterate through all direct children of the given dataset.Each child is returned as a string containing the full dataset name, e.g.'pool/fs/child'.
dataset (string)Must be a valid filesystem or volume.
zfs.list.properties(dataset)
Iterate through all user properties for the given dataset.
dataset (string)Must be a valid filesystem, snapshot, or volume.
zfs.list.system_properties(dataset)
Returns an array of strings, the names of the valid system (non-user defined)properties for the given dataset.Throws a Lua error if the dataset is invalid.
dataset (string)Must be a valid filesystem, snapshot or volume.
EXAMPLES
Example 1
The following channel program recursively destroys a filesystem and all itssnapshots and children in a naive manner.Note that this does not involve any error handling or reporting.
Returning Multiple Values In Lua To C Free
Example 2
A more verbose and robust version of the same channel program, whichproperly detects and reports errors, and also takes the dataset to destroyas a command line argument, would be as follows:
Example 3
The following function performs a forced promote operation by attempting topromote the given clone and destroying any conflicting snapshots.
Index
NAME
SYNOPSIS
DESCRIPTION
OPTIONS
LUA INTERFACE
Arguments
Return Values
Fatal Errors
Lua to C Value Conversion
LUA STANDARD LIBRARY
ZFS API
Function Arguments
Function Return Values
API Functions
EXAMPLES
Example 1
Example 2
Example 3
This document was created byman2html,using the manual pages.