Hi

This is the initial patch submission of autofs filesystem support for
OpenBSD, which was originally written for FreeBSD and later ported to
DragonFlyBSD and NetBSD.

Autofs is a generic filesystem automounter filesystem, not limited to
mounting NFS. This OpenBSD port actually started off with the NetBSD
code rather than FreeBSD though all versions are quite similar except
for the autofs filesystem code in kernel space. While I currently
maintain it as an out-of-tree filesystem on GitHub, I'm aiming for
this to get merged by OpentBSD.

The initial patch is available from below in three formats. The patch
applies to the current src as of March 24 (and builds on amd64).

diff -aNur
https://leaf.dragonflybsd.org/~tkusumi/diff/openbsd/OpenBSD-autofs-v1.patch
git format-patch
https://leaf.dragonflybsd.org/~tkusumi/diff/openbsd/0001-OpenBSD-autofs-v1.patch
GitHub
https://github.com/kusumi/src/tree/autofs-20180325

Online documentation and man pages for FreeBSD (which are also part
of the patch) would/should work against OpenBSD with a few exceptions.
Below links are FreeBSD autofs info you can find on the web. Note
that FreeBSD autofs is not a port of Linux autofs which has existed
for a long(er) time. Although they are quite similar in terms of
features, there is no compatibility in configuration files and such,
thus the same for OpenBSD and Linux.
https://people.freebsd.org/~trasz/autofs.pdf
https://wiki.freebsd.org/Automounter
http://freebsdfoundation.blogspot.fi/2015/03/freebsd-from-trenches-using-autofs5-to_13.html


---
How to use autofs (currently only enabled on amd64)

1. Build kernel (autofs enabled by default atm in sys/conf/GENERIC)
   and world.
2. Enable etc/rc.d/automountd and etc/rc.d/autounmountd via rcctl(8).
3. Create a character device /dev/autofs via /dev/MAKEDEV.
4. Write auto mount configuration(s) to /etc/auto_master. FreeBSD
   documentation should help, though configuration needed to do a
   simple NFS auto mounting is quite simple (2 lines basically -
   i.e. 1 line in /etc/auto_master to specify a configuration file for
   eithre direct or indirect map, and 1 line in that file to specify
   NFS mount details).
5. Run automount(8) command (no options needed) to mount autofs(5)
   based on /etc/auto_master contents, and confirm autofs(5) is
   mounted via mount(8) command.
6. Restart automountd(8) and autounmountd(8). This could be before or
   after running automount(8) command.
7. Access autofs(5) mount point, and see if auto mounting works. I've
   only tested with NFS with both direct/indirect mapping, which is
   probably what majority of people use autofs for, however the basic
   automounting mechanism is filesystem-agnostic.


I'll write down some more details of newly added code.

---
Newly added subsystems

