The client
By Roberto Arato of aratoingegneria.it
Every machine that uses the filesystem mounts it with nexfs-client, a
user-space program that talks to the kernel through FUSE. No kernel module is
needed other than FUSE itself, which every distribution has.
Mounting
nexfs-client -c /etc/nexfs/nexfs.json /nex
The program stays in the foreground as long as the filesystem is mounted: it
is usually started by systemd (see below). SIGTERM unmounts.
| Option | What it does |
|---|---|
-c FILE |
the configuration (default /etc/nexfs/nexfs.json): the list of meta nodes and the certificates are enough, see Configuration |
-s NAME |
the source name in /proc/mounts (default nexfs) |
-o OPTIONS |
the mount options, separated by commas |
--version |
the version |
The mount options are the usual ones:
| Option | Effect |
|---|---|
noatime (default) |
the last access time is never updated: the best performance |
relatime |
the last access time is updated only if it is older than the last modification, or older than one day |
strictatime |
it is updated on every open for reading |
nodiratime |
never for folders |
ro, rw |
read-only, read-write |
nodev, nosuid (and dev, suid) |
as for any filesystem |
Why noatime is the default. Keeping the last access time up to date
means that reading a file also changes it: every read becomes a small update
sent to the metadata nodes. With noatime reading is only reading, and that
gives the best performance, especially with many small files. Very few
programs need the access time (some mail readers and backup tools): only for
them mount with -o relatime.
With systemd
The package ships the nexfs-client@.service unit: one instance per folder,
with the folder name written the way systemd-escape --path writes it
(/nex becomes nex, /mnt/data becomes mnt-data).
systemctl enable --now nexfs-client@nex.service
mounts /nex at boot, after the network and before remote-fs.target.
When systemctl start returns, the folder is already usable: the services
that use it (with RequiresMountsFor=/nex) start afterwards. The options go
in /etc/nexfs/client-nex.env, or for all folders in
/etc/nexfs/client.env:
# /etc/nexfs/client-nex.env
NEXFS_CLIENT_ARGS="-c /etc/nexfs/nexfs.json -o noatime"
With /etc/fstab
The type is nexfs (or fuse.nexfs); the source is any name you like, or
the configuration file:
nexfs /nex nexfs _netdev,noatime 0 0
mount /nex calls mount.nexfs, which the package installs next to the
client, and returns when the folder is usable. The options are the ones
above, plus config=FILE for a configuration other than the default one;
mount -o remount,ro /nex switches to read-only without unmounting. The
client's messages go to the journal: journalctl -t nexfs-client, or
journalctl -u nex.mount if systemd does the mount at boot.
Restarting the client without unmounting
systemctl reload nexfs-client@nex.service # or: kill -HUP $(pidof nexfs-client)
The client re-executes itself with the program that is on disk now, that is the new one if the package has just been upgraded, keeping the filesystem mounted. A package upgrade does this by itself for every folder mounted with the unit. The programs working inside don't notice: open files stay open, confirmed writes stay, locks stay held, whoever was waiting for a lock keeps waiting for it, a folder read halfway is read to the end. The pause is about a tenth of a second.
What users see
- What one node has written and closed, another reads by opening the file, always. While a file is open on several nodes at once, writers write directly to the data nodes and nobody keeps stale pages in memory.
- Closing a file does not wait for the network. In a folder where a node
works alone,
closereturns at once and the data travels to the copies in the background, like the cache of a local disk; whoever opens the file from another node, even a moment later, still reads all of it. If a write fails after the close, the error is returned by the nextfsyncor the next close of the same file: a program that must know its data is safe callsfsync, which returns only when the data is on the disk of all copies. - Names and attributes changed by one node are seen immediately by every other node.
- Permissions are checked by the kernel and checked again by the meta nodes, with the user and groups of the caller.
flock, POSIX and OFD locks apply across all nodes.- A file deleted while it is open can still be used, even if the name was removed by another node; the space comes back when the last one closes it.
- If the servers do not respond, a call waits and retries up to the
request timeout (8 seconds,
timeouts.request_msin Configuration). If they come back in the meantime, for example after a new leader is elected, the call succeeds; otherwise it returns an error (ETIMEDOUT, "Connection timed out") instead of hanging, and the filesystem can still be unmounted.
Folder attributes
You read and write them with the extended attribute tools (getfattr,
setfattr, from the attr package). They do not show up in listings.
| Attribute | What it is |
|---|---|
nexfs.dir.durability |
group (default) or full: the durability of the metadata under the folder, see Security |
nexfs.dir.rbytes |
the bytes of everything underneath, subfolders included (read-only) |
nexfs.dir.rfiles, nexfs.dir.rsubdirs, nexfs.dir.rentries |
how many files, subfolders, entries in total (read-only) |
nexfs.quota.max_bytes |
the folder's space quota, in bytes; 0 = no limit |
nexfs.quota.max_files |
the quota on entries (files plus folders); 0 = no limit |
getfattr -n nexfs.dir.rbytes /nex/home/anna # how much it takes up, always up to date
setfattr -n nexfs.quota.max_bytes -v 50000000000 /nex/home/anna # 50 GB at most
setfattr -n nexfs.dir.durability -v full /nex/accounting
Whoever exceeds a quota gets EDQUOT ("quota exceeded"), from whichever node
they write. The counts are always exact: there is nothing to recompute. For
those coming from CephFS, the ceph.dir.* and ceph.quota.* names are
accepted too.
The number of copies of a folder is changed with nexfsctl copies, see
Administration.
Snapshots
Every folder has a hidden .snap folder, which does not show up in listings
but can be opened:
mkdir /nex/projects/.snap/before-release # take a picture of the folder now
ls /nex/projects/.snap/ # the folder's snapshots
cp -a /nex/projects/.snap/before-release/x.c /nex/projects/ # get a file back
rmdir /nex/projects/.snap/before-release # remove it
A snapshot is instantaneous and copies nothing: blocks are duplicated only
when someone changes them afterwards. Inside .snap everything is as it was,
attributes included, read-only. When a snapshot is removed, the space of the
blocks that only it was holding becomes free again.
For those who measure
On any file or folder of the mount, four attributes tell you what the client is doing:
| Attribute | What it counts |
|---|---|
nexfs.client.stats |
metadata requests, answers served from the folder cache, changes made locally and batches sent |
nexfs.client.ops |
the metadata requests, per operation |
nexfs.client.kernel |
the requests coming from the kernel, per operation |
nexfs.client.kernel_us |
the microseconds spent serving them, per operation: divided by the count in nexfs.client.kernel it is the average time a program waits for the client on that operation |