Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: support temporary mount options #78

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/os/macos/zfs/sys/zfs_mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct zfs_mount_args {
#define MS_DETACH MNT_DETACH
#define MS_OVERLAY MNT_UNION
#define MS_CRYPT MNT_CPROTECT
#define MS_NOATIME MNT_NOATIME
#define MS_STRICTATIME MNT_STRICTATIME
#endif

#endif /* _SYS_ZFS_IOCTL_H */
4 changes: 2 additions & 2 deletions include/sys/mntent.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
#define MNTOPT_SETUID "setuid" /* Set uid allowed */
#define MNTOPT_NOSETUID "nosetuid" /* Set uid not allowed */
#elif defined(__APPLE__)
#define MNTOPT_SETUID "setuid" /* Set uid allowed */
#define MNTOPT_NOSETUID "nosetuid" /* Set uid not allowed */
#define MNTOPT_SETUID "suid" /* Set uid allowed */
#define MNTOPT_NOSETUID "nosuid" /* Set uid not allowed */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this undo the #ifdef apple (you will translate later), then we can drop the #ifdef?

#define MNTOPT_BROWSE "browse" /* browsable autofs mount */
#define MNTOPT_NOBROWSE "nobrowse" /* non-browsable autofs mount */
#define MNTOPT_OWNERS "owners" /* use ownership */
Expand Down
4 changes: 2 additions & 2 deletions lib/libspl/include/os/macos/mntent.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ extern "C" {
#define MNTOPT_NOGLOBAL "noglobal" /* Mount local to single node */
#define MNTOPT_DFRATIME "dfratime" /* Deferred access time updates */
#define MNTOPT_NODFRATIME "nodfratime" /* No Deferred access time updates */
#define MNTOPT_NBMAND "nbmand" /* allow non-blocking mandatory locks */
#define MNTOPT_NONBMAND "nonbmand" /* deny non-blocking mandatory locks */
#define MNTOPT_NBMAND "mand" /* allow non-blocking mandatory locks */
#define MNTOPT_NONBMAND "nomand" /* deny non-blocking mandatory locks */
#define MNTOPT_XATTR "xattr" /* enable extended attributes */
#define MNTOPT_NOXATTR "noxattr" /* disable extended attributes */
#define MNTOPT_EXEC "exec" /* enable executables */
Expand Down
1 change: 0 additions & 1 deletion lib/libspl/include/os/macos/sys/mnttab.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <sys/mount.h>
#define MNTTAB _PATH_DEVNULL
#define MS_NOMNTTAB 0x0
#define MS_RDONLY 0x1
#define umount2(p, f) unmount(p, f)
#define MNT_LINE_MAX 4096

Expand Down
4 changes: 4 additions & 0 deletions lib/libspl/include/os/macos/sys/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define MS_POSIXACL (1<<16)
#endif

#define MS_RDONLY MNT_RDONLY
#define MS_NOSUID MNT_NOSUID
#define MS_NOEXEC MNT_NOEXEC
#define MS_NODEV MNT_NODEV
Expand All @@ -83,5 +84,8 @@
#define MS_DETACH MNT_DETACH
#define MS_OVERLAY MNT_UNION
#define MS_CRYPT MNT_CPROTECT
#define MS_NOATIME MNT_NOATIME
#define MS_STRICTATIME MNT_STRICTATIME
#define MS_MANDLOCK 0

#endif /* _LIBSPL_SYS_MOUNT_H */
32 changes: 20 additions & 12 deletions lib/libzfs/os/macos/libzfs_mount_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,12 @@ static const option_map_t option_map[] = {
#endif
/* Custom zfs options */
{ MNTOPT_XATTR, MS_COMMENT, ZS_COMMENT },
{ MNTOPT_NOXATTR, MS_COMMENT, ZS_COMMENT },
{ MNTOPT_NOXATTR, MNT_NOUSERXATTR, ZS_COMMENT },
{ MNTOPT_ZFSUTIL, MS_COMMENT, ZS_ZFSUTIL },
{ MNTOPT_BROWSE, MS_COMMENT, ZS_COMMENT },
{ MNTOPT_NOBROWSE, MNT_DONTBROWSE, ZS_COMMENT },
{ MNTOPT_OWNERS, MS_COMMENT, ZS_COMMENT },
{ MNTOPT_NOOWNERS, MNT_IGNORE_OWNERSHIP, ZS_COMMENT },
{ NULL, 0, 0 } };

/*
Expand Down Expand Up @@ -502,16 +506,20 @@ do_mount(zfs_handle_t *zhp, const char *dir, char *optptr, int mflag)
}
}

// We don't pass flags to XNU, we use optstr
mflag = 0;
char badopt[MNT_LINE_MAX] = {0};
unsigned long mntflags = mflag, zfsflags;
char myopts[MNT_LINE_MAX] = {0};

// Some arguments need to be told to XNU
if (strstr(optptr, "remount") != NULL)
mflag |= MNT_UPDATE;
if (zfs_parse_mount_options(optptr, &mntflags,
&zfsflags, 0, badopt, NULL)) {
return (EINVAL);
}
strlcat(myopts, optptr, MNT_LINE_MAX);
zfs_adjust_mount_options(zhp, dir, myopts, NULL);

mnt_args.mflag = mflag;
mnt_args.optptr = optptr;
mnt_args.optlen = optlen;
mnt_args.mflag = mntflags;
mnt_args.optptr = myopts;
mnt_args.optlen = MNT_LINE_MAX;
mnt_args.struct_size = sizeof (mnt_args);

/*
Expand All @@ -523,13 +531,13 @@ do_mount(zfs_handle_t *zhp, const char *dir, char *optptr, int mflag)
rpath = realpath(dir, NULL);

#ifdef ZFS_DEBUG
printf("%s calling mount with fstype %s, %s %s, fspec %s, mflag %d,"
printf("%s calling mount with fstype %s, %s %s, fspec %s, mntflags %lu,"
" optptr %s, optlen %d, devdisk %d, ispool %d\n",
__func__, fstype, (rpath ? "rpath" : "dir"),
(rpath ? rpath : dir), mnt_args.fspec, mflag, optptr, optlen,
(rpath ? rpath : dir), mnt_args.fspec, mntflags, optptr, optlen,
devdisk, ispool);
#endif
rv = mount(fstype, rpath ? rpath : dir, mflag, &mnt_args);
rv = mount(fstype, rpath ? rpath : dir, mntflags, &mnt_args);

/* Check if we need to create/update icon */
if (rv == 0)
Expand Down
64 changes: 64 additions & 0 deletions module/os/macos/zfs/zfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,70 @@ zfs_vfs_mount(struct mount *vfsp, vnode_t *mvp /* devvp */,
cmdflags |= MNT_UPDATE;
}

// MS_NODEV
if (mflag & MNT_NODEV) {
dprintf("%s: adding MNT_NODEV\n", __func__);
cmdflags |= MNT_NODEV;
}

// MS_NOSUID
if (mflag & MNT_NOSUID) {
dprintf("%s: adding MNT_NOSUID\n", __func__);
cmdflags |= MNT_NOSUID;
}

// MS_NOEXEC
if (mflag & MNT_NOEXEC) {
dprintf("%s: adding MNT_NOEXEC\n", __func__);
cmdflags |= MNT_NOEXEC;
}

#if 0
// zfsvfs->z_xattr needs to be set instead of MNT_NOUSERXATTR
if (mflag & MNT_NOUSERXATTR) {
dprintf("%s: adding MNT_NOUSERXATTR\n", __func__);
cmdflags |= MNT_NOUSERXATTR;
}
#endif

// MS_NOATIME
if (mflag & MNT_NOATIME) {
dprintf("%s: adding MNT_NOATIME\n", __func__);
cmdflags |= MNT_NOATIME;
}

// nobrowse
if (mflag & MNT_DONTBROWSE) {
dprintf("%s: adding MNT_DONTBROWSE\n", __func__);
cmdflags |= MNT_DONTBROWSE;
}

// noowners
if (mflag & MNT_IGNORE_OWNERSHIP) {
dprintf("%s: adding MNT_IGNORE_OWNERSHIP\n", __func__);
cmdflags |= MNT_IGNORE_OWNERSHIP;
}

// These aren't handled by zfs_register_callbacks yet.
#if 0
if (mflag & MNT_ASYNC) {
dprintf("%s: adding MNT_ASYNC\n", __func__);
cmdflags |= MNT_ASYNC;
}

// MS_SYNCHRONOUS
if (mflag & MNT_SYNCHRONOUS) {
dprintf("%s: adding MNT_SYNCHRONOUS\n", __func__);
cmdflags |= MNT_SYNCHRONOUS;
}

// MS_STRICTATIME
if (mflag & MNT_STRICTATIME) {
dprintf("%s: adding MNT_STRICTATIME\n", __func__);
cmdflags |= MNT_STRICTATIME;
}
#endif

vfs_setflags(vfsp, (uint64_t)cmdflags);

/*
Expand Down