1. sys/miscfs/autofs
 The autofs(5) filesystem catches some of the vnode operations, and
 notifies the user space daemon automountd(8) that auto mounting
 requests from user process have arrived. The character device
 /dev/autofs (with major# 98) is used as a communication channel
 between autofs(5) and automountd(8) daemon via ioctl(2). Once
 automountd(8) receives the request from autofs(5) filesystem, it
 attempts to mount a target filesystem which corresponds to the
 autofs(5) mount point accessed by the user process, based on what
 auto_master(5) (/etc/auto_master file) has. The actual mounting is
 done by a child process forked from automountd(8) using mount(8) and
 variants.

2. usr.sbin/autofs
 User space is basically the same as the FreeBSD code as well as
 DragonFlyBSD and NetBSD ports with minimum changes needed for
 OpenBSD. The changes mostly come from difference in library/syscall
 interface, FreeBSD specific syscalls, workaround code specific to
 OpenBSD, etc. The directory contains followings.
  * autmount(8) - a command to mount autofs(5) filesystem.
  * automountd(8) - a daemon to auto mount target filesystems
    specified in /etc/auto_master.
  * autounmountd(8) - a daemon to auto unmount the auto mounted
    filesystems if no longer used when the timer has expired.
 These executable binaries actually consist of a single inode,
 i.e. /usr/sbin/automountd and /usr/sbin/autounmountd are hardlinks
 to /usr/sbin/automount, and they do what they do by checking argv[0]
 in its main().

3. etc/auto_master and etc/autofs/*
 etc/auto_master is a configuration file which describes relations
 between autofs(5) mount points and target filesystems to auto mount.
 As mentioned above, automountd(8) mounts filesystems based on this
 file. The auto_master(5) man page explains details of the format.
 etc/autofs/* are collection of scripts used by auto_master(5) when
 pre-defined special mappings are used. These are just copied from
 FreeBSD unless a script contains FreeBSD specific stuff
 (e.g. etc/autofs/special_media uses FreeBSD specific sysctl).

4. usr.sbin/fstyp
 Fstyp(8) is an utility to detect filesystem type of the given block
 device, and was originally added to FreeBSD for autofs. It's been
 used by automountd(8) to detect filesystem type of a block device
 when automountd(5) tries to mount a local filesystem (i.e. not NFS)
 by checking its signature. See "-media" mapping section in
 auto_master(5) for details. Fstyp(8) supports filesystems such as
 UFS, ext2, ISO9660, FAT, NTFS. FreeBSD version also supports ZFS,
 and DragonFlyBSD version supports HAMMER, but these two are dropped
 in OpenBSD, basically due to not being supported in OpenBSD (lacks
 library and header files defining ondisk format).

---
Changes to the existing C code

1. Add MNT_AUTOMOUNTED, MOUNT_AUTOFS, struct autofs_args, etc to
   sys/sys/mount.h. MNT_AUTOMOUNTED flag allows VFS to recognize auto
   mounted filesystems (i.e. not the autofs(5) itself, but filesystems
   mounted by automountd(8)). Filesystems mounted with this flag set
   are shown as "automounted" in mount(8) output.
2. Add VT_AUTOFS to sys/sys/vnode.h.
3. Add MOPT_AUTOMOUNTED to sbin/mount.
4. Add cdev_autofs_init() to sys/sys/conf.h.
5. Add autofs to cdevsw[] in sys/arch/amd64/amd64/conf.c.
6. Add autofs to vfsconflist[] in sys/kern/vfs_init.c.
7. Add autofs to vfsinit() in sbin/sysctl/sysctl.c.
8. Add -E option to usr.bin/showmount/showmount.c. This is used by
   "-hosts" map of autofs which is etc/autofs/special_hosts. This
   option originate FreeBSD.
9. Add EVFILT_FS event for kqueue(2) in sys/sys/event.h and
   sys/kern/kern_event.c, which gets triggered on mount and unmount
   of any filesystem. This is needed by autounmountd(8) daemon.
   EVFILT_FS has existed in FreeBSD for a long time, but not in
   OpenBSD.

---
Notes

1. Autofs(5) is currently only enabled on amd64, i.e.
   sys/arch/amd64/* and etc/etc.amd64/MAKEDEV, which is the arch used
   to port autofs.
2. "xxx first appeared in OpenBSD <version>" in newly added man pages
   have "6.x" for <version> at the moment. There are 6 new man pages,
   autofs(5), auto_master(5), automount(8), automountd(8),
   autounmountd(8) and fstyp(8) which originate FreeBSD.
3. The "-media" map is currently unsupported due to
   etc/autofs/special_media not being functional. The same script in
   FreeBSD uses GEOM sysctl, whereas there seems to be no easy way to
   achieve the same result on OpenBSD. See the bottom part of
   etc/autofs/special_media for details. I'd apply if this is doable
   on OpenBSD, which is to list all possible block devices and
   partitions for fstyp to check filesystem type.

Reply via email to