Skip to content

Commit

Permalink
Add overlay(-O) mount option support
Browse files Browse the repository at this point in the history
Linux supports mounting over non-empty directories by default.
In Solaris this is not the case and -O option is required for
zfs mount to mount a zfs filesystem over a non-empty directory.

For compatibility, I've added support for -O option to mount
zfs filesystems over non-empty directories if the user wants
to, just like in Solaris.

I've defined MS_OVERLAY to record it in the flags variable if
the -O option is supplied.  The flags variable passes through
a few functions and its checked before performing the empty
directory check in zfs_mount function.  If -O is given, the
check is not performed.

Signed-off-by: Brian Behlendorf <[email protected]>
Closes openzfs#473
  • Loading branch information
Suman Chakravartula authored and Rudd-O committed Feb 1, 2012
1 parent e30639f commit 1d861ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5469,7 +5469,7 @@ share_mount(int op, int argc, char **argv)
int flags = 0;

/* check options */
while ((c = getopt(argc, argv, op == OP_MOUNT ? ":avo:" : "a"))
while ((c = getopt(argc, argv, op == OP_MOUNT ? ":avo:O" : "a"))
!= -1) {
switch (c) {
case 'a':
Expand All @@ -5491,7 +5491,9 @@ share_mount(int op, int argc, char **argv)
/* option validation is done later */
append_options(options, optarg);
break;

case 'O':
flags |= MS_OVERLAY;
break;
case ':':
(void) fprintf(stderr, gettext("missing argument for "
"'%c' option\n"), optopt);
Expand Down
7 changes: 7 additions & 0 deletions lib/libspl/include/sys/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@
# define MS_DETACH 0x00000002
#endif /* MNT_DETACH */

/*
* Overlay mount is default in Linux, but for solaris/zfs
* compatibility, MS_OVERLAY is defined to explicitly have the user
* provide a flag (-O) to mount over a non empty directory.
*/
#define MS_OVERLAY 0x00000004

#endif /* _LIBSPL_SYS_MOUNT_H */
6 changes: 4 additions & 2 deletions lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,11 @@ zfs_mount(zfs_handle_t *zhp, const char *options, int flags)

/*
* Determine if the mountpoint is empty. If so, refuse to perform the
* mount. We don't perform this check if 'remount' is specified.
* mount. We don't perform this check if 'remount' is
* specified or if overlay option(-O) is given
*/
if (!remount && !dir_is_empty(mountpoint)) {
if ((flags & MS_OVERLAY) == 0 && !remount &&
!dir_is_empty(mountpoint)) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"directory is not empty"));
return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
Expand Down

0 comments on commit 1d861ac

Please sign in to comment.