2019-09-27 20:46:28 +03:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* Portions Copyright 2011 Martin Matuska
|
|
|
|
* Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
|
|
|
|
* Portions Copyright 2012 Pawel Jakub Dawidek <pawel@dawidek.net>
|
|
|
|
* Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
|
|
|
|
* Copyright 2016 Nexenta Systems, Inc. All rights reserved.
|
|
|
|
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
|
|
|
|
* Copyright (c) 2011, 2018 by Delphix. All rights reserved.
|
|
|
|
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
|
|
|
|
* Copyright (c) 2013 Steven Hartland. All rights reserved.
|
|
|
|
* Copyright (c) 2014 Integros [integros.com]
|
|
|
|
* Copyright 2016 Toomas Soome <tsoome@me.com>
|
|
|
|
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
|
|
|
|
* Copyright (c) 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
|
|
|
|
* Copyright 2017 RackTop Systems.
|
|
|
|
* Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
|
|
|
|
* Copyright (c) 2019 Datto Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
|
|
|
#include <sys/zfs_vfsops.h>
|
|
|
|
#include <sys/zap.h>
|
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/nvpair.h>
|
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/zfs_ctldir.h>
|
|
|
|
#include <sys/zfs_dir.h>
|
|
|
|
#include <sys/zfs_onexit.h>
|
|
|
|
#include <sys/zvol.h>
|
|
|
|
#include <sys/fm/util.h>
|
|
|
|
#include <sys/dsl_crypt.h>
|
2022-03-31 18:20:50 +03:00
|
|
|
#include <sys/crypto/icp.h>
|
|
|
|
#include <sys/zstd/zstd.h>
|
2019-09-27 20:46:28 +03:00
|
|
|
|
|
|
|
#include <sys/zfs_ioctl_impl.h>
|
|
|
|
|
|
|
|
#include <sys/zfs_sysfs.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
2019-12-10 20:21:07 +03:00
|
|
|
boolean_t
|
|
|
|
zfs_vfs_held(zfsvfs_t *zfsvfs)
|
|
|
|
{
|
|
|
|
return (zfsvfs->z_sb != NULL);
|
|
|
|
}
|
|
|
|
|
2019-09-27 20:46:28 +03:00
|
|
|
int
|
|
|
|
zfs_vfs_ref(zfsvfs_t **zfvp)
|
|
|
|
{
|
|
|
|
if (*zfvp == NULL || (*zfvp)->z_sb == NULL ||
|
|
|
|
!atomic_inc_not_zero(&((*zfvp)->z_sb->s_active))) {
|
|
|
|
return (SET_ERROR(ESRCH));
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2019-12-10 20:21:07 +03:00
|
|
|
void
|
|
|
|
zfs_vfs_rele(zfsvfs_t *zfsvfs)
|
|
|
|
{
|
|
|
|
deactivate_super(zfsvfs->z_sb);
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:04:58 +03:00
|
|
|
void
|
|
|
|
zfsdev_private_set_state(void *priv, zfsdev_state_t *zs)
|
2019-09-27 20:46:28 +03:00
|
|
|
{
|
2021-03-16 16:04:58 +03:00
|
|
|
struct file *filp = priv;
|
2019-09-27 20:46:28 +03:00
|
|
|
|
|
|
|
filp->private_data = zs;
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:04:58 +03:00
|
|
|
zfsdev_state_t *
|
|
|
|
zfsdev_private_get_state(void *priv)
|
2019-09-27 20:46:28 +03:00
|
|
|
{
|
2021-03-16 16:04:58 +03:00
|
|
|
struct file *filp = priv;
|
2019-09-27 20:46:28 +03:00
|
|
|
|
2021-03-16 16:04:58 +03:00
|
|
|
return (filp->private_data);
|
2019-09-27 20:46:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfsdev_open(struct inode *ino, struct file *filp)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
mutex_enter(&zfsdev_state_lock);
|
|
|
|
error = zfsdev_state_init(filp);
|
|
|
|
mutex_exit(&zfsdev_state_lock);
|
|
|
|
|
|
|
|
return (-error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfsdev_release(struct inode *ino, struct file *filp)
|
|
|
|
{
|
2021-04-02 21:09:05 +03:00
|
|
|
zfsdev_state_destroy(filp);
|
2019-09-27 20:46:28 +03:00
|
|
|
|
2021-04-02 21:09:05 +03:00
|
|
|
return (0);
|
2019-09-27 20:46:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
|
|
|
zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
uint_t vecnum;
|
2019-12-02 21:08:27 +03:00
|
|
|
zfs_cmd_t *zc;
|
|
|
|
int error, rc;
|
2019-09-27 20:46:28 +03:00
|
|
|
|
|
|
|
vecnum = cmd - ZFS_IOC_FIRST;
|
2019-12-02 21:08:27 +03:00
|
|
|
|
|
|
|
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
|
|
|
|
|
|
|
|
if (ddi_copyin((void *)(uintptr_t)arg, zc, sizeof (zfs_cmd_t), 0)) {
|
|
|
|
error = -SET_ERROR(EFAULT);
|
|
|
|
goto out;
|
|
|
|
}
|
2020-06-08 23:57:22 +03:00
|
|
|
error = -zfsdev_ioctl_common(vecnum, zc, 0);
|
2019-12-02 21:08:27 +03:00
|
|
|
rc = ddi_copyout(zc, (void *)(uintptr_t)arg, sizeof (zfs_cmd_t), 0);
|
|
|
|
if (error == 0 && rc != 0)
|
|
|
|
error = -SET_ERROR(EFAULT);
|
|
|
|
out:
|
|
|
|
kmem_free(zc, sizeof (zfs_cmd_t));
|
|
|
|
return (error);
|
|
|
|
|
2019-09-27 20:46:28 +03:00
|
|
|
}
|
|
|
|
|
2020-08-18 19:33:55 +03:00
|
|
|
uint64_t
|
|
|
|
zfs_max_nvlist_src_size_os(void)
|
|
|
|
{
|
|
|
|
if (zfs_max_nvlist_src_size != 0)
|
|
|
|
return (zfs_max_nvlist_src_size);
|
|
|
|
|
2021-02-24 20:57:18 +03:00
|
|
|
return (MIN(ptob(zfs_totalram_pages) / 4, 128 * 1024 * 1024));
|
2020-08-18 19:33:55 +03:00
|
|
|
}
|
|
|
|
|
libzfs: On FreeBSD, use MNT_NOWAIT with getfsstat
`getfsstat(2)` is used to retrieve the list of mounted file systems,
which libzfs uses when fetching properties like mountpoint, atime,
setuid, etc. The `mode` parameter may be `MNT_NOWAIT`, which uses
information in the VFS's cache, or `MNT_WAIT`, which effectively does a
`statfs` on every single mounted file system in order to fetch the most
up-to-date information. As far as I can tell, the only fields that
libzfs cares about are the filesystem's name, mountpoint, fstypename,
and mount flags. Those things are always updated on mount and unmount,
so they will always be accurate in the VFS's mount cache except in two
circumstances:
1) When a file system is busy unmounting
2) When a ZFS file system changes the value of a mount-overridable
property like atime or setuid, but doesn't remount the file system.
Right now that only happens when the property is changed by an
unprivileged user who has delegated authority to change the property
but not to mount the dataset. But perhaps libzfs could choose to do
it for other reasons in the future.
Switching to `MNT_NOWAIT` will greatly improve speed with no downside,
as long as we explicitly update the mount cache whenever we change a
mount-overridable property.
For comparison, Illumos gets this information using the native
`getmntany` and `getmntent` functions, which also use cached
information. The illumos function that would refresh the cache,
`resetmnttab`, is never called by libzfs.
And on GNU/Linux, `getmntany` and `getmntent` don't even communicate
with the kernel directly. They simply parse the file they are given,
which is usually /etc/mtab or /proc/mounts. Perhaps the implementation
of /proc/mounts is synchronous, ala MNT_WAIT; I don't know.
Sponsored-by: Axcient
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alan Somers <asomers@gmail.com>
Closes: #12091
2021-06-08 16:36:43 +03:00
|
|
|
/* Update the VFS's cache of mountpoint properties */
|
|
|
|
void
|
|
|
|
zfs_ioctl_update_mount_cache(const char *dsname)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-27 20:46:28 +03:00
|
|
|
void
|
|
|
|
zfs_ioctl_init_os(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
static long
|
|
|
|
zfsdev_compat_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
return (zfsdev_ioctl(filp, cmd, arg));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define zfsdev_compat_ioctl NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct file_operations zfsdev_fops = {
|
|
|
|
.open = zfsdev_open,
|
|
|
|
.release = zfsdev_release,
|
|
|
|
.unlocked_ioctl = zfsdev_ioctl,
|
|
|
|
.compat_ioctl = zfsdev_compat_ioctl,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice zfs_misc = {
|
|
|
|
.minor = ZFS_DEVICE_MINOR,
|
|
|
|
.name = ZFS_DRIVER,
|
|
|
|
.fops = &zfsdev_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_ALIAS_MISCDEV(ZFS_DEVICE_MINOR);
|
|
|
|
MODULE_ALIAS("devname:zfs");
|
|
|
|
|
|
|
|
int
|
|
|
|
zfsdev_attach(void)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = misc_register(&zfs_misc);
|
|
|
|
if (error == -EBUSY) {
|
|
|
|
/*
|
|
|
|
* Fallback to dynamic minor allocation in the event of a
|
|
|
|
* collision with a reserved minor in linux/miscdevice.h.
|
|
|
|
* In this case the kernel modules must be manually loaded.
|
|
|
|
*/
|
|
|
|
printk(KERN_INFO "ZFS: misc_register() with static minor %d "
|
|
|
|
"failed %d, retrying with MISC_DYNAMIC_MINOR\n",
|
|
|
|
ZFS_DEVICE_MINOR, error);
|
|
|
|
|
|
|
|
zfs_misc.minor = MISC_DYNAMIC_MINOR;
|
|
|
|
error = misc_register(&zfs_misc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
printk(KERN_INFO "ZFS: misc_register() failed %d\n", error);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zfsdev_detach(void)
|
|
|
|
{
|
|
|
|
misc_deregister(&zfs_misc);
|
|
|
|
}
|
|
|
|
|
2020-07-26 06:07:44 +03:00
|
|
|
#ifdef ZFS_DEBUG
|
2019-09-27 20:46:28 +03:00
|
|
|
#define ZFS_DEBUG_STR " (DEBUG mode)"
|
|
|
|
#else
|
|
|
|
#define ZFS_DEBUG_STR ""
|
|
|
|
#endif
|
|
|
|
|
2022-03-31 18:20:50 +03:00
|
|
|
static int
|
|
|
|
openzfs_init_os(void)
|
2019-09-27 20:46:28 +03:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((error = zfs_kmod_init()) != 0) {
|
|
|
|
printk(KERN_NOTICE "ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
|
|
|
|
", rc = %d\n", ZFS_META_VERSION, ZFS_META_RELEASE,
|
|
|
|
ZFS_DEBUG_STR, error);
|
|
|
|
|
|
|
|
return (-error);
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_sysfs_init();
|
|
|
|
|
|
|
|
printk(KERN_NOTICE "ZFS: Loaded module v%s-%s%s, "
|
|
|
|
"ZFS pool version %s, ZFS filesystem version %s\n",
|
|
|
|
ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR,
|
|
|
|
SPA_VERSION_STRING, ZPL_VERSION_STRING);
|
|
|
|
#ifndef CONFIG_FS_POSIX_ACL
|
|
|
|
printk(KERN_NOTICE "ZFS: Posix ACLs disabled by kernel\n");
|
|
|
|
#endif /* CONFIG_FS_POSIX_ACL */
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2022-03-31 18:20:50 +03:00
|
|
|
static void
|
|
|
|
openzfs_fini_os(void)
|
2019-09-27 20:46:28 +03:00
|
|
|
{
|
|
|
|
zfs_sysfs_fini();
|
|
|
|
zfs_kmod_fini();
|
|
|
|
|
|
|
|
printk(KERN_NOTICE "ZFS: Unloaded module v%s-%s%s\n",
|
|
|
|
ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR);
|
|
|
|
}
|
|
|
|
|
2022-03-31 18:20:50 +03:00
|
|
|
|
|
|
|
extern int __init zcommon_init(void);
|
|
|
|
extern void zcommon_fini(void);
|
|
|
|
|
|
|
|
static int __init
|
|
|
|
openzfs_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if ((err = zcommon_init()) != 0)
|
|
|
|
goto zcommon_failed;
|
|
|
|
if ((err = icp_init()) != 0)
|
|
|
|
goto icp_failed;
|
|
|
|
if ((err = zstd_init()) != 0)
|
|
|
|
goto zstd_failed;
|
|
|
|
if ((err = openzfs_init_os()) != 0)
|
|
|
|
goto openzfs_os_failed;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
openzfs_os_failed:
|
|
|
|
zstd_fini();
|
|
|
|
zstd_failed:
|
|
|
|
icp_fini();
|
|
|
|
icp_failed:
|
|
|
|
zcommon_fini();
|
|
|
|
zcommon_failed:
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit
|
|
|
|
openzfs_fini(void)
|
|
|
|
{
|
|
|
|
openzfs_fini_os();
|
|
|
|
zstd_fini();
|
|
|
|
icp_fini();
|
|
|
|
zcommon_fini();
|
|
|
|
}
|
|
|
|
|
2019-09-27 20:46:28 +03:00
|
|
|
#if defined(_KERNEL)
|
2021-05-20 06:46:42 +03:00
|
|
|
module_init(openzfs_init);
|
|
|
|
module_exit(openzfs_fini);
|
2019-09-27 20:46:28 +03:00
|
|
|
#endif
|
2019-11-01 20:41:03 +03:00
|
|
|
|
2022-03-31 18:20:50 +03:00
|
|
|
MODULE_ALIAS("zavl");
|
|
|
|
MODULE_ALIAS("icp");
|
|
|
|
MODULE_ALIAS("zlua");
|
|
|
|
MODULE_ALIAS("znvpair");
|
|
|
|
MODULE_ALIAS("zunicode");
|
|
|
|
MODULE_ALIAS("zcommon");
|
|
|
|
MODULE_ALIAS("zzstd");
|
|
|
|
MODULE_DESCRIPTION("ZFS");
|
|
|
|
MODULE_AUTHOR(ZFS_META_AUTHOR);
|
|
|
|
MODULE_LICENSE("Lua: MIT");
|
|
|
|
MODULE_LICENSE("zstd: Dual BSD/GPL");
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
MODULE_LICENSE(ZFS_META_LICENSE);
|
|
|
|
MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
|