openzfsonosx/zfs — pull request #185 by ilovezfs (2014-05-19 15:40:08+00:00)
Title: Support legacy mountpoints

Bringing in illumos's manual_mount() and manual_unmount() allows us
to support mountpoint=legacy. As in FreeBSD, manual_mount calls a
new function zmount(), which has the same arguments as illumos's
mount() function. zfs_mount() in libzfs now calls zmount() as well.

manual_mount() is called if the name of the binary is 'mount_zfs',
and we hardlink 'mount_zfs' to the standard 'zfs' command. This
differs from upstream use of the name 'mount' because OS X will
pass through calls to mount -t somefs to mount_somefs.

zfs_mount_args is moved out of zfs_context.h and into its own file
zfs_mount.h so that zmount() can live in libspl without needing to
include the entire zfs_context.h. The illumos-compatible flags
MS_OVERLAY, MS_FORCE, etc. are moved here, as well.

zfs_mount_args is expanded to allow zmount to pass in the option
string to the kernel for processing (not implemented here). Also,
in zfs_mount_args an illumos compatible variable named 'mflag'
replaces the OS X compatible variable named 'flags'. The
translation from the illumos compatible flags (MS_*) to OS X
compatible flags (MNT_*) is now handled in the kernel in
zfs_vfs_mount(). To complete this change, instances in userland
where we were using MNT_* flags are switched to their MS_*
counterparts. Going forward, this should simplify porting
insofar as we can for the most part stick to the upstream
MS_* flags in userland. The major exception is in getmntany
where getfsstat() will return statfs structs with the
variable f_flags, which uses MNT_* flags.

A memory leak has been fixed in zfs_vfs_mount(), where we were
allocating 'osname' but not freeing it.

Since we print "Mount successful" changelist_postfix() when a
previously mounted file system is re-mounted, changelist_postfix()
cannot trust zfs_mount()'s return value. zfs_mount() can return 0
even if the file system did not actually mount, as is the case for
file systems with legacy mountpoints. To avoid being misleading,
we now check that the value of the property ZFS_PROP_MOUNTED is
"yes" before declaring "Mount successful" in changelist_postfix().