/sharedb

FreeBSD DB-based NFS exports & ZFS sharenfs support

Primary LanguageCBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

# sharedb

Version: 1.1 (2024-07-18)
Author:  Peter Eriksson <pen@lysator.liu.se>

The files in this repo can be used to implement DB-based (B-Tree)
NFS exports for ZFS and mountd for FreeBSD 13+.

It also allows "multiline" exports for ZFS (using ";" to separate the options).

There is a significant speed improvement for servers with many exported
ZFS filesystems. One test of "zfs share -a" on a server with 11000 filesystems
made the time go from 41 seconds to 2.7s.


The project consists of three parts:

1. share - a small CLI utility to update/view sharedb files
2. A patch for mountd to make it read DB files
3. A patch for libshare in ZFS to make it update DB files
4. A patch for /etc/rc.d/zfs handling exports.db

Build and install "share" with "make install-share"

There are slightly different versions of the zfs patch in
the subdirectory Patches but the Makefile will automatically
apply the correct version based on the FreeBSD source in /usr/src:

- FreeBSD 14/CURRENT
- FreeBSD 13-STABLE
- FreeBSD 13.2-RELEASE. 
- FreeBSD 13.3-RELEASE. 

Apply the patches with "make SRCDIR=/usr/src apply-patches".
Build and install libzfs.so.4 into /lib and mountd into /usr/sbin with:

make install-mountd
make install-libzfs

(Building libzfs also builds mountd since it runs "make -DNO_CLEAR buildworld"...


The patch to zfs enables updating of the database files when
you use:

  zfs set sharenfs="<options>" FILESYS

It will check if the DB-based Btree /etc/zfs/exports.db file exists,
and then use the new code automatically.

If it doesn't exist then it will use the old text-based /etc/zfs/exports file.

You can use ";" to separate multiline options per above like this:

  zfs set sharenfs="-sec=krb5;-sec=sys somehost.somewhere" FILESYS


The patch to mountd adds reading the DB files in preference to the text
versions if it finds it when scanning the list of exports sources.



As long as you don't have any "multiline" exports looking like this
in /etc/exports:

  /export/foo -sec=krb5
  /export/foo -sec=sys somehost.somewhere

then you can use "makemap" to populate DB files like this:

  makemap -f btree /etc/exports.db </etc/exports
  makemap -f btree /etc/zfs/exports.db </etc/zfs/exports

There is no need to use makemap for /etc/zfs/exports.db if you use the
zfs patch though. To enable DB files usage you must first create an
empty file - touch /etc/zfs/exports.db


The 'share' CLI utility too can be used to view and update the DB files.
It's still a work in progress. Run it with "-h" for usage information. 

- Peter