Difference between revisions of "Projects/ZFS Channel Programs"

Jump to navigation Jump to search
Line 35: Line 35:
Examples of how a channel program would be written by a person in either a procedural or functional language are below:
Examples of how a channel program would be written by a person in either a procedural or functional language are below:


{| border="1" style="border-collapse:collapse; text-align: center"
<center>
{| border="1" style="border-collapse:collapse; text-align: left"
|-
|-
| '''Procedural (Python-esque)''' || '''Functional (Scheme-esque)'''
| '''Procedural (Python-esque)''' || '''Functional (Scheme-esque)'''
|-
|-
|
|
   fs = argv[0]
   fs = zfs.''get_filesystem''(argv[0])
   for snap in fs.snapshots():
   for snap in fs.''snapshots''():
    snap."""destroy"""()
      snap.''destroy''()
||
||
   (iterate_snapshots fs snap
   (''iterate_snapshots'' fs snap
    (destroy_snapshot snap))
      (''destroy_snapshot'' snap))
|-
|-
|}
|}
</center>
Both of these high-level representations could be compiled to a common nvlist IR representation and stored in a .zcp file. This .zcp file could then be passed to a new ZFS command, zfs program <zcp-file> which would read the stored nvlist and pass it directly to the kernel.
This nvlist representation can also be constructed “manually” by any user application using ZCP libraries to support construction of ZCP channel programs programmatically. For example, the same application could be constructed with code similar to:
<center>
{| border="1" style="border-collapse:collapse; text-align: left"
|-
| '''Programmatic Construction (C/C++ API)'''
|-
|
  int main(int argc, char **argv) {
      ...
      char *fs_name = argv[0];
      const char *snaps_iterator = "snap";
      zcp_control_stmt *iterate_snaps = ''zcp_create_iterator_snapshots''(fs_name, snaps_iterator);
      zcp_op_stmt *destroy_snap = ''zcp_create_destroy_snapshot''(snaps_iterator);
      ''zcp_add_child_op''(iterate_snaps, destroy_snap);
      ...
      ''zcp_execute''(iterate_snaps);
      ...
  }
|-
|}
</center
The zcp_control_stmt and zc_op_stmt objects defined above are nvpair objects in a hierarchical nvlist. This allows the program constructed in this example to be passed immediately to the kernel for execution. Initially, ZFS channel program construction will be done using a C/C++ API like this one (perhaps a little more rough around the edges).
The nvlist object created from this source code would look something like this:
Editor
90

edits

Navigation menu