2008-11-20 23:01:55 +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
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2016-05-11 06:49:02 +03:00
|
|
|
* Copyright (c) 2012, 2015 by Delphix. All rights reserved.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
/* Portions Copyright 2010 Robert Milkowski */
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/pathname.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
#include <sys/vfs_opreg.h>
|
|
|
|
#include <sys/mntent.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/cmn_err.h>
|
|
|
|
#include "fs/fs_subr.h"
|
|
|
|
#include <sys/zfs_znode.h>
|
2011-02-08 22:16:06 +03:00
|
|
|
#include <sys/zfs_vnops.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/zfs_dir.h>
|
|
|
|
#include <sys/zil.h>
|
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
#include <sys/dsl_prop.h>
|
|
|
|
#include <sys/dsl_dataset.h>
|
|
|
|
#include <sys/dsl_deleg.h>
|
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/zap.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
#include <sys/sa.h>
|
2013-01-14 21:31:53 +04:00
|
|
|
#include <sys/sa_impl.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/varargs.h>
|
|
|
|
#include <sys/policy.h>
|
|
|
|
#include <sys/atomic.h>
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#include <sys/modctl.h>
|
|
|
|
#include <sys/refstr.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
2011-11-11 11:15:53 +04:00
|
|
|
#include <sys/zfs_ctldir.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/zfs_fuid.h>
|
|
|
|
#include <sys/bootconf.h>
|
|
|
|
#include <sys/sunddi.h>
|
|
|
|
#include <sys/dnlc.h>
|
|
|
|
#include <sys/dmu_objset.h>
|
|
|
|
#include <sys/spa_boot.h>
|
2011-02-08 22:16:06 +03:00
|
|
|
#include <sys/zpl.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
#include "zfs_comutil.h"
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
enum {
|
|
|
|
TOKEN_RO,
|
|
|
|
TOKEN_RW,
|
|
|
|
TOKEN_SETUID,
|
|
|
|
TOKEN_NOSETUID,
|
|
|
|
TOKEN_EXEC,
|
|
|
|
TOKEN_NOEXEC,
|
|
|
|
TOKEN_DEVICES,
|
|
|
|
TOKEN_NODEVICES,
|
|
|
|
TOKEN_DIRXATTR,
|
|
|
|
TOKEN_SAXATTR,
|
|
|
|
TOKEN_XATTR,
|
|
|
|
TOKEN_NOXATTR,
|
|
|
|
TOKEN_ATIME,
|
|
|
|
TOKEN_NOATIME,
|
|
|
|
TOKEN_RELATIME,
|
|
|
|
TOKEN_NORELATIME,
|
|
|
|
TOKEN_NBMAND,
|
|
|
|
TOKEN_NONBMAND,
|
|
|
|
TOKEN_MNTPOINT,
|
|
|
|
TOKEN_LAST,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const match_table_t zpl_tokens = {
|
|
|
|
{ TOKEN_RO, MNTOPT_RO },
|
|
|
|
{ TOKEN_RW, MNTOPT_RW },
|
|
|
|
{ TOKEN_SETUID, MNTOPT_SETUID },
|
|
|
|
{ TOKEN_NOSETUID, MNTOPT_NOSETUID },
|
|
|
|
{ TOKEN_EXEC, MNTOPT_EXEC },
|
|
|
|
{ TOKEN_NOEXEC, MNTOPT_NOEXEC },
|
|
|
|
{ TOKEN_DEVICES, MNTOPT_DEVICES },
|
|
|
|
{ TOKEN_NODEVICES, MNTOPT_NODEVICES },
|
|
|
|
{ TOKEN_DIRXATTR, MNTOPT_DIRXATTR },
|
|
|
|
{ TOKEN_SAXATTR, MNTOPT_SAXATTR },
|
|
|
|
{ TOKEN_XATTR, MNTOPT_XATTR },
|
|
|
|
{ TOKEN_NOXATTR, MNTOPT_NOXATTR },
|
|
|
|
{ TOKEN_ATIME, MNTOPT_ATIME },
|
|
|
|
{ TOKEN_NOATIME, MNTOPT_NOATIME },
|
|
|
|
{ TOKEN_RELATIME, MNTOPT_RELATIME },
|
|
|
|
{ TOKEN_NORELATIME, MNTOPT_NORELATIME },
|
|
|
|
{ TOKEN_NBMAND, MNTOPT_NBMAND },
|
|
|
|
{ TOKEN_NONBMAND, MNTOPT_NONBMAND },
|
|
|
|
{ TOKEN_MNTPOINT, MNTOPT_MNTPOINT "=%s" },
|
|
|
|
{ TOKEN_LAST, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
zfsvfs_vfs_free(vfs_t *vfsp)
|
|
|
|
{
|
|
|
|
if (vfsp != NULL) {
|
|
|
|
if (vfsp->vfs_mntpoint != NULL)
|
|
|
|
strfree(vfsp->vfs_mntpoint);
|
|
|
|
|
|
|
|
kmem_free(vfsp, sizeof (vfs_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfsvfs_parse_option(char *option, int token, substring_t *args, vfs_t *vfsp)
|
|
|
|
{
|
|
|
|
switch (token) {
|
|
|
|
case TOKEN_RO:
|
|
|
|
vfsp->vfs_readonly = B_TRUE;
|
|
|
|
vfsp->vfs_do_readonly = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_RW:
|
|
|
|
vfsp->vfs_readonly = B_FALSE;
|
|
|
|
vfsp->vfs_do_readonly = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_SETUID:
|
|
|
|
vfsp->vfs_setuid = B_TRUE;
|
|
|
|
vfsp->vfs_do_setuid = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NOSETUID:
|
|
|
|
vfsp->vfs_setuid = B_FALSE;
|
|
|
|
vfsp->vfs_do_setuid = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_EXEC:
|
|
|
|
vfsp->vfs_exec = B_TRUE;
|
|
|
|
vfsp->vfs_do_exec = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NOEXEC:
|
|
|
|
vfsp->vfs_exec = B_FALSE;
|
|
|
|
vfsp->vfs_do_exec = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_DEVICES:
|
|
|
|
vfsp->vfs_devices = B_TRUE;
|
|
|
|
vfsp->vfs_do_devices = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NODEVICES:
|
|
|
|
vfsp->vfs_devices = B_FALSE;
|
|
|
|
vfsp->vfs_do_devices = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_DIRXATTR:
|
|
|
|
vfsp->vfs_xattr = ZFS_XATTR_DIR;
|
|
|
|
vfsp->vfs_do_xattr = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_SAXATTR:
|
|
|
|
vfsp->vfs_xattr = ZFS_XATTR_SA;
|
|
|
|
vfsp->vfs_do_xattr = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_XATTR:
|
|
|
|
vfsp->vfs_xattr = ZFS_XATTR_DIR;
|
|
|
|
vfsp->vfs_do_xattr = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NOXATTR:
|
|
|
|
vfsp->vfs_xattr = ZFS_XATTR_OFF;
|
|
|
|
vfsp->vfs_do_xattr = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_ATIME:
|
|
|
|
vfsp->vfs_atime = B_TRUE;
|
|
|
|
vfsp->vfs_do_atime = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NOATIME:
|
|
|
|
vfsp->vfs_atime = B_FALSE;
|
|
|
|
vfsp->vfs_do_atime = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_RELATIME:
|
|
|
|
vfsp->vfs_relatime = B_TRUE;
|
|
|
|
vfsp->vfs_do_relatime = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NORELATIME:
|
|
|
|
vfsp->vfs_relatime = B_FALSE;
|
|
|
|
vfsp->vfs_do_relatime = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NBMAND:
|
|
|
|
vfsp->vfs_nbmand = B_TRUE;
|
|
|
|
vfsp->vfs_do_nbmand = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_NONBMAND:
|
|
|
|
vfsp->vfs_nbmand = B_FALSE;
|
|
|
|
vfsp->vfs_do_nbmand = B_TRUE;
|
|
|
|
break;
|
|
|
|
case TOKEN_MNTPOINT:
|
|
|
|
vfsp->vfs_mntpoint = match_strdup(&args[0]);
|
|
|
|
if (vfsp->vfs_mntpoint == NULL)
|
|
|
|
return (SET_ERROR(ENOMEM));
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse the raw mntopts and return a vfs_t describing the options.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfsvfs_parse_options(char *mntopts, vfs_t **vfsp)
|
|
|
|
{
|
|
|
|
vfs_t *tmp_vfsp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
tmp_vfsp = kmem_zalloc(sizeof (vfs_t), KM_SLEEP);
|
|
|
|
|
|
|
|
if (mntopts != NULL) {
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
|
|
|
char *tmp_mntopts, *p, *t;
|
|
|
|
int token;
|
|
|
|
|
|
|
|
tmp_mntopts = t = strdup(mntopts);
|
|
|
|
if (tmp_mntopts == NULL)
|
|
|
|
return (SET_ERROR(ENOMEM));
|
|
|
|
|
|
|
|
while ((p = strsep(&t, ",")) != NULL) {
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
args[0].to = args[0].from = NULL;
|
|
|
|
token = match_token(p, zpl_tokens, args);
|
|
|
|
error = zfsvfs_parse_option(p, token, args, tmp_vfsp);
|
|
|
|
if (error) {
|
|
|
|
strfree(tmp_mntopts);
|
|
|
|
zfsvfs_vfs_free(tmp_vfsp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strfree(tmp_mntopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
*vfsp = tmp_vfsp;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
|
|
|
zfs_is_readonly(zfsvfs_t *zfsvfs)
|
|
|
|
{
|
|
|
|
return (!!(zfsvfs->z_sb->s_flags & MS_RDONLY));
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2011-03-15 22:03:42 +03:00
|
|
|
zfs_sync(struct super_block *sb, int wait, cred_t *cr)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = sb->s_fs_info;
|
2011-03-15 22:03:42 +03:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Data integrity is job one. We don't want a compromised kernel
|
|
|
|
* writing to the storage pool, so we never sync during panic.
|
|
|
|
*/
|
2011-01-07 01:07:41 +03:00
|
|
|
if (unlikely(oops_in_progress))
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
|
2011-03-15 22:03:42 +03:00
|
|
|
/*
|
|
|
|
* Semantically, the only requirement is that the sync be initiated.
|
|
|
|
* The DMU syncs out txgs frequently, so there's nothing to do.
|
|
|
|
*/
|
|
|
|
if (!wait)
|
|
|
|
return (0);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs != NULL) {
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Sync a specific filesystem.
|
|
|
|
*/
|
2009-07-03 02:44:48 +04:00
|
|
|
dsl_pool_t *dp;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_ENTER(zfsvfs);
|
|
|
|
dp = dmu_objset_pool(zfsvfs->z_os);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the system is shutting down, then skip any
|
|
|
|
* filesystems which may exist on a suspended pool.
|
|
|
|
*/
|
2011-03-15 22:03:42 +03:00
|
|
|
if (spa_suspended(dp->dp_spa)) {
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2009-07-03 02:44:48 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_log != NULL)
|
|
|
|
zil_commit(zfsvfs->z_log, 0);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Sync all ZFS filesystems. This is what happens when you
|
|
|
|
* run sync(1M). Unlike other filesystems, ZFS honors the
|
|
|
|
* request by waiting for all pools to commit all dirty data.
|
|
|
|
*/
|
|
|
|
spa_sync_allpools();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
atime_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
((zfsvfs_t *)arg)->z_atime = newval;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2014-01-18 23:00:53 +04:00
|
|
|
static void
|
|
|
|
relatime_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
((zfsvfs_t *)arg)->z_relatime = newval;
|
2014-01-18 23:00:53 +04:00
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
static void
|
|
|
|
xattr_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = arg;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2011-10-25 03:55:20 +04:00
|
|
|
if (newval == ZFS_XATTR_OFF) {
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_flags &= ~ZSB_XATTR;
|
2011-10-25 03:55:20 +04:00
|
|
|
} else {
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_flags |= ZSB_XATTR;
|
2011-10-25 03:55:20 +04:00
|
|
|
|
|
|
|
if (newval == ZFS_XATTR_SA)
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_xattr_sa = B_TRUE;
|
2011-10-25 03:55:20 +04:00
|
|
|
else
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_xattr_sa = B_FALSE;
|
2011-10-25 03:55:20 +04:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2013-10-28 20:22:15 +04:00
|
|
|
static void
|
|
|
|
acltype_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = arg;
|
2013-10-28 20:22:15 +04:00
|
|
|
|
|
|
|
switch (newval) {
|
|
|
|
case ZFS_ACLTYPE_OFF:
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_acl_type = ZFS_ACLTYPE_OFF;
|
|
|
|
zfsvfs->z_sb->s_flags &= ~MS_POSIXACL;
|
2013-10-28 20:22:15 +04:00
|
|
|
break;
|
|
|
|
case ZFS_ACLTYPE_POSIXACL:
|
2013-11-03 03:40:26 +04:00
|
|
|
#ifdef CONFIG_FS_POSIX_ACL
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_acl_type = ZFS_ACLTYPE_POSIXACL;
|
|
|
|
zfsvfs->z_sb->s_flags |= MS_POSIXACL;
|
2013-11-03 03:40:26 +04:00
|
|
|
#else
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_acl_type = ZFS_ACLTYPE_OFF;
|
|
|
|
zfsvfs->z_sb->s_flags &= ~MS_POSIXACL;
|
2013-11-03 03:40:26 +04:00
|
|
|
#endif /* CONFIG_FS_POSIX_ACL */
|
2013-10-28 20:22:15 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
static void
|
|
|
|
blksz_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = arg;
|
|
|
|
ASSERT3U(newval, <=, spa_maxblocksize(dmu_objset_spa(zfsvfs->z_os)));
|
2014-11-03 23:15:08 +03:00
|
|
|
ASSERT3U(newval, >=, SPA_MINBLOCKSIZE);
|
|
|
|
ASSERT(ISP2(newval));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_max_blksz = newval;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
readonly_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = arg;
|
|
|
|
struct super_block *sb = zfsvfs->z_sb;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2011-05-19 22:44:07 +04:00
|
|
|
if (sb == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (newval)
|
2011-02-08 22:16:06 +03:00
|
|
|
sb->s_flags |= MS_RDONLY;
|
2011-05-19 22:44:07 +04:00
|
|
|
else
|
2011-02-08 22:16:06 +03:00
|
|
|
sb->s_flags &= ~MS_RDONLY;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
devices_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setuid_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
exec_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nbmand_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = arg;
|
|
|
|
struct super_block *sb = zfsvfs->z_sb;
|
2011-02-08 22:16:06 +03:00
|
|
|
|
2011-05-19 22:44:07 +04:00
|
|
|
if (sb == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (newval == TRUE)
|
2011-02-08 22:16:06 +03:00
|
|
|
sb->s_flags |= MS_MANDLOCK;
|
2011-05-19 22:44:07 +04:00
|
|
|
else
|
2011-02-08 22:16:06 +03:00
|
|
|
sb->s_flags &= ~MS_MANDLOCK;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
snapdir_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
((zfsvfs_t *)arg)->z_show_ctldir = newval;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vscan_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
((zfsvfs_t *)arg)->z_vscan = newval;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acl_inherit_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
((zfsvfs_t *)arg)->z_acl_inherit = newval;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
static int
|
|
|
|
zfs_register_callbacks(vfs_t *vfsp)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
struct dsl_dataset *ds = NULL;
|
2017-03-09 03:56:09 +03:00
|
|
|
objset_t *os = NULL;
|
|
|
|
zfsvfs_t *zfsvfs = NULL;
|
2008-11-20 23:01:55 +03:00
|
|
|
int error = 0;
|
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
ASSERT(vfsp);
|
|
|
|
zfsvfs = vfsp->vfs_data;
|
2017-03-08 03:21:37 +03:00
|
|
|
ASSERT(zfsvfs);
|
2017-03-09 03:56:09 +03:00
|
|
|
os = zfsvfs->z_os;
|
2015-09-01 02:46:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The act of registering our callbacks will destroy any mount
|
|
|
|
* options we may have. In order to enable temporary overrides
|
|
|
|
* of mount options, we stash away the current values and
|
|
|
|
* restore them after we register the callbacks.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfs_is_readonly(zfsvfs) || !spa_writeable(dmu_objset_spa(os))) {
|
2017-03-09 03:56:09 +03:00
|
|
|
vfsp->vfs_do_readonly = B_TRUE;
|
|
|
|
vfsp->vfs_readonly = B_TRUE;
|
2015-09-01 02:46:01 +03:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register property callbacks.
|
|
|
|
*
|
|
|
|
* It would probably be fine to just check for i/o error from
|
|
|
|
* the first prop_register(), but I guess I like to go
|
|
|
|
* overboard...
|
|
|
|
*/
|
|
|
|
ds = dmu_objset_ds(os);
|
2013-09-04 16:00:57 +04:00
|
|
|
dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
|
2011-02-08 22:16:06 +03:00
|
|
|
error = dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_ATIME), atime_changed_cb, zfsvfs);
|
2014-02-11 17:34:17 +04:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_RELATIME), relatime_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_XATTR), xattr_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_RECORDSIZE), blksz_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_READONLY), readonly_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_DEVICES), devices_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_SETUID), setuid_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_EXEC), exec_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_SNAPDIR), snapdir_changed_cb, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_ACLTYPE), acltype_changed_cb, zfsvfs);
|
2013-10-28 20:22:15 +04:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_ACLINHERIT), acl_inherit_changed_cb,
|
|
|
|
zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_VSCAN), vscan_changed_cb, zfsvfs);
|
2011-05-19 22:44:07 +04:00
|
|
|
error = error ? error : dsl_prop_register(ds,
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_prop_to_name(ZFS_PROP_NBMAND), nbmand_changed_cb, zfsvfs);
|
2013-09-04 16:00:57 +04:00
|
|
|
dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (error)
|
|
|
|
goto unregister;
|
|
|
|
|
2015-09-01 02:46:01 +03:00
|
|
|
/*
|
|
|
|
* Invoke our callbacks to restore temporary mount options.
|
|
|
|
*/
|
2017-03-09 03:56:09 +03:00
|
|
|
if (vfsp->vfs_do_readonly)
|
|
|
|
readonly_changed_cb(zfsvfs, vfsp->vfs_readonly);
|
|
|
|
if (vfsp->vfs_do_setuid)
|
|
|
|
setuid_changed_cb(zfsvfs, vfsp->vfs_setuid);
|
|
|
|
if (vfsp->vfs_do_exec)
|
|
|
|
exec_changed_cb(zfsvfs, vfsp->vfs_exec);
|
|
|
|
if (vfsp->vfs_do_devices)
|
|
|
|
devices_changed_cb(zfsvfs, vfsp->vfs_devices);
|
|
|
|
if (vfsp->vfs_do_xattr)
|
|
|
|
xattr_changed_cb(zfsvfs, vfsp->vfs_xattr);
|
|
|
|
if (vfsp->vfs_do_atime)
|
|
|
|
atime_changed_cb(zfsvfs, vfsp->vfs_atime);
|
|
|
|
if (vfsp->vfs_do_relatime)
|
|
|
|
relatime_changed_cb(zfsvfs, vfsp->vfs_relatime);
|
|
|
|
if (vfsp->vfs_do_nbmand)
|
|
|
|
nbmand_changed_cb(zfsvfs, vfsp->vfs_nbmand);
|
2013-07-17 20:15:46 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
unregister:
|
2017-03-08 03:21:37 +03:00
|
|
|
dsl_prop_unregister_all(ds, zfsvfs);
|
2011-02-08 22:16:06 +03:00
|
|
|
return (error);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
static int
|
|
|
|
zfs_space_delta_cb(dmu_object_type_t bonustype, void *data,
|
|
|
|
uint64_t *userp, uint64_t *groupp)
|
2009-07-03 02:44:48 +04:00
|
|
|
{
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
|
|
|
* Is it a valid type of object to track?
|
|
|
|
*/
|
|
|
|
if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOENT));
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
|
|
|
* If we have a NULL data pointer
|
|
|
|
* then assume the id's aren't changing and
|
|
|
|
* return EEXIST to the dmu to let it know to
|
|
|
|
* use the same ids
|
|
|
|
*/
|
|
|
|
if (data == NULL)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EEXIST));
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (bonustype == DMU_OT_ZNODE) {
|
2013-01-14 21:31:53 +04:00
|
|
|
znode_phys_t *znp = data;
|
2010-05-29 00:45:14 +04:00
|
|
|
*userp = znp->zp_uid;
|
|
|
|
*groupp = znp->zp_gid;
|
2009-07-03 02:44:48 +04:00
|
|
|
} else {
|
2010-05-29 00:45:14 +04:00
|
|
|
int hdrsize;
|
2013-01-14 21:31:53 +04:00
|
|
|
sa_hdr_phys_t *sap = data;
|
|
|
|
sa_hdr_phys_t sa = *sap;
|
|
|
|
boolean_t swap = B_FALSE;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT(bonustype == DMU_OT_SA);
|
|
|
|
|
2013-01-14 21:31:53 +04:00
|
|
|
if (sa.sa_magic == 0) {
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
|
|
|
* This should only happen for newly created
|
|
|
|
* files that haven't had the znode data filled
|
|
|
|
* in yet.
|
|
|
|
*/
|
|
|
|
*userp = 0;
|
|
|
|
*groupp = 0;
|
2013-01-14 21:31:53 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (sa.sa_magic == BSWAP_32(SA_MAGIC)) {
|
|
|
|
sa.sa_magic = SA_MAGIC;
|
|
|
|
sa.sa_layout_info = BSWAP_16(sa.sa_layout_info);
|
|
|
|
swap = B_TRUE;
|
|
|
|
} else {
|
|
|
|
VERIFY3U(sa.sa_magic, ==, SA_MAGIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
hdrsize = sa_hdrsize(&sa);
|
|
|
|
VERIFY3U(hdrsize, >=, sizeof (sa_hdr_phys_t));
|
|
|
|
*userp = *((uint64_t *)((uintptr_t)data + hdrsize +
|
|
|
|
SA_UID_OFFSET));
|
|
|
|
*groupp = *((uint64_t *)((uintptr_t)data + hdrsize +
|
|
|
|
SA_GID_OFFSET));
|
|
|
|
if (swap) {
|
|
|
|
*userp = BSWAP_64(*userp);
|
|
|
|
*groupp = BSWAP_64(*groupp);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
2013-09-04 16:00:57 +04:00
|
|
|
return (0);
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 03:21:37 +03:00
|
|
|
fuidstr_to_sid(zfsvfs_t *zfsvfs, const char *fuidstr,
|
2009-07-03 02:44:48 +04:00
|
|
|
char *domainbuf, int buflen, uid_t *ridp)
|
|
|
|
{
|
|
|
|
uint64_t fuid;
|
|
|
|
const char *domain;
|
|
|
|
|
2017-06-13 06:16:28 +03:00
|
|
|
fuid = zfs_strtonum(fuidstr, NULL);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
domain = zfs_fuid_find_by_idx(zfsvfs, FUID_INDEX(fuid));
|
2009-07-03 02:44:48 +04:00
|
|
|
if (domain)
|
|
|
|
(void) strlcpy(domainbuf, domain, buflen);
|
|
|
|
else
|
|
|
|
domainbuf[0] = '\0';
|
|
|
|
*ridp = FUID_RID(fuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_userquota_prop_to_obj(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type)
|
2009-07-03 02:44:48 +04:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ZFS_PROP_USERUSED:
|
2016-10-04 21:46:10 +03:00
|
|
|
case ZFS_PROP_USEROBJUSED:
|
2009-07-03 02:44:48 +04:00
|
|
|
return (DMU_USERUSED_OBJECT);
|
|
|
|
case ZFS_PROP_GROUPUSED:
|
2016-10-04 21:46:10 +03:00
|
|
|
case ZFS_PROP_GROUPOBJUSED:
|
2009-07-03 02:44:48 +04:00
|
|
|
return (DMU_GROUPUSED_OBJECT);
|
|
|
|
case ZFS_PROP_USERQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
return (zfsvfs->z_userquota_obj);
|
2009-07-03 02:44:48 +04:00
|
|
|
case ZFS_PROP_GROUPQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
return (zfsvfs->z_groupquota_obj);
|
2016-10-04 21:46:10 +03:00
|
|
|
case ZFS_PROP_USEROBJQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
return (zfsvfs->z_userobjquota_obj);
|
2016-10-04 21:46:10 +03:00
|
|
|
case ZFS_PROP_GROUPOBJQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
return (zfsvfs->z_groupobjquota_obj);
|
2010-12-17 01:05:42 +03:00
|
|
|
default:
|
2016-10-04 21:46:10 +03:00
|
|
|
return (ZFS_NO_OBJECT);
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_userspace_many(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
|
2009-07-03 02:44:48 +04:00
|
|
|
uint64_t *cookiep, void *vbuf, uint64_t *bufsizep)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
zap_cursor_t zc;
|
|
|
|
zap_attribute_t za;
|
|
|
|
zfs_useracct_t *buf = vbuf;
|
|
|
|
uint64_t obj;
|
2016-10-04 21:46:10 +03:00
|
|
|
int offset = 0;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (!dmu_objset_userspace_present(zfsvfs->z_os))
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
if ((type == ZFS_PROP_USEROBJUSED || type == ZFS_PROP_GROUPOBJUSED ||
|
|
|
|
type == ZFS_PROP_USEROBJQUOTA || type == ZFS_PROP_GROUPOBJQUOTA) &&
|
2017-03-08 03:21:37 +03:00
|
|
|
!dmu_objset_userobjspace_present(zfsvfs->z_os))
|
2016-10-04 21:46:10 +03:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
obj = zfs_userquota_prop_to_obj(zfsvfs, type);
|
2016-10-04 21:46:10 +03:00
|
|
|
if (obj == ZFS_NO_OBJECT) {
|
2009-07-03 02:44:48 +04:00
|
|
|
*bufsizep = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
if (type == ZFS_PROP_USEROBJUSED || type == ZFS_PROP_GROUPOBJUSED)
|
|
|
|
offset = DMU_OBJACCT_PREFIX_LEN;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
for (zap_cursor_init_serialized(&zc, zfsvfs->z_os, obj, *cookiep);
|
2009-07-03 02:44:48 +04:00
|
|
|
(error = zap_cursor_retrieve(&zc, &za)) == 0;
|
|
|
|
zap_cursor_advance(&zc)) {
|
|
|
|
if ((uintptr_t)buf - (uintptr_t)vbuf + sizeof (zfs_useracct_t) >
|
|
|
|
*bufsizep)
|
|
|
|
break;
|
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
/*
|
|
|
|
* skip object quota (with zap name prefix DMU_OBJACCT_PREFIX)
|
|
|
|
* when dealing with block quota and vice versa.
|
|
|
|
*/
|
|
|
|
if ((offset > 0) != (strncmp(za.za_name, DMU_OBJACCT_PREFIX,
|
|
|
|
DMU_OBJACCT_PREFIX_LEN) == 0))
|
|
|
|
continue;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
fuidstr_to_sid(zfsvfs, za.za_name + offset,
|
2009-07-03 02:44:48 +04:00
|
|
|
buf->zu_domain, sizeof (buf->zu_domain), &buf->zu_rid);
|
|
|
|
|
|
|
|
buf->zu_space = za.za_first_integer;
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
if (error == ENOENT)
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
ASSERT3U((uintptr_t)buf - (uintptr_t)vbuf, <=, *bufsizep);
|
|
|
|
*bufsizep = (uintptr_t)buf - (uintptr_t)vbuf;
|
|
|
|
*cookiep = zap_cursor_serialize(&zc);
|
|
|
|
zap_cursor_fini(&zc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* buf must be big enough (eg, 32 bytes)
|
|
|
|
*/
|
|
|
|
static int
|
2017-03-08 03:21:37 +03:00
|
|
|
id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid,
|
2009-07-03 02:44:48 +04:00
|
|
|
char *buf, boolean_t addok)
|
|
|
|
{
|
|
|
|
uint64_t fuid;
|
|
|
|
int domainid = 0;
|
|
|
|
|
|
|
|
if (domain && domain[0]) {
|
2017-03-08 03:21:37 +03:00
|
|
|
domainid = zfs_fuid_find_by_domain(zfsvfs, domain, NULL, addok);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (domainid == -1)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOENT));
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
|
|
|
fuid = FUID_ENCODE(domainid, rid);
|
|
|
|
(void) sprintf(buf, "%llx", (longlong_t)fuid);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
|
2009-07-03 02:44:48 +04:00
|
|
|
const char *domain, uint64_t rid, uint64_t *valp)
|
|
|
|
{
|
2016-10-04 21:46:10 +03:00
|
|
|
char buf[20 + DMU_OBJACCT_PREFIX_LEN];
|
|
|
|
int offset = 0;
|
2009-07-03 02:44:48 +04:00
|
|
|
int err;
|
|
|
|
uint64_t obj;
|
|
|
|
|
|
|
|
*valp = 0;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (!dmu_objset_userspace_present(zfsvfs->z_os))
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
if ((type == ZFS_PROP_USEROBJUSED || type == ZFS_PROP_GROUPOBJUSED ||
|
|
|
|
type == ZFS_PROP_USEROBJQUOTA || type == ZFS_PROP_GROUPOBJQUOTA) &&
|
2017-03-08 03:21:37 +03:00
|
|
|
!dmu_objset_userobjspace_present(zfsvfs->z_os))
|
2016-10-04 21:46:10 +03:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
obj = zfs_userquota_prop_to_obj(zfsvfs, type);
|
2016-10-04 21:46:10 +03:00
|
|
|
if (obj == ZFS_NO_OBJECT)
|
2009-07-03 02:44:48 +04:00
|
|
|
return (0);
|
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
if (type == ZFS_PROP_USEROBJUSED || type == ZFS_PROP_GROUPOBJUSED) {
|
2017-11-29 22:59:22 +03:00
|
|
|
strlcpy(buf, DMU_OBJACCT_PREFIX, DMU_OBJACCT_PREFIX_LEN + 1);
|
2016-10-04 21:46:10 +03:00
|
|
|
offset = DMU_OBJACCT_PREFIX_LEN;
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
err = id_to_fuidstr(zfsvfs, domain, rid, buf + offset, B_FALSE);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
err = zap_lookup(zfsvfs->z_os, obj, buf, 8, 1, valp);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (err == ENOENT)
|
|
|
|
err = 0;
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
|
2009-07-03 02:44:48 +04:00
|
|
|
const char *domain, uint64_t rid, uint64_t quota)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
int err;
|
|
|
|
dmu_tx_t *tx;
|
|
|
|
uint64_t *objp;
|
|
|
|
boolean_t fuid_dirtied;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_version < ZPL_VERSION_USERSPACE)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
switch (type) {
|
|
|
|
case ZFS_PROP_USERQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
objp = &zfsvfs->z_userquota_obj;
|
2016-10-04 21:46:10 +03:00
|
|
|
break;
|
|
|
|
case ZFS_PROP_GROUPQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
objp = &zfsvfs->z_groupquota_obj;
|
2016-10-04 21:46:10 +03:00
|
|
|
break;
|
|
|
|
case ZFS_PROP_USEROBJQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
objp = &zfsvfs->z_userobjquota_obj;
|
2016-10-04 21:46:10 +03:00
|
|
|
break;
|
|
|
|
case ZFS_PROP_GROUPOBJQUOTA:
|
2017-03-08 03:21:37 +03:00
|
|
|
objp = &zfsvfs->z_groupobjquota_obj;
|
2016-10-04 21:46:10 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (SET_ERROR(EINVAL));
|
|
|
|
}
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_TRUE);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (err)
|
|
|
|
return (err);
|
2017-03-08 03:21:37 +03:00
|
|
|
fuid_dirtied = zfsvfs->z_fuid_dirty;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
tx = dmu_tx_create(zfsvfs->z_os);
|
2009-07-03 02:44:48 +04:00
|
|
|
dmu_tx_hold_zap(tx, *objp ? *objp : DMU_NEW_OBJECT, B_TRUE, NULL);
|
|
|
|
if (*objp == 0) {
|
|
|
|
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
|
|
|
|
zfs_userquota_prop_prefixes[type]);
|
|
|
|
}
|
|
|
|
if (fuid_dirtied)
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_fuid_txhold(zfsvfs, tx);
|
2009-07-03 02:44:48 +04:00
|
|
|
err = dmu_tx_assign(tx, TXG_WAIT);
|
|
|
|
if (err) {
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_enter(&zfsvfs->z_lock);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (*objp == 0) {
|
2017-03-08 03:21:37 +03:00
|
|
|
*objp = zap_create(zfsvfs->z_os, DMU_OT_USERGROUP_QUOTA,
|
2009-07-03 02:44:48 +04:00
|
|
|
DMU_OT_NONE, 0, tx);
|
2017-03-08 03:21:37 +03:00
|
|
|
VERIFY(0 == zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
|
2009-07-03 02:44:48 +04:00
|
|
|
zfs_userquota_prop_prefixes[type], 8, 1, objp, tx));
|
|
|
|
}
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_exit(&zfsvfs->z_lock);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
if (quota == 0) {
|
2017-03-08 03:21:37 +03:00
|
|
|
err = zap_remove(zfsvfs->z_os, *objp, buf, tx);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (err == ENOENT)
|
|
|
|
err = 0;
|
|
|
|
} else {
|
2017-03-08 03:21:37 +03:00
|
|
|
err = zap_update(zfsvfs->z_os, *objp, buf, 8, 1, "a, tx);
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
|
|
|
ASSERT(err == 0);
|
|
|
|
if (fuid_dirtied)
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_fuid_sync(zfsvfs, tx);
|
2009-07-03 02:44:48 +04:00
|
|
|
dmu_tx_commit(tx);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
boolean_t
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_fuid_overobjquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid)
|
2016-10-04 21:46:10 +03:00
|
|
|
{
|
|
|
|
char buf[20 + DMU_OBJACCT_PREFIX_LEN];
|
|
|
|
uint64_t used, quota, usedobj, quotaobj;
|
|
|
|
int err;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (!dmu_objset_userobjspace_present(zfsvfs->z_os)) {
|
2017-11-11 00:37:10 +03:00
|
|
|
if (dmu_objset_userobjspace_upgradable(zfsvfs->z_os)) {
|
|
|
|
dsl_pool_config_enter(
|
|
|
|
dmu_objset_pool(zfsvfs->z_os), FTAG);
|
2017-03-08 03:21:37 +03:00
|
|
|
dmu_objset_userobjspace_upgrade(zfsvfs->z_os);
|
2017-11-11 00:37:10 +03:00
|
|
|
dsl_pool_config_exit(
|
|
|
|
dmu_objset_pool(zfsvfs->z_os), FTAG);
|
|
|
|
}
|
2016-10-04 21:46:10 +03:00
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
|
2017-03-08 03:21:37 +03:00
|
|
|
quotaobj = isgroup ? zfsvfs->z_groupobjquota_obj :
|
|
|
|
zfsvfs->z_userobjquota_obj;
|
|
|
|
if (quotaobj == 0 || zfsvfs->z_replay)
|
2016-10-04 21:46:10 +03:00
|
|
|
return (B_FALSE);
|
|
|
|
|
|
|
|
(void) sprintf(buf, "%llx", (longlong_t)fuid);
|
2017-03-08 03:21:37 +03:00
|
|
|
err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a);
|
2016-10-04 21:46:10 +03:00
|
|
|
if (err != 0)
|
|
|
|
return (B_FALSE);
|
|
|
|
|
|
|
|
(void) sprintf(buf, DMU_OBJACCT_PREFIX "%llx", (longlong_t)fuid);
|
2017-03-08 03:21:37 +03:00
|
|
|
err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used);
|
2016-10-04 21:46:10 +03:00
|
|
|
if (err != 0)
|
|
|
|
return (B_FALSE);
|
|
|
|
return (used >= quota);
|
|
|
|
}
|
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
boolean_t
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_fuid_overquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid)
|
2009-07-03 02:44:48 +04:00
|
|
|
{
|
2016-10-04 21:46:10 +03:00
|
|
|
char buf[20];
|
2009-07-03 02:44:48 +04:00
|
|
|
uint64_t used, quota, usedobj, quotaobj;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT;
|
2017-03-08 03:21:37 +03:00
|
|
|
quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (quotaobj == 0 || zfsvfs->z_replay)
|
2009-07-03 02:44:48 +04:00
|
|
|
return (B_FALSE);
|
|
|
|
|
|
|
|
(void) sprintf(buf, "%llx", (longlong_t)fuid);
|
2017-03-08 03:21:37 +03:00
|
|
|
err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (err != 0)
|
|
|
|
return (B_FALSE);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used);
|
2009-07-03 02:44:48 +04:00
|
|
|
if (err != 0)
|
|
|
|
return (B_FALSE);
|
|
|
|
return (used >= quota);
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
boolean_t
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_owner_overquota(zfsvfs_t *zfsvfs, znode_t *zp, boolean_t isgroup)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
|
|
|
uint64_t fuid;
|
|
|
|
uint64_t quotaobj;
|
2016-05-22 14:15:57 +03:00
|
|
|
struct inode *ip = ZTOI(zp);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2016-05-22 14:15:57 +03:00
|
|
|
fuid = isgroup ? KGID_TO_SGID(ip->i_gid) : KUID_TO_SUID(ip->i_uid);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (quotaobj == 0 || zfsvfs->z_replay)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (B_FALSE);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
return (zfs_fuid_overquota(zfsvfs, isgroup, fuid));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
/*
|
|
|
|
* Associate this zfsvfs with the given objset, which must be owned.
|
|
|
|
* This will cache a bunch of on-disk state from the objset in the
|
|
|
|
* zfsvfs.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfsvfs_init(zfsvfs_t *zfsvfs, objset_t *os)
|
2009-07-03 02:44:48 +04:00
|
|
|
{
|
2016-05-11 06:49:02 +03:00
|
|
|
int error;
|
|
|
|
uint64_t val;
|
2015-09-01 02:46:01 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_max_blksz = SPA_OLD_MAXBLOCKSIZE;
|
|
|
|
zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE;
|
|
|
|
zfsvfs->z_os = os;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (zfsvfs->z_version >
|
|
|
|
zfs_zpl_version_map(spa_version(dmu_objset_spa(os)))) {
|
|
|
|
(void) printk("Can't mount a version %lld file system "
|
|
|
|
"on a version %lld pool\n. Pool must be upgraded to mount "
|
|
|
|
"this file system.", (u_longlong_t)zfsvfs->z_version,
|
|
|
|
(u_longlong_t)spa_version(dmu_objset_spa(os)));
|
|
|
|
return (SET_ERROR(ENOTSUP));
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
2016-05-11 06:49:02 +03:00
|
|
|
error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &val);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
zfsvfs->z_norm = (int)val;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &val);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
zfsvfs->z_utf8 = (val != 0);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
error = zfs_get_zplprop(os, ZFS_PROP_CASE, &val);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
zfsvfs->z_case = (uint_t)val;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
if ((error = zfs_get_zplprop(os, ZFS_PROP_ACLTYPE, &val)) != 0)
|
|
|
|
return (error);
|
|
|
|
zfsvfs->z_acl_type = (uint_t)val;
|
2013-10-28 20:22:15 +04:00
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
/*
|
|
|
|
* Fold case on file systems that are always or sometimes case
|
|
|
|
* insensitive.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
|
|
|
|
zfsvfs->z_case == ZFS_CASE_MIXED)
|
|
|
|
zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
|
|
|
|
zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
uint64_t sa_obj = 0;
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_use_sa) {
|
2010-05-29 00:45:14 +04:00
|
|
|
/* should either have both of these objects or none */
|
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1,
|
|
|
|
&sa_obj);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2011-10-25 03:55:20 +04:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
error = zfs_get_zplprop(os, ZFS_PROP_XATTR, &val);
|
|
|
|
if ((error == 0) && (val == ZFS_XATTR_SA))
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_xattr_sa = B_TRUE;
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
|
2017-03-08 03:21:37 +03:00
|
|
|
&zfsvfs->z_attr_table);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_version >= ZPL_VERSION_SA)
|
2010-05-29 00:45:14 +04:00
|
|
|
sa_register_update_callback(os, zfs_sa_upgrade);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
|
2017-03-08 03:21:37 +03:00
|
|
|
&zfsvfs->z_root);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2017-03-08 03:21:37 +03:00
|
|
|
ASSERT(zfsvfs->z_root != 0);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
|
2017-03-08 03:21:37 +03:00
|
|
|
&zfsvfs->z_unlinkedobj);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ,
|
|
|
|
zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA],
|
2017-03-08 03:21:37 +03:00
|
|
|
8, 1, &zfsvfs->z_userquota_obj);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error == ENOENT)
|
|
|
|
zfsvfs->z_userquota_obj = 0;
|
|
|
|
else if (error != 0)
|
|
|
|
return (error);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ,
|
|
|
|
zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA],
|
2017-03-08 03:21:37 +03:00
|
|
|
8, 1, &zfsvfs->z_groupquota_obj);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error == ENOENT)
|
|
|
|
zfsvfs->z_groupquota_obj = 0;
|
|
|
|
else if (error != 0)
|
|
|
|
return (error);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-10-04 21:46:10 +03:00
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ,
|
|
|
|
zfs_userquota_prop_prefixes[ZFS_PROP_USEROBJQUOTA],
|
2017-03-08 03:21:37 +03:00
|
|
|
8, 1, &zfsvfs->z_userobjquota_obj);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error == ENOENT)
|
|
|
|
zfsvfs->z_userobjquota_obj = 0;
|
|
|
|
else if (error != 0)
|
|
|
|
return (error);
|
2016-10-04 21:46:10 +03:00
|
|
|
|
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ,
|
|
|
|
zfs_userquota_prop_prefixes[ZFS_PROP_GROUPOBJQUOTA],
|
2017-03-08 03:21:37 +03:00
|
|
|
8, 1, &zfsvfs->z_groupobjquota_obj);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error == ENOENT)
|
|
|
|
zfsvfs->z_groupobjquota_obj = 0;
|
|
|
|
else if (error != 0)
|
|
|
|
return (error);
|
2016-10-04 21:46:10 +03:00
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
|
2017-03-08 03:21:37 +03:00
|
|
|
&zfsvfs->z_fuid_obj);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error == ENOENT)
|
|
|
|
zfsvfs->z_fuid_obj = 0;
|
|
|
|
else if (error != 0)
|
|
|
|
return (error);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1,
|
2017-03-08 03:21:37 +03:00
|
|
|
&zfsvfs->z_shares_dir);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error == ENOENT)
|
|
|
|
zfsvfs->z_shares_dir = 0;
|
|
|
|
else if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zfsvfs_create(const char *osname, zfsvfs_t **zfvp)
|
|
|
|
{
|
|
|
|
objset_t *os;
|
|
|
|
zfsvfs_t *zfsvfs;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We claim to always be readonly so we can open snapshots;
|
|
|
|
* other ZPL code will prevent us from writing to snapshots.
|
|
|
|
*/
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, B_TRUE,
|
|
|
|
zfsvfs, &os);
|
2016-05-11 06:49:02 +03:00
|
|
|
if (error) {
|
|
|
|
kmem_free(zfsvfs, sizeof (zfsvfs_t));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
zfsvfs->z_vfs = NULL;
|
|
|
|
zfsvfs->z_sb = NULL;
|
|
|
|
zfsvfs->z_parent = zfsvfs;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
|
2009-07-03 02:44:48 +04:00
|
|
|
offsetof(znode_t, z_link_node));
|
2017-03-08 03:21:37 +03:00
|
|
|
rrm_init(&zfsvfs->z_teardown_lock, B_FALSE);
|
|
|
|
rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL);
|
|
|
|
rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL);
|
2015-03-16 04:21:21 +03:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
int size = MIN(1 << (highbit64(zfs_object_mutex_size) - 1),
|
|
|
|
ZFS_OBJ_MTX_MAX);
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_hold_size = size;
|
|
|
|
zfsvfs->z_hold_trees = vmem_zalloc(sizeof (avl_tree_t) * size,
|
|
|
|
KM_SLEEP);
|
|
|
|
zfsvfs->z_hold_locks = vmem_zalloc(sizeof (kmutex_t) * size, KM_SLEEP);
|
2016-05-11 06:49:02 +03:00
|
|
|
for (int i = 0; i != size; i++) {
|
2017-03-08 03:21:37 +03:00
|
|
|
avl_create(&zfsvfs->z_hold_trees[i], zfs_znode_hold_compare,
|
2015-12-23 00:47:38 +03:00
|
|
|
sizeof (znode_hold_t), offsetof(znode_hold_t, zh_node));
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_init(&zfsvfs->z_hold_locks[i], NULL, MUTEX_DEFAULT, NULL);
|
2015-12-23 00:47:38 +03:00
|
|
|
}
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
error = zfsvfs_init(zfsvfs, os);
|
|
|
|
if (error != 0) {
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
dmu_objset_disown(os, B_TRUE, zfsvfs);
|
2016-05-11 06:49:02 +03:00
|
|
|
*zfvp = NULL;
|
|
|
|
kmem_free(zfsvfs, sizeof (zfsvfs_t));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
*zfvp = zfsvfs;
|
2009-07-03 02:44:48 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
static int
|
2017-03-09 01:56:19 +03:00
|
|
|
zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
error = zfs_register_callbacks(zfsvfs->z_vfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* If we are not mounting (ie: online recv), then we don't
|
|
|
|
* have to worry about replaying the log as we blocked all
|
|
|
|
* operations out since we closed the ZIL.
|
|
|
|
*/
|
|
|
|
if (mounting) {
|
2008-12-03 23:09:06 +03:00
|
|
|
boolean_t readonly;
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* During replay we remove the read only flag to
|
|
|
|
* allow replays to succeed.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
readonly = zfs_is_readonly(zfsvfs);
|
2009-01-16 00:59:39 +03:00
|
|
|
if (readonly != 0)
|
2017-03-08 03:21:37 +03:00
|
|
|
readonly_changed_cb(zfsvfs, B_FALSE);
|
2009-01-16 00:59:39 +03:00
|
|
|
else
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_unlinked_drain(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
|
|
|
* Parse and replay the intent log.
|
|
|
|
*
|
|
|
|
* Because of ziltest, this must be done after
|
|
|
|
* zfs_unlinked_drain(). (Further note: ziltest
|
|
|
|
* doesn't use readonly mounts, where
|
|
|
|
* zfs_unlinked_drain() isn't called.) This is because
|
|
|
|
* ziltest causes spa_sync() to think it's committed,
|
|
|
|
* but actually it is not, so the intent log contains
|
|
|
|
* many txg's worth of changes.
|
|
|
|
*
|
|
|
|
* In particular, if object N is in the unlinked set in
|
|
|
|
* the last txg to actually sync, then it could be
|
|
|
|
* actually freed in a later txg and then reallocated
|
|
|
|
* in a yet later txg. This would write a "create
|
|
|
|
* object N" record to the intent log. Normally, this
|
|
|
|
* would be fine because the spa_sync() would have
|
|
|
|
* written out the fact that object N is free, before
|
|
|
|
* we could write the "create object N" intent log
|
|
|
|
* record.
|
|
|
|
*
|
|
|
|
* But when we are in ziltest mode, we advance the "open
|
|
|
|
* txg" without actually spa_sync()-ing the changes to
|
|
|
|
* disk. So we would see that object N is still
|
|
|
|
* allocated and in the unlinked set, and there is an
|
|
|
|
* intent log record saying to allocate it.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (spa_writeable(dmu_objset_spa(zfsvfs->z_os))) {
|
2010-08-27 01:24:34 +04:00
|
|
|
if (zil_replay_disable) {
|
2017-03-08 03:21:37 +03:00
|
|
|
zil_destroy(zfsvfs->z_log, B_FALSE);
|
2010-08-27 01:24:34 +04:00
|
|
|
} else {
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_replay = B_TRUE;
|
|
|
|
zil_replay(zfsvfs->z_os, zfsvfs,
|
2010-08-27 01:24:34 +04:00
|
|
|
zfs_replay_vector);
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_replay = B_FALSE;
|
2010-08-27 01:24:34 +04:00
|
|
|
}
|
2009-01-16 00:59:39 +03:00
|
|
|
}
|
2011-05-19 22:44:07 +04:00
|
|
|
|
|
|
|
/* restore readonly bit */
|
|
|
|
if (readonly != 0)
|
2017-03-08 03:21:37 +03:00
|
|
|
readonly_changed_cb(zfsvfs, B_TRUE);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-01-14 02:29:32 +03:00
|
|
|
/*
|
2017-03-08 03:21:37 +03:00
|
|
|
* Set the objset user_ptr to track its zfsvfs.
|
2017-01-14 02:29:32 +03:00
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
|
|
|
|
dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
|
|
|
|
mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
|
2017-01-14 02:29:32 +03:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
void
|
2017-03-09 01:56:19 +03:00
|
|
|
zfsvfs_free(zfsvfs_t *zfsvfs)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
int i, size = zfsvfs->z_hold_size;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_fuid_destroy(zfsvfs);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_destroy(&zfsvfs->z_znodes_lock);
|
|
|
|
mutex_destroy(&zfsvfs->z_lock);
|
|
|
|
list_destroy(&zfsvfs->z_all_znodes);
|
|
|
|
rrm_destroy(&zfsvfs->z_teardown_lock);
|
|
|
|
rw_destroy(&zfsvfs->z_teardown_inactive_lock);
|
|
|
|
rw_destroy(&zfsvfs->z_fuid_lock);
|
2015-12-23 00:47:38 +03:00
|
|
|
for (i = 0; i != size; i++) {
|
2017-03-08 03:21:37 +03:00
|
|
|
avl_destroy(&zfsvfs->z_hold_trees[i]);
|
|
|
|
mutex_destroy(&zfsvfs->z_hold_locks[i]);
|
2015-12-23 00:47:38 +03:00
|
|
|
}
|
2017-03-08 03:21:37 +03:00
|
|
|
vmem_free(zfsvfs->z_hold_trees, sizeof (avl_tree_t) * size);
|
|
|
|
vmem_free(zfsvfs->z_hold_locks, sizeof (kmutex_t) * size);
|
2017-03-09 03:56:09 +03:00
|
|
|
zfsvfs_vfs_free(zfsvfs->z_vfs);
|
2017-03-08 03:21:37 +03:00
|
|
|
kmem_free(zfsvfs, sizeof (zfsvfs_t));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
static void
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_set_fuid_feature(zfsvfs_t *zfsvfs)
|
2009-07-03 02:44:48 +04:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os);
|
|
|
|
zfsvfs->z_use_sa = USE_SA(zfsvfs->z_version, zfsvfs->z_os);
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
void
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_unregister_callbacks(zfsvfs_t *zfsvfs)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
objset_t *os = zfsvfs->z_os;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2015-11-05 02:00:58 +03:00
|
|
|
if (!dmu_objset_is_snapshot(os))
|
2017-03-08 03:21:37 +03:00
|
|
|
dsl_prop_unregister_all(dmu_objset_ds(os), zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2011-01-07 03:47:31 +03:00
|
|
|
#ifdef HAVE_MLSLABEL
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
2013-06-11 21:12:34 +04:00
|
|
|
* Check that the hex label string is appropriate for the dataset being
|
|
|
|
* mounted into the global_zone proper.
|
2010-05-29 00:45:14 +04:00
|
|
|
*
|
2013-06-11 21:12:34 +04:00
|
|
|
* Return an error if the hex label string is not default or
|
|
|
|
* admin_low/admin_high. For admin_low labels, the corresponding
|
|
|
|
* dataset must be readonly.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_check_global_label(const char *dsname, const char *hexsl)
|
|
|
|
{
|
|
|
|
if (strcasecmp(hexsl, ZFS_MLSLABEL_DEFAULT) == 0)
|
|
|
|
return (0);
|
|
|
|
if (strcasecmp(hexsl, ADMIN_HIGH) == 0)
|
|
|
|
return (0);
|
|
|
|
if (strcasecmp(hexsl, ADMIN_LOW) == 0) {
|
|
|
|
/* must be readonly */
|
|
|
|
uint64_t rdonly;
|
|
|
|
|
|
|
|
if (dsl_prop_get_integer(dsname,
|
|
|
|
zfs_prop_to_name(ZFS_PROP_READONLY), &rdonly, NULL))
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EACCES));
|
2010-05-29 00:45:14 +04:00
|
|
|
return (rdonly ? 0 : EACCES);
|
|
|
|
}
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EACCES));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2011-01-07 03:47:31 +03:00
|
|
|
#endif /* HAVE_MLSLABEL */
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2010-12-17 22:18:08 +03:00
|
|
|
int
|
2011-02-08 22:16:06 +03:00
|
|
|
zfs_statvfs(struct dentry *dentry, struct kstatfs *statp)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info;
|
2008-11-20 23:01:55 +03:00
|
|
|
uint64_t refdbytes, availbytes, usedobjs, availobjs;
|
2012-08-24 16:38:55 +04:00
|
|
|
uint64_t fsid;
|
2011-02-08 22:16:06 +03:00
|
|
|
uint32_t bshift;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_ENTER(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
dmu_objset_space(zfsvfs->z_os,
|
2008-11-20 23:01:55 +03:00
|
|
|
&refdbytes, &availbytes, &usedobjs, &availobjs);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
fsid = dmu_objset_fsid_guid(zfsvfs->z_os);
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2011-02-24 00:57:50 +03:00
|
|
|
* The underlying storage pool actually uses multiple block
|
|
|
|
* size. Under Solaris frsize (fragment size) is reported as
|
|
|
|
* the smallest block size we support, and bsize (block size)
|
|
|
|
* as the filesystem's maximum block size. Unfortunately,
|
|
|
|
* under Linux the fragment size and block size are often used
|
|
|
|
* interchangeably. Thus we are forced to report both of them
|
|
|
|
* as the filesystem's maximum block size.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
statp->f_frsize = zfsvfs->z_max_blksz;
|
|
|
|
statp->f_bsize = zfsvfs->z_max_blksz;
|
2011-02-08 22:16:06 +03:00
|
|
|
bshift = fls(statp->f_bsize) - 1;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
2011-02-08 22:16:06 +03:00
|
|
|
* The following report "total" blocks of various kinds in
|
|
|
|
* the file system, but reported in terms of f_bsize - the
|
|
|
|
* "preferred" size.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
statp->f_blocks = (refdbytes + availbytes) >> bshift;
|
|
|
|
statp->f_bfree = availbytes >> bshift;
|
2008-11-20 23:01:55 +03:00
|
|
|
statp->f_bavail = statp->f_bfree; /* no root reservation */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* statvfs() should really be called statufs(), because it assumes
|
|
|
|
* static metadata. ZFS doesn't preallocate files, so the best
|
|
|
|
* we can do is report the max that could possibly fit in f_files,
|
|
|
|
* and that minus the number actually used in f_ffree.
|
|
|
|
* For f_ffree, report the smaller of the number of object available
|
|
|
|
* and the number of blocks (each object will take at least a block).
|
|
|
|
*/
|
2011-09-16 13:22:00 +04:00
|
|
|
statp->f_ffree = MIN(availobjs, availbytes >> DNODE_SHIFT);
|
2008-11-20 23:01:55 +03:00
|
|
|
statp->f_files = statp->f_ffree + usedobjs;
|
2012-08-24 16:38:55 +04:00
|
|
|
statp->f_fsid.val[0] = (uint32_t)fsid;
|
|
|
|
statp->f_fsid.val[1] = (uint32_t)(fsid >> 32);
|
2011-02-08 22:16:06 +03:00
|
|
|
statp->f_type = ZFS_SUPER_MAGIC;
|
2016-06-16 00:28:36 +03:00
|
|
|
statp->f_namelen = MAXNAMELEN - 1;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
2011-02-08 22:16:06 +03:00
|
|
|
* We have all of 40 characters to stuff a string here.
|
2008-11-20 23:01:55 +03:00
|
|
|
* Is there anything useful we could/should provide?
|
|
|
|
*/
|
2011-02-08 22:16:06 +03:00
|
|
|
bzero(statp->f_spare, sizeof (statp->f_spare));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2010-12-17 22:18:08 +03:00
|
|
|
int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_root(zfsvfs_t *zfsvfs, struct inode **ipp)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
znode_t *rootzp;
|
|
|
|
int error;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_ENTER(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (error == 0)
|
2011-02-08 22:16:06 +03:00
|
|
|
*ipp = ZTOI(rootzp);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2016-06-16 18:19:32 +03:00
|
|
|
#ifdef HAVE_D_PRUNE_ALIASES
|
2015-06-18 19:21:19 +03:00
|
|
|
/*
|
|
|
|
* Linux kernels older than 3.1 do not support a per-filesystem shrinker.
|
|
|
|
* To accommodate this we must improvise and manually walk the list of znodes
|
|
|
|
* attempting to prune dentries in order to be able to drop the inodes.
|
|
|
|
*
|
|
|
|
* To avoid scanning the same znodes multiple times they are always rotated
|
|
|
|
* to the end of the z_all_znodes list. New znodes are inserted at the
|
|
|
|
* end of the list so we're always scanning the oldest znodes first.
|
|
|
|
*/
|
|
|
|
static int
|
2017-03-09 01:56:19 +03:00
|
|
|
zfs_prune_aliases(zfsvfs_t *zfsvfs, unsigned long nr_to_scan)
|
2015-06-18 19:21:19 +03:00
|
|
|
{
|
|
|
|
znode_t **zp_array, *zp;
|
|
|
|
int max_array = MIN(nr_to_scan, PAGE_SIZE * 8 / sizeof (znode_t *));
|
|
|
|
int objects = 0;
|
|
|
|
int i = 0, j = 0;
|
|
|
|
|
|
|
|
zp_array = kmem_zalloc(max_array * sizeof (znode_t *), KM_SLEEP);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_enter(&zfsvfs->z_znodes_lock);
|
|
|
|
while ((zp = list_head(&zfsvfs->z_all_znodes)) != NULL) {
|
2015-06-18 19:21:19 +03:00
|
|
|
|
|
|
|
if ((i++ > nr_to_scan) || (j >= max_array))
|
|
|
|
break;
|
|
|
|
|
|
|
|
ASSERT(list_link_active(&zp->z_link_node));
|
2017-03-08 03:21:37 +03:00
|
|
|
list_remove(&zfsvfs->z_all_znodes, zp);
|
|
|
|
list_insert_tail(&zfsvfs->z_all_znodes, zp);
|
2015-06-18 19:21:19 +03:00
|
|
|
|
|
|
|
/* Skip active znodes and .zfs entries */
|
|
|
|
if (MUTEX_HELD(&zp->z_lock) || zp->z_is_ctldir)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (igrab(ZTOI(zp)) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
zp_array[j] = zp;
|
|
|
|
j++;
|
|
|
|
}
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_exit(&zfsvfs->z_znodes_lock);
|
2015-06-18 19:21:19 +03:00
|
|
|
|
|
|
|
for (i = 0; i < j; i++) {
|
|
|
|
zp = zp_array[i];
|
|
|
|
|
|
|
|
ASSERT3P(zp, !=, NULL);
|
|
|
|
d_prune_aliases(ZTOI(zp));
|
|
|
|
|
|
|
|
if (atomic_read(&ZTOI(zp)->i_count) == 1)
|
|
|
|
objects++;
|
|
|
|
|
|
|
|
iput(ZTOI(zp));
|
|
|
|
}
|
|
|
|
|
|
|
|
kmem_free(zp_array, max_array * sizeof (znode_t *));
|
|
|
|
|
|
|
|
return (objects);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_D_PRUNE_ALIASES */
|
|
|
|
|
2015-03-18 01:07:47 +03:00
|
|
|
/*
|
|
|
|
* The ARC has requested that the filesystem drop entries from the dentry
|
|
|
|
* and inode caches. This can occur when the ARC needs to free meta data
|
|
|
|
* blocks but can't because they are all pinned by entries in these caches.
|
|
|
|
*/
|
2011-12-23 00:20:43 +04:00
|
|
|
int
|
2017-03-09 01:56:19 +03:00
|
|
|
zfs_prune(struct super_block *sb, unsigned long nr_to_scan, int *objects)
|
2011-12-23 00:20:43 +04:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = sb->s_fs_info;
|
2015-03-18 01:07:47 +03:00
|
|
|
int error = 0;
|
|
|
|
#if defined(HAVE_SHRINK) || defined(HAVE_SPLIT_SHRINKER_CALLBACK)
|
2011-12-23 00:20:43 +04:00
|
|
|
struct shrinker *shrinker = &sb->s_shrink;
|
|
|
|
struct shrink_control sc = {
|
|
|
|
.nr_to_scan = nr_to_scan,
|
|
|
|
.gfp_mask = GFP_KERNEL,
|
|
|
|
};
|
2015-03-18 01:07:47 +03:00
|
|
|
#endif
|
2011-12-23 00:20:43 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_ENTER(zfsvfs);
|
2015-03-18 01:07:47 +03:00
|
|
|
|
2015-06-14 19:19:40 +03:00
|
|
|
#if defined(HAVE_SPLIT_SHRINKER_CALLBACK) && \
|
|
|
|
defined(SHRINK_CONTROL_HAS_NID) && \
|
|
|
|
defined(SHRINKER_NUMA_AWARE)
|
|
|
|
if (sb->s_shrink.flags & SHRINKER_NUMA_AWARE) {
|
|
|
|
*objects = 0;
|
2016-12-12 21:46:26 +03:00
|
|
|
for_each_online_node(sc.nid) {
|
2015-06-14 19:19:40 +03:00
|
|
|
*objects += (*shrinker->scan_objects)(shrinker, &sc);
|
2016-12-12 21:46:26 +03:00
|
|
|
}
|
2015-06-14 19:19:40 +03:00
|
|
|
} else {
|
|
|
|
*objects = (*shrinker->scan_objects)(shrinker, &sc);
|
|
|
|
}
|
2016-06-16 18:19:32 +03:00
|
|
|
|
2015-06-14 19:19:40 +03:00
|
|
|
#elif defined(HAVE_SPLIT_SHRINKER_CALLBACK)
|
2014-12-18 19:08:47 +03:00
|
|
|
*objects = (*shrinker->scan_objects)(shrinker, &sc);
|
2015-03-18 01:07:47 +03:00
|
|
|
#elif defined(HAVE_SHRINK)
|
2011-12-23 00:20:43 +04:00
|
|
|
*objects = (*shrinker->shrink)(shrinker, &sc);
|
2015-06-18 19:21:19 +03:00
|
|
|
#elif defined(HAVE_D_PRUNE_ALIASES)
|
2016-06-16 18:19:32 +03:00
|
|
|
#define D_PRUNE_ALIASES_IS_DEFAULT
|
2017-03-09 01:56:19 +03:00
|
|
|
*objects = zfs_prune_aliases(zfsvfs, nr_to_scan);
|
2015-03-18 01:07:47 +03:00
|
|
|
#else
|
2015-06-18 19:21:19 +03:00
|
|
|
#error "No available dentry and inode cache pruning mechanism."
|
2014-12-18 19:08:47 +03:00
|
|
|
#endif
|
2016-06-16 18:19:32 +03:00
|
|
|
|
|
|
|
#if defined(HAVE_D_PRUNE_ALIASES) && !defined(D_PRUNE_ALIASES_IS_DEFAULT)
|
|
|
|
#undef D_PRUNE_ALIASES_IS_DEFAULT
|
|
|
|
/*
|
2017-03-09 01:56:19 +03:00
|
|
|
* Fall back to zfs_prune_aliases if the kernel's per-superblock
|
2016-06-16 18:19:32 +03:00
|
|
|
* shrinker couldn't free anything, possibly due to the inodes being
|
|
|
|
* allocated in a different memcg.
|
|
|
|
*/
|
|
|
|
if (*objects == 0)
|
2017-03-09 01:56:19 +03:00
|
|
|
*objects = zfs_prune_aliases(zfsvfs, nr_to_scan);
|
2016-06-16 18:19:32 +03:00
|
|
|
#endif
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2011-12-23 00:20:43 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
dprintf_ds(zfsvfs->z_os->os_dsl_dataset,
|
2015-03-18 01:07:47 +03:00
|
|
|
"pruning, nr_to_scan=%lu objects=%d error=%d\n",
|
|
|
|
nr_to_scan, *objects, error);
|
|
|
|
|
|
|
|
return (error);
|
2011-12-23 00:20:43 +04:00
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2017-03-08 03:21:37 +03:00
|
|
|
* Teardown the zfsvfs_t.
|
2008-11-20 23:01:55 +03:00
|
|
|
*
|
2017-01-27 22:46:39 +03:00
|
|
|
* Note, if 'unmounting' is FALSE, we return with the 'z_teardown_lock'
|
2008-11-20 23:01:55 +03:00
|
|
|
* and 'z_teardown_inactive_lock' held.
|
|
|
|
*/
|
2017-03-09 01:56:19 +03:00
|
|
|
static int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
znode_t *zp;
|
|
|
|
|
2014-01-08 22:25:42 +04:00
|
|
|
/*
|
|
|
|
* If someone has not already unmounted this file system,
|
|
|
|
* drain the iput_taskq to ensure all active references to the
|
2017-03-08 03:21:37 +03:00
|
|
|
* zfsvfs_t have been handled only then can it be safely destroyed.
|
2014-01-08 22:25:42 +04:00
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_os) {
|
2015-05-02 08:47:06 +03:00
|
|
|
/*
|
|
|
|
* If we're unmounting we have to wait for the list to
|
|
|
|
* drain completely.
|
|
|
|
*
|
|
|
|
* If we're not unmounting there's no guarantee the list
|
|
|
|
* will drain completely, but iputs run from the taskq
|
|
|
|
* may add the parents of dir-based xattrs to the taskq
|
|
|
|
* so we want to wait for these.
|
|
|
|
*
|
|
|
|
* We can safely read z_nr_znodes without locking because the
|
|
|
|
* VFS has already blocked operations which add to the
|
|
|
|
* z_all_znodes list and thus increment z_nr_znodes.
|
|
|
|
*/
|
|
|
|
int round = 0;
|
2017-03-08 03:21:37 +03:00
|
|
|
while (zfsvfs->z_nr_znodes > 0) {
|
2015-06-05 21:26:35 +03:00
|
|
|
taskq_wait_outstanding(dsl_pool_iput_taskq(
|
2017-03-08 03:21:37 +03:00
|
|
|
dmu_objset_pool(zfsvfs->z_os)), 0);
|
2015-05-02 08:47:06 +03:00
|
|
|
if (++round > 1 && !unmounting)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-08 22:25:42 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
rrm_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (!unmounting) {
|
|
|
|
/*
|
2011-02-05 03:54:34 +03:00
|
|
|
* We purge the parent filesystem's super block as the
|
|
|
|
* parent filesystem and all of its snapshots have their
|
|
|
|
* inode's super block set to the parent's filesystem's
|
|
|
|
* super block. Note, 'z_parent' is self referential
|
|
|
|
* for non-snapshots.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
shrink_dcache_sb(zfsvfs->z_parent->z_sb);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the zil. NB: Can't close the zil while zfs_inactive
|
|
|
|
* threads are blocked as zil_close can call zfs_inactive.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_log) {
|
|
|
|
zil_close(zfsvfs->z_log);
|
|
|
|
zfsvfs->z_log = NULL;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are not unmounting (ie: online recv) and someone already
|
|
|
|
* unmounted this file system while we were doing the switcheroo,
|
|
|
|
* or a reopen of z_os failed then just bail out now.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) {
|
|
|
|
rw_exit(&zfsvfs->z_teardown_inactive_lock);
|
|
|
|
rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EIO));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-01-16 04:41:09 +04:00
|
|
|
* At this point there are no VFS ops active, and any new VFS ops
|
|
|
|
* will fail with EIO since we have z_teardown_lock for writer (only
|
|
|
|
* relevant for forced unmount).
|
2008-11-20 23:01:55 +03:00
|
|
|
*
|
|
|
|
* Release all holds on dbufs.
|
|
|
|
*/
|
2015-05-02 08:47:06 +03:00
|
|
|
if (!unmounting) {
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_enter(&zfsvfs->z_znodes_lock);
|
|
|
|
for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL;
|
|
|
|
zp = list_next(&zfsvfs->z_all_znodes, zp)) {
|
2015-05-02 08:47:06 +03:00
|
|
|
if (zp->z_sa_hdl)
|
|
|
|
zfs_znode_dmu_fini(zp);
|
|
|
|
}
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_exit(&zfsvfs->z_znodes_lock);
|
2013-01-16 04:41:09 +04:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
2013-01-16 04:41:09 +04:00
|
|
|
* If we are unmounting, set the unmounted flag and let new VFS ops
|
2008-11-20 23:01:55 +03:00
|
|
|
* unblock. zfs_inactive will have the unmounted behavior, and all
|
2013-01-16 04:41:09 +04:00
|
|
|
* other VFS ops will fail with EIO.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
if (unmounting) {
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_unmounted = B_TRUE;
|
|
|
|
rw_exit(&zfsvfs->z_teardown_inactive_lock);
|
|
|
|
rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* z_os will be NULL if there was an error in attempting to reopen
|
2017-03-08 03:21:37 +03:00
|
|
|
* zfsvfs, so just return as the properties had already been
|
2011-02-08 22:16:06 +03:00
|
|
|
*
|
2008-11-20 23:01:55 +03:00
|
|
|
* unregistered and cached data had been evicted before.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_os == NULL)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister properties.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_unregister_callbacks(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Evict cached data
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (dsl_dataset_is_dirty(dmu_objset_ds(zfsvfs->z_os)) &&
|
|
|
|
!zfs_is_readonly(zfsvfs))
|
|
|
|
txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0);
|
|
|
|
dmu_objset_evict_dbufs(zfsvfs->z_os);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-05-25 19:55:55 +03:00
|
|
|
#if !defined(HAVE_2ARGS_BDI_SETUP_AND_REGISTER) && \
|
2015-02-28 03:09:52 +03:00
|
|
|
!defined(HAVE_3ARGS_BDI_SETUP_AND_REGISTER)
|
2011-11-08 04:39:03 +04:00
|
|
|
atomic_long_t zfs_bdi_seq = ATOMIC_LONG_INIT(0);
|
2015-02-28 03:09:52 +03:00
|
|
|
#endif
|
2011-08-02 05:24:40 +04:00
|
|
|
|
2010-12-17 22:18:08 +03:00
|
|
|
int
|
2017-03-09 03:56:09 +03:00
|
|
|
zfs_domount(struct super_block *sb, zfs_mnt_t *zm, int silent)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-03-09 03:56:09 +03:00
|
|
|
const char *osname = zm->mnt_osname;
|
2011-02-08 22:16:06 +03:00
|
|
|
struct inode *root_inode;
|
|
|
|
uint64_t recordsize;
|
2017-03-09 03:56:09 +03:00
|
|
|
int error = 0;
|
|
|
|
zfsvfs_t *zfsvfs;
|
|
|
|
|
|
|
|
ASSERT(zm);
|
|
|
|
ASSERT(osname);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
error = zfsvfs_create(osname, &zfsvfs);
|
2011-02-08 22:16:06 +03:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
error = zfsvfs_parse_options(zm->mnt_data, &zfsvfs->z_vfs);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
if ((error = dsl_prop_get_integer(osname, "recordsize",
|
|
|
|
&recordsize, NULL)))
|
|
|
|
goto out;
|
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
zfsvfs->z_vfs->vfs_data = zfsvfs;
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_sb = sb;
|
|
|
|
sb->s_fs_info = zfsvfs;
|
2011-02-08 22:16:06 +03:00
|
|
|
sb->s_magic = ZFS_SUPER_MAGIC;
|
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
|
|
|
sb->s_time_gran = 1;
|
|
|
|
sb->s_blocksize = recordsize;
|
|
|
|
sb->s_blocksize_bits = ilog2(recordsize);
|
2011-11-08 04:39:03 +04:00
|
|
|
|
2017-05-02 19:46:18 +03:00
|
|
|
error = -zpl_bdi_setup(sb, "zfs");
|
2011-11-08 04:39:03 +04:00
|
|
|
if (error)
|
|
|
|
goto out;
|
2011-02-08 22:16:06 +03:00
|
|
|
|
2017-05-02 19:46:18 +03:00
|
|
|
sb->s_bdi->ra_pages = 0;
|
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
/* Set callback operations for the file system. */
|
|
|
|
sb->s_op = &zpl_super_operations;
|
|
|
|
sb->s_xattr = zpl_xattr_handlers;
|
2011-04-28 20:35:50 +04:00
|
|
|
sb->s_export_op = &zpl_export_operations;
|
2013-01-19 02:11:40 +04:00
|
|
|
#ifdef HAVE_S_D_OP
|
|
|
|
sb->s_d_op = &zpl_dentry_operations;
|
|
|
|
#endif /* HAVE_S_D_OP */
|
2011-02-08 22:16:06 +03:00
|
|
|
|
|
|
|
/* Set features for file system. */
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_set_fuid_feature(zfsvfs);
|
2011-02-08 22:16:06 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (dmu_objset_is_snapshot(zfsvfs->z_os)) {
|
2011-02-08 22:16:06 +03:00
|
|
|
uint64_t pval;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
atime_changed_cb(zfsvfs, B_FALSE);
|
|
|
|
readonly_changed_cb(zfsvfs, B_TRUE);
|
2013-11-01 23:26:11 +04:00
|
|
|
if ((error = dsl_prop_get_integer(osname,
|
|
|
|
"xattr", &pval, NULL)))
|
2011-02-08 22:16:06 +03:00
|
|
|
goto out;
|
2017-03-08 03:21:37 +03:00
|
|
|
xattr_changed_cb(zfsvfs, pval);
|
2013-11-01 23:26:11 +04:00
|
|
|
if ((error = dsl_prop_get_integer(osname,
|
|
|
|
"acltype", &pval, NULL)))
|
2013-10-28 20:22:15 +04:00
|
|
|
goto out;
|
2017-03-08 03:21:37 +03:00
|
|
|
acltype_changed_cb(zfsvfs, pval);
|
|
|
|
zfsvfs->z_issnap = B_TRUE;
|
|
|
|
zfsvfs->z_os->os_sync = ZFS_SYNC_DISABLED;
|
|
|
|
zfsvfs->z_snap_defer_time = jiffies;
|
|
|
|
|
|
|
|
mutex_enter(&zfsvfs->z_os->os_user_ptr_lock);
|
|
|
|
dmu_objset_set_user(zfsvfs->z_os, zfsvfs);
|
|
|
|
mutex_exit(&zfsvfs->z_os->os_user_ptr_lock);
|
2011-02-08 22:16:06 +03:00
|
|
|
} else {
|
2017-03-09 01:56:19 +03:00
|
|
|
if ((error = zfsvfs_setup(zfsvfs, B_TRUE)))
|
2016-07-19 22:02:33 +03:00
|
|
|
goto out;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
/* Allocate a root inode for the filesystem. */
|
2017-03-08 03:21:37 +03:00
|
|
|
error = zfs_root(zfsvfs, &root_inode);
|
2011-02-08 22:16:06 +03:00
|
|
|
if (error) {
|
|
|
|
(void) zfs_umount(sb);
|
|
|
|
goto out;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
/* Allocate a root dentry for the filesystem */
|
2012-06-06 21:08:00 +04:00
|
|
|
sb->s_root = d_make_root(root_inode);
|
2011-02-08 22:16:06 +03:00
|
|
|
if (sb->s_root == NULL) {
|
|
|
|
(void) zfs_umount(sb);
|
2013-03-08 22:41:28 +04:00
|
|
|
error = SET_ERROR(ENOMEM);
|
2011-02-08 22:16:06 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2011-11-11 11:15:53 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (!zfsvfs->z_issnap)
|
|
|
|
zfsctl_create(zfsvfs);
|
2015-03-18 01:07:47 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_arc_prune = arc_add_prune_callback(zpl_prune_sb, sb);
|
2011-02-08 22:16:06 +03:00
|
|
|
out:
|
|
|
|
if (error) {
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
dmu_objset_disown(zfsvfs->z_os, B_TRUE, zfsvfs);
|
2017-03-09 01:56:19 +03:00
|
|
|
zfsvfs_free(zfsvfs);
|
2016-07-19 22:02:33 +03:00
|
|
|
/*
|
|
|
|
* make sure we don't have dangling sb->s_fs_info which
|
|
|
|
* zfs_preumount will use.
|
|
|
|
*/
|
|
|
|
sb->s_fs_info = NULL;
|
2011-02-08 22:16:06 +03:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-11-11 11:15:53 +04:00
|
|
|
/*
|
|
|
|
* Called when an unmount is requested and certain sanity checks have
|
|
|
|
* already passed. At this point no dentries or inodes have been reclaimed
|
|
|
|
* from their respective caches. We drop the extra reference on the .zfs
|
|
|
|
* control directory to allow everything to be reclaimed. All snapshots
|
|
|
|
* must already have been unmounted to reach this point.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
zfs_preumount(struct super_block *sb)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = sb->s_fs_info;
|
2011-11-11 11:15:53 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
/* zfsvfs is NULL when zfs_domount fails during mount */
|
|
|
|
if (zfsvfs) {
|
2015-04-25 02:21:13 +03:00
|
|
|
zfsctl_destroy(sb->s_fs_info);
|
2016-07-19 22:02:33 +03:00
|
|
|
/*
|
|
|
|
* Wait for iput_async before entering evict_inodes in
|
|
|
|
* generic_shutdown_super. The reason we must finish before
|
|
|
|
* evict_inodes is when lazytime is on, or when zfs_purgedir
|
|
|
|
* calls zfs_zget, iput would bump i_count from 0 to 1. This
|
|
|
|
* would race with the i_count check in evict_inodes. This means
|
|
|
|
* it could destroy the inode while we are still using it.
|
|
|
|
*
|
|
|
|
* We wait for two passes. xattr directories in the first pass
|
|
|
|
* may add xattr entries in zfs_purgedir, so in the second pass
|
|
|
|
* we wait for them. We don't use taskq_wait here because it is
|
|
|
|
* a pool wide taskq. Other mounted filesystems can constantly
|
|
|
|
* do iput_async and there's no guarantee when taskq will be
|
|
|
|
* empty.
|
|
|
|
*/
|
|
|
|
taskq_wait_outstanding(dsl_pool_iput_taskq(
|
2017-03-08 03:21:37 +03:00
|
|
|
dmu_objset_pool(zfsvfs->z_os)), 0);
|
2016-07-19 22:02:33 +03:00
|
|
|
taskq_wait_outstanding(dsl_pool_iput_taskq(
|
2017-03-08 03:21:37 +03:00
|
|
|
dmu_objset_pool(zfsvfs->z_os)), 0);
|
2016-07-19 22:02:33 +03:00
|
|
|
}
|
2011-11-11 11:15:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called once all other unmount released tear down has occurred.
|
|
|
|
* It is our responsibility to release any remaining infrastructure.
|
|
|
|
*/
|
2011-02-08 22:16:06 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
|
|
|
zfs_umount(struct super_block *sb)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = sb->s_fs_info;
|
2011-02-08 22:16:06 +03:00
|
|
|
objset_t *os;
|
|
|
|
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
if (zfsvfs->z_arc_prune != NULL)
|
|
|
|
arc_remove_prune_callback(zfsvfs->z_arc_prune);
|
2017-03-08 03:21:37 +03:00
|
|
|
VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0);
|
|
|
|
os = zfsvfs->z_os;
|
2017-05-02 19:46:18 +03:00
|
|
|
zpl_bdi_destroy(sb);
|
2011-08-02 05:24:40 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* z_os will be NULL if there was an error in
|
2017-03-08 03:21:37 +03:00
|
|
|
* attempting to reopen zfsvfs.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
if (os != NULL) {
|
|
|
|
/*
|
|
|
|
* Unset the objset user_ptr.
|
|
|
|
*/
|
2010-05-29 00:45:14 +04:00
|
|
|
mutex_enter(&os->os_user_ptr_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
dmu_objset_set_user(os, NULL);
|
2010-05-29 00:45:14 +04:00
|
|
|
mutex_exit(&os->os_user_ptr_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
2008-12-03 23:09:06 +03:00
|
|
|
* Finally release the objset
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
dmu_objset_disown(os, B_TRUE, zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 01:56:19 +03:00
|
|
|
zfsvfs_free(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-03-15 22:41:19 +03:00
|
|
|
int
|
2017-03-09 03:56:09 +03:00
|
|
|
zfs_remount(struct super_block *sb, int *flags, zfs_mnt_t *zm)
|
2011-03-15 22:41:19 +03:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = sb->s_fs_info;
|
2017-03-09 03:56:09 +03:00
|
|
|
vfs_t *vfsp;
|
2017-08-18 00:28:17 +03:00
|
|
|
boolean_t issnap = dmu_objset_is_snapshot(zfsvfs->z_os);
|
2015-09-01 02:46:01 +03:00
|
|
|
int error;
|
|
|
|
|
2017-08-18 00:28:17 +03:00
|
|
|
if ((issnap || !spa_writeable(dmu_objset_spa(zfsvfs->z_os))) &&
|
|
|
|
!(*flags & MS_RDONLY)) {
|
|
|
|
*flags |= MS_RDONLY;
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
2017-03-09 03:56:09 +03:00
|
|
|
error = zfsvfs_parse_options(zm->mnt_data, &vfsp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_unregister_callbacks(zfsvfs);
|
2017-03-09 03:56:09 +03:00
|
|
|
zfsvfs_vfs_free(zfsvfs->z_vfs);
|
|
|
|
|
|
|
|
vfsp->vfs_data = zfsvfs;
|
|
|
|
zfsvfs->z_vfs = vfsp;
|
2017-08-18 00:28:17 +03:00
|
|
|
if (!issnap)
|
|
|
|
(void) zfs_register_callbacks(vfsp);
|
2015-09-01 02:46:01 +03:00
|
|
|
|
|
|
|
return (error);
|
2011-03-15 22:41:19 +03:00
|
|
|
}
|
|
|
|
|
2010-12-17 22:18:08 +03:00
|
|
|
int
|
2011-05-19 22:44:07 +04:00
|
|
|
zfs_vget(struct super_block *sb, struct inode **ipp, fid_t *fidp)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfsvfs = sb->s_fs_info;
|
2008-11-20 23:01:55 +03:00
|
|
|
znode_t *zp;
|
|
|
|
uint64_t object = 0;
|
|
|
|
uint64_t fid_gen = 0;
|
|
|
|
uint64_t gen_mask;
|
|
|
|
uint64_t zp_gen;
|
2011-02-08 22:16:06 +03:00
|
|
|
int i, err;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
*ipp = NULL;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 20:26:33 +03:00
|
|
|
if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) {
|
|
|
|
zfid_short_t *zfid = (zfid_short_t *)fidp;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (zfid->zf_object); i++)
|
|
|
|
object |= ((uint64_t)zfid->zf_object[i]) << (8 * i);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 20:26:33 +03:00
|
|
|
for (i = 0; i < sizeof (zfid->zf_gen); i++)
|
|
|
|
fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i);
|
|
|
|
} else {
|
|
|
|
return (SET_ERROR(EINVAL));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LONG_FID_LEN means snapdirs */
|
2008-11-20 23:01:55 +03:00
|
|
|
if (fidp->fid_len == LONG_FID_LEN) {
|
|
|
|
zfid_long_t *zlfid = (zfid_long_t *)fidp;
|
|
|
|
uint64_t objsetid = 0;
|
|
|
|
uint64_t setgen = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (zlfid->zf_setid); i++)
|
|
|
|
objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i);
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
|
|
|
|
setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i);
|
|
|
|
|
2017-03-08 20:26:33 +03:00
|
|
|
if (objsetid != ZFSCTL_INO_SNAPDIRS - object) {
|
|
|
|
dprintf("snapdir fid: objsetid (%llu) != "
|
|
|
|
"ZFSCTL_INO_SNAPDIRS (%llu) - object (%llu)\n",
|
|
|
|
objsetid, ZFSCTL_INO_SNAPDIRS, object);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EINVAL));
|
2017-03-08 20:26:33 +03:00
|
|
|
}
|
2011-11-11 11:15:53 +04:00
|
|
|
|
2017-03-08 20:26:33 +03:00
|
|
|
if (fid_gen > 1 || setgen != 0) {
|
|
|
|
dprintf("snapdir fid: fid_gen (%llu) and setgen "
|
|
|
|
"(%llu)\n", fid_gen, setgen);
|
|
|
|
return (SET_ERROR(EINVAL));
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 20:26:33 +03:00
|
|
|
return (zfsctl_snapdir_vget(sb, objsetid, fid_gen, ipp));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_ENTER(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
/* A zero fid_gen means we are in the .zfs control directories */
|
|
|
|
if (fid_gen == 0 &&
|
|
|
|
(object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) {
|
2017-03-08 03:21:37 +03:00
|
|
|
*ipp = zfsvfs->z_ctldir;
|
2011-02-08 22:16:06 +03:00
|
|
|
ASSERT(*ipp != NULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (object == ZFSCTL_INO_SNAPDIR) {
|
2011-11-11 11:15:53 +04:00
|
|
|
VERIFY(zfsctl_root_lookup(*ipp, "snapshot", ipp,
|
|
|
|
0, kcred, NULL, NULL) == 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
2011-02-08 22:16:06 +03:00
|
|
|
igrab(*ipp);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_mask = -1ULL >> (64 - 8 * i);
|
|
|
|
|
2014-10-24 03:59:27 +04:00
|
|
|
dprintf("getting %llu [%llu mask %llx]\n", object, fid_gen, gen_mask);
|
2017-03-08 03:21:37 +03:00
|
|
|
if ((err = zfs_zget(zfsvfs, object, &zp))) {
|
|
|
|
ZFS_EXIT(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
2016-07-07 02:54:19 +03:00
|
|
|
|
|
|
|
/* Don't export xattr stuff */
|
|
|
|
if (zp->z_pflags & ZFS_XATTR) {
|
|
|
|
iput(ZTOI(zp));
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2016-07-07 02:54:19 +03:00
|
|
|
return (SET_ERROR(ENOENT));
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs), &zp_gen,
|
2010-05-29 00:45:14 +04:00
|
|
|
sizeof (uint64_t));
|
|
|
|
zp_gen = zp_gen & gen_mask;
|
2008-11-20 23:01:55 +03:00
|
|
|
if (zp_gen == 0)
|
|
|
|
zp_gen = 1;
|
2017-03-08 03:21:37 +03:00
|
|
|
if ((fid_gen == 0) && (zfsvfs->z_root == object))
|
2015-08-29 00:54:32 +03:00
|
|
|
fid_gen = zp_gen;
|
2008-11-20 23:01:55 +03:00
|
|
|
if (zp->z_unlinked || zp_gen != fid_gen) {
|
2014-10-24 03:59:27 +04:00
|
|
|
dprintf("znode gen (%llu) != fid gen (%llu)\n", zp_gen,
|
|
|
|
fid_gen);
|
2011-02-08 22:16:06 +03:00
|
|
|
iput(ZTOI(zp));
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2016-07-09 00:51:42 +03:00
|
|
|
return (SET_ERROR(ENOENT));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
*ipp = ZTOI(zp);
|
|
|
|
if (*ipp)
|
|
|
|
zfs_inode_update(ITOZ(*ipp));
|
2011-01-06 01:27:30 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ZFS_EXIT(zfsvfs);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-03-08 03:21:37 +03:00
|
|
|
* Block out VFS ops and close zfsvfs_t
|
2008-11-20 23:01:55 +03:00
|
|
|
*
|
|
|
|
* Note, if successful, then we return with the 'z_teardown_lock' and
|
2013-07-27 21:50:07 +04:00
|
|
|
* 'z_teardown_inactive_lock' write held. We leave ownership of the underlying
|
|
|
|
* dataset and objset intact so that they can be atomically handed off during
|
|
|
|
* a subsequent rollback or recv operation and the resume thereafter.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_suspend_fs(zfsvfs_t *zfsvfs)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (error);
|
2013-01-16 04:41:09 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-05-11 06:49:02 +03:00
|
|
|
* Rebuild SA and release VOPs. Note that ownership of the underlying dataset
|
|
|
|
* is an invariant across any of the operations that can be performed while the
|
|
|
|
* filesystem was suspended. Whether it succeeded or failed, the preconditions
|
|
|
|
* are the same: the relevant objset and associated dataset are owned by
|
|
|
|
* zfsvfs, held, and long held on entry.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_resume_fs(zfsvfs_t *zfsvfs, dsl_dataset_t *ds)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2013-11-10 05:22:06 +04:00
|
|
|
int err, err2;
|
2013-07-27 21:50:07 +04:00
|
|
|
znode_t *zp;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ASSERT(RRM_WRITE_HELD(&zfsvfs->z_teardown_lock));
|
|
|
|
ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2013-07-27 21:50:07 +04:00
|
|
|
/*
|
2017-01-23 21:53:46 +03:00
|
|
|
* We already own this, so just update the objset_t, as the one we
|
|
|
|
* had before may have been evicted.
|
2013-07-27 21:50:07 +04:00
|
|
|
*/
|
2016-05-11 06:49:02 +03:00
|
|
|
objset_t *os;
|
2017-03-08 03:21:37 +03:00
|
|
|
VERIFY3P(ds->ds_owner, ==, zfsvfs);
|
2017-01-23 21:53:46 +03:00
|
|
|
VERIFY(dsl_dataset_long_held(ds));
|
2016-05-11 06:49:02 +03:00
|
|
|
VERIFY0(dmu_objset_from_ds(ds, &os));
|
2010-08-18 23:59:31 +04:00
|
|
|
|
2016-05-11 06:49:02 +03:00
|
|
|
err = zfsvfs_init(zfsvfs, os);
|
|
|
|
if (err != 0)
|
2013-07-27 21:50:07 +04:00
|
|
|
goto bail;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-09 01:56:19 +03:00
|
|
|
VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0);
|
2010-08-18 23:59:31 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_set_fuid_feature(zfsvfs);
|
|
|
|
zfsvfs->z_rollback_time = jiffies;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2013-07-27 21:50:07 +04:00
|
|
|
/*
|
|
|
|
* Attempt to re-establish all the active inodes with their
|
|
|
|
* dbufs. If a zfs_rezget() fails, then we unhash the inode
|
|
|
|
* and mark it stale. This prevents a collision if a new
|
|
|
|
* inode/object is created which must use the same inode
|
|
|
|
* number. The stale inode will be be released when the
|
|
|
|
* VFS prunes the dentry holding the remaining references
|
|
|
|
* on the stale inode.
|
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_enter(&zfsvfs->z_znodes_lock);
|
|
|
|
for (zp = list_head(&zfsvfs->z_all_znodes); zp;
|
|
|
|
zp = list_next(&zfsvfs->z_all_znodes, zp)) {
|
2013-11-10 05:22:06 +04:00
|
|
|
err2 = zfs_rezget(zp);
|
|
|
|
if (err2) {
|
2013-07-27 21:50:07 +04:00
|
|
|
remove_inode_hash(ZTOI(zp));
|
|
|
|
zp->z_is_stale = B_TRUE;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-08 03:21:37 +03:00
|
|
|
mutex_exit(&zfsvfs->z_znodes_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
bail:
|
2013-01-16 04:41:09 +04:00
|
|
|
/* release the VFS ops */
|
2017-03-08 03:21:37 +03:00
|
|
|
rw_exit(&zfsvfs->z_teardown_inactive_lock);
|
|
|
|
rrm_exit(&zfsvfs->z_teardown_lock, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
/*
|
2013-07-27 21:50:07 +04:00
|
|
|
* Since we couldn't setup the sa framework, try to force
|
|
|
|
* unmount this file system.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
2017-03-08 03:21:37 +03:00
|
|
|
if (zfsvfs->z_os)
|
|
|
|
(void) zfs_umount(zfsvfs->z_sb);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
int error;
|
2017-03-08 03:21:37 +03:00
|
|
|
objset_t *os = zfsvfs->z_os;
|
2008-11-20 23:01:55 +03:00
|
|
|
dmu_tx_t *tx;
|
|
|
|
|
|
|
|
if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (newvers < zfsvfs->z_version)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zfs_spa_version_map(newvers) >
|
2017-03-08 03:21:37 +03:00
|
|
|
spa_version(dmu_objset_spa(zfsvfs->z_os)))
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
tx = dmu_tx_create(os);
|
2009-07-03 02:44:48 +04:00
|
|
|
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR);
|
2017-03-08 03:21:37 +03:00
|
|
|
if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
|
2010-05-29 00:45:14 +04:00
|
|
|
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE,
|
|
|
|
ZFS_SA_ATTRS);
|
|
|
|
dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
error = dmu_tx_assign(tx, TXG_WAIT);
|
|
|
|
if (error) {
|
|
|
|
dmu_tx_abort(tx);
|
2009-07-03 02:44:48 +04:00
|
|
|
return (error);
|
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
|
|
|
|
8, 1, &newvers, tx);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
return (error);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
if (newvers >= ZPL_VERSION_SA && !zfsvfs->z_use_sa) {
|
2010-05-29 00:45:14 +04:00
|
|
|
uint64_t sa_obj;
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
ASSERT3U(spa_version(dmu_objset_spa(zfsvfs->z_os)), >=,
|
2010-05-29 00:45:14 +04:00
|
|
|
SPA_VERSION_SA);
|
|
|
|
sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
|
|
|
|
DMU_OT_NONE, 0, tx);
|
|
|
|
|
|
|
|
error = zap_add(os, MASTER_NODE_OBJ,
|
|
|
|
ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
|
2013-05-11 01:17:03 +04:00
|
|
|
ASSERT0(error);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
VERIFY(0 == sa_set_sa_object(os, sa_obj));
|
|
|
|
sa_register_update_callback(os, zfs_sa_upgrade);
|
|
|
|
}
|
|
|
|
|
2013-08-28 15:45:09 +04:00
|
|
|
spa_history_log_internal_ds(dmu_objset_ds(os), "upgrade", tx,
|
2017-03-08 03:21:37 +03:00
|
|
|
"from %llu to %llu", zfsvfs->z_version, newvers);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
dmu_tx_commit(tx);
|
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs->z_version = newvers;
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2017-03-08 03:21:37 +03:00
|
|
|
zfs_set_fuid_feature(zfsvfs);
|
2009-07-03 02:44:48 +04:00
|
|
|
|
|
|
|
return (0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a property stored within the master node.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value)
|
|
|
|
{
|
|
|
|
const char *pname;
|
2013-03-08 22:41:28 +04:00
|
|
|
int error = SET_ERROR(ENOENT);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up the file system's value for the property. For the
|
|
|
|
* version property, we look up a slightly different string.
|
|
|
|
*/
|
|
|
|
if (prop == ZFS_PROP_VERSION)
|
|
|
|
pname = ZPL_VERSION_STR;
|
|
|
|
else
|
|
|
|
pname = zfs_prop_to_name(prop);
|
|
|
|
|
2017-04-14 00:32:08 +03:00
|
|
|
if (os != NULL) {
|
|
|
|
ASSERT3U(os->os_phys->os_type, ==, DMU_OST_ZFS);
|
2008-12-03 23:09:06 +03:00
|
|
|
error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value);
|
2017-04-14 00:32:08 +03:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (error == ENOENT) {
|
|
|
|
/* No value set, use the default value */
|
|
|
|
switch (prop) {
|
|
|
|
case ZFS_PROP_VERSION:
|
|
|
|
*value = ZPL_VERSION;
|
|
|
|
break;
|
|
|
|
case ZFS_PROP_NORMALIZE:
|
|
|
|
case ZFS_PROP_UTF8ONLY:
|
|
|
|
*value = 0;
|
|
|
|
break;
|
|
|
|
case ZFS_PROP_CASE:
|
|
|
|
*value = ZFS_CASE_SENSITIVE;
|
|
|
|
break;
|
2013-10-28 20:22:15 +04:00
|
|
|
case ZFS_PROP_ACLTYPE:
|
|
|
|
*value = ZFS_ACLTYPE_OFF;
|
|
|
|
break;
|
2008-11-20 23:01:55 +03:00
|
|
|
default:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
2011-02-08 22:16:06 +03:00
|
|
|
|
2017-01-27 22:46:39 +03:00
|
|
|
/*
|
|
|
|
* Return true if the coresponding vfs's unmounted flag is set.
|
|
|
|
* Otherwise return false.
|
|
|
|
* If this function returns true we know VFS unmount has been initiated.
|
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
zfs_get_vfs_flag_unmounted(objset_t *os)
|
|
|
|
{
|
2017-03-08 03:21:37 +03:00
|
|
|
zfsvfs_t *zfvp;
|
2017-01-27 22:46:39 +03:00
|
|
|
boolean_t unmounted = B_FALSE;
|
|
|
|
|
|
|
|
ASSERT(dmu_objset_type(os) == DMU_OST_ZFS);
|
|
|
|
|
|
|
|
mutex_enter(&os->os_user_ptr_lock);
|
|
|
|
zfvp = dmu_objset_get_user(os);
|
|
|
|
if (zfvp != NULL && zfvp->z_unmounted)
|
|
|
|
unmounted = B_TRUE;
|
|
|
|
mutex_exit(&os->os_user_ptr_lock);
|
|
|
|
|
|
|
|
return (unmounted);
|
|
|
|
}
|
|
|
|
|
2011-02-08 22:16:06 +03:00
|
|
|
void
|
|
|
|
zfs_init(void)
|
|
|
|
{
|
2011-11-11 11:15:53 +04:00
|
|
|
zfsctl_init();
|
2011-02-08 22:16:06 +03:00
|
|
|
zfs_znode_init();
|
|
|
|
dmu_objset_register_type(DMU_OST_ZFS, zfs_space_delta_cb);
|
|
|
|
register_filesystem(&zpl_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zfs_fini(void)
|
|
|
|
{
|
2016-10-28 23:37:00 +03:00
|
|
|
/*
|
|
|
|
* we don't use outstanding because zpl_posix_acl_free might add more.
|
|
|
|
*/
|
2016-12-01 00:56:50 +03:00
|
|
|
taskq_wait(system_delay_taskq);
|
2016-10-28 23:37:00 +03:00
|
|
|
taskq_wait(system_taskq);
|
2011-02-08 22:16:06 +03:00
|
|
|
unregister_filesystem(&zpl_fs_type);
|
|
|
|
zfs_znode_fini();
|
2011-11-11 11:15:53 +04:00
|
|
|
zfsctl_fini();
|
2011-02-08 22:16:06 +03:00
|
|
|
}
|
2017-03-09 01:56:19 +03:00
|
|
|
|
|
|
|
#if defined(_KERNEL) && defined(HAVE_SPL)
|
|
|
|
EXPORT_SYMBOL(zfs_suspend_fs);
|
|
|
|
EXPORT_SYMBOL(zfs_resume_fs);
|
|
|
|
EXPORT_SYMBOL(zfs_userspace_one);
|
|
|
|
EXPORT_SYMBOL(zfs_userspace_many);
|
|
|
|
EXPORT_SYMBOL(zfs_set_userquota);
|
|
|
|
EXPORT_SYMBOL(zfs_owner_overquota);
|
|
|
|
EXPORT_SYMBOL(zfs_fuid_overquota);
|
|
|
|
EXPORT_SYMBOL(zfs_fuid_overobjquota);
|
|
|
|
EXPORT_SYMBOL(zfs_set_version);
|
|
|
|
EXPORT_SYMBOL(zfsvfs_create);
|
|
|
|
EXPORT_SYMBOL(zfsvfs_free);
|
|
|
|
EXPORT_SYMBOL(zfs_is_readonly);
|
|
|
|
EXPORT_SYMBOL(zfs_domount);
|
|
|
|
EXPORT_SYMBOL(zfs_preumount);
|
|
|
|
EXPORT_SYMBOL(zfs_umount);
|
|
|
|
EXPORT_SYMBOL(zfs_remount);
|
|
|
|
EXPORT_SYMBOL(zfs_statvfs);
|
|
|
|
EXPORT_SYMBOL(zfs_vget);
|
|
|
|
EXPORT_SYMBOL(zfs_prune);
|
|
|
|
#endif
|