Skip to content

Commit

Permalink
Merge pull request networkupstools#2594 from jimklimov/issue-2591
Browse files Browse the repository at this point in the history
Follow-up for the FUSE PoC: integrate with `make check-NIT` prepared sandboxes
  • Loading branch information
jimklimov authored Aug 15, 2024
2 parents 822d04e + f141059 commit 0b1c6fe
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
39 changes: 35 additions & 4 deletions scripts/fuse/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,43 @@ to rebuild and restart a daemon).

Installation:

* Get pre-requisites to build FUSE clients, e.g. `apt install libfuse-dev`
on Debian-like systems, or `brew install --cask macfuse@dev` on MacOS with
Homebrew community packaging.
* Download and build the `execfuse` daemon:
----
:; git clone https://github.com/vi/execfuse
:; cd execfuse
:; make
:; make && ls -la execfuse
----
That's about it, an `execfuse` binary should appear.

To run with the PoC scripts here, assuming a built NUT in `~/nut` location:
NOTE: Examples below assume a built NUT in `~/nut` location, and a temporary
mount point in `/tmp/nut-fuse`.

You can also prepare an enviroment using NUT Integration Tests (NIT) scripts:
----
:; mkdir /tmp/nut-fuse
:; ( cd ~/nut && DEBUG_SLEEP=600 make check-NIT ) &

# ...wait a few seconds for it to say the sandbox is ready
:; . "${HOME}/nut/tests/NIT/tmp/etc/NIT.env"
----

Before mounting the FUSE file system, you can also request to debug the PoC
scripts:
----
:; NUT_DEBUG_FUSE=true
:; export NUT_DEBUG_FUSE

# After running some queries, so the log-files to watch appear:
:; tail -F /tmp/nut-debug-fuse-*.log &
----
To run with the PoC scripts here:
----
:; mkdir -p /tmp/nut-fuse
:; PATH="$HOME/nut/clients:$PATH" \
./execfuse "$HOME/nut/scripts/fuse/execfuse-nut" /tmp/nut-fuse
----
Expand Down Expand Up @@ -76,17 +101,23 @@ total 23
drwxr-xr-x 16 root root 4096 Jan 1 1970 .
drwxrwxrwt 154 root root 20480 Aug 13 23:55 ..
drwxr-xr-x 16 root root 4096 Jan 1 1970 by-server
-r--r--r-- 1 root root 0 Jan 1 1970 client-location
-r--r--r-- 1 root root 0 Jan 1 1970 client-version
:; cat /tmp/nut-fuse/client-version
:; cat /tmp/nut-fuse/client-location
/home/abuild/nut/clients/upsc
:; cat /tmp/nut-fuse/client-version
Network UPS Tools upsc 2.8.2.901.2-903-g533aa7eaf (development iteration after 2.8.2)
----
Eventually, to stop this experiment:
----
:; fusermount -u /tmp/nut-fuse
# Or if user-land programs are missing, like in "macfuse@dev", just `umount`:
:; umount /tmp/nut-fuse
----
As far as a PoC goes, this is already a fun and quickly achieved result,
Expand Down
2 changes: 1 addition & 1 deletion scripts/fuse/execfuse-nut/getattr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case "$1" in
# UPSSRV
D="`basename "$1"`"
;;
/client-version)
/client-location|/client-version)
F="$1"
;;
*)
Expand Down
5 changes: 4 additions & 1 deletion scripts/fuse/execfuse-nut/read_file
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ case "$1" in
upsc "$UPS" "$VARNAME"
exit $?
;;
/client-location)
command -v upsc
exit $?
;;
/client-version)
if [ x"$NUT_DEBUG_FUSE" = xtrue ] ; then
#echo "+upsc '$UPS' '$VARNAME'" >&2
set -x
fi
command -v upsc
NUT_DEBUG_LEVEL=6 upsc -V
exit $?
;;
Expand Down
9 changes: 7 additions & 2 deletions scripts/fuse/execfuse-nut/readdir
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ case "$1" in
for D in "by-server" ; do
printf 'ino=1 mode=drwxr-xr-x nlink=4 uid=0 gid=0 rdev=0 size=4096 blksize=512 blocks=2 atime=0 mtime=0 ctime=0 %s\0' "$D"
done
for F in "client-version" ; do
for F in "client-location" "client-version" ; do
printf 'ino=1 mode=-r--r--r-- nlink=1 uid=0 gid=0 rdev=0 size=4096 blksize=512 blocks=2 atime=0 mtime=0 ctime=0 %s\0' "$F"
done
;;
/by-server)
print_dots
printf 'ino=1 mode=drwxr-xr-x nlink=16 uid=0 gid=0 rdev=0 size=16 blksize=512 blocks=1 atime=0 mtime=0 ctime=0 %s\0' "localhost:3493"
printf 'ino=1 mode=drwxr-xr-x nlink=16 uid=0 gid=0 rdev=0 size=16 blksize=512 blocks=1 atime=0 mtime=0 ctime=0 %s\0' "localhost"
# Primarily this is a value arranged by `make check-NIT`:
set -x
if [ -n "${NUT_PORT-}" ] && [ x"${NUT_PORT}" != x3493 ]; then
printf 'ino=1 mode=drwxr-xr-x nlink=16 uid=0 gid=0 rdev=0 size=16 blksize=512 blocks=1 atime=0 mtime=0 ctime=0 %s\0' "localhost:${NUT_PORT}"
fi
;;
/by-server/*/*/*) # Don't want subdirs here
exit 2 # ENOENT
Expand Down

0 comments on commit 0b1c6fe

Please sign in to comment.