NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/52888: Add autofs for NetBSD



>Number:         52888
>Category:       kern
>Synopsis:       Add autofs for NetBSD
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          support
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 02 19:15:00 +0000 2018
>Originator:     Tomohiro Kusumi
>Release:        NetBSD-current
>Organization:
>Environment:
Architecture independent.
# uname -r
8.99.9

>Description:
This is the initial patch submission for autofs filesystem on NetBSD ported from FreeBSD.
I'm aiming for this to get merged by NetBSD.

Autofs is a generic filesystem automounter filesystem, not limited to mounting NFS. It's been mentioned in the NetBSD project wiki as well.
https://wiki.netbsd.org/projects/project/new-automounter/

The initial patch is available from below. The first one is a Git format-patch style diff (I use Git mirror at https://github.com/NetBSD/src), and the second one is via diff -aNur. The patch is created on top of 8.99.9 as of around 2017.12.28. It also applies to 8.99.10, but recent src commit(s) broke buildworld on my environment. I didn't separate the patch into a series of patch sets, since most of the C code come from newly added subsystems, but I could if requested to do so.
https://leaf.dragonflybsd.org/~tkusumi/diff/netbsd/0001-NetBSD-autofs-v1.patch
https://leaf.dragonflybsd.org/~tkusumi/diff/netbsd/NetBSD-autofs-v1.patch

Online documentation and man pages for FreeBSD (which are also part of the patch) would/should work against NetBSD with a few exceptions. Below links are FreeBSD autofs info you can find on the web. Note that the FreeBSD autofs is not a port of Linux autofs which has existed for a long(er) time. There is no compatibility in configuration files and such, thus the same for NetBSD 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-Repeat:
How to use autofs

1. Add autofs_enable=YES to /etc/rc.conf.
2. Write configurations to /etc/auto_master. FreeBSD documentation should help, though configuration needed to do a simple NFS auto mounting is quite simple (1 line basically).
3. Reboot or restart autofs, have access to autofs(5) mount point, and see if auto mounting works. I've only tested with NFS (e.g. auto mount an exported FreeBSD directory via NFS via autofs), which is probably what majority of people use autofs for.

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

---
Newly added subsystems

1. sys/fs/autofs - Autofs filesystem
Autofs(5) filesystem is a rewrite of the FreeBSD autofs(5) code. The autofs(5) filesystem catches some of the vnode operations from user processes, and notifies the user space daemon automountd(8) that auto mounting requests from user process have arrived. The character device /dev/autofs (with major# 343) is used as a communication channel between autofs(5) and automountd(8) daemon. 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) configuration file /etc/auto_master has. The actual mounting is done by a child process forked from automountd(8) using mount(8) and variants.

2. usr.sbin/autofs - Autofs user space command and daemons
User space code are basically the same as the original FreeBSD code (and DragonFlyBSD port) with minimum changes needed for NetBSD. The changes mostly come from difference in library/syscall interface, FreeBSD specific syscall, workaround code specific to NetBSD, 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 auto unmounting timer has expired.
These executable binaries actually consist of a single file, 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/* - Autofs configuration files
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.

4. usr.sbin/fstyp - Filesystem type detection utility
Fstyp(8) is an utility to detect filesystem type of the given block device, and it was originally added to FreeBSD for autofs. It's been used by automountd(8) to detect filesystem type of block devices to auto mount when "-media" map is specified in auto_master(5). See auto_master(5) for details of "-media" map. 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 NetBSD. Note that auto mounting NFS doesn't require fstyp(8) or "-media" map.

---
Changes to the existing C code

1. Add MNT_AUTOMOUNTED to sys/sys/fstypes.h. This 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 MOUNT_AUTOFS to sys/sys/mount.h.
3. Add VT_AUTOFS to sys/sys/vnode.h.
4. 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 exists in FreeBSD as well.
5. Add a warning (exporting of auto mounted fs isn't supported) to usr.sbin/mountd/mountd.c. This warning exists in FreeBSD as well.
6. Add EVFILT_FS event for kqueue(2) 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 NetBSD.

---
Notes

1. The autofs kernel code is located under sys/fs/autofs rather than sys/miscfs/autofs, since that's where FreeBSD autofs is located at. FreeBSD seems to be more or less aiming for compatibility with Solaris autofs, and Solaris autofs user space seems to assume autofs headers are under sys/fs/autofs. But I personally don't have any preference and free to change to sys/miscfs/autofs. DragonFlyBSD has it under sys/vfs/autofs as there is no sys/fs directory.
2. I've only added autofs to conf files for x86_64 (i.e. sys/arch/amd64/conf/...) which is the arch I used for porting autofs.
3. Changes to NetBSD configuration files, including above, are based on what other filesystems do, which may or may not be wrong in case of autofs. Any correction is appreciated.
4. "xxx first appeared in NetBSD <version>" in newly added man pages have "8.99.1" for <version> at the moment. There are several new man pages, such as autofs(5), auto_master(5), automount(8), automountd(8), autounmountd(8), fstyp(8). These man pages are all from FreeBSD as well.
5. 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 NetBSD. See the bottom part of etc/autofs/special_media for details. I'd apply if anyone knows how to do this on NetBSD, which is to list all possible block devices and partitions for fstyp to check filesystem type.



Home | Main Index | Thread Index | Old Index