svn commit: r357001 - in stable: 11/cddl/contrib/opensolaris/lib/libzfs/common 11/lib/libbe 12/cddl/contrib/opensolaris/lib/libzfs/common 12/lib/libbe
Kyle Evans
kevans at FreeBSD.org
Wed Jan 22 22:51:57 UTC 2020
Author: kevans
Date: Wed Jan 22 22:51:55 2020
New Revision: 357001
URL: https://svnweb.freebsd.org/changeset/base/357001
Log:
MFC r356876-r356877: add zfs_mount_at
r356876:
libzfs: add zfs_mount_at
This will be used in libbe in place of the internal zmount(); libbe only
wants to be able to mount a dataset at an arbitrary mountpoint without
altering dataset/pool properties. The natural way to do this in a portable
way is by creating a zfs_mount_at() interface that's effectively zfs_mount()
+ a mountpoint parameter. zfs_mount() is now a light wrapper around the new
method.
The interface and implementation have already been accepted into ZFS On
Linux, and the next commit to switch libbe() over to this new interface will
solve the last compatibility issue with ZoL. The next sysutils/openzfs
rebase against ZoL should be able to build libbe/bectl with only minor
adjustments to build glue.
r356877:
libbe: use the new zfs_mount_at()
More background is available in r356876, but this new interface is more
portable across ZFS implementations and cleaner for what libbe is attempting
to achieve anyways.
Modified:
stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h
stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c
stable/12/lib/libbe/be_access.c
Directory Properties:
stable/12/ (props changed)
Changes in other areas also in this revision:
Modified:
stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h
stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c
stable/11/lib/libbe/be_access.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h
==============================================================================
--- stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h Wed Jan 22 22:08:02 2020 (r357000)
+++ stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h Wed Jan 22 22:51:55 2020 (r357001)
@@ -752,6 +752,7 @@ extern boolean_t zfs_bookmark_exists(const char *path)
extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
extern int zfs_mount(zfs_handle_t *, const char *, int);
+extern int zfs_mount_at(zfs_handle_t *, const char *, int, const char *);
extern int zfs_unmount(zfs_handle_t *, const char *, int);
extern int zfs_unmountall(zfs_handle_t *, int);
Modified: stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c
==============================================================================
--- stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c Wed Jan 22 22:08:02 2020 (r357000)
+++ stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c Wed Jan 22 22:51:55 2020 (r357001)
@@ -301,6 +301,17 @@ zfs_is_mounted(zfs_handle_t *zhp, char **where)
return (is_mounted(zhp->zfs_hdl, zfs_get_name(zhp), where));
}
+static boolean_t
+zfs_is_mountable_internal(zfs_handle_t *zhp, const char *mountpoint)
+{
+
+ if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED) &&
+ getzoneid() == GLOBAL_ZONEID)
+ return (B_FALSE);
+
+ return (B_TRUE);
+}
+
/*
* Returns true if the given dataset is mountable, false otherwise. Returns the
* mountpoint in 'buf'.
@@ -325,8 +336,7 @@ zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t
if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_OFF)
return (B_FALSE);
- if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED) &&
- getzoneid() == GLOBAL_ZONEID)
+ if (!zfs_is_mountable_internal(zhp, buf))
return (B_FALSE);
if (source)
@@ -341,8 +351,19 @@ zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t
int
zfs_mount(zfs_handle_t *zhp, const char *options, int flags)
{
- struct stat buf;
char mountpoint[ZFS_MAXPROPLEN];
+
+ if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL))
+ return (0);
+
+ return (zfs_mount_at(zhp, options, flags, mountpoint));
+}
+
+int
+zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
+ const char *mountpoint)
+{
+ struct stat buf;
char mntopts[MNT_LINE_MAX];
libzfs_handle_t *hdl = zhp->zfs_hdl;
@@ -357,8 +378,8 @@ zfs_mount(zfs_handle_t *zhp, const char *options, int
if (zpool_get_prop_int(zhp->zpool_hdl, ZPOOL_PROP_READONLY, NULL))
flags |= MS_RDONLY;
- if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL))
- return (0);
+ if (!zfs_is_mountable_internal(zhp, mountpoint))
+ return (B_FALSE);
/* Create the directory if it doesn't already exist */
if (lstat(mountpoint, &buf) != 0) {
Modified: stable/12/lib/libbe/be_access.c
==============================================================================
--- stable/12/lib/libbe/be_access.c Wed Jan 22 22:08:02 2020 (r357000)
+++ stable/12/lib/libbe/be_access.c Wed Jan 22 22:51:55 2020 (r357001)
@@ -82,7 +82,6 @@ be_mount_iter(zfs_handle_t *zfs_hdl, void *data)
char *mountpoint;
char tmp[BE_MAXPATHLEN], zfs_mnt[BE_MAXPATHLEN];
struct be_mount_info *info;
- char opt;
info = (struct be_mount_info *)data;
@@ -121,9 +120,7 @@ be_mount_iter(zfs_handle_t *zfs_hdl, void *data)
mountpoint);
}
- opt = '\0';
- if ((err = zmount(zfs_get_name(zfs_hdl), tmp, info->mntflags,
- __DECONST(char *, MNTTYPE_ZFS), NULL, 0, &opt, 1)) != 0) {
+ if ((err = zfs_mount_at(zfs_hdl, NULL, info->mntflags, tmp)) != 0) {
switch (errno) {
case ENAMETOOLONG:
return (set_error(info->lbh, BE_ERR_PATHLEN));
More information about the svn-src-stable-12
mailing list