ligurio / unreliablefs

A FUSE-based fault injection filesystem.
https://ligurio.github.io/unreliablefs/unreliablefs.1.html
MIT License
173 stars 9 forks source link

Add support of JSON API via network socket #121

Open ligurio opened 1 year ago

ligurio commented 1 year ago

Currently, unreliablefs supports a single interface of setting fault injections - plain text file with INI-style configuration options. It would be quite convenient to have yet another interface with access via network socket and JSON API.

New command-line option

Add a new option socket that allows to specify a path to a control UNIX socket. Mount with socket:

$ unreliablefs /tmp/fs -base_dir=/tmp -seed=1618680646 -socket=/tmp/unreliablefs.socket

JSON API:

JSON API has the same keywords as used in a configuration file.

# Show current fault-injections:
$ cat /tmp/unreliablefs.socket
{ "err-injections":[] }
...
# Set an error injection with `noop`:
$ echo '{ "err-injections": [ {"name": "errinj_noop", "path_regexp": "", "op_regexp": "", "probability": 5 } ] }' >  /tmp/unreliablefs.socket
...
# Set two error injections: `errinj_kill_caller` and `errinj_errno`:
$ echo '{ "err-injections":[ { "name": "errinj_kill_caller", "path_regexp": "" }, { "name": "errinj_errno", "path_regexp": "" } ] }' >  /tmp/unreliablefs.socket
...
# Cleanup all fault-injections:
$ echo '{ "err-injections": [] }' >  /tmp/unreliablefs.socket

Setting options using jo(1):

$ jo err_injections[]=$(jo name=errinj_errno) err_injections[]=$(jo name=errinj_noop)
{"err_injections":[{"name":"errinj_errno"},{"name":"errinj_noop"}]}
$ jo err_injections[]=$(jo name=errinj_errno) err_injections[]=$(jo name=errinj_noop) > /tmp/unreliablefs.socket

References