2008-11-20 20:01:55 +00: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-28 20:45:14 +00:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2014-07-07 19:49:36 +00:00
|
|
|
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Portions Copyright 2007 Jeremy Teo */
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/mntent.h>
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#include <sys/u8_textprep.h>
|
|
|
|
#include <sys/dsl_dataset.h>
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
#include <sys/vfs_opreg.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/mode.h>
|
|
|
|
#include <sys/atomic.h>
|
|
|
|
#include <vm/pvn.h>
|
|
|
|
#include "fs/fs_subr.h"
|
|
|
|
#include <sys/zfs_dir.h>
|
|
|
|
#include <sys/zfs_acl.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
|
|
|
#include <sys/zfs_rlock.h>
|
|
|
|
#include <sys/zfs_fuid.h>
|
2011-02-08 19:16:06 +00:00
|
|
|
#include <sys/zfs_vnops.h>
|
2011-11-11 07:15:53 +00:00
|
|
|
#include <sys/zfs_ctldir.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/dnode.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/kidmap.h>
|
2011-02-08 19:16:06 +00:00
|
|
|
#include <sys/zpl.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
|
|
|
#include <sys/dmu.h>
|
2014-11-03 20:15:08 +00:00
|
|
|
#include <sys/dmu_objset.h>
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
#include <sys/dmu_tx.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/refcount.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/zap.h>
|
|
|
|
#include <sys/zfs_znode.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/sa.h>
|
|
|
|
#include <sys/zfs_sa.h>
|
2010-08-26 21:24:34 +00:00
|
|
|
#include <sys/zfs_stat.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
#include "zfs_prop.h"
|
2010-05-28 20:45:14 +00:00
|
|
|
#include "zfs_comutil.h"
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
|
|
|
* Define ZNODE_STATS to turn on statistic gathering. By default, it is only
|
|
|
|
* turned on when DEBUG is also defined.
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define ZNODE_STATS
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
#ifdef ZNODE_STATS
|
|
|
|
#define ZNODE_STAT_ADD(stat) ((stat)++)
|
|
|
|
#else
|
|
|
|
#define ZNODE_STAT_ADD(stat) /* nothing */
|
|
|
|
#endif /* ZNODE_STATS */
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Functions needed for userland (ie: libzpool) are not put under
|
|
|
|
* #ifdef_KERNEL; the rest of the functions have dependencies
|
|
|
|
* (such as VFS logic) that will not compile easily in userland.
|
|
|
|
*/
|
|
|
|
#ifdef _KERNEL
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
static kmem_cache_t *znode_cache = NULL;
|
2015-12-22 21:47:38 +00:00
|
|
|
static kmem_cache_t *znode_hold_cache = NULL;
|
2015-12-18 20:19:14 +00:00
|
|
|
unsigned int zfs_object_mutex_size = ZFS_OBJ_MTX_SZ;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static int
|
2008-12-03 20:09:06 +00:00
|
|
|
zfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
znode_t *zp = buf;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
inode_init_once(ZTOI(zp));
|
2008-12-03 20:09:06 +00:00
|
|
|
list_link_init(&zp->z_link_node);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
mutex_init(&zp->z_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
rw_init(&zp->z_parent_lock, NULL, RW_DEFAULT, NULL);
|
Identify locks flagged by lockdep
When running a kernel with CONFIG_LOCKDEP=y, lockdep reports possible
recursive locking in some cases and possible circular locking dependency
in others, within the SPL and ZFS modules.
This patch uses a mutex type defined in SPL, MUTEX_NOLOCKDEP, to mark
such mutexes when they are initialized. This mutex type causes
attempts to take or release those locks to be wrapped in lockdep_off()
and lockdep_on() calls to silence the dependency checker and allow the
use of lock_stats to examine contention.
For RW locks, it uses an analogous lock type, RW_NOLOCKDEP.
The goal is that these locks are ultimately changed back to type
MUTEX_DEFAULT or RW_DEFAULT, after the locks are annotated to reflect
their relationship (e.g. z_name_lock below) or any real problem with the
lock dependencies are fixed.
Some of the affected locks are:
tc_open_lock:
=============
This is an array of locks, all with same name, which txg_quiesce must
take all of in order to move txg to next state. All default to the same
lockdep class, and so to lockdep appears recursive.
zp->z_name_lock:
================
In zfs_rmdir,
dzp = znode for the directory (input to zfs_dirent_lock)
zp = znode for the entry being removed (output of zfs_dirent_lock)
zfs_rmdir()->zfs_dirent_lock() takes z_name_lock in dzp
zfs_rmdir() takes z_name_lock in zp
Since both dzp and zp are type znode_t, the locks have the same default
class, and lockdep considers it a possible recursive lock attempt.
l->l_rwlock:
============
zap_expand_leaf() sometimes creates two new zap leaf structures, via
these call paths:
zap_deref_leaf()->zap_get_leaf_byblk()->zap_leaf_open()
zap_expand_leaf()->zap_create_leaf()->zap_expand_leaf()->zap_create_leaf()
Because both zap_leaf_open() and zap_create_leaf() initialize
l->l_rwlock in their (separate) leaf structures, the lockdep class is
the same, and the linux kernel believes these might both be the same
lock, and emits a possible recursive lock warning.
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3895
2015-10-15 20:08:27 +00:00
|
|
|
rw_init(&zp->z_name_lock, NULL, RW_NOLOCKDEP, NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
|
2011-10-24 23:55:20 +00:00
|
|
|
rw_init(&zp->z_xattr_lock, NULL, RW_DEFAULT, NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2016-04-11 21:53:48 +00:00
|
|
|
zfs_rlock_init(&zp->z_range_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
zp->z_dirlocks = NULL;
|
2009-08-18 18:43:27 +00:00
|
|
|
zp->z_acl_cached = NULL;
|
2011-10-24 23:55:20 +00:00
|
|
|
zp->z_xattr_cached = NULL;
|
2016-10-13 00:30:46 +00:00
|
|
|
zp->z_xattr_parent = 0;
|
2010-08-26 21:24:34 +00:00
|
|
|
zp->z_moved = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static void
|
2008-12-03 20:09:06 +00:00
|
|
|
zfs_znode_cache_destructor(void *buf, void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
znode_t *zp = buf;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
ASSERT(!list_link_active(&zp->z_link_node));
|
2008-11-20 20:01:55 +00:00
|
|
|
mutex_destroy(&zp->z_lock);
|
|
|
|
rw_destroy(&zp->z_parent_lock);
|
|
|
|
rw_destroy(&zp->z_name_lock);
|
|
|
|
mutex_destroy(&zp->z_acl_lock);
|
2011-10-24 23:55:20 +00:00
|
|
|
rw_destroy(&zp->z_xattr_lock);
|
2016-04-11 21:53:48 +00:00
|
|
|
zfs_rlock_destroy(&zp->z_range_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
ASSERT(zp->z_dirlocks == NULL);
|
2009-08-18 18:43:27 +00:00
|
|
|
ASSERT(zp->z_acl_cached == NULL);
|
2011-10-24 23:55:20 +00:00
|
|
|
ASSERT(zp->z_xattr_cached == NULL);
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 21:47:38 +00:00
|
|
|
static int
|
|
|
|
zfs_znode_hold_cache_constructor(void *buf, void *arg, int kmflags)
|
|
|
|
{
|
|
|
|
znode_hold_t *zh = buf;
|
|
|
|
|
|
|
|
mutex_init(&zh->zh_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
refcount_create(&zh->zh_refcount);
|
|
|
|
zh->zh_obj = ZFS_NO_OBJECT;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zfs_znode_hold_cache_destructor(void *buf, void *arg)
|
|
|
|
{
|
|
|
|
znode_hold_t *zh = buf;
|
|
|
|
|
|
|
|
mutex_destroy(&zh->zh_lock);
|
|
|
|
refcount_destroy(&zh->zh_refcount);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
void
|
|
|
|
zfs_znode_init(void)
|
|
|
|
{
|
|
|
|
/*
|
2015-04-14 05:06:40 +00:00
|
|
|
* Initialize zcache. The KMC_SLAB hint is used in order that it be
|
|
|
|
* backed by kmalloc() when on the Linux slab in order that any
|
|
|
|
* wait_on_bit() operations on the related inode operate properly.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
ASSERT(znode_cache == NULL);
|
|
|
|
znode_cache = kmem_cache_create("zfs_znode_cache",
|
|
|
|
sizeof (znode_t), 0, zfs_znode_cache_constructor,
|
2015-04-14 05:06:40 +00:00
|
|
|
zfs_znode_cache_destructor, NULL, NULL, NULL, KMC_SLAB);
|
2015-12-22 21:47:38 +00:00
|
|
|
|
|
|
|
ASSERT(znode_hold_cache == NULL);
|
|
|
|
znode_hold_cache = kmem_cache_create("zfs_znode_hold_cache",
|
|
|
|
sizeof (znode_hold_t), 0, zfs_znode_hold_cache_constructor,
|
|
|
|
zfs_znode_hold_cache_destructor, NULL, NULL, NULL, 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zfs_znode_fini(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Cleanup zcache
|
|
|
|
*/
|
|
|
|
if (znode_cache)
|
|
|
|
kmem_cache_destroy(znode_cache);
|
|
|
|
znode_cache = NULL;
|
2015-12-22 21:47:38 +00:00
|
|
|
|
|
|
|
if (znode_hold_cache)
|
|
|
|
kmem_cache_destroy(znode_hold_cache);
|
|
|
|
znode_hold_cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The zfs_znode_hold_enter() / zfs_znode_hold_exit() functions are used to
|
|
|
|
* serialize access to a znode and its SA buffer while the object is being
|
|
|
|
* created or destroyed. This kind of locking would normally reside in the
|
|
|
|
* znode itself but in this case that's impossible because the znode and SA
|
|
|
|
* buffer may not yet exist. Therefore the locking is handled externally
|
|
|
|
* with an array of mutexs and AVLs trees which contain per-object locks.
|
|
|
|
*
|
|
|
|
* In zfs_znode_hold_enter() a per-object lock is created as needed, inserted
|
|
|
|
* in to the correct AVL tree and finally the per-object lock is held. In
|
|
|
|
* zfs_znode_hold_exit() the process is reversed. The per-object lock is
|
|
|
|
* released, removed from the AVL tree and destroyed if there are no waiters.
|
|
|
|
*
|
|
|
|
* This scheme has two important properties:
|
|
|
|
*
|
|
|
|
* 1) No memory allocations are performed while holding one of the z_hold_locks.
|
|
|
|
* This ensures evict(), which can be called from direct memory reclaim, will
|
|
|
|
* never block waiting on a z_hold_locks which just happens to have hashed
|
|
|
|
* to the same index.
|
|
|
|
*
|
|
|
|
* 2) All locks used to serialize access to an object are per-object and never
|
|
|
|
* shared. This minimizes lock contention without creating a large number
|
|
|
|
* of dedicated locks.
|
|
|
|
*
|
|
|
|
* On the downside it does require znode_lock_t structures to be frequently
|
|
|
|
* allocated and freed. However, because these are backed by a kmem cache
|
|
|
|
* and very short lived this cost is minimal.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_znode_hold_compare(const void *a, const void *b)
|
|
|
|
{
|
2016-08-27 18:12:53 +00:00
|
|
|
const znode_hold_t *zh_a = (const znode_hold_t *)a;
|
|
|
|
const znode_hold_t *zh_b = (const znode_hold_t *)b;
|
|
|
|
|
|
|
|
return (AVL_CMP(zh_a->zh_obj, zh_b->zh_obj));
|
2015-12-22 21:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_held(zfsvfs_t *zfsvfs, uint64_t obj)
|
2015-12-22 21:47:38 +00:00
|
|
|
{
|
|
|
|
znode_hold_t *zh, search;
|
2017-03-08 00:21:37 +00:00
|
|
|
int i = ZFS_OBJ_HASH(zfsvfs, obj);
|
2016-01-19 18:41:21 +00:00
|
|
|
boolean_t held;
|
2015-12-22 21:47:38 +00:00
|
|
|
|
|
|
|
search.zh_obj = obj;
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_enter(&zfsvfs->z_hold_locks[i]);
|
|
|
|
zh = avl_find(&zfsvfs->z_hold_trees[i], &search, NULL);
|
2016-01-19 18:41:21 +00:00
|
|
|
held = (zh && MUTEX_HELD(&zh->zh_lock)) ? B_TRUE : B_FALSE;
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_exit(&zfsvfs->z_hold_locks[i]);
|
2015-12-22 21:47:38 +00:00
|
|
|
|
2016-01-19 18:41:21 +00:00
|
|
|
return (held);
|
2015-12-22 21:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static znode_hold_t *
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_enter(zfsvfs_t *zfsvfs, uint64_t obj)
|
2015-12-22 21:47:38 +00:00
|
|
|
{
|
|
|
|
znode_hold_t *zh, *zh_new, search;
|
2017-03-08 00:21:37 +00:00
|
|
|
int i = ZFS_OBJ_HASH(zfsvfs, obj);
|
2015-12-22 21:47:38 +00:00
|
|
|
boolean_t found = B_FALSE;
|
|
|
|
|
|
|
|
zh_new = kmem_cache_alloc(znode_hold_cache, KM_SLEEP);
|
|
|
|
zh_new->zh_obj = obj;
|
|
|
|
search.zh_obj = obj;
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_enter(&zfsvfs->z_hold_locks[i]);
|
|
|
|
zh = avl_find(&zfsvfs->z_hold_trees[i], &search, NULL);
|
2015-12-22 21:47:38 +00:00
|
|
|
if (likely(zh == NULL)) {
|
|
|
|
zh = zh_new;
|
2017-03-08 00:21:37 +00:00
|
|
|
avl_add(&zfsvfs->z_hold_trees[i], zh);
|
2015-12-22 21:47:38 +00:00
|
|
|
} else {
|
|
|
|
ASSERT3U(zh->zh_obj, ==, obj);
|
|
|
|
found = B_TRUE;
|
|
|
|
}
|
|
|
|
refcount_add(&zh->zh_refcount, NULL);
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_exit(&zfsvfs->z_hold_locks[i]);
|
2015-12-22 21:47:38 +00:00
|
|
|
|
|
|
|
if (found == B_TRUE)
|
|
|
|
kmem_cache_free(znode_hold_cache, zh_new);
|
|
|
|
|
|
|
|
ASSERT(MUTEX_NOT_HELD(&zh->zh_lock));
|
|
|
|
ASSERT3S(refcount_count(&zh->zh_refcount), >, 0);
|
|
|
|
mutex_enter(&zh->zh_lock);
|
|
|
|
|
|
|
|
return (zh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs_t *zfsvfs, znode_hold_t *zh)
|
2015-12-22 21:47:38 +00:00
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
int i = ZFS_OBJ_HASH(zfsvfs, zh->zh_obj);
|
2015-12-22 21:47:38 +00:00
|
|
|
boolean_t remove = B_FALSE;
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
ASSERT(zfs_znode_held(zfsvfs, zh->zh_obj));
|
2015-12-22 21:47:38 +00:00
|
|
|
ASSERT3S(refcount_count(&zh->zh_refcount), >, 0);
|
|
|
|
mutex_exit(&zh->zh_lock);
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_enter(&zfsvfs->z_hold_locks[i]);
|
2015-12-22 21:47:38 +00:00
|
|
|
if (refcount_remove(&zh->zh_refcount, NULL) == 0) {
|
2017-03-08 00:21:37 +00:00
|
|
|
avl_remove(&zfsvfs->z_hold_trees[i], zh);
|
2015-12-22 21:47:38 +00:00
|
|
|
remove = B_TRUE;
|
|
|
|
}
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_exit(&zfsvfs->z_hold_locks[i]);
|
2015-12-22 21:47:38 +00:00
|
|
|
|
|
|
|
if (remove == B_TRUE)
|
|
|
|
kmem_cache_free(znode_hold_cache, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_create_share_dir(zfsvfs_t *zfsvfs, dmu_tx_t *tx)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-07-02 19:34:12 +00:00
|
|
|
#ifdef HAVE_SMB_SHARE
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_acl_ids_t acl_ids;
|
|
|
|
vattr_t vattr;
|
|
|
|
znode_t *sharezp;
|
|
|
|
vnode_t *vp;
|
|
|
|
znode_t *zp;
|
|
|
|
int error;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
|
2011-02-08 19:16:06 +00:00
|
|
|
vattr.va_mode = S_IFDIR | 0555;
|
2009-07-02 22:44:48 +00:00
|
|
|
vattr.va_uid = crgetuid(kcred);
|
|
|
|
vattr.va_gid = crgetgid(kcred);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2014-11-21 00:09:39 +00:00
|
|
|
sharezp = kmem_cache_alloc(znode_cache, KM_SLEEP);
|
2010-08-26 21:24:34 +00:00
|
|
|
sharezp->z_moved = 0;
|
2009-07-02 22:44:48 +00:00
|
|
|
sharezp->z_unlinked = 0;
|
|
|
|
sharezp->z_atime_dirty = 0;
|
|
|
|
sharezp->z_zfsvfs = zfsvfs;
|
2010-05-28 20:45:14 +00:00
|
|
|
sharezp->z_is_sa = zfsvfs->z_use_sa;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
vp = ZTOV(sharezp);
|
|
|
|
vn_reinit(vp);
|
|
|
|
vp->v_type = VDIR;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
VERIFY(0 == zfs_acl_ids_create(sharezp, IS_ROOT_NODE, &vattr,
|
|
|
|
kcred, NULL, &acl_ids));
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_mknode(sharezp, &vattr, tx, kcred, IS_ROOT_NODE, &zp, &acl_ids);
|
2009-07-02 22:44:48 +00:00
|
|
|
ASSERT3P(zp, ==, sharezp);
|
|
|
|
ASSERT(!vn_in_dnlc(ZTOV(sharezp))); /* not valid to move */
|
|
|
|
POINTER_INVALIDATE(&sharezp->z_zfsvfs);
|
|
|
|
error = zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
|
|
|
|
ZFS_SHARES_DIR, 8, 1, &sharezp->z_id, tx);
|
|
|
|
zfsvfs->z_shares_dir = sharezp->z_id;
|
|
|
|
|
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2011-02-08 19:16:06 +00:00
|
|
|
// ZTOV(sharezp)->v_count = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
sa_handle_destroy(sharezp->z_sa_hdl);
|
2009-07-02 22:44:48 +00:00
|
|
|
kmem_cache_free(znode_cache, sharezp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
return (error);
|
2011-01-07 19:51:27 +00:00
|
|
|
#else
|
|
|
|
return (0);
|
2011-07-02 19:34:12 +00:00
|
|
|
#endif /* HAVE_SMB_SHARE */
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_sa_init(zfsvfs_t *zfsvfs, znode_t *zp,
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_buf_t *db, dmu_object_type_t obj_type, sa_handle_t *sa_hdl)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
ASSERT(zfs_znode_held(zfsvfs, zp->z_id));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
mutex_enter(&zp->z_lock);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(zp->z_sa_hdl == NULL);
|
|
|
|
ASSERT(zp->z_acl_cached == NULL);
|
|
|
|
if (sa_hdl == NULL) {
|
2017-03-08 00:21:37 +00:00
|
|
|
VERIFY(0 == sa_handle_get_from_db(zfsvfs->z_os, db, zp,
|
2010-05-28 20:45:14 +00:00
|
|
|
SA_HDL_SHARED, &zp->z_sa_hdl));
|
|
|
|
} else {
|
|
|
|
zp->z_sa_hdl = sa_hdl;
|
|
|
|
sa_set_userp(sa_hdl, zp);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zp->z_is_sa = (obj_type == DMU_OT_SA) ? B_TRUE : B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zfs_znode_dmu_fini(znode_t *zp)
|
|
|
|
{
|
2015-12-22 21:47:38 +00:00
|
|
|
ASSERT(zfs_znode_held(ZTOZSB(zp), zp->z_id) || zp->z_unlinked ||
|
2011-02-08 19:16:06 +00:00
|
|
|
RW_WRITE_HELD(&ZTOZSB(zp)->z_teardown_inactive_lock));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
sa_handle_destroy(zp->z_sa_hdl);
|
|
|
|
zp->z_sa_hdl = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-02-08 19:16:06 +00:00
|
|
|
* Called by new_inode() to allocate a new inode.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_inode_alloc(struct super_block *sb, struct inode **ip)
|
|
|
|
{
|
|
|
|
znode_t *zp;
|
|
|
|
|
2014-11-21 00:09:39 +00:00
|
|
|
zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
|
2011-02-08 19:16:06 +00:00
|
|
|
*ip = ZTOI(zp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called in multiple places when an inode should be destroyed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
zfs_inode_destroy(struct inode *ip)
|
|
|
|
{
|
|
|
|
znode_t *zp = ITOZ(ip);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_enter(&zfsvfs->z_znodes_lock);
|
2013-01-16 00:41:09 +00:00
|
|
|
if (list_link_active(&zp->z_link_node)) {
|
2017-03-08 00:21:37 +00:00
|
|
|
list_remove(&zfsvfs->z_all_znodes, zp);
|
|
|
|
zfsvfs->z_nr_znodes--;
|
2013-01-16 00:41:09 +00:00
|
|
|
}
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_exit(&zfsvfs->z_znodes_lock);
|
2011-02-08 19:16:06 +00:00
|
|
|
|
|
|
|
if (zp->z_acl_cached) {
|
|
|
|
zfs_acl_free(zp->z_acl_cached);
|
|
|
|
zp->z_acl_cached = NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-24 23:55:20 +00:00
|
|
|
if (zp->z_xattr_cached) {
|
|
|
|
nvlist_free(zp->z_xattr_cached);
|
|
|
|
zp->z_xattr_cached = NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
kmem_cache_free(znode_cache, zp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_inode_set_ops(zfsvfs_t *zfsvfs, struct inode *ip)
|
2011-02-08 19:16:06 +00:00
|
|
|
{
|
2011-05-09 19:31:56 +00:00
|
|
|
uint64_t rdev = 0;
|
2011-02-08 19:16:06 +00:00
|
|
|
|
|
|
|
switch (ip->i_mode & S_IFMT) {
|
|
|
|
case S_IFREG:
|
|
|
|
ip->i_op = &zpl_inode_operations;
|
|
|
|
ip->i_fop = &zpl_file_operations;
|
|
|
|
ip->i_mapping->a_ops = &zpl_address_space_operations;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFDIR:
|
|
|
|
ip->i_op = &zpl_dir_inode_operations;
|
|
|
|
ip->i_fop = &zpl_dir_file_operations;
|
|
|
|
ITOZ(ip)->z_zn_prefetch = B_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFLNK:
|
|
|
|
ip->i_op = &zpl_symlink_inode_operations;
|
|
|
|
break;
|
|
|
|
|
2011-05-09 19:31:56 +00:00
|
|
|
/*
|
|
|
|
* rdev is only stored in a SA only for device files.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
case S_IFCHR:
|
|
|
|
case S_IFBLK:
|
2017-03-08 00:21:37 +00:00
|
|
|
(void) sa_lookup(ITOZ(ip)->z_sa_hdl, SA_ZPL_RDEV(zfsvfs), &rdev,
|
2015-07-13 21:51:59 +00:00
|
|
|
sizeof (rdev));
|
2011-05-09 19:31:56 +00:00
|
|
|
/*FALLTHROUGH*/
|
|
|
|
case S_IFIFO:
|
|
|
|
case S_IFSOCK:
|
2011-02-08 19:16:06 +00:00
|
|
|
init_special_inode(ip, ip->i_mode, rdev);
|
|
|
|
ip->i_op = &zpl_special_inode_operations;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-07-13 21:51:59 +00:00
|
|
|
zfs_panic_recover("inode %llu has invalid mode: 0x%x\n",
|
|
|
|
(u_longlong_t)ip->i_ino, ip->i_mode);
|
|
|
|
|
|
|
|
/* Assume the inode is a file and attempt to continue */
|
|
|
|
ip->i_mode = S_IFREG | 0644;
|
|
|
|
ip->i_op = &zpl_inode_operations;
|
|
|
|
ip->i_fop = &zpl_file_operations;
|
|
|
|
ip->i_mapping->a_ops = &zpl_address_space_operations;
|
|
|
|
break;
|
2011-02-08 19:16:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 22:18:53 +00:00
|
|
|
void
|
|
|
|
zfs_set_inode_flags(znode_t *zp, struct inode *ip)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Linux and Solaris have different sets of file attributes, so we
|
|
|
|
* restrict this conversion to the intersection of the two.
|
|
|
|
*/
|
2016-12-16 21:54:51 +00:00
|
|
|
#ifdef HAVE_INODE_SET_FLAGS
|
|
|
|
unsigned int flags = 0;
|
|
|
|
if (zp->z_pflags & ZFS_IMMUTABLE)
|
|
|
|
flags |= S_IMMUTABLE;
|
|
|
|
if (zp->z_pflags & ZFS_APPENDONLY)
|
|
|
|
flags |= S_APPEND;
|
2016-12-14 22:18:53 +00:00
|
|
|
|
2016-12-16 21:54:51 +00:00
|
|
|
inode_set_flags(ip, flags, S_IMMUTABLE|S_APPEND);
|
|
|
|
#else
|
2016-12-14 22:18:53 +00:00
|
|
|
if (zp->z_pflags & ZFS_IMMUTABLE)
|
|
|
|
ip->i_flags |= S_IMMUTABLE;
|
|
|
|
else
|
|
|
|
ip->i_flags &= ~S_IMMUTABLE;
|
|
|
|
|
|
|
|
if (zp->z_pflags & ZFS_APPENDONLY)
|
|
|
|
ip->i_flags |= S_APPEND;
|
|
|
|
else
|
|
|
|
ip->i_flags &= ~S_APPEND;
|
2016-12-16 21:54:51 +00:00
|
|
|
#endif
|
2016-12-14 22:18:53 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 23:52:03 +00:00
|
|
|
/*
|
|
|
|
* Update the embedded inode given the znode. We should work toward
|
|
|
|
* eliminating this function as soon as possible by removing values
|
|
|
|
* which are duplicated between the znode and inode. If the generic
|
|
|
|
* inode has the correct field it should be used, and the ZFS code
|
|
|
|
* updated to access the inode. This can be done incrementally.
|
|
|
|
*/
|
2016-08-01 20:02:25 +00:00
|
|
|
void
|
|
|
|
zfs_inode_update(znode_t *zp)
|
2016-03-31 23:52:03 +00:00
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs;
|
2016-03-31 23:52:03 +00:00
|
|
|
struct inode *ip;
|
|
|
|
uint32_t blksize;
|
|
|
|
u_longlong_t i_blocks;
|
|
|
|
|
|
|
|
ASSERT(zp != NULL);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs = ZTOZSB(zp);
|
2016-03-31 23:52:03 +00:00
|
|
|
ip = ZTOI(zp);
|
|
|
|
|
|
|
|
/* Skip .zfs control nodes which do not exist on disk. */
|
|
|
|
if (zfsctl_is_node(ip))
|
|
|
|
return;
|
|
|
|
|
|
|
|
dmu_object_size_from_db(sa_get_db(zp->z_sa_hdl), &blksize, &i_blocks);
|
|
|
|
|
|
|
|
spin_lock(&ip->i_lock);
|
|
|
|
ip->i_blocks = i_blocks;
|
|
|
|
i_size_write(ip, zp->z_size);
|
|
|
|
spin_unlock(&ip->i_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
/*
|
|
|
|
* Construct a znode+inode and initialize.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* This does not do a call to dmu_set_user() that is
|
|
|
|
* up to the caller to do, in case you don't want to
|
|
|
|
* return the znode
|
|
|
|
*/
|
|
|
|
static znode_t *
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
|
2016-07-06 00:24:36 +00:00
|
|
|
dmu_object_type_t obj_type, uint64_t obj, sa_handle_t *hdl)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
znode_t *zp;
|
2011-02-08 19:16:06 +00:00
|
|
|
struct inode *ip;
|
2014-01-07 22:16:46 +00:00
|
|
|
uint64_t mode;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t parent;
|
2016-04-18 19:08:53 +00:00
|
|
|
uint64_t tmp_gen;
|
2016-07-14 14:44:38 +00:00
|
|
|
uint64_t links;
|
2016-05-22 11:15:57 +00:00
|
|
|
uint64_t z_uid, z_gid;
|
2016-08-01 20:02:25 +00:00
|
|
|
uint64_t atime[2], mtime[2], ctime[2];
|
|
|
|
sa_bulk_attr_t bulk[11];
|
2010-05-28 20:45:14 +00:00
|
|
|
int count = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
ASSERT(zfsvfs != NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
ip = new_inode(zfsvfs->z_sb);
|
2011-02-08 19:16:06 +00:00
|
|
|
if (ip == NULL)
|
|
|
|
return (NULL);
|
2011-01-05 21:16:12 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
zp = ITOZ(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
ASSERT(zp->z_dirlocks == NULL);
|
2011-11-11 07:15:53 +00:00
|
|
|
ASSERT3P(zp->z_acl_cached, ==, NULL);
|
|
|
|
ASSERT3P(zp->z_xattr_cached, ==, NULL);
|
2010-08-26 21:24:34 +00:00
|
|
|
zp->z_moved = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
zp->z_sa_hdl = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
zp->z_unlinked = 0;
|
|
|
|
zp->z_atime_dirty = 0;
|
|
|
|
zp->z_mapcnt = 0;
|
|
|
|
zp->z_id = db->db_object;
|
|
|
|
zp->z_blksz = blksz;
|
|
|
|
zp->z_seq = 0x7A4653;
|
|
|
|
zp->z_sync_cnt = 0;
|
2011-11-11 07:15:53 +00:00
|
|
|
zp->z_is_mapped = B_FALSE;
|
|
|
|
zp->z_is_ctldir = B_FALSE;
|
2013-01-16 00:41:09 +00:00
|
|
|
zp->z_is_stale = B_FALSE;
|
2016-04-11 21:53:48 +00:00
|
|
|
zp->z_range_lock.zr_size = &zp->z_size;
|
|
|
|
zp->z_range_lock.zr_blksz = &zp->z_blksz;
|
|
|
|
zp->z_range_lock.zr_max_blksz = &ZTOZSB(zp)->z_max_blksz;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_sa_init(zfsvfs, zp, db, obj_type, hdl);
|
2011-02-08 19:16:06 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL, &mode, 8);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zfsvfs), NULL, &tmp_gen, 8);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
|
|
|
|
&zp->z_size, 8);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL, &links, 8);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_pflags, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL,
|
2011-01-05 21:16:12 +00:00
|
|
|
&parent, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL, &z_uid, 8);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL, &z_gid, 8);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL, &atime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2016-12-12 18:46:26 +00:00
|
|
|
if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count) != 0 || tmp_gen == 0) {
|
2010-05-28 20:45:14 +00:00
|
|
|
if (hdl == NULL)
|
|
|
|
sa_handle_destroy(zp->z_sa_hdl);
|
2015-10-09 19:27:01 +00:00
|
|
|
zp->z_sa_hdl = NULL;
|
2011-02-08 19:16:06 +00:00
|
|
|
goto error;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2011-01-05 21:16:12 +00:00
|
|
|
|
2016-09-27 21:08:52 +00:00
|
|
|
zp->z_mode = ip->i_mode = mode;
|
2016-04-18 19:08:53 +00:00
|
|
|
ip->i_generation = (uint32_t)tmp_gen;
|
2016-07-29 17:02:59 +00:00
|
|
|
ip->i_blkbits = SPA_MINBLOCKSHIFT;
|
2016-07-14 14:44:38 +00:00
|
|
|
set_nlink(ip, (uint32_t)links);
|
2016-05-22 11:15:57 +00:00
|
|
|
zfs_uid_write(ip, z_uid);
|
|
|
|
zfs_gid_write(ip, z_gid);
|
2016-12-14 22:18:53 +00:00
|
|
|
zfs_set_inode_flags(zp, ip);
|
2014-01-07 22:16:46 +00:00
|
|
|
|
2016-10-13 00:30:46 +00:00
|
|
|
/* Cache the xattr parent id */
|
|
|
|
if (zp->z_pflags & ZFS_XATTR)
|
|
|
|
zp->z_xattr_parent = parent;
|
|
|
|
|
2016-08-01 20:02:25 +00:00
|
|
|
ZFS_TIME_DECODE(&ip->i_atime, atime);
|
|
|
|
ZFS_TIME_DECODE(&ip->i_mtime, mtime);
|
|
|
|
ZFS_TIME_DECODE(&ip->i_ctime, ctime);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ip->i_ino = obj;
|
2016-08-01 20:02:25 +00:00
|
|
|
zfs_inode_update(zp);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_inode_set_ops(zfsvfs, ip);
|
2011-02-08 19:16:06 +00:00
|
|
|
|
2013-01-16 00:41:09 +00:00
|
|
|
/*
|
|
|
|
* The only way insert_inode_locked() can fail is if the ip->i_ino
|
|
|
|
* number is already hashed for this super block. This can never
|
|
|
|
* happen because the inode numbers map 1:1 with the object numbers.
|
|
|
|
*
|
|
|
|
* The one exception is rolling back a mounted file system, but in
|
|
|
|
* this case all the active inode are unhashed during the rollback.
|
|
|
|
*/
|
|
|
|
VERIFY3S(insert_inode_locked(ip), ==, 0);
|
2011-03-30 06:04:39 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_enter(&zfsvfs->z_znodes_lock);
|
|
|
|
list_insert_tail(&zfsvfs->z_all_znodes, zp);
|
|
|
|
zfsvfs->z_nr_znodes++;
|
2008-12-03 20:09:06 +00:00
|
|
|
membar_producer();
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_exit(&zfsvfs->z_znodes_lock);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
unlock_new_inode(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
iput(ip);
|
2013-11-01 19:26:11 +00:00
|
|
|
return (NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2014-07-15 20:29:57 +00:00
|
|
|
/*
|
|
|
|
* Safely mark an inode dirty. Inodes which are part of a read-only
|
|
|
|
* file system or snapshot may not be dirtied.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
zfs_mark_inode_dirty(struct inode *ip)
|
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ITOZSB(ip);
|
2014-07-15 20:29:57 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
if (zfs_is_readonly(zfsvfs) || dmu_objset_is_snapshot(zfsvfs->z_os))
|
2014-07-15 20:29:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
mark_inode_dirty(ip);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
static uint64_t empty_xattr;
|
|
|
|
static uint64_t pad[4];
|
|
|
|
static zfs_acl_phys_t acl_phys;
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Create a new DMU object to hold a zfs znode.
|
|
|
|
*
|
|
|
|
* IN: dzp - parent directory for new znode
|
|
|
|
* vap - file attributes for new znode
|
|
|
|
* tx - dmu transaction id for zap operations
|
|
|
|
* cr - credentials of caller
|
|
|
|
* flag - flags:
|
|
|
|
* IS_ROOT_NODE - new object will be root
|
|
|
|
* IS_XATTR - new object is an attribute
|
|
|
|
* bonuslen - length of bonus buffer
|
|
|
|
* setaclp - File/Dir initial ACL
|
|
|
|
* fuidp - Tracks fuid allocation.
|
|
|
|
*
|
|
|
|
* OUT: zpp - allocated znode
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
|
2010-05-28 20:45:14 +00:00
|
|
|
uint_t flag, znode_t **zpp, zfs_acl_ids_t *acl_ids)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t crtime[2], atime[2], mtime[2], ctime[2];
|
|
|
|
uint64_t mode, size, links, parent, pflags;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t dzp_pflags = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t rdev = 0;
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(dzp);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_buf_t *db;
|
2008-11-20 20:01:55 +00:00
|
|
|
timestruc_t now;
|
|
|
|
uint64_t gen, obj;
|
2010-05-28 20:45:14 +00:00
|
|
|
int bonuslen;
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
int dnodesize;
|
2010-05-28 20:45:14 +00:00
|
|
|
sa_handle_t *sa_hdl;
|
|
|
|
dmu_object_type_t obj_type;
|
2011-01-07 21:47:47 +00:00
|
|
|
sa_bulk_attr_t *sa_attrs;
|
2010-05-28 20:45:14 +00:00
|
|
|
int cnt = 0;
|
|
|
|
zfs_acl_locator_cb_t locate = { 0 };
|
2015-12-22 21:47:38 +00:00
|
|
|
znode_hold_t *zh;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
if (zfsvfs->z_replay) {
|
2008-11-20 20:01:55 +00:00
|
|
|
obj = vap->va_nodeid;
|
|
|
|
now = vap->va_ctime; /* see zfs_replay_create() */
|
|
|
|
gen = vap->va_nblocks; /* ditto */
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
dnodesize = vap->va_fsid; /* ditto */
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
obj = 0;
|
|
|
|
gethrestime(&now);
|
|
|
|
gen = dmu_tx_get_txg(tx);
|
2017-03-08 00:21:37 +00:00
|
|
|
dnodesize = dmu_objset_dnodesize(zfsvfs->z_os);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
if (dnodesize == 0)
|
|
|
|
dnodesize = DNODE_MIN_SIZE;
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
obj_type = zfsvfs->z_use_sa ? DMU_OT_SA : DMU_OT_ZNODE;
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
bonuslen = (obj_type == DMU_OT_SA) ?
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
DN_BONUS_SIZE(dnodesize) : ZFS_OLD_ZNODE_PHYS_SIZE;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Create a new DMU object.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* There's currently no mechanism for pre-reading the blocks that will
|
2010-08-26 21:24:34 +00:00
|
|
|
* be needed to allocate a new object, so we accept the small chance
|
2008-11-20 20:01:55 +00:00
|
|
|
* that there will be an i/o error and we will fail one of the
|
|
|
|
* assertions below.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(vap->va_mode)) {
|
2017-03-08 00:21:37 +00:00
|
|
|
if (zfsvfs->z_replay) {
|
|
|
|
VERIFY0(zap_create_claim_norm_dnsize(zfsvfs->z_os, obj,
|
|
|
|
zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
obj_type, bonuslen, dnodesize, tx));
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2017-03-08 00:21:37 +00:00
|
|
|
obj = zap_create_norm_dnsize(zfsvfs->z_os,
|
|
|
|
zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
obj_type, bonuslen, dnodesize, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-08 00:21:37 +00:00
|
|
|
if (zfsvfs->z_replay) {
|
|
|
|
VERIFY0(dmu_object_claim_dnsize(zfsvfs->z_os, obj,
|
2008-11-20 20:01:55 +00:00
|
|
|
DMU_OT_PLAIN_FILE_CONTENTS, 0,
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
obj_type, bonuslen, dnodesize, tx));
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2017-03-08 00:21:37 +00:00
|
|
|
obj = dmu_object_alloc_dnsize(zfsvfs->z_os,
|
2008-11-20 20:01:55 +00:00
|
|
|
DMU_OT_PLAIN_FILE_CONTENTS, 0,
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
obj_type, bonuslen, dnodesize, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zh = zfs_znode_hold_enter(zfsvfs, obj);
|
2017-08-08 15:38:53 +00:00
|
|
|
VERIFY0(sa_buf_hold(zfsvfs->z_os, obj, NULL, &db));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the root, fix up the half-initialized parent pointer
|
|
|
|
* to reference the just-allocated physical data area.
|
|
|
|
*/
|
|
|
|
if (flag & IS_ROOT_NODE) {
|
|
|
|
dzp->z_id = obj;
|
2010-05-28 20:45:14 +00:00
|
|
|
} else {
|
|
|
|
dzp_pflags = dzp->z_pflags;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If parent is an xattr, so am I.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (dzp_pflags & ZFS_XATTR) {
|
2008-11-20 20:01:55 +00:00
|
|
|
flag |= IS_XATTR;
|
|
|
|
}
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
if (zfsvfs->z_use_fuids)
|
2010-05-28 20:45:14 +00:00
|
|
|
pflags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
|
|
|
|
else
|
|
|
|
pflags = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(vap->va_mode)) {
|
2010-05-28 20:45:14 +00:00
|
|
|
size = 2; /* contents ("." and "..") */
|
2016-07-14 14:44:38 +00:00
|
|
|
links = 2;
|
2010-05-28 20:45:14 +00:00
|
|
|
} else {
|
2016-07-14 14:44:38 +00:00
|
|
|
size = 0;
|
2016-01-26 20:29:46 +00:00
|
|
|
links = (flag & IS_TMPFILE) ? 0 : 1;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-09 19:31:56 +00:00
|
|
|
if (S_ISBLK(vap->va_mode) || S_ISCHR(vap->va_mode))
|
2011-02-23 23:13:03 +00:00
|
|
|
rdev = vap->va_rdev;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
parent = dzp->z_id;
|
|
|
|
mode = acl_ids->z_mode;
|
2008-11-20 20:01:55 +00:00
|
|
|
if (flag & IS_XATTR)
|
2010-05-28 20:45:14 +00:00
|
|
|
pflags |= ZFS_XATTR;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* No execs denied will be deterimed when zfs_mode_compute() is called.
|
|
|
|
*/
|
|
|
|
pflags |= acl_ids->z_aclp->z_hints &
|
|
|
|
(ZFS_ACL_TRIVIAL|ZFS_INHERIT_ACE|ZFS_ACL_AUTO_INHERIT|
|
|
|
|
ZFS_ACL_DEFAULTED|ZFS_ACL_PROTECTED);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_TIME_ENCODE(&now, crtime);
|
|
|
|
ZFS_TIME_ENCODE(&now, ctime);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (vap->va_mask & ATTR_ATIME) {
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_TIME_ENCODE(&vap->va_atime, atime);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_TIME_ENCODE(&now, atime);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (vap->va_mask & ATTR_MTIME) {
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
|
|
|
|
} else {
|
|
|
|
ZFS_TIME_ENCODE(&now, mtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now add in all of the "SA" attributes */
|
2017-03-08 00:21:37 +00:00
|
|
|
VERIFY(0 == sa_handle_get_from_db(zfsvfs->z_os, db, NULL, SA_HDL_SHARED,
|
2010-05-28 20:45:14 +00:00
|
|
|
&sa_hdl));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the array of attributes to be replaced/set on the new file
|
|
|
|
*
|
|
|
|
* order for DMU_OT_ZNODE is critical since it needs to be constructed
|
|
|
|
* in the old znode_phys_t format. Don't change this ordering
|
|
|
|
*/
|
2014-11-21 00:09:39 +00:00
|
|
|
sa_attrs = kmem_alloc(sizeof (sa_bulk_attr_t) * ZPL_END, KM_SLEEP);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (obj_type == DMU_OT_ZNODE) {
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &atime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &mtime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &ctime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &crtime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &gen, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &mode, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &size, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &parent, 8);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &mode, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &size, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &gen, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zfsvfs),
|
2011-02-08 19:16:06 +00:00
|
|
|
NULL, &acl_ids->z_fuid, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zfsvfs),
|
2011-02-08 19:16:06 +00:00
|
|
|
NULL, &acl_ids->z_fgid, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &parent, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &pflags, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &atime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &mtime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &ctime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &crtime, 16);
|
|
|
|
}
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_LINKS(zfsvfs), NULL, &links, 8);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (obj_type == DMU_OT_ZNODE) {
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_XATTR(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&empty_xattr, 8);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
if (obj_type == DMU_OT_ZNODE ||
|
2011-05-09 19:31:56 +00:00
|
|
|
(S_ISBLK(vap->va_mode) || S_ISCHR(vap->va_mode))) {
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_RDEV(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &rdev, 8);
|
|
|
|
}
|
|
|
|
if (obj_type == DMU_OT_ZNODE) {
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &pflags, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&acl_ids->z_fuid, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&acl_ids->z_fgid, 8);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PAD(zfsvfs), NULL, pad,
|
2010-05-28 20:45:14 +00:00
|
|
|
sizeof (uint64_t) * 4);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ZNODE_ACL(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&acl_phys, sizeof (zfs_acl_phys_t));
|
|
|
|
} else if (acl_ids->z_aclp->z_version >= ZFS_ACL_VERSION_FUID) {
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_COUNT(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&acl_ids->z_aclp->z_acl_count, 8);
|
|
|
|
locate.cb_aclp = acl_ids->z_aclp;
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_ACES(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_data_locator, &locate,
|
|
|
|
acl_ids->z_aclp->z_acl_bytes);
|
|
|
|
mode = zfs_mode_compute(mode, acl_ids->z_aclp, &pflags,
|
|
|
|
acl_ids->z_fuid, acl_ids->z_fgid);
|
|
|
|
}
|
|
|
|
|
|
|
|
VERIFY(sa_replace_all_by_template(sa_hdl, sa_attrs, cnt, tx) == 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (!(flag & IS_ROOT_NODE)) {
|
2017-03-24 01:26:50 +00:00
|
|
|
/*
|
|
|
|
* The call to zfs_znode_alloc() may fail if memory is low
|
|
|
|
* via the call path: alloc_inode() -> inode_init_always() ->
|
|
|
|
* security_inode_alloc() -> inode_alloc_security(). Since
|
|
|
|
* the existing code is written such that zfs_mknode() can
|
|
|
|
* not fail retry until sufficient memory has been reclaimed.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
*zpp = zfs_znode_alloc(zfsvfs, db, 0, obj_type, obj,
|
|
|
|
sa_hdl);
|
|
|
|
} while (*zpp == NULL);
|
|
|
|
|
2013-01-16 00:41:09 +00:00
|
|
|
VERIFY(*zpp != NULL);
|
|
|
|
VERIFY(dzp != NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If we are creating the root node, the "parent" we
|
|
|
|
* passed in is the znode for the root.
|
|
|
|
*/
|
|
|
|
*zpp = dzp;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
(*zpp)->z_sa_hdl = sa_hdl;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
(*zpp)->z_pflags = pflags;
|
2016-09-27 21:08:52 +00:00
|
|
|
(*zpp)->z_mode = ZTOI(*zpp)->i_mode = mode;
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 01:25:34 +00:00
|
|
|
(*zpp)->z_dnodesize = dnodesize;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (obj_type == DMU_OT_ZNODE ||
|
|
|
|
acl_ids->z_aclp->z_version < ZFS_ACL_VERSION_FUID) {
|
2013-12-09 18:37:51 +00:00
|
|
|
VERIFY0(zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2013-11-01 19:26:11 +00:00
|
|
|
kmem_free(sa_attrs, sizeof (sa_bulk_attr_t) * ZPL_END);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
/*
|
2013-06-11 17:12:34 +00:00
|
|
|
* Update in-core attributes. It is assumed the caller will be doing an
|
|
|
|
* sa_bulk_update to push the changes out.
|
2011-03-01 20:24:09 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
xoptattr_t *xoap;
|
2016-12-14 22:18:53 +00:00
|
|
|
boolean_t update_inode = B_FALSE;
|
2011-03-01 20:24:09 +00:00
|
|
|
|
|
|
|
xoap = xva_getxoptattr(xvap);
|
|
|
|
ASSERT(xoap);
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
|
|
|
|
uint64_t times[2];
|
|
|
|
ZFS_TIME_ENCODE(&xoap->xoa_createtime, times);
|
|
|
|
(void) sa_update(zp->z_sa_hdl, SA_ZPL_CRTIME(ZTOZSB(zp)),
|
|
|
|
×, sizeof (times), tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_CREATETIME);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_READONLY, xoap->xoa_readonly,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_READONLY);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_HIDDEN, xoap->xoa_hidden,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_HIDDEN);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_SYSTEM, xoap->xoa_system,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_SYSTEM);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_ARCHIVE, xoap->xoa_archive,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_ARCHIVE);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_IMMUTABLE);
|
2016-10-05 21:47:29 +00:00
|
|
|
|
2016-12-14 22:18:53 +00:00
|
|
|
update_inode = B_TRUE;
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_NOUNLINK, xoap->xoa_nounlink,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_NOUNLINK);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_APPENDONLY);
|
2016-10-05 21:47:29 +00:00
|
|
|
|
2016-12-14 22:18:53 +00:00
|
|
|
update_inode = B_TRUE;
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_NODUMP, xoap->xoa_nodump,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_NODUMP);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_OPAQUE, xoap->xoa_opaque,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_OPAQUE);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_AV_QUARANTINED,
|
|
|
|
xoap->xoa_av_quarantined, zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_AV_MODIFIED, xoap->xoa_av_modified,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
|
|
|
|
zfs_sa_set_scanstamp(zp, xvap, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_REPARSE, xoap->xoa_reparse,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_REPARSE);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_OFFLINE)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_OFFLINE, xoap->xoa_offline,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_OFFLINE);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
|
|
|
|
ZFS_ATTR_SET(zp, ZFS_SPARSE, xoap->xoa_sparse,
|
|
|
|
zp->z_pflags, tx);
|
|
|
|
XVA_SET_RTN(xvap, XAT_SPARSE);
|
|
|
|
}
|
2016-12-14 22:18:53 +00:00
|
|
|
|
|
|
|
if (update_inode)
|
|
|
|
zfs_set_inode_flags(zp, ZTOI(zp));
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
int
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dmu_object_info_t doi;
|
|
|
|
dmu_buf_t *db;
|
|
|
|
znode_t *zp;
|
2015-12-22 21:47:38 +00:00
|
|
|
znode_hold_t *zh;
|
2008-11-20 20:01:55 +00:00
|
|
|
int err;
|
2010-05-28 20:45:14 +00:00
|
|
|
sa_handle_t *hdl;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
*zpp = NULL;
|
|
|
|
|
2014-03-25 19:41:18 +00:00
|
|
|
again:
|
2017-03-08 00:21:37 +00:00
|
|
|
zh = zfs_znode_hold_enter(zfsvfs, obj_num);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err) {
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
dmu_object_info_from_db(db, &doi);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (doi.doi_bonus_type != DMU_OT_SA &&
|
|
|
|
(doi.doi_bonus_type != DMU_OT_ZNODE ||
|
|
|
|
(doi.doi_bonus_type == DMU_OT_ZNODE &&
|
|
|
|
doi.doi_bonus_size < sizeof (znode_phys_t)))) {
|
|
|
|
sa_buf_rele(db, NULL);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
hdl = dmu_buf_get_user(db);
|
|
|
|
if (hdl != NULL) {
|
2011-04-14 20:07:24 +00:00
|
|
|
zp = sa_get_userdata(hdl);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2014-04-03 21:26:16 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Since "SA" does immediate eviction we
|
|
|
|
* should never find a sa handle that doesn't
|
|
|
|
* know about the znode.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
ASSERT3P(zp, !=, NULL);
|
|
|
|
|
|
|
|
mutex_enter(&zp->z_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
ASSERT3U(zp->z_id, ==, obj_num);
|
2016-10-13 00:30:46 +00:00
|
|
|
/*
|
|
|
|
* If igrab() returns NULL the VFS has independently
|
|
|
|
* determined the inode should be evicted and has
|
|
|
|
* called iput_final() to start the eviction process.
|
|
|
|
* The SA handle is still valid but because the VFS
|
|
|
|
* requires that the eviction succeed we must drop
|
|
|
|
* our locks and references to allow the eviction to
|
|
|
|
* complete. The zfs_zget() may then be retried.
|
|
|
|
*
|
|
|
|
* This unlikely case could be optimized by registering
|
|
|
|
* a sops->drop_inode() callback. The callback would
|
|
|
|
* need to detect the active SA hold thereby informing
|
|
|
|
* the VFS that this inode should not be evicted.
|
|
|
|
*/
|
|
|
|
if (igrab(ZTOI(zp)) == NULL) {
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
sa_buf_rele(db, NULL);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2016-10-13 00:30:46 +00:00
|
|
|
/* inode might need this to finish evict */
|
|
|
|
cond_resched();
|
|
|
|
goto again;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2016-10-13 00:30:46 +00:00
|
|
|
*zpp = zp;
|
|
|
|
err = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
mutex_exit(&zp->z_lock);
|
2014-03-25 21:49:47 +00:00
|
|
|
sa_buf_rele(db, NULL);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-02-08 19:16:06 +00:00
|
|
|
* Not found create new znode/vnode but only if file exists.
|
2010-05-28 20:45:14 +00:00
|
|
|
*
|
|
|
|
* There is a small window where zfs_vget() could
|
|
|
|
* find this object while a file create is still in
|
|
|
|
* progress. This is checked for in zfs_znode_alloc()
|
|
|
|
*
|
|
|
|
* if zfs_znode_alloc() fails it will drop the hold on the
|
|
|
|
* bonus buffer.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2017-03-08 00:21:37 +00:00
|
|
|
zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size,
|
2016-07-06 00:24:36 +00:00
|
|
|
doi.doi_bonus_type, obj_num, NULL);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (zp == NULL) {
|
2013-03-08 18:41:28 +00:00
|
|
|
err = SET_ERROR(ENOENT);
|
2010-05-28 20:45:14 +00:00
|
|
|
} else {
|
|
|
|
*zpp = zp;
|
|
|
|
}
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zfs_rezget(znode_t *zp)
|
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_object_info_t doi;
|
|
|
|
dmu_buf_t *db;
|
|
|
|
uint64_t obj_num = zp->z_id;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t mode;
|
2016-07-14 14:44:38 +00:00
|
|
|
uint64_t links;
|
2016-08-01 20:02:25 +00:00
|
|
|
sa_bulk_attr_t bulk[10];
|
2008-11-20 20:01:55 +00:00
|
|
|
int err;
|
2010-05-28 20:45:14 +00:00
|
|
|
int count = 0;
|
|
|
|
uint64_t gen;
|
2016-05-22 11:15:57 +00:00
|
|
|
uint64_t z_uid, z_gid;
|
2016-08-01 20:02:25 +00:00
|
|
|
uint64_t atime[2], mtime[2], ctime[2];
|
2015-12-22 21:47:38 +00:00
|
|
|
znode_hold_t *zh;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2016-05-20 00:04:27 +00:00
|
|
|
/*
|
|
|
|
* skip ctldir, otherwise they will always get invalidated. This will
|
|
|
|
* cause funny behaviour for the mounted snapdirs. Especially for
|
|
|
|
* Linux >= 3.18, d_invalidate will detach the mountpoint and prevent
|
|
|
|
* anyone automount it again as long as someone is still using the
|
|
|
|
* detached mount.
|
|
|
|
*/
|
|
|
|
if (zp->z_is_ctldir)
|
|
|
|
return (0);
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zh = zfs_znode_hold_enter(zfsvfs, obj_num);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_enter(&zp->z_acl_lock);
|
|
|
|
if (zp->z_acl_cached) {
|
|
|
|
zfs_acl_free(zp->z_acl_cached);
|
|
|
|
zp->z_acl_cached = NULL;
|
|
|
|
}
|
|
|
|
mutex_exit(&zp->z_acl_lock);
|
2013-01-16 00:41:09 +00:00
|
|
|
|
2015-12-21 17:12:37 +00:00
|
|
|
rw_enter(&zp->z_xattr_lock, RW_WRITER);
|
2013-01-16 00:41:09 +00:00
|
|
|
if (zp->z_xattr_cached) {
|
|
|
|
nvlist_free(zp->z_xattr_cached);
|
|
|
|
zp->z_xattr_cached = NULL;
|
|
|
|
}
|
|
|
|
rw_exit(&zp->z_xattr_lock);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(zp->z_sa_hdl == NULL);
|
2017-03-08 00:21:37 +00:00
|
|
|
err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err) {
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
dmu_object_info_from_db(db, &doi);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (doi.doi_bonus_type != DMU_OT_SA &&
|
|
|
|
(doi.doi_bonus_type != DMU_OT_ZNODE ||
|
|
|
|
(doi.doi_bonus_type == DMU_OT_ZNODE &&
|
|
|
|
doi.doi_bonus_size < sizeof (znode_phys_t)))) {
|
|
|
|
sa_buf_rele(db, NULL);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_sa_init(zfsvfs, zp, db, doi.doi_bonus_type, NULL);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
/* reload cached values */
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&gen, sizeof (gen));
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_size, sizeof (zp->z_size));
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL,
|
2016-07-14 14:44:38 +00:00
|
|
|
&links, sizeof (links));
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_pflags, sizeof (zp->z_pflags));
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL,
|
2016-05-22 11:15:57 +00:00
|
|
|
&z_uid, sizeof (z_uid));
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL,
|
2016-05-22 11:15:57 +00:00
|
|
|
&z_gid, sizeof (z_gid));
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&mode, sizeof (mode));
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
|
2016-08-01 20:02:25 +00:00
|
|
|
&atime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
|
2016-08-01 20:02:25 +00:00
|
|
|
&mtime, 16);
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
|
2016-08-01 20:02:25 +00:00
|
|
|
&ctime, 16);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) {
|
|
|
|
zfs_znode_dmu_fini(zp);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EIO));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 21:08:52 +00:00
|
|
|
zp->z_mode = ZTOI(zp)->i_mode = mode;
|
2016-05-22 11:15:57 +00:00
|
|
|
zfs_uid_write(ZTOI(zp), z_uid);
|
|
|
|
zfs_gid_write(ZTOI(zp), z_gid);
|
2010-08-26 21:24:34 +00:00
|
|
|
|
2016-08-01 20:02:25 +00:00
|
|
|
ZFS_TIME_DECODE(&ZTOI(zp)->i_atime, atime);
|
|
|
|
ZFS_TIME_DECODE(&ZTOI(zp)->i_mtime, mtime);
|
|
|
|
ZFS_TIME_DECODE(&ZTOI(zp)->i_ctime, ctime);
|
|
|
|
|
2016-04-18 19:08:53 +00:00
|
|
|
if (gen != ZTOI(zp)->i_generation) {
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_znode_dmu_fini(zp);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EIO));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 14:44:38 +00:00
|
|
|
set_nlink(ZTOI(zp), (uint32_t)links);
|
2016-12-14 22:18:53 +00:00
|
|
|
zfs_set_inode_flags(zp, ZTOI(zp));
|
2016-07-14 14:44:38 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
zp->z_blksz = doi.doi_data_block_size;
|
2016-03-31 23:52:03 +00:00
|
|
|
zp->z_atime_dirty = 0;
|
2016-08-01 20:02:25 +00:00
|
|
|
zfs_inode_update(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2017-09-12 13:35:48 +00:00
|
|
|
/*
|
|
|
|
* If the file has zero links, then it has been unlinked on the send
|
|
|
|
* side and it must be in the received unlinked set.
|
|
|
|
* We call zfs_znode_dmu_fini() now to prevent any accesses to the
|
|
|
|
* stale data and to prevent automatical removal of the file in
|
|
|
|
* zfs_zinactive(). The file will be removed either when it is removed
|
|
|
|
* on the send side and the next incremental stream is received or
|
|
|
|
* when the unlinked set gets processed.
|
|
|
|
*/
|
|
|
|
zp->z_unlinked = (ZTOI(zp)->i_nlink == 0);
|
|
|
|
if (zp->z_unlinked)
|
|
|
|
zfs_znode_dmu_fini(zp);
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zfs_znode_delete(znode_t *zp, dmu_tx_t *tx)
|
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
|
|
|
objset_t *os = zfsvfs->z_os;
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t obj = zp->z_id;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t acl_obj = zfs_external_acl(zp);
|
2015-12-22 21:47:38 +00:00
|
|
|
znode_hold_t *zh;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zh = zfs_znode_hold_enter(zfsvfs, obj);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (acl_obj) {
|
|
|
|
VERIFY(!zp->z_is_sa);
|
2008-12-03 20:09:06 +00:00
|
|
|
VERIFY(0 == dmu_object_free(os, acl_obj, tx));
|
2010-08-26 21:24:34 +00:00
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
VERIFY(0 == dmu_object_free(os, obj, tx));
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_znode_dmu_fini(zp);
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zfs_zinactive(znode_t *zp)
|
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t z_id = zp->z_id;
|
2015-12-22 21:47:38 +00:00
|
|
|
znode_hold_t *zh;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(zp->z_sa_hdl);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-03-21 17:19:30 +00:00
|
|
|
* Don't allow a zfs_zget() while were trying to release this znode.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2017-03-08 00:21:37 +00:00
|
|
|
zh = zfs_znode_hold_enter(zfsvfs, z_id);
|
2011-03-21 17:19:30 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
mutex_enter(&zp->z_lock);
|
|
|
|
|
|
|
|
/*
|
2017-09-12 13:35:48 +00:00
|
|
|
* If this was the last reference to a file with no links, remove
|
|
|
|
* the file from the file system unless the file system is mounted
|
|
|
|
* read-only. That can happen, for example, if the file system was
|
|
|
|
* originally read-write, the file was opened, then unlinked and
|
|
|
|
* the file system was made read-only before the file was finally
|
|
|
|
* closed. The file will remain in the unlinked set.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
if (zp->z_unlinked) {
|
2017-09-12 13:35:48 +00:00
|
|
|
ASSERT(!zfsvfs->z_issnap);
|
|
|
|
if (!zfs_is_readonly(zfsvfs)) {
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
|
|
|
zfs_rmnode(zp);
|
|
|
|
return;
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
zfs_znode_dmu_fini(zp);
|
2011-03-21 17:19:30 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zfs_znode_hold_exit(zfsvfs, zh);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2014-01-18 19:00:53 +00:00
|
|
|
static inline int
|
|
|
|
zfs_compare_timespec(struct timespec *t1, struct timespec *t2)
|
|
|
|
{
|
|
|
|
if (t1->tv_sec < t2->tv_sec)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (t1->tv_sec > t2->tv_sec)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (t1->tv_nsec - t2->tv_nsec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare to update znode time stamps.
|
|
|
|
*
|
|
|
|
* IN: zp - znode requiring timestamp update
|
Fix atime handling and relatime
The problem for atime:
We have 3 places for atime: inode->i_atime, znode->z_atime and SA. And its
handling is a mess. A huge part of mess regarding atime comes from
zfs_tstamp_update_setup, zfs_inode_update, and zfs_getattr, which behave
inconsistently with those three values.
zfs_tstamp_update_setup clears z_atime_dirty unconditionally as long as you
don't pass ATTR_ATIME. Which means every write(2) operation which only updates
ctime and mtime will cause atime changes to not be written to disk.
Also zfs_inode_update from write(2) will replace inode->i_atime with what's
inside SA(stale). But doesn't touch z_atime. So after read(2) and write(2).
You'll have i_atime(stale), z_atime(new), SA(stale) and z_atime_dirty=0.
Now, if you do stat(2), zfs_getattr will actually replace i_atime with what's
inside, z_atime. So you will have now you'll have i_atime(new), z_atime(new),
SA(stale) and z_atime_dirty=0. These will all gone after umount. And you'll
leave with a stale atime.
The problem for relatime:
We do have a relatime config inside ZFS dataset, but how it should interact
with the mount flag MS_RELATIME is not well defined. It seems it wanted
relatime mount option to override the dataset config by showing it as
temporary in `zfs get`. But at the same time, `zfs set relatime=on|off` would
also seems to want to override the mount option. Not to mention that
MS_RELATIME flag is actually never passed into ZFS, so it never really worked.
How Linux handles atime:
The Linux kernel actually handles atime completely in VFS, except for writing
it to disk. So if we remove the atime handling in ZFS, things would just work,
no matter it's strictatime, relatime, noatime, or even O_NOATIME. And whenever
VFS updates the i_atime, it will notify the underlying filesystem via
sb->dirty_inode().
And also there's one thing to note about atime flags like MS_RELATIME and
other flags like MS_NODEV, etc. They are mount point flags rather than
filesystem(sb) flags. Since native linux filesystem can be mounted at multiple
places at the same time, they can all have different atime settings. So these
flags are never passed down to filesystem drivers.
What this patch tries to do:
We remove znode->z_atime, since we won't gain anything from it. We remove most
of the atime handling and leave it to VFS. The only thing we do with atime is
to write it when dirty_inode() or setattr() is called. We also add
file_accessed() in zpl_read() since it's not provided in vfs_read().
After this patch, only the MS_RELATIME flag will have effect. The setting in
dataset won't do anything. We will make zfstuil to mount ZFS with MS_RELATIME
set according to the setting in dataset in future patch.
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #4482
2016-03-30 00:53:34 +00:00
|
|
|
* flag - ATTR_MTIME, ATTR_CTIME flags
|
2014-01-18 19:00:53 +00:00
|
|
|
*
|
Fix atime handling and relatime
The problem for atime:
We have 3 places for atime: inode->i_atime, znode->z_atime and SA. And its
handling is a mess. A huge part of mess regarding atime comes from
zfs_tstamp_update_setup, zfs_inode_update, and zfs_getattr, which behave
inconsistently with those three values.
zfs_tstamp_update_setup clears z_atime_dirty unconditionally as long as you
don't pass ATTR_ATIME. Which means every write(2) operation which only updates
ctime and mtime will cause atime changes to not be written to disk.
Also zfs_inode_update from write(2) will replace inode->i_atime with what's
inside SA(stale). But doesn't touch z_atime. So after read(2) and write(2).
You'll have i_atime(stale), z_atime(new), SA(stale) and z_atime_dirty=0.
Now, if you do stat(2), zfs_getattr will actually replace i_atime with what's
inside, z_atime. So you will have now you'll have i_atime(new), z_atime(new),
SA(stale) and z_atime_dirty=0. These will all gone after umount. And you'll
leave with a stale atime.
The problem for relatime:
We do have a relatime config inside ZFS dataset, but how it should interact
with the mount flag MS_RELATIME is not well defined. It seems it wanted
relatime mount option to override the dataset config by showing it as
temporary in `zfs get`. But at the same time, `zfs set relatime=on|off` would
also seems to want to override the mount option. Not to mention that
MS_RELATIME flag is actually never passed into ZFS, so it never really worked.
How Linux handles atime:
The Linux kernel actually handles atime completely in VFS, except for writing
it to disk. So if we remove the atime handling in ZFS, things would just work,
no matter it's strictatime, relatime, noatime, or even O_NOATIME. And whenever
VFS updates the i_atime, it will notify the underlying filesystem via
sb->dirty_inode().
And also there's one thing to note about atime flags like MS_RELATIME and
other flags like MS_NODEV, etc. They are mount point flags rather than
filesystem(sb) flags. Since native linux filesystem can be mounted at multiple
places at the same time, they can all have different atime settings. So these
flags are never passed down to filesystem drivers.
What this patch tries to do:
We remove znode->z_atime, since we won't gain anything from it. We remove most
of the atime handling and leave it to VFS. The only thing we do with atime is
to write it when dirty_inode() or setattr() is called. We also add
file_accessed() in zpl_read() since it's not provided in vfs_read().
After this patch, only the MS_RELATIME flag will have effect. The setting in
dataset won't do anything. We will make zfstuil to mount ZFS with MS_RELATIME
set according to the setting in dataset in future patch.
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #4482
2016-03-30 00:53:34 +00:00
|
|
|
* OUT: zp - z_seq
|
2014-01-18 19:00:53 +00:00
|
|
|
* mtime - new mtime
|
|
|
|
* ctime - new ctime
|
|
|
|
*
|
Fix atime handling and relatime
The problem for atime:
We have 3 places for atime: inode->i_atime, znode->z_atime and SA. And its
handling is a mess. A huge part of mess regarding atime comes from
zfs_tstamp_update_setup, zfs_inode_update, and zfs_getattr, which behave
inconsistently with those three values.
zfs_tstamp_update_setup clears z_atime_dirty unconditionally as long as you
don't pass ATTR_ATIME. Which means every write(2) operation which only updates
ctime and mtime will cause atime changes to not be written to disk.
Also zfs_inode_update from write(2) will replace inode->i_atime with what's
inside SA(stale). But doesn't touch z_atime. So after read(2) and write(2).
You'll have i_atime(stale), z_atime(new), SA(stale) and z_atime_dirty=0.
Now, if you do stat(2), zfs_getattr will actually replace i_atime with what's
inside, z_atime. So you will have now you'll have i_atime(new), z_atime(new),
SA(stale) and z_atime_dirty=0. These will all gone after umount. And you'll
leave with a stale atime.
The problem for relatime:
We do have a relatime config inside ZFS dataset, but how it should interact
with the mount flag MS_RELATIME is not well defined. It seems it wanted
relatime mount option to override the dataset config by showing it as
temporary in `zfs get`. But at the same time, `zfs set relatime=on|off` would
also seems to want to override the mount option. Not to mention that
MS_RELATIME flag is actually never passed into ZFS, so it never really worked.
How Linux handles atime:
The Linux kernel actually handles atime completely in VFS, except for writing
it to disk. So if we remove the atime handling in ZFS, things would just work,
no matter it's strictatime, relatime, noatime, or even O_NOATIME. And whenever
VFS updates the i_atime, it will notify the underlying filesystem via
sb->dirty_inode().
And also there's one thing to note about atime flags like MS_RELATIME and
other flags like MS_NODEV, etc. They are mount point flags rather than
filesystem(sb) flags. Since native linux filesystem can be mounted at multiple
places at the same time, they can all have different atime settings. So these
flags are never passed down to filesystem drivers.
What this patch tries to do:
We remove znode->z_atime, since we won't gain anything from it. We remove most
of the atime handling and leave it to VFS. The only thing we do with atime is
to write it when dirty_inode() or setattr() is called. We also add
file_accessed() in zpl_read() since it's not provided in vfs_read().
After this patch, only the MS_RELATIME flag will have effect. The setting in
dataset won't do anything. We will make zfstuil to mount ZFS with MS_RELATIME
set according to the setting in dataset in future patch.
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #4482
2016-03-30 00:53:34 +00:00
|
|
|
* Note: We don't update atime here, because we rely on Linux VFS to do
|
|
|
|
* atime updating.
|
2014-01-18 19:00:53 +00:00
|
|
|
*/
|
2008-11-20 20:01:55 +00:00
|
|
|
void
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_tstamp_update_setup(znode_t *zp, uint_t flag, uint64_t mtime[2],
|
Fix atime handling and relatime
The problem for atime:
We have 3 places for atime: inode->i_atime, znode->z_atime and SA. And its
handling is a mess. A huge part of mess regarding atime comes from
zfs_tstamp_update_setup, zfs_inode_update, and zfs_getattr, which behave
inconsistently with those three values.
zfs_tstamp_update_setup clears z_atime_dirty unconditionally as long as you
don't pass ATTR_ATIME. Which means every write(2) operation which only updates
ctime and mtime will cause atime changes to not be written to disk.
Also zfs_inode_update from write(2) will replace inode->i_atime with what's
inside SA(stale). But doesn't touch z_atime. So after read(2) and write(2).
You'll have i_atime(stale), z_atime(new), SA(stale) and z_atime_dirty=0.
Now, if you do stat(2), zfs_getattr will actually replace i_atime with what's
inside, z_atime. So you will have now you'll have i_atime(new), z_atime(new),
SA(stale) and z_atime_dirty=0. These will all gone after umount. And you'll
leave with a stale atime.
The problem for relatime:
We do have a relatime config inside ZFS dataset, but how it should interact
with the mount flag MS_RELATIME is not well defined. It seems it wanted
relatime mount option to override the dataset config by showing it as
temporary in `zfs get`. But at the same time, `zfs set relatime=on|off` would
also seems to want to override the mount option. Not to mention that
MS_RELATIME flag is actually never passed into ZFS, so it never really worked.
How Linux handles atime:
The Linux kernel actually handles atime completely in VFS, except for writing
it to disk. So if we remove the atime handling in ZFS, things would just work,
no matter it's strictatime, relatime, noatime, or even O_NOATIME. And whenever
VFS updates the i_atime, it will notify the underlying filesystem via
sb->dirty_inode().
And also there's one thing to note about atime flags like MS_RELATIME and
other flags like MS_NODEV, etc. They are mount point flags rather than
filesystem(sb) flags. Since native linux filesystem can be mounted at multiple
places at the same time, they can all have different atime settings. So these
flags are never passed down to filesystem drivers.
What this patch tries to do:
We remove znode->z_atime, since we won't gain anything from it. We remove most
of the atime handling and leave it to VFS. The only thing we do with atime is
to write it when dirty_inode() or setattr() is called. We also add
file_accessed() in zpl_read() since it's not provided in vfs_read().
After this patch, only the MS_RELATIME flag will have effect. The setting in
dataset won't do anything. We will make zfstuil to mount ZFS with MS_RELATIME
set according to the setting in dataset in future patch.
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #4482
2016-03-30 00:53:34 +00:00
|
|
|
uint64_t ctime[2])
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
timestruc_t now;
|
|
|
|
|
|
|
|
gethrestime(&now);
|
|
|
|
|
Fix atime handling and relatime
The problem for atime:
We have 3 places for atime: inode->i_atime, znode->z_atime and SA. And its
handling is a mess. A huge part of mess regarding atime comes from
zfs_tstamp_update_setup, zfs_inode_update, and zfs_getattr, which behave
inconsistently with those three values.
zfs_tstamp_update_setup clears z_atime_dirty unconditionally as long as you
don't pass ATTR_ATIME. Which means every write(2) operation which only updates
ctime and mtime will cause atime changes to not be written to disk.
Also zfs_inode_update from write(2) will replace inode->i_atime with what's
inside SA(stale). But doesn't touch z_atime. So after read(2) and write(2).
You'll have i_atime(stale), z_atime(new), SA(stale) and z_atime_dirty=0.
Now, if you do stat(2), zfs_getattr will actually replace i_atime with what's
inside, z_atime. So you will have now you'll have i_atime(new), z_atime(new),
SA(stale) and z_atime_dirty=0. These will all gone after umount. And you'll
leave with a stale atime.
The problem for relatime:
We do have a relatime config inside ZFS dataset, but how it should interact
with the mount flag MS_RELATIME is not well defined. It seems it wanted
relatime mount option to override the dataset config by showing it as
temporary in `zfs get`. But at the same time, `zfs set relatime=on|off` would
also seems to want to override the mount option. Not to mention that
MS_RELATIME flag is actually never passed into ZFS, so it never really worked.
How Linux handles atime:
The Linux kernel actually handles atime completely in VFS, except for writing
it to disk. So if we remove the atime handling in ZFS, things would just work,
no matter it's strictatime, relatime, noatime, or even O_NOATIME. And whenever
VFS updates the i_atime, it will notify the underlying filesystem via
sb->dirty_inode().
And also there's one thing to note about atime flags like MS_RELATIME and
other flags like MS_NODEV, etc. They are mount point flags rather than
filesystem(sb) flags. Since native linux filesystem can be mounted at multiple
places at the same time, they can all have different atime settings. So these
flags are never passed down to filesystem drivers.
What this patch tries to do:
We remove znode->z_atime, since we won't gain anything from it. We remove most
of the atime handling and leave it to VFS. The only thing we do with atime is
to write it when dirty_inode() or setattr() is called. We also add
file_accessed() in zpl_read() since it's not provided in vfs_read().
After this patch, only the MS_RELATIME flag will have effect. The setting in
dataset won't do anything. We will make zfstuil to mount ZFS with MS_RELATIME
set according to the setting in dataset in future patch.
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #4482
2016-03-30 00:53:34 +00:00
|
|
|
zp->z_seq++;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (flag & ATTR_MTIME) {
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_TIME_ENCODE(&now, mtime);
|
2016-08-01 20:02:25 +00:00
|
|
|
ZFS_TIME_DECODE(&(ZTOI(zp)->i_mtime), mtime);
|
2011-02-08 19:16:06 +00:00
|
|
|
if (ZTOZSB(zp)->z_use_fuids) {
|
2010-05-28 20:45:14 +00:00
|
|
|
zp->z_pflags |= (ZFS_ARCHIVE |
|
|
|
|
ZFS_AV_MODIFIED);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (flag & ATTR_CTIME) {
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_TIME_ENCODE(&now, ctime);
|
2016-08-01 20:02:25 +00:00
|
|
|
ZFS_TIME_DECODE(&(ZTOI(zp)->i_ctime), ctime);
|
2011-02-08 19:16:06 +00:00
|
|
|
if (ZTOZSB(zp)->z_use_fuids)
|
2010-05-28 20:45:14 +00:00
|
|
|
zp->z_pflags |= ZFS_ARCHIVE;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grow the block size for a file.
|
|
|
|
*
|
|
|
|
* IN: zp - znode of file to free data in.
|
|
|
|
* size - requested block size
|
|
|
|
* tx - open transaction.
|
|
|
|
*
|
|
|
|
* NOTE: this function assumes that the znode is write locked.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
u_longlong_t dummy;
|
|
|
|
|
|
|
|
if (size <= zp->z_blksz)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* If the file size is already greater than the current blocksize,
|
|
|
|
* we will not grow. If there is more than one block in a file,
|
|
|
|
* the blocksize cannot change.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (zp->z_blksz && zp->z_size > zp->z_blksz)
|
2008-11-20 20:01:55 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
error = dmu_object_set_blocksize(ZTOZSB(zp)->z_os, zp->z_id,
|
2008-11-20 20:01:55 +00:00
|
|
|
size, 0, tx);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error == ENOTSUP)
|
|
|
|
return;
|
2013-05-10 21:17:03 +00:00
|
|
|
ASSERT0(error);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* What blocksize did we actually get? */
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_object_size_from_db(sa_get_db(zp->z_sa_hdl), &zp->z_blksz, &dummy);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-12-03 20:09:06 +00:00
|
|
|
* Increase the file length
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* IN: zp - znode of file to free data in.
|
2008-12-03 20:09:06 +00:00
|
|
|
* end - new end-of-file
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2014-07-07 19:49:36 +00:00
|
|
|
* RETURN: 0 on success, error code on failure
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2008-12-03 20:09:06 +00:00
|
|
|
static int
|
|
|
|
zfs_extend(znode_t *zp, uint64_t end)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
2008-12-03 20:09:06 +00:00
|
|
|
dmu_tx_t *tx;
|
2008-11-20 20:01:55 +00:00
|
|
|
rl_t *rl;
|
2008-12-03 20:09:06 +00:00
|
|
|
uint64_t newblksz;
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
2008-12-03 20:09:06 +00:00
|
|
|
* We will change zp_size, lock the whole file.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2016-04-11 21:53:48 +00:00
|
|
|
rl = zfs_range_lock(&zp->z_range_lock, 0, UINT64_MAX, RL_WRITER);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing to do if file already at desired length.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (end <= zp->z_size) {
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_range_unlock(rl);
|
|
|
|
return (0);
|
|
|
|
}
|
2017-03-08 00:21:37 +00:00
|
|
|
tx = dmu_tx_create(zfsvfs->z_os);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (end > zp->z_blksz &&
|
2017-03-08 00:21:37 +00:00
|
|
|
(!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* We are growing the file past the current block size.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zp->z_blksz > ZTOZSB(zp)->z_max_blksz) {
|
2014-11-03 20:15:08 +00:00
|
|
|
/*
|
|
|
|
* File's blocksize is already larger than the
|
|
|
|
* "recordsize" property. Only let it grow to
|
|
|
|
* the next power of 2.
|
|
|
|
*/
|
2008-11-20 20:01:55 +00:00
|
|
|
ASSERT(!ISP2(zp->z_blksz));
|
2014-11-03 20:15:08 +00:00
|
|
|
newblksz = MIN(end, 1 << highbit64(zp->z_blksz));
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2011-02-08 19:16:06 +00:00
|
|
|
newblksz = MIN(end, ZTOZSB(zp)->z_max_blksz);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
dmu_tx_hold_write(tx, zp->z_id, 0, newblksz);
|
|
|
|
} else {
|
|
|
|
newblksz = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 23:13:18 +00:00
|
|
|
error = dmu_tx_assign(tx, TXG_WAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
zfs_range_unlock(rl);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (newblksz)
|
|
|
|
zfs_grow_blocksize(zp, newblksz, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zp->z_size = end;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(ZTOZSB(zp)),
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_size, sizeof (zp->z_size), tx));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
zfs_range_unlock(rl);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
dmu_tx_commit(tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-08-20 22:35:13 +00:00
|
|
|
/*
|
|
|
|
* zfs_zero_partial_page - Modeled after update_pages() but
|
|
|
|
* with different arguments and semantics for use by zfs_freesp().
|
|
|
|
*
|
|
|
|
* Zeroes a piece of a single page cache entry for zp at offset
|
|
|
|
* start and length len.
|
|
|
|
*
|
|
|
|
* Caller must acquire a range lock on the file for the region
|
|
|
|
* being zeroed in order that the ARC and page cache stay in sync.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
zfs_zero_partial_page(znode_t *zp, uint64_t start, uint64_t len)
|
|
|
|
{
|
|
|
|
struct address_space *mp = ZTOI(zp)->i_mapping;
|
|
|
|
struct page *pp;
|
|
|
|
int64_t off;
|
|
|
|
void *pb;
|
|
|
|
|
2016-04-05 19:39:37 +00:00
|
|
|
ASSERT((start & PAGE_MASK) == ((start + len - 1) & PAGE_MASK));
|
2014-08-20 22:35:13 +00:00
|
|
|
|
2016-04-05 19:39:37 +00:00
|
|
|
off = start & (PAGE_SIZE - 1);
|
|
|
|
start &= PAGE_MASK;
|
2014-08-20 22:35:13 +00:00
|
|
|
|
2016-04-05 19:39:37 +00:00
|
|
|
pp = find_lock_page(mp, start >> PAGE_SHIFT);
|
2014-08-20 22:35:13 +00:00
|
|
|
if (pp) {
|
|
|
|
if (mapping_writably_mapped(mp))
|
|
|
|
flush_dcache_page(pp);
|
|
|
|
|
|
|
|
pb = kmap(pp);
|
|
|
|
bzero(pb + off, len);
|
|
|
|
kunmap(pp);
|
|
|
|
|
|
|
|
if (mapping_writably_mapped(mp))
|
|
|
|
flush_dcache_page(pp);
|
|
|
|
|
|
|
|
mark_page_accessed(pp);
|
|
|
|
SetPageUptodate(pp);
|
|
|
|
ClearPageError(pp);
|
|
|
|
unlock_page(pp);
|
2016-04-05 19:39:37 +00:00
|
|
|
put_page(pp);
|
2014-08-20 22:35:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
|
|
|
* Free space in a file.
|
|
|
|
*
|
|
|
|
* IN: zp - znode of file to free data in.
|
|
|
|
* off - start of section to free.
|
|
|
|
* len - length of section to free.
|
|
|
|
*
|
2014-07-07 19:49:36 +00:00
|
|
|
* RETURN: 0 on success, error code on failure
|
2008-12-03 20:09:06 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
|
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
2008-12-03 20:09:06 +00:00
|
|
|
rl_t *rl;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the range being freed.
|
|
|
|
*/
|
2016-04-11 21:53:48 +00:00
|
|
|
rl = zfs_range_lock(&zp->z_range_lock, off, len, RL_WRITER);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing to do if file already at desired length.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (off >= zp->z_size) {
|
2008-12-03 20:09:06 +00:00
|
|
|
zfs_range_unlock(rl);
|
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (off + len > zp->z_size)
|
|
|
|
len = zp->z_size - off;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2014-08-20 22:35:13 +00:00
|
|
|
/*
|
|
|
|
* Zero partial page cache entries. This must be done under a
|
|
|
|
* range lock in order to keep the ARC and page cache in sync.
|
|
|
|
*/
|
|
|
|
if (zp->z_is_mapped) {
|
|
|
|
loff_t first_page, last_page, page_len;
|
|
|
|
loff_t first_page_offset, last_page_offset;
|
|
|
|
|
|
|
|
/* first possible full page in hole */
|
2016-04-05 19:39:37 +00:00
|
|
|
first_page = (off + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
2014-08-20 22:35:13 +00:00
|
|
|
/* last page of hole */
|
2016-04-05 19:39:37 +00:00
|
|
|
last_page = (off + len) >> PAGE_SHIFT;
|
2014-08-20 22:35:13 +00:00
|
|
|
|
|
|
|
/* offset of first_page */
|
2016-04-05 19:39:37 +00:00
|
|
|
first_page_offset = first_page << PAGE_SHIFT;
|
2014-08-20 22:35:13 +00:00
|
|
|
/* offset of last_page */
|
2016-04-05 19:39:37 +00:00
|
|
|
last_page_offset = last_page << PAGE_SHIFT;
|
2014-08-20 22:35:13 +00:00
|
|
|
|
2014-09-26 04:40:41 +00:00
|
|
|
/* truncate whole pages */
|
|
|
|
if (last_page_offset > first_page_offset) {
|
|
|
|
truncate_inode_pages_range(ZTOI(zp)->i_mapping,
|
|
|
|
first_page_offset, last_page_offset - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* truncate sub-page ranges */
|
2014-08-20 22:35:13 +00:00
|
|
|
if (first_page > last_page) {
|
|
|
|
/* entire punched area within a single page */
|
|
|
|
zfs_zero_partial_page(zp, off, len);
|
|
|
|
} else {
|
|
|
|
/* beginning of punched area at the end of a page */
|
|
|
|
page_len = first_page_offset - off;
|
|
|
|
if (page_len > 0)
|
|
|
|
zfs_zero_partial_page(zp, off, page_len);
|
|
|
|
|
|
|
|
/* end of punched area at the beginning of a page */
|
|
|
|
page_len = off + len - last_page_offset;
|
|
|
|
if (page_len > 0)
|
|
|
|
zfs_zero_partial_page(zp, last_page_offset,
|
|
|
|
page_len);
|
|
|
|
}
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_range_unlock(rl);
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Truncate a file
|
|
|
|
*
|
|
|
|
* IN: zp - znode of file to free data in.
|
|
|
|
* end - new end-of-file.
|
|
|
|
*
|
2014-07-07 19:49:36 +00:00
|
|
|
* RETURN: 0 on success, error code on failure
|
2008-12-03 20:09:06 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_trunc(znode_t *zp, uint64_t end)
|
|
|
|
{
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
2008-12-03 20:09:06 +00:00
|
|
|
dmu_tx_t *tx;
|
|
|
|
rl_t *rl;
|
|
|
|
int error;
|
2010-08-26 21:24:34 +00:00
|
|
|
sa_bulk_attr_t bulk[2];
|
|
|
|
int count = 0;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We will change zp_size, lock the whole file.
|
|
|
|
*/
|
2016-04-11 21:53:48 +00:00
|
|
|
rl = zfs_range_lock(&zp->z_range_lock, 0, UINT64_MAX, RL_WRITER);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing to do if file already at desired length.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (end >= zp->z_size) {
|
2008-12-03 20:09:06 +00:00
|
|
|
zfs_range_unlock(rl);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-09-19 19:19:08 +00:00
|
|
|
error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end,
|
|
|
|
DMU_OBJECT_END);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (error) {
|
|
|
|
zfs_range_unlock(rl);
|
|
|
|
return (error);
|
|
|
|
}
|
2017-03-08 00:21:37 +00:00
|
|
|
tx = dmu_tx_create(zfsvfs->z_os);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
2014-07-07 19:49:36 +00:00
|
|
|
dmu_tx_mark_netfree(tx);
|
2014-07-21 17:19:25 +00:00
|
|
|
error = dmu_tx_assign(tx, TXG_WAIT);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (error) {
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
zfs_range_unlock(rl);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zp->z_size = end;
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs),
|
2010-08-26 21:24:34 +00:00
|
|
|
NULL, &zp->z_size, sizeof (zp->z_size));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (end == 0) {
|
|
|
|
zp->z_pflags &= ~ZFS_SPARSE;
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
|
2010-08-26 21:24:34 +00:00
|
|
|
NULL, &zp->z_pflags, 8);
|
|
|
|
}
|
|
|
|
VERIFY(sa_bulk_update(zp->z_sa_hdl, bulk, count, tx) == 0);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_commit(tx);
|
|
|
|
|
2009-02-18 20:51:31 +00:00
|
|
|
zfs_range_unlock(rl);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
|
|
|
* Free space in a file
|
|
|
|
*
|
|
|
|
* IN: zp - znode of file to free data in.
|
|
|
|
* off - start of range
|
|
|
|
* len - end of range (0 => EOF)
|
|
|
|
* flag - current file open mode flags.
|
|
|
|
* log - TRUE if this action should be logged
|
|
|
|
*
|
2014-07-07 19:49:36 +00:00
|
|
|
* RETURN: 0 on success, error code on failure
|
2008-12-03 20:09:06 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
|
|
|
|
{
|
|
|
|
dmu_tx_t *tx;
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs = ZTOZSB(zp);
|
|
|
|
zilog_t *zilog = zfsvfs->z_log;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t mode;
|
|
|
|
uint64_t mtime[2], ctime[2];
|
|
|
|
sa_bulk_attr_t bulk[3];
|
|
|
|
int count = 0;
|
2008-12-03 20:09:06 +00:00
|
|
|
int error;
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs), &mode,
|
2010-05-28 20:45:14 +00:00
|
|
|
sizeof (mode))) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (off > zp->z_size) {
|
2008-12-03 20:09:06 +00:00
|
|
|
error = zfs_extend(zp, off+len);
|
|
|
|
if (error == 0 && log)
|
|
|
|
goto log;
|
2014-08-20 22:35:13 +00:00
|
|
|
goto out;
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
error = zfs_trunc(zp, off);
|
|
|
|
} else {
|
|
|
|
if ((error = zfs_free_range(zp, off, len)) == 0 &&
|
2010-05-28 20:45:14 +00:00
|
|
|
off + len > zp->z_size)
|
2008-12-03 20:09:06 +00:00
|
|
|
error = zfs_extend(zp, off+len);
|
|
|
|
}
|
|
|
|
if (error || !log)
|
2014-08-20 22:35:13 +00:00
|
|
|
goto out;
|
2008-12-03 20:09:06 +00:00
|
|
|
log:
|
2017-03-08 00:21:37 +00:00
|
|
|
tx = dmu_tx_create(zfsvfs->z_os);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
2013-11-22 23:13:18 +00:00
|
|
|
error = dmu_tx_assign(tx, TXG_WAIT);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (error) {
|
|
|
|
dmu_tx_abort(tx);
|
2014-08-20 22:35:13 +00:00
|
|
|
goto out;
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, mtime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, ctime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &zp->z_pflags, 8);
|
Fix atime handling and relatime
The problem for atime:
We have 3 places for atime: inode->i_atime, znode->z_atime and SA. And its
handling is a mess. A huge part of mess regarding atime comes from
zfs_tstamp_update_setup, zfs_inode_update, and zfs_getattr, which behave
inconsistently with those three values.
zfs_tstamp_update_setup clears z_atime_dirty unconditionally as long as you
don't pass ATTR_ATIME. Which means every write(2) operation which only updates
ctime and mtime will cause atime changes to not be written to disk.
Also zfs_inode_update from write(2) will replace inode->i_atime with what's
inside SA(stale). But doesn't touch z_atime. So after read(2) and write(2).
You'll have i_atime(stale), z_atime(new), SA(stale) and z_atime_dirty=0.
Now, if you do stat(2), zfs_getattr will actually replace i_atime with what's
inside, z_atime. So you will have now you'll have i_atime(new), z_atime(new),
SA(stale) and z_atime_dirty=0. These will all gone after umount. And you'll
leave with a stale atime.
The problem for relatime:
We do have a relatime config inside ZFS dataset, but how it should interact
with the mount flag MS_RELATIME is not well defined. It seems it wanted
relatime mount option to override the dataset config by showing it as
temporary in `zfs get`. But at the same time, `zfs set relatime=on|off` would
also seems to want to override the mount option. Not to mention that
MS_RELATIME flag is actually never passed into ZFS, so it never really worked.
How Linux handles atime:
The Linux kernel actually handles atime completely in VFS, except for writing
it to disk. So if we remove the atime handling in ZFS, things would just work,
no matter it's strictatime, relatime, noatime, or even O_NOATIME. And whenever
VFS updates the i_atime, it will notify the underlying filesystem via
sb->dirty_inode().
And also there's one thing to note about atime flags like MS_RELATIME and
other flags like MS_NODEV, etc. They are mount point flags rather than
filesystem(sb) flags. Since native linux filesystem can be mounted at multiple
places at the same time, they can all have different atime settings. So these
flags are never passed down to filesystem drivers.
What this patch tries to do:
We remove znode->z_atime, since we won't gain anything from it. We remove most
of the atime handling and leave it to VFS. The only thing we do with atime is
to write it when dirty_inode() or setattr() is called. We also add
file_accessed() in zpl_read() since it's not provided in vfs_read().
After this patch, only the MS_RELATIME flag will have effect. The setting in
dataset won't do anything. We will make zfstuil to mount ZFS with MS_RELATIME
set according to the setting in dataset in future patch.
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #4482
2016-03-30 00:53:34 +00:00
|
|
|
zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime);
|
2010-05-28 20:45:14 +00:00
|
|
|
error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
|
|
|
|
ASSERT(error == 0);
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
|
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
2014-08-20 22:35:13 +00:00
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(zp);
|
2014-08-20 22:35:13 +00:00
|
|
|
error = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* Truncate the page cache - for file truncate operations, use
|
|
|
|
* the purpose-built API for truncations. For punching operations,
|
2014-09-26 04:40:41 +00:00
|
|
|
* the truncation is handled under a range lock in zfs_free_range.
|
2014-08-20 22:35:13 +00:00
|
|
|
*/
|
|
|
|
if (len == 0)
|
|
|
|
truncate_setsize(ZTOI(zp), off);
|
|
|
|
return (error);
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
void
|
|
|
|
zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
|
|
|
|
{
|
2011-07-20 23:50:22 +00:00
|
|
|
struct super_block *sb;
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs_t *zfsvfs;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t moid, obj, sa_obj, version;
|
2011-07-20 23:50:22 +00:00
|
|
|
uint64_t sense = ZFS_CASE_SENSITIVE;
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t norm = 0;
|
|
|
|
nvpair_t *elem;
|
2015-12-22 21:47:38 +00:00
|
|
|
int size;
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
2011-07-20 23:50:22 +00:00
|
|
|
int i;
|
|
|
|
znode_t *rootzp = NULL;
|
|
|
|
vattr_t vattr;
|
|
|
|
znode_t *zp;
|
|
|
|
zfs_acl_ids_t acl_ids;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First attempt to create master node.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* In an empty objset, there are no blocks to read and thus
|
|
|
|
* there can be no i/o errors (which we assert below).
|
|
|
|
*/
|
|
|
|
moid = MASTER_NODE_OBJ;
|
|
|
|
error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
|
|
|
|
DMU_OT_NONE, 0, tx);
|
|
|
|
ASSERT(error == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set starting attributes.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
version = zfs_zpl_version_map(spa_version(dmu_objset_spa(os)));
|
2008-11-20 20:01:55 +00:00
|
|
|
elem = NULL;
|
|
|
|
while ((elem = nvlist_next_nvpair(zplprops, elem)) != NULL) {
|
|
|
|
/* For the moment we expect all zpl props to be uint64_ts */
|
|
|
|
uint64_t val;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
ASSERT(nvpair_type(elem) == DATA_TYPE_UINT64);
|
|
|
|
VERIFY(nvpair_value_uint64(elem, &val) == 0);
|
|
|
|
name = nvpair_name(elem);
|
|
|
|
if (strcmp(name, zfs_prop_to_name(ZFS_PROP_VERSION)) == 0) {
|
2009-07-02 22:44:48 +00:00
|
|
|
if (val < version)
|
|
|
|
version = val;
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
error = zap_update(os, moid, name, 8, 1, &val, tx);
|
|
|
|
}
|
|
|
|
ASSERT(error == 0);
|
|
|
|
if (strcmp(name, zfs_prop_to_name(ZFS_PROP_NORMALIZE)) == 0)
|
|
|
|
norm = val;
|
2011-07-20 23:50:22 +00:00
|
|
|
else if (strcmp(name, zfs_prop_to_name(ZFS_PROP_CASE)) == 0)
|
|
|
|
sense = val;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
ASSERT(version != 0);
|
2009-07-02 22:44:48 +00:00
|
|
|
error = zap_update(os, moid, ZPL_VERSION_STR, 8, 1, &version, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* Create zap object used for SA attribute registration
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (version >= ZPL_VERSION_SA) {
|
|
|
|
sa_obj = zap_create(os, DMU_OT_SA_MASTER_NODE,
|
|
|
|
DMU_OT_NONE, 0, tx);
|
|
|
|
error = zap_add(os, moid, ZFS_SA_ATTRS, 8, 1, &sa_obj, tx);
|
|
|
|
ASSERT(error == 0);
|
|
|
|
} else {
|
|
|
|
sa_obj = 0;
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Create a delete queue.
|
|
|
|
*/
|
2009-07-02 22:44:48 +00:00
|
|
|
obj = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &obj, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
ASSERT(error == 0);
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
/*
|
2017-03-08 00:21:37 +00:00
|
|
|
* Create root znode. Create minimal znode/inode/zfsvfs/sb
|
2011-07-20 23:50:22 +00:00
|
|
|
* to allow zfs_mknode to work.
|
2009-07-02 22:44:48 +00:00
|
|
|
*/
|
2011-07-20 23:50:22 +00:00
|
|
|
vattr.va_mask = ATTR_MODE|ATTR_UID|ATTR_GID;
|
|
|
|
vattr.va_mode = S_IFDIR|0755;
|
|
|
|
vattr.va_uid = crgetuid(cr);
|
|
|
|
vattr.va_gid = crgetgid(cr);
|
|
|
|
|
2014-11-21 00:09:39 +00:00
|
|
|
rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
|
2011-07-20 23:50:22 +00:00
|
|
|
rootzp->z_moved = 0;
|
|
|
|
rootzp->z_unlinked = 0;
|
|
|
|
rootzp->z_atime_dirty = 0;
|
|
|
|
rootzp->z_is_sa = USE_SA(version, os);
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
|
|
|
|
zfsvfs->z_os = os;
|
|
|
|
zfsvfs->z_parent = zfsvfs;
|
|
|
|
zfsvfs->z_version = version;
|
|
|
|
zfsvfs->z_use_fuids = USE_FUIDS(version, os);
|
|
|
|
zfsvfs->z_use_sa = USE_SA(version, os);
|
|
|
|
zfsvfs->z_norm = norm;
|
2011-07-20 23:50:22 +00:00
|
|
|
|
2014-11-21 00:09:39 +00:00
|
|
|
sb = kmem_zalloc(sizeof (struct super_block), KM_SLEEP);
|
2017-03-08 00:21:37 +00:00
|
|
|
sb->s_fs_info = zfsvfs;
|
2011-07-20 23:50:22 +00:00
|
|
|
|
|
|
|
ZTOI(rootzp)->i_sb = sb;
|
|
|
|
|
|
|
|
error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
|
2017-03-08 00:21:37 +00:00
|
|
|
&zfsvfs->z_attr_table);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2011-07-20 23:50:22 +00:00
|
|
|
ASSERT(error == 0);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2010-08-26 18:45:02 +00:00
|
|
|
/*
|
2011-07-20 23:50:22 +00:00
|
|
|
* Fold case on file systems that are always or sometimes case
|
|
|
|
* insensitive.
|
2010-08-26 18:45:02 +00:00
|
|
|
*/
|
2011-07-20 23:50:22 +00:00
|
|
|
if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
|
2017-03-08 00:21:37 +00:00
|
|
|
zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
|
2010-08-26 18:45:02 +00:00
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
|
2011-07-20 23:50:22 +00:00
|
|
|
offsetof(znode_t, z_link_node));
|
2010-08-26 18:45:02 +00:00
|
|
|
|
2015-12-22 21:47:38 +00:00
|
|
|
size = MIN(1 << (highbit64(zfs_object_mutex_size)-1), ZFS_OBJ_MTX_MAX);
|
2017-03-08 00:21:37 +00: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);
|
2015-12-22 21:47:38 +00:00
|
|
|
for (i = 0; i != size; i++) {
|
2017-03-08 00:21:37 +00:00
|
|
|
avl_create(&zfsvfs->z_hold_trees[i], zfs_znode_hold_compare,
|
2015-12-22 21:47:38 +00:00
|
|
|
sizeof (znode_hold_t), offsetof(znode_hold_t, zh_node));
|
2017-03-08 00:21:37 +00:00
|
|
|
mutex_init(&zfsvfs->z_hold_locks[i], NULL, MUTEX_DEFAULT, NULL);
|
2015-12-22 21:47:38 +00:00
|
|
|
}
|
2010-08-26 18:45:02 +00:00
|
|
|
|
2011-07-20 23:50:22 +00:00
|
|
|
VERIFY(0 == zfs_acl_ids_create(rootzp, IS_ROOT_NODE, &vattr,
|
|
|
|
cr, NULL, &acl_ids));
|
|
|
|
zfs_mknode(rootzp, &vattr, tx, cr, IS_ROOT_NODE, &zp, &acl_ids);
|
|
|
|
ASSERT3P(zp, ==, rootzp);
|
|
|
|
error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &rootzp->z_id, tx);
|
|
|
|
ASSERT(error == 0);
|
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2010-08-26 18:45:02 +00:00
|
|
|
|
2011-07-20 23:50:22 +00:00
|
|
|
atomic_set(&ZTOI(rootzp)->i_count, 0);
|
|
|
|
sa_handle_destroy(rootzp->z_sa_hdl);
|
|
|
|
kmem_cache_free(znode_cache, rootzp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create shares directory
|
|
|
|
*/
|
2017-03-08 00:21:37 +00:00
|
|
|
error = zfs_create_share_dir(zfsvfs, tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
ASSERT(error == 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2015-12-22 21:47:38 +00:00
|
|
|
for (i = 0; i != size; i++) {
|
2017-03-08 00:21:37 +00:00
|
|
|
avl_destroy(&zfsvfs->z_hold_trees[i]);
|
|
|
|
mutex_destroy(&zfsvfs->z_hold_locks[i]);
|
2015-12-22 21:47:38 +00:00
|
|
|
}
|
2011-09-09 17:24:55 +00:00
|
|
|
|
2016-11-26 20:30:44 +00:00
|
|
|
mutex_destroy(&zfsvfs->z_znodes_lock);
|
|
|
|
|
2017-03-08 00:21:37 +00:00
|
|
|
vmem_free(zfsvfs->z_hold_trees, sizeof (avl_tree_t) * size);
|
|
|
|
vmem_free(zfsvfs->z_hold_locks, sizeof (kmutex_t) * size);
|
2011-09-09 17:24:55 +00:00
|
|
|
kmem_free(sb, sizeof (struct super_block));
|
2017-03-08 00:21:37 +00:00
|
|
|
kmem_free(zfsvfs, sizeof (zfsvfs_t));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
#endif /* _KERNEL */
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
static int
|
2010-08-26 21:24:34 +00:00
|
|
|
zfs_sa_setup(objset_t *osp, sa_attr_type_t **sa_table)
|
|
|
|
{
|
|
|
|
uint64_t sa_obj = 0;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = zap_lookup(osp, MASTER_NODE_OBJ, ZFS_SA_ATTRS, 8, 1, &sa_obj);
|
|
|
|
if (error != 0 && error != ENOENT)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = sa_setup(osp, sa_obj, zfs_attr_table, ZPL_END, sa_table);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_grab_sa_handle(objset_t *osp, uint64_t obj, sa_handle_t **hdlp,
|
2011-07-26 23:38:27 +00:00
|
|
|
dmu_buf_t **db, void *tag)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dmu_object_info_t doi;
|
|
|
|
int error;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-07-26 23:38:27 +00:00
|
|
|
if ((error = sa_buf_hold(osp, obj, tag, db)) != 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
dmu_object_info_from_db(*db, &doi);
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((doi.doi_bonus_type != DMU_OT_SA &&
|
|
|
|
doi.doi_bonus_type != DMU_OT_ZNODE) ||
|
2010-08-26 16:52:39 +00:00
|
|
|
(doi.doi_bonus_type == DMU_OT_ZNODE &&
|
|
|
|
doi.doi_bonus_size < sizeof (znode_phys_t))) {
|
2011-07-26 23:38:27 +00:00
|
|
|
sa_buf_rele(*db, tag);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
error = sa_handle_get(osp, obj, NULL, SA_HDL_PRIVATE, hdlp);
|
|
|
|
if (error != 0) {
|
2011-07-26 23:38:27 +00:00
|
|
|
sa_buf_rele(*db, tag);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-07-26 23:38:27 +00:00
|
|
|
zfs_release_sa_handle(sa_handle_t *hdl, dmu_buf_t *db, void *tag)
|
2010-08-26 21:24:34 +00:00
|
|
|
{
|
|
|
|
sa_handle_destroy(hdl);
|
2011-07-26 23:38:27 +00:00
|
|
|
sa_buf_rele(db, tag);
|
2010-08-26 21:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an object number, return its parent object number and whether
|
|
|
|
* or not the object is an extended attribute directory.
|
|
|
|
*/
|
|
|
|
static int
|
2015-12-31 15:41:52 +00:00
|
|
|
zfs_obj_to_pobj(objset_t *osp, sa_handle_t *hdl, sa_attr_type_t *sa_table,
|
|
|
|
uint64_t *pobjp, int *is_xattrdir)
|
2010-08-26 21:24:34 +00:00
|
|
|
{
|
|
|
|
uint64_t parent;
|
|
|
|
uint64_t pflags;
|
|
|
|
uint64_t mode;
|
2015-12-31 15:41:52 +00:00
|
|
|
uint64_t parent_mode;
|
2010-08-26 21:24:34 +00:00
|
|
|
sa_bulk_attr_t bulk[3];
|
2015-12-31 15:41:52 +00:00
|
|
|
sa_handle_t *sa_hdl;
|
|
|
|
dmu_buf_t *sa_db;
|
2010-08-26 21:24:34 +00:00
|
|
|
int count = 0;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_PARENT], NULL,
|
|
|
|
&parent, sizeof (parent));
|
2010-05-28 20:45:14 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_FLAGS], NULL,
|
2010-08-26 21:24:34 +00:00
|
|
|
&pflags, sizeof (pflags));
|
2010-05-28 20:45:14 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_MODE], NULL,
|
2010-08-26 21:24:34 +00:00
|
|
|
&mode, sizeof (mode));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if ((error = sa_bulk_lookup(hdl, bulk, count)) != 0)
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
2010-08-26 21:24:34 +00:00
|
|
|
|
2015-12-31 15:41:52 +00:00
|
|
|
/*
|
|
|
|
* When a link is removed its parent pointer is not changed and will
|
|
|
|
* be invalid. There are two cases where a link is removed but the
|
|
|
|
* file stays around, when it goes to the delete queue and when there
|
|
|
|
* are additional links.
|
|
|
|
*/
|
|
|
|
error = zfs_grab_sa_handle(osp, parent, &sa_hdl, &sa_db, FTAG);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = sa_lookup(sa_hdl, ZPL_MODE, &parent_mode, sizeof (parent_mode));
|
|
|
|
zfs_release_sa_handle(sa_hdl, sa_db, FTAG);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
*is_xattrdir = ((pflags & ZFS_XATTR) != 0) && S_ISDIR(mode);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2015-12-31 15:41:52 +00:00
|
|
|
/*
|
|
|
|
* Extended attributes can be applied to files, directories, etc.
|
|
|
|
* Otherwise the parent must be a directory.
|
|
|
|
*/
|
|
|
|
if (!*is_xattrdir && !S_ISDIR(parent_mode))
|
2017-08-03 04:16:12 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2015-12-31 15:41:52 +00:00
|
|
|
|
|
|
|
*pobjp = parent;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
/*
|
|
|
|
* Given an object number, return some zpl level statistics
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_obj_to_stats_impl(sa_handle_t *hdl, sa_attr_type_t *sa_table,
|
|
|
|
zfs_stat_t *sb)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-08-26 21:24:34 +00:00
|
|
|
sa_bulk_attr_t bulk[4];
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_MODE], NULL,
|
|
|
|
&sb->zs_mode, sizeof (sb->zs_mode));
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_GEN], NULL,
|
|
|
|
&sb->zs_gen, sizeof (sb->zs_gen));
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_LINKS], NULL,
|
|
|
|
&sb->zs_links, sizeof (sb->zs_links));
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, sa_table[ZPL_CTIME], NULL,
|
|
|
|
&sb->zs_ctime, sizeof (sb->zs_ctime));
|
|
|
|
|
|
|
|
return (sa_bulk_lookup(hdl, bulk, count));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
|
|
|
|
sa_attr_type_t *sa_table, char *buf, int len)
|
|
|
|
{
|
|
|
|
sa_handle_t *sa_hdl;
|
|
|
|
sa_handle_t *prevhdl = NULL;
|
|
|
|
dmu_buf_t *prevdb = NULL;
|
|
|
|
dmu_buf_t *sa_db = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
char *path = buf + len - 1;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
*path = '\0';
|
2010-08-26 21:24:34 +00:00
|
|
|
sa_hdl = hdl;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
for (;;) {
|
2013-09-13 20:10:36 +00:00
|
|
|
uint64_t pobj = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
char component[MAXNAMELEN + 2];
|
|
|
|
size_t complen;
|
2013-09-13 20:10:36 +00:00
|
|
|
int is_xattrdir = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (prevdb)
|
2011-07-26 23:38:27 +00:00
|
|
|
zfs_release_sa_handle(prevhdl, prevdb, FTAG);
|
2010-08-26 21:24:34 +00:00
|
|
|
|
2015-12-31 15:41:52 +00:00
|
|
|
if ((error = zfs_obj_to_pobj(osp, sa_hdl, sa_table, &pobj,
|
2010-08-26 21:24:34 +00:00
|
|
|
&is_xattrdir)) != 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (pobj == obj) {
|
|
|
|
if (path[0] != '/')
|
|
|
|
*--path = '/';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
component[0] = '/';
|
|
|
|
if (is_xattrdir) {
|
|
|
|
(void) sprintf(component + 1, "<xattrdir>");
|
|
|
|
} else {
|
|
|
|
error = zap_value_search(osp, pobj, obj,
|
|
|
|
ZFS_DIRENT_OBJ(-1ULL), component + 1);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
complen = strlen(component);
|
|
|
|
path -= complen;
|
|
|
|
ASSERT(path >= buf);
|
|
|
|
bcopy(component, path, complen);
|
|
|
|
obj = pobj;
|
2010-08-26 21:24:34 +00:00
|
|
|
|
|
|
|
if (sa_hdl != hdl) {
|
|
|
|
prevhdl = sa_hdl;
|
|
|
|
prevdb = sa_db;
|
|
|
|
}
|
2011-07-26 23:38:27 +00:00
|
|
|
error = zfs_grab_sa_handle(osp, obj, &sa_hdl, &sa_db, FTAG);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (error != 0) {
|
|
|
|
sa_hdl = prevhdl;
|
|
|
|
sa_db = prevdb;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sa_hdl != NULL && sa_hdl != hdl) {
|
|
|
|
ASSERT(sa_db != NULL);
|
2011-07-26 23:38:27 +00:00
|
|
|
zfs_release_sa_handle(sa_hdl, sa_db, FTAG);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error == 0)
|
|
|
|
(void) memmove(buf, path, buf + len - path);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-08-26 21:24:34 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
zfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len)
|
|
|
|
{
|
|
|
|
sa_attr_type_t *sa_table;
|
|
|
|
sa_handle_t *hdl;
|
|
|
|
dmu_buf_t *db;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = zfs_sa_setup(osp, &sa_table);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
2011-07-26 23:38:27 +00:00
|
|
|
error = zfs_grab_sa_handle(osp, obj, &hdl, &db, FTAG);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = zfs_obj_to_path_impl(osp, obj, hdl, sa_table, buf, len);
|
|
|
|
|
2011-07-26 23:38:27 +00:00
|
|
|
zfs_release_sa_handle(hdl, db, FTAG);
|
2010-08-26 21:24:34 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zfs_obj_to_stats(objset_t *osp, uint64_t obj, zfs_stat_t *sb,
|
|
|
|
char *buf, int len)
|
|
|
|
{
|
|
|
|
char *path = buf + len - 1;
|
|
|
|
sa_attr_type_t *sa_table;
|
|
|
|
sa_handle_t *hdl;
|
|
|
|
dmu_buf_t *db;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
*path = '\0';
|
|
|
|
|
|
|
|
error = zfs_sa_setup(osp, &sa_table);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
2011-07-26 23:38:27 +00:00
|
|
|
error = zfs_grab_sa_handle(osp, obj, &hdl, &db, FTAG);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = zfs_obj_to_stats_impl(hdl, sa_table, sb);
|
|
|
|
if (error != 0) {
|
2011-07-26 23:38:27 +00:00
|
|
|
zfs_release_sa_handle(hdl, db, FTAG);
|
2010-08-26 21:24:34 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = zfs_obj_to_path_impl(osp, obj, hdl, sa_table, buf, len);
|
|
|
|
|
2011-07-26 23:38:27 +00:00
|
|
|
zfs_release_sa_handle(hdl, db, FTAG);
|
2010-08-26 21:24:34 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-08-26 18:49:16 +00:00
|
|
|
|
|
|
|
#if defined(_KERNEL) && defined(HAVE_SPL)
|
|
|
|
EXPORT_SYMBOL(zfs_create_fs);
|
|
|
|
EXPORT_SYMBOL(zfs_obj_to_path);
|
2015-12-18 20:19:14 +00:00
|
|
|
|
2016-12-12 18:46:26 +00:00
|
|
|
/* CSTYLED */
|
2015-12-18 20:19:14 +00:00
|
|
|
module_param(zfs_object_mutex_size, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(zfs_object_mutex_size, "Size of znode hold array");
|
2010-08-26 18:49:16 +00:00
|
|
|
#endif
|