2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2018-05-31 20:29:12 +03:00
|
|
|
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
|
2015-04-02 06:44:32 +03:00
|
|
|
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
|
2020-08-27 07:48:29 +03:00
|
|
|
* Copyright 2020 Oxide Computer Company
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#include <sys/dbuf.h>
|
|
|
|
#include <sys/dnode.h>
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
#include <sys/dmu_tx.h>
|
|
|
|
#include <sys/dmu_objset.h>
|
2018-10-10 00:05:13 +03:00
|
|
|
#include <sys/dmu_recv.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/dsl_dataset.h>
|
|
|
|
#include <sys/spa.h>
|
2014-04-16 07:40:22 +04:00
|
|
|
#include <sys/range_tree.h>
|
2013-12-09 22:37:51 +04:00
|
|
|
#include <sys/zfeature.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
dnode_increase_indirection(dnode_t *dn, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dmu_buf_impl_t *db;
|
|
|
|
int txgoff = tx->tx_txg & TXG_MASK;
|
|
|
|
int nblkptr = dn->dn_phys->dn_nblkptr;
|
|
|
|
int old_toplvl = dn->dn_phys->dn_nlevels - 1;
|
|
|
|
int new_level = dn->dn_next_nlevels[txgoff];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
|
|
|
|
|
|
|
|
/* this dnode can't be paged out because it's dirty */
|
|
|
|
ASSERT(dn->dn_phys->dn_type != DMU_OT_NONE);
|
|
|
|
ASSERT(new_level > 1 && dn->dn_phys->dn_nlevels > 0);
|
|
|
|
|
|
|
|
db = dbuf_hold_level(dn, dn->dn_phys->dn_nlevels, 0, FTAG);
|
|
|
|
ASSERT(db != NULL);
|
|
|
|
|
|
|
|
dn->dn_phys->dn_nlevels = new_level;
|
|
|
|
dprintf("os=%p obj=%llu, increase to %d\n", dn->dn_objset,
|
|
|
|
dn->dn_object, dn->dn_phys->dn_nlevels);
|
|
|
|
|
2019-07-08 23:18:50 +03:00
|
|
|
/*
|
|
|
|
* Lock ordering requires that we hold the children's db_mutexes (by
|
|
|
|
* calling dbuf_find()) before holding the parent's db_rwlock. The lock
|
|
|
|
* order is imposed by dbuf_read's steps of "grab the lock to protect
|
|
|
|
* db_parent, get db_parent, hold db_parent's db_rwlock".
|
|
|
|
*/
|
|
|
|
dmu_buf_impl_t *children[DN_MAX_NBLKPTR];
|
|
|
|
ASSERT3U(nblkptr, <=, DN_MAX_NBLKPTR);
|
|
|
|
for (i = 0; i < nblkptr; i++) {
|
|
|
|
children[i] =
|
|
|
|
dbuf_find(dn->dn_objset, dn->dn_object, old_toplvl, i);
|
|
|
|
}
|
|
|
|
|
2016-05-15 18:02:28 +03:00
|
|
|
/* transfer dnode's block pointers to new indirect block */
|
|
|
|
(void) dbuf_read(db, NULL, DB_RF_MUST_SUCCEED|DB_RF_HAVESTRUCT);
|
2019-07-08 23:18:50 +03:00
|
|
|
if (dn->dn_dbuf != NULL)
|
|
|
|
rw_enter(&dn->dn_dbuf->db_rwlock, RW_WRITER);
|
|
|
|
rw_enter(&db->db_rwlock, RW_WRITER);
|
2016-05-15 18:02:28 +03:00
|
|
|
ASSERT(db->db.db_data);
|
|
|
|
ASSERT(arc_released(db->db_buf));
|
|
|
|
ASSERT3U(sizeof (blkptr_t) * nblkptr, <=, db->db.db_size);
|
|
|
|
bcopy(dn->dn_phys->dn_blkptr, db->db.db_data,
|
|
|
|
sizeof (blkptr_t) * nblkptr);
|
|
|
|
arc_buf_freeze(db->db_buf);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/* set dbuf's parent pointers to new indirect buf */
|
|
|
|
for (i = 0; i < nblkptr; i++) {
|
2019-07-08 23:18:50 +03:00
|
|
|
dmu_buf_impl_t *child = children[i];
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (child == NULL)
|
|
|
|
continue;
|
2020-07-26 06:07:44 +03:00
|
|
|
#ifdef ZFS_DEBUG
|
2010-08-27 01:24:34 +04:00
|
|
|
DB_DNODE_ENTER(child);
|
|
|
|
ASSERT3P(DB_DNODE(child), ==, dn);
|
|
|
|
DB_DNODE_EXIT(child);
|
|
|
|
#endif /* DEBUG */
|
2008-11-20 23:01:55 +03:00
|
|
|
if (child->db_parent && child->db_parent != dn->dn_dbuf) {
|
|
|
|
ASSERT(child->db_parent->db_level == db->db_level);
|
|
|
|
ASSERT(child->db_blkptr !=
|
|
|
|
&dn->dn_phys->dn_blkptr[child->db_blkid]);
|
|
|
|
mutex_exit(&child->db_mtx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ASSERT(child->db_parent == NULL ||
|
|
|
|
child->db_parent == dn->dn_dbuf);
|
|
|
|
|
|
|
|
child->db_parent = db;
|
|
|
|
dbuf_add_ref(db, child);
|
|
|
|
if (db->db.db_data)
|
|
|
|
child->db_blkptr = (blkptr_t *)db->db.db_data + i;
|
|
|
|
else
|
|
|
|
child->db_blkptr = NULL;
|
|
|
|
dprintf_dbuf_bp(child, child->db_blkptr,
|
|
|
|
"changed db_blkptr to new indirect %s", "");
|
|
|
|
|
|
|
|
mutex_exit(&child->db_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(dn->dn_phys->dn_blkptr, sizeof (blkptr_t) * nblkptr);
|
|
|
|
|
2019-07-08 23:18:50 +03:00
|
|
|
rw_exit(&db->db_rwlock);
|
|
|
|
if (dn->dn_dbuf != NULL)
|
|
|
|
rw_exit(&dn->dn_dbuf->db_rwlock);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
dbuf_rele(db, FTAG);
|
|
|
|
|
|
|
|
rw_exit(&dn->dn_struct_rwlock);
|
|
|
|
}
|
|
|
|
|
2013-12-09 22:37:51 +04:00
|
|
|
static void
|
2008-11-20 23:01:55 +03:00
|
|
|
free_blocks(dnode_t *dn, blkptr_t *bp, int num, dmu_tx_t *tx)
|
|
|
|
{
|
2008-12-03 23:09:06 +03:00
|
|
|
dsl_dataset_t *ds = dn->dn_objset->os_dsl_dataset;
|
2008-11-20 23:01:55 +03:00
|
|
|
uint64_t bytesfreed = 0;
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
dprintf("ds=%p obj=%llx num=%d\n", ds, dn->dn_object, num);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int i = 0; i < num; i++, bp++) {
|
2008-11-20 23:01:55 +03:00
|
|
|
if (BP_IS_HOLE(bp))
|
|
|
|
continue;
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
bytesfreed += dsl_dataset_block_kill(ds, bp, tx, B_FALSE);
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT3U(bytesfreed, <=, DN_USED_BYTES(dn->dn_phys));
|
2013-12-09 22:37:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save some useful information on the holes being
|
|
|
|
* punched, including logical size, type, and indirection
|
|
|
|
* level. Retaining birth time enables detection of when
|
|
|
|
* holes are punched for reducing the number of free
|
|
|
|
* records transmitted during a zfs send.
|
|
|
|
*/
|
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
uint64_t lsize = BP_GET_LSIZE(bp);
|
|
|
|
dmu_object_type_t type = BP_GET_TYPE(bp);
|
|
|
|
uint64_t lvl = BP_GET_LEVEL(bp);
|
2013-12-09 22:37:51 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
bzero(bp, sizeof (blkptr_t));
|
2013-12-09 22:37:51 +04:00
|
|
|
|
|
|
|
if (spa_feature_is_active(dn->dn_objset->os_spa,
|
|
|
|
SPA_FEATURE_HOLE_BIRTH)) {
|
|
|
|
BP_SET_LSIZE(bp, lsize);
|
|
|
|
BP_SET_TYPE(bp, type);
|
|
|
|
BP_SET_LEVEL(bp, lvl);
|
|
|
|
BP_SET_BIRTH(bp, dmu_tx_get_txg(tx), 0);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
dnode_diduse_space(dn, -bytesfreed);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ZFS_DEBUG
|
|
|
|
static void
|
|
|
|
free_verify(dmu_buf_impl_t *db, uint64_t start, uint64_t end, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
int off, num;
|
|
|
|
int i, err, epbs;
|
|
|
|
uint64_t txg = tx->tx_txg;
|
2010-08-27 01:24:34 +04:00
|
|
|
dnode_t *dn;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
DB_DNODE_ENTER(db);
|
|
|
|
dn = DB_DNODE(db);
|
|
|
|
epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
|
2008-11-20 23:01:55 +03:00
|
|
|
off = start - (db->db_blkid * 1<<epbs);
|
|
|
|
num = end - start + 1;
|
|
|
|
|
|
|
|
ASSERT3U(off, >=, 0);
|
|
|
|
ASSERT3U(num, >=, 0);
|
|
|
|
ASSERT3U(db->db_level, >, 0);
|
2010-08-27 01:24:34 +04:00
|
|
|
ASSERT3U(db->db.db_size, ==, 1 << dn->dn_phys->dn_indblkshift);
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT3U(off+num, <=, db->db.db_size >> SPA_BLKPTRSHIFT);
|
|
|
|
ASSERT(db->db_blkptr != NULL);
|
|
|
|
|
|
|
|
for (i = off; i < off+num; i++) {
|
|
|
|
uint64_t *buf;
|
|
|
|
dmu_buf_impl_t *child;
|
|
|
|
dbuf_dirty_record_t *dr;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
ASSERT(db->db_level == 1);
|
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
2019-07-08 23:18:50 +03:00
|
|
|
err = dbuf_hold_impl(dn, db->db_level - 1,
|
2015-12-22 04:31:57 +03:00
|
|
|
(db->db_blkid << epbs) + i, TRUE, FALSE, FTAG, &child);
|
2010-08-27 01:24:34 +04:00
|
|
|
rw_exit(&dn->dn_struct_rwlock);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (err == ENOENT)
|
|
|
|
continue;
|
|
|
|
ASSERT(err == 0);
|
|
|
|
ASSERT(child->db_level == 0);
|
2020-02-05 22:07:19 +03:00
|
|
|
dr = dbuf_find_dirty_eq(child, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/* data_old better be zeroed */
|
|
|
|
if (dr) {
|
|
|
|
buf = dr->dt.dl.dr_data->b_data;
|
|
|
|
for (j = 0; j < child->db.db_size >> 3; j++) {
|
|
|
|
if (buf[j] != 0) {
|
|
|
|
panic("freed data not zero: "
|
|
|
|
"child=%p i=%d off=%d num=%d\n",
|
2008-12-03 23:09:06 +03:00
|
|
|
(void *)child, i, off, num);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* db_data better be zeroed unless it's dirty in a
|
|
|
|
* future txg.
|
|
|
|
*/
|
|
|
|
mutex_enter(&child->db_mtx);
|
|
|
|
buf = child->db.db_data;
|
|
|
|
if (buf != NULL && child->db_state != DB_FILL &&
|
2020-02-05 22:07:19 +03:00
|
|
|
list_is_empty(&child->db_dirty_records)) {
|
2008-11-20 23:01:55 +03:00
|
|
|
for (j = 0; j < child->db.db_size >> 3; j++) {
|
|
|
|
if (buf[j] != 0) {
|
|
|
|
panic("freed data not zero: "
|
|
|
|
"child=%p i=%d off=%d num=%d\n",
|
2008-12-03 23:09:06 +03:00
|
|
|
(void *)child, i, off, num);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_exit(&child->db_mtx);
|
|
|
|
|
|
|
|
dbuf_rele(child, FTAG);
|
|
|
|
}
|
2010-08-27 01:24:34 +04:00
|
|
|
DB_DNODE_EXIT(db);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
/*
|
|
|
|
* We don't usually free the indirect blocks here. If in one txg we have a
|
|
|
|
* free_range and a write to the same indirect block, it's important that we
|
|
|
|
* preserve the hole's birth times. Therefore, we don't free any any indirect
|
|
|
|
* blocks in free_children(). If an indirect block happens to turn into all
|
|
|
|
* holes, it will be freed by dbuf_write_children_ready, which happens at a
|
|
|
|
* point in the syncing process where we know for certain the contents of the
|
|
|
|
* indirect block.
|
|
|
|
*
|
|
|
|
* However, if we're freeing a dnode, its space accounting must go to zero
|
|
|
|
* before we actually try to free the dnode, or we will trip an assertion. In
|
|
|
|
* addition, we know the case described above cannot occur, because the dnode is
|
|
|
|
* being freed. Therefore, we free the indirect blocks immediately in that
|
|
|
|
* case.
|
|
|
|
*/
|
2013-12-09 22:37:51 +04:00
|
|
|
static void
|
|
|
|
free_children(dmu_buf_impl_t *db, uint64_t blkid, uint64_t nblks,
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
boolean_t free_indirects, dmu_tx_t *tx)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2010-08-27 01:24:34 +04:00
|
|
|
dnode_t *dn;
|
2008-11-20 23:01:55 +03:00
|
|
|
blkptr_t *bp;
|
|
|
|
dmu_buf_impl_t *subdb;
|
2017-01-28 23:11:09 +03:00
|
|
|
uint64_t start, end, dbstart, dbend;
|
|
|
|
unsigned int epbs, shift, i;
|
2008-12-03 23:09:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There is a small possibility that this block will not be cached:
|
|
|
|
* 1 - if level > 1 and there are no children with level <= 1
|
2013-12-09 22:37:51 +04:00
|
|
|
* 2 - if this block was evicted since we read it from
|
|
|
|
* dmu_tx_hold_free().
|
2008-12-03 23:09:06 +03:00
|
|
|
*/
|
|
|
|
if (db->db_state != DB_CACHED)
|
|
|
|
(void) dbuf_read(db, NULL, DB_RF_MUST_SUCCEED);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2016-10-31 20:42:37 +03:00
|
|
|
/*
|
|
|
|
* If we modify this indirect block, and we are not freeing the
|
|
|
|
* dnode (!free_indirects), then this indirect block needs to get
|
|
|
|
* written to disk by dbuf_write(). If it is dirty, we know it will
|
|
|
|
* be written (otherwise, we would have incorrect on-disk state
|
|
|
|
* because the space would be freed but still referenced by the BP
|
|
|
|
* in this indirect block). Therefore we VERIFY that it is
|
|
|
|
* dirty.
|
|
|
|
*
|
|
|
|
* Our VERIFY covers some cases that do not actually have to be
|
|
|
|
* dirty, but the open-context code happens to dirty. E.g. if the
|
|
|
|
* blocks we are freeing are all holes, because in that case, we
|
|
|
|
* are only freeing part of this indirect block, so it is an
|
|
|
|
* ancestor of the first or last block to be freed. The first and
|
|
|
|
* last L1 indirect blocks are always dirtied by dnode_free_range().
|
|
|
|
*/
|
2019-07-08 23:18:50 +03:00
|
|
|
db_lock_type_t dblt = dmu_buf_lock_parent(db, RW_READER, FTAG);
|
2016-10-31 20:42:37 +03:00
|
|
|
VERIFY(BP_GET_FILL(db->db_blkptr) == 0 || db->db_dirtycnt > 0);
|
2019-07-08 23:18:50 +03:00
|
|
|
dmu_buf_unlock_parent(db, dblt, FTAG);
|
2016-10-31 20:42:37 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
dbuf_release_bp(db);
|
2013-12-09 22:37:51 +04:00
|
|
|
bp = db->db.db_data;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
DB_DNODE_ENTER(db);
|
|
|
|
dn = DB_DNODE(db);
|
|
|
|
epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
|
2017-01-28 23:11:09 +03:00
|
|
|
ASSERT3U(epbs, <, 31);
|
2008-11-20 23:01:55 +03:00
|
|
|
shift = (db->db_level - 1) * epbs;
|
|
|
|
dbstart = db->db_blkid << epbs;
|
|
|
|
start = blkid >> shift;
|
|
|
|
if (dbstart < start) {
|
|
|
|
bp += start - dbstart;
|
|
|
|
} else {
|
|
|
|
start = dbstart;
|
|
|
|
}
|
|
|
|
dbend = ((db->db_blkid + 1) << epbs) - 1;
|
|
|
|
end = (blkid + nblks - 1) >> shift;
|
|
|
|
if (dbend <= end)
|
|
|
|
end = dbend;
|
2013-12-09 22:37:51 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT3U(start, <=, end);
|
|
|
|
|
|
|
|
if (db->db_level == 1) {
|
|
|
|
FREE_VERIFY(db, start, end, tx);
|
2019-07-08 23:18:50 +03:00
|
|
|
rw_enter(&db->db_rwlock, RW_WRITER);
|
|
|
|
free_blocks(dn, bp, end - start + 1, tx);
|
|
|
|
rw_exit(&db->db_rwlock);
|
2013-12-09 22:37:51 +04:00
|
|
|
} else {
|
2017-11-04 23:25:13 +03:00
|
|
|
for (uint64_t id = start; id <= end; id++, bp++) {
|
2013-12-09 22:37:51 +04:00
|
|
|
if (BP_IS_HOLE(bp))
|
|
|
|
continue;
|
|
|
|
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
|
|
|
VERIFY0(dbuf_hold_impl(dn, db->db_level - 1,
|
2017-01-28 23:11:09 +03:00
|
|
|
id, TRUE, FALSE, FTAG, &subdb));
|
2013-12-09 22:37:51 +04:00
|
|
|
rw_exit(&dn->dn_struct_rwlock);
|
|
|
|
ASSERT3P(bp, ==, subdb->db_blkptr);
|
|
|
|
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
free_children(subdb, blkid, nblks, free_indirects, tx);
|
2013-12-09 22:37:51 +04:00
|
|
|
dbuf_rele(subdb, FTAG);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
if (free_indirects) {
|
2019-07-08 23:18:50 +03:00
|
|
|
rw_enter(&db->db_rwlock, RW_WRITER);
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
for (i = 0, bp = db->db.db_data; i < 1 << epbs; i++, bp++)
|
|
|
|
ASSERT(BP_IS_HOLE(bp));
|
2013-12-09 22:37:51 +04:00
|
|
|
bzero(db->db.db_data, db->db.db_size);
|
|
|
|
free_blocks(dn, db->db_blkptr, 1, tx);
|
2019-07-08 23:18:50 +03:00
|
|
|
rw_exit(&db->db_rwlock);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2013-12-09 22:37:51 +04:00
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
DB_DNODE_EXIT(db);
|
2008-11-20 23:01:55 +03:00
|
|
|
arc_buf_freeze(db->db_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-06-11 21:12:34 +04:00
|
|
|
* Traverse the indicated range of the provided file
|
2008-11-20 23:01:55 +03:00
|
|
|
* and "free" all the blocks contained there.
|
|
|
|
*/
|
|
|
|
static void
|
2014-04-16 07:40:22 +04:00
|
|
|
dnode_sync_free_range_impl(dnode_t *dn, uint64_t blkid, uint64_t nblks,
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
boolean_t free_indirects, dmu_tx_t *tx)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
blkptr_t *bp = dn->dn_phys->dn_blkptr;
|
|
|
|
int dnlevel = dn->dn_phys->dn_nlevels;
|
2013-12-09 22:37:51 +04:00
|
|
|
boolean_t trunc = B_FALSE;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (blkid > dn->dn_phys->dn_maxblkid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ASSERT(dn->dn_phys->dn_maxblkid < UINT64_MAX);
|
2013-12-09 22:37:51 +04:00
|
|
|
if (blkid + nblks > dn->dn_phys->dn_maxblkid) {
|
2008-11-20 23:01:55 +03:00
|
|
|
nblks = dn->dn_phys->dn_maxblkid - blkid + 1;
|
2013-12-09 22:37:51 +04:00
|
|
|
trunc = B_TRUE;
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/* There are no indirect blocks in the object */
|
|
|
|
if (dnlevel == 1) {
|
|
|
|
if (blkid >= dn->dn_phys->dn_nblkptr) {
|
|
|
|
/* this range was never made persistent */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSERT3U(blkid + nblks, <=, dn->dn_phys->dn_nblkptr);
|
2013-12-09 22:37:51 +04:00
|
|
|
free_blocks(dn, bp + blkid, nblks, tx);
|
|
|
|
} else {
|
|
|
|
int shift = (dnlevel - 1) *
|
|
|
|
(dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT);
|
|
|
|
int start = blkid >> shift;
|
|
|
|
int end = (blkid + nblks - 1) >> shift;
|
|
|
|
dmu_buf_impl_t *db;
|
|
|
|
|
|
|
|
ASSERT(start < dn->dn_phys->dn_nblkptr);
|
|
|
|
bp += start;
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int i = start; i <= end; i++, bp++) {
|
2013-12-09 22:37:51 +04:00
|
|
|
if (BP_IS_HOLE(bp))
|
|
|
|
continue;
|
|
|
|
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
|
|
|
VERIFY0(dbuf_hold_impl(dn, dnlevel - 1, i,
|
2015-12-22 04:31:57 +03:00
|
|
|
TRUE, FALSE, FTAG, &db));
|
2013-12-09 22:37:51 +04:00
|
|
|
rw_exit(&dn->dn_struct_rwlock);
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
free_children(db, blkid, nblks, free_indirects, tx);
|
2013-12-09 22:37:51 +04:00
|
|
|
dbuf_rele(db, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:47:34 +03:00
|
|
|
/*
|
|
|
|
* Do not truncate the maxblkid if we are performing a raw
|
|
|
|
* receive. The raw receive sets the maxblkid manually and
|
|
|
|
* must not be overridden. Usually, the last DRR_FREE record
|
|
|
|
* will be at the maxblkid, because the source system sets
|
|
|
|
* the maxblkid when truncating. However, if the last block
|
|
|
|
* was freed by overwriting with zeros and being compressed
|
|
|
|
* away to a hole, the source system will generate a DRR_FREE
|
|
|
|
* record while leaving the maxblkid after the end of that
|
|
|
|
* record. In this case we need to leave the maxblkid as
|
|
|
|
* indicated in the DRR_OBJECT record, so that it matches the
|
|
|
|
* source system, ensuring that the cryptographic hashes will
|
|
|
|
* match.
|
|
|
|
*/
|
|
|
|
if (trunc && !dn->dn_objset->os_raw_receive) {
|
2019-12-05 23:37:00 +03:00
|
|
|
uint64_t off __maybe_unused;
|
2013-12-09 22:37:51 +04:00
|
|
|
dn->dn_phys->dn_maxblkid = blkid == 0 ? 0 : blkid - 1;
|
|
|
|
|
2019-12-05 23:37:00 +03:00
|
|
|
off = (dn->dn_phys->dn_maxblkid + 1) *
|
|
|
|
(dn->dn_phys->dn_datablkszsec << SPA_MINBLOCKSHIFT);
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT(off < dn->dn_phys->dn_maxblkid ||
|
|
|
|
dn->dn_phys->dn_maxblkid == 0 ||
|
2008-12-03 23:09:06 +03:00
|
|
|
dnode_next_offset(dn, 0, &off, 1, 1, 0) != 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 07:40:22 +04:00
|
|
|
typedef struct dnode_sync_free_range_arg {
|
|
|
|
dnode_t *dsfra_dnode;
|
|
|
|
dmu_tx_t *dsfra_tx;
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
boolean_t dsfra_free_indirects;
|
2014-04-16 07:40:22 +04:00
|
|
|
} dnode_sync_free_range_arg_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
dnode_sync_free_range(void *arg, uint64_t blkid, uint64_t nblks)
|
|
|
|
{
|
|
|
|
dnode_sync_free_range_arg_t *dsfra = arg;
|
|
|
|
dnode_t *dn = dsfra->dsfra_dnode;
|
|
|
|
|
|
|
|
mutex_exit(&dn->dn_mtx);
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
dnode_sync_free_range_impl(dn, blkid, nblks,
|
|
|
|
dsfra->dsfra_free_indirects, dsfra->dsfra_tx);
|
2014-04-16 07:40:22 +04:00
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2013-06-11 21:12:34 +04:00
|
|
|
* Try to kick all the dnode's dbufs out of the cache...
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
dnode_evict_dbufs(dnode_t *dn)
|
|
|
|
{
|
2015-04-02 06:44:32 +03:00
|
|
|
dmu_buf_impl_t *db_marker;
|
|
|
|
dmu_buf_impl_t *db, *db_next;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2015-04-02 06:44:32 +03:00
|
|
|
db_marker = kmem_alloc(sizeof (dmu_buf_impl_t), KM_SLEEP);
|
|
|
|
|
|
|
|
mutex_enter(&dn->dn_dbufs_mtx);
|
|
|
|
for (db = avl_first(&dn->dn_dbufs); db != NULL; db = db_next) {
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2020-07-26 06:07:44 +03:00
|
|
|
#ifdef ZFS_DEBUG
|
2015-04-02 06:44:32 +03:00
|
|
|
DB_DNODE_ENTER(db);
|
|
|
|
ASSERT3P(DB_DNODE(db), ==, dn);
|
|
|
|
DB_DNODE_EXIT(db);
|
2010-08-27 01:24:34 +04:00
|
|
|
#endif /* DEBUG */
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2015-04-02 06:44:32 +03:00
|
|
|
mutex_enter(&db->db_mtx);
|
|
|
|
if (db->db_state != DB_EVICTING &&
|
2018-10-01 20:42:05 +03:00
|
|
|
zfs_refcount_is_zero(&db->db_holds)) {
|
2015-04-02 06:44:32 +03:00
|
|
|
db_marker->db_level = db->db_level;
|
|
|
|
db_marker->db_blkid = db->db_blkid;
|
|
|
|
db_marker->db_state = DB_SEARCH;
|
|
|
|
avl_insert_here(&dn->dn_dbufs, db_marker, db,
|
|
|
|
AVL_BEFORE);
|
|
|
|
|
2018-05-31 20:29:12 +03:00
|
|
|
/*
|
|
|
|
* We need to use the "marker" dbuf rather than
|
|
|
|
* simply getting the next dbuf, because
|
|
|
|
* dbuf_destroy() may actually remove multiple dbufs.
|
|
|
|
* It can call itself recursively on the parent dbuf,
|
|
|
|
* which may also be removed from dn_dbufs. The code
|
|
|
|
* flow would look like:
|
|
|
|
*
|
|
|
|
* dbuf_destroy():
|
2018-08-01 00:51:15 +03:00
|
|
|
* dnode_rele_and_unlock(parent_dbuf, evicting=TRUE):
|
2018-05-31 20:29:12 +03:00
|
|
|
* if (!cacheable || pending_evict)
|
|
|
|
* dbuf_destroy()
|
|
|
|
*/
|
2016-06-02 07:04:53 +03:00
|
|
|
dbuf_destroy(db);
|
2015-04-02 06:44:32 +03:00
|
|
|
|
|
|
|
db_next = AVL_NEXT(&dn->dn_dbufs, db_marker);
|
|
|
|
avl_remove(&dn->dn_dbufs, db_marker);
|
|
|
|
} else {
|
2015-10-14 00:09:45 +03:00
|
|
|
db->db_pending_evict = TRUE;
|
2015-04-02 06:44:32 +03:00
|
|
|
mutex_exit(&db->db_mtx);
|
|
|
|
db_next = AVL_NEXT(&dn->dn_dbufs, db);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2015-04-02 06:44:32 +03:00
|
|
|
}
|
|
|
|
mutex_exit(&dn->dn_dbufs_mtx);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2015-04-02 06:44:32 +03:00
|
|
|
kmem_free(db_marker, sizeof (dmu_buf_impl_t));
|
2010-08-26 21:24:44 +04:00
|
|
|
|
2015-03-12 03:10:35 +03:00
|
|
|
dnode_evict_bonus(dn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dnode_evict_bonus(dnode_t *dn)
|
|
|
|
{
|
2008-11-20 23:01:55 +03:00
|
|
|
rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
|
2015-10-14 00:09:45 +03:00
|
|
|
if (dn->dn_bonus != NULL) {
|
2018-10-01 20:42:05 +03:00
|
|
|
if (zfs_refcount_is_zero(&dn->dn_bonus->db_holds)) {
|
2015-10-14 00:09:45 +03:00
|
|
|
mutex_enter(&dn->dn_bonus->db_mtx);
|
2016-06-02 07:04:53 +03:00
|
|
|
dbuf_destroy(dn->dn_bonus);
|
2015-10-14 00:09:45 +03:00
|
|
|
dn->dn_bonus = NULL;
|
|
|
|
} else {
|
|
|
|
dn->dn_bonus->db_pending_evict = TRUE;
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
rw_exit(&dn->dn_struct_rwlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dnode_undirty_dbufs(list_t *list)
|
|
|
|
{
|
|
|
|
dbuf_dirty_record_t *dr;
|
|
|
|
|
2010-08-26 20:52:42 +04:00
|
|
|
while ((dr = list_head(list))) {
|
2008-11-20 23:01:55 +03:00
|
|
|
dmu_buf_impl_t *db = dr->dr_dbuf;
|
|
|
|
uint64_t txg = dr->dr_txg;
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (db->db_level != 0)
|
|
|
|
dnode_undirty_dbufs(&dr->dt.di.dr_children);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&db->db_mtx);
|
|
|
|
/* XXX - use dbuf_undirty()? */
|
|
|
|
list_remove(list, dr);
|
2020-02-05 22:07:19 +03:00
|
|
|
ASSERT(list_head(&db->db_dirty_records) == dr);
|
|
|
|
list_remove_head(&db->db_dirty_records);
|
|
|
|
ASSERT(list_is_empty(&db->db_dirty_records));
|
2008-11-20 23:01:55 +03:00
|
|
|
db->db_dirtycnt -= 1;
|
|
|
|
if (db->db_level == 0) {
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT(db->db_blkid == DMU_BONUS_BLKID ||
|
2008-11-20 23:01:55 +03:00
|
|
|
dr->dt.dl.dr_data == db->db_buf);
|
|
|
|
dbuf_unoverride(dr);
|
2015-04-01 16:49:14 +03:00
|
|
|
} else {
|
|
|
|
mutex_destroy(&dr->dt.di.dr_mtx);
|
|
|
|
list_destroy(&dr->dt.di.dr_children);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
kmem_free(dr, sizeof (dbuf_dirty_record_t));
|
2018-08-01 00:51:15 +03:00
|
|
|
dbuf_rele_and_unlock(db, (void *)(uintptr_t)txg, B_FALSE);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dnode_sync_free(dnode_t *dn, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
int txgoff = tx->tx_txg & TXG_MASK;
|
|
|
|
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
/*
|
|
|
|
* Our contents should have been freed in dnode_sync() by the
|
|
|
|
* free range record inserted by the caller of dnode_free().
|
|
|
|
*/
|
2013-05-11 01:17:03 +04:00
|
|
|
ASSERT0(DN_USED_BYTES(dn->dn_phys));
|
2008-12-03 23:09:06 +03:00
|
|
|
ASSERT(BP_IS_HOLE(dn->dn_phys->dn_blkptr));
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
dnode_undirty_dbufs(&dn->dn_dirty_records[txgoff]);
|
|
|
|
dnode_evict_dbufs(dn);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - It would be nice to assert this, but we may still
|
|
|
|
* have residual holds from async evictions from the arc...
|
|
|
|
*
|
|
|
|
* zfs_obj_to_path() also depends on this being
|
|
|
|
* commented out.
|
|
|
|
*
|
2018-10-01 20:42:05 +03:00
|
|
|
* ASSERT3U(zfs_refcount_count(&dn->dn_holds), ==, 1);
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Undirty next bits */
|
|
|
|
dn->dn_next_nlevels[txgoff] = 0;
|
|
|
|
dn->dn_next_indblkshift[txgoff] = 0;
|
|
|
|
dn->dn_next_blksz[txgoff] = 0;
|
2017-11-08 22:12:59 +03:00
|
|
|
dn->dn_next_maxblkid[txgoff] = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/* ASSERT(blkptrs are zero); */
|
|
|
|
ASSERT(dn->dn_phys->dn_type != DMU_OT_NONE);
|
|
|
|
ASSERT(dn->dn_type != DMU_OT_NONE);
|
|
|
|
|
|
|
|
ASSERT(dn->dn_free_txg > 0);
|
|
|
|
if (dn->dn_allocated_txg != dn->dn_free_txg)
|
2013-12-09 22:37:51 +04:00
|
|
|
dmu_buf_will_dirty(&dn->dn_dbuf->db, tx);
|
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 04:25:34 +03:00
|
|
|
bzero(dn->dn_phys, sizeof (dnode_phys_t) * dn->dn_num_slots);
|
2018-01-19 12:19:47 +03:00
|
|
|
dnode_free_interior_slots(dn);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
dn->dn_type = DMU_OT_NONE;
|
|
|
|
dn->dn_maxblkid = 0;
|
|
|
|
dn->dn_allocated_txg = 0;
|
|
|
|
dn->dn_free_txg = 0;
|
2010-05-29 00:45:14 +04:00
|
|
|
dn->dn_have_spill = B_FALSE;
|
2018-01-19 12:19:47 +03:00
|
|
|
dn->dn_num_slots = 1;
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
|
|
|
|
ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT);
|
|
|
|
|
|
|
|
dnode_rele(dn, (void *)(uintptr_t)tx->tx_txg);
|
|
|
|
/*
|
|
|
|
* Now that we've released our hold, the dnode may
|
2017-01-03 20:31:18 +03:00
|
|
|
* be evicted, so we mustn't access it.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out the dnode's dirty buffers.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dnode_sync(dnode_t *dn, dmu_tx_t *tx)
|
|
|
|
{
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
objset_t *os = dn->dn_objset;
|
2008-11-20 23:01:55 +03:00
|
|
|
dnode_phys_t *dnp = dn->dn_phys;
|
|
|
|
int txgoff = tx->tx_txg & TXG_MASK;
|
|
|
|
list_t *list = &dn->dn_dirty_records[txgoff];
|
2019-12-05 23:37:00 +03:00
|
|
|
static const dnode_phys_t zerodn __maybe_unused = { 0 };
|
2017-11-04 23:25:13 +03:00
|
|
|
boolean_t kill_spill = B_FALSE;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
ASSERT(dnp->dn_type != DMU_OT_NONE || dn->dn_allocated_txg);
|
2009-07-03 02:44:48 +04:00
|
|
|
ASSERT(dnp->dn_type != DMU_OT_NONE ||
|
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 04:25:34 +03:00
|
|
|
bcmp(dnp, &zerodn, DNODE_MIN_SIZE) == 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
DNODE_VERIFY(dn);
|
|
|
|
|
|
|
|
ASSERT(dn->dn_dbuf == NULL || arc_released(dn->dn_dbuf->db_buf));
|
|
|
|
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
/*
|
|
|
|
* Do user accounting if it is enabled and this is not
|
|
|
|
* an encrypted receive.
|
|
|
|
*/
|
|
|
|
if (dmu_objset_userused_enabled(os) &&
|
|
|
|
!DMU_OBJECT_IS_SPECIAL(dn->dn_object) &&
|
|
|
|
(!os->os_encrypted || !dmu_objset_is_receiving(os))) {
|
2010-05-29 00:45:14 +04:00
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
dn->dn_oldused = DN_USED_BYTES(dn->dn_phys);
|
|
|
|
dn->dn_oldflags = dn->dn_phys->dn_flags;
|
2009-07-03 02:44:48 +04:00
|
|
|
dn->dn_phys->dn_flags |= DNODE_FLAG_USERUSED_ACCOUNTED;
|
2016-10-04 21:46:10 +03:00
|
|
|
if (dmu_objset_userobjused_enabled(dn->dn_objset))
|
|
|
|
dn->dn_phys->dn_flags |=
|
|
|
|
DNODE_FLAG_USEROBJUSED_ACCOUNTED;
|
2010-05-29 00:45:14 +04:00
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
dmu_objset_userquota_get_ids(dn, B_FALSE, tx);
|
2009-07-03 02:44:48 +04:00
|
|
|
} else {
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
/* Once we account for it, we should always account for it */
|
2009-07-03 02:44:48 +04:00
|
|
|
ASSERT(!(dn->dn_phys->dn_flags &
|
|
|
|
DNODE_FLAG_USERUSED_ACCOUNTED));
|
2016-10-04 21:46:10 +03:00
|
|
|
ASSERT(!(dn->dn_phys->dn_flags &
|
|
|
|
DNODE_FLAG_USEROBJUSED_ACCOUNTED));
|
2009-07-03 02:44:48 +04:00
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
if (dn->dn_allocated_txg == tx->tx_txg) {
|
|
|
|
/* The dnode is newly allocated or reallocated */
|
|
|
|
if (dnp->dn_type == DMU_OT_NONE) {
|
|
|
|
/* this is a first alloc, not a realloc */
|
|
|
|
dnp->dn_nlevels = 1;
|
2009-02-18 23:51:31 +03:00
|
|
|
dnp->dn_nblkptr = dn->dn_nblkptr;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dnp->dn_type = dn->dn_type;
|
|
|
|
dnp->dn_bonustype = dn->dn_bonustype;
|
|
|
|
dnp->dn_bonuslen = dn->dn_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 04:25:34 +03:00
|
|
|
|
|
|
|
dnp->dn_extra_slots = dn->dn_num_slots - 1;
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT(dnp->dn_nlevels > 1 ||
|
|
|
|
BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
|
2014-06-06 01:19:08 +04:00
|
|
|
BP_IS_EMBEDDED(&dnp->dn_blkptr[0]) ||
|
2008-11-20 23:01:55 +03:00
|
|
|
BP_GET_LSIZE(&dnp->dn_blkptr[0]) ==
|
|
|
|
dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
|
2014-06-06 01:19:08 +04:00
|
|
|
ASSERT(dnp->dn_nlevels < 2 ||
|
|
|
|
BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
|
|
|
|
BP_GET_LSIZE(&dnp->dn_blkptr[0]) == 1 << dnp->dn_indblkshift);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2013-10-08 21:13:05 +04:00
|
|
|
if (dn->dn_next_type[txgoff] != 0) {
|
|
|
|
dnp->dn_type = dn->dn_type;
|
|
|
|
dn->dn_next_type[txgoff] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dn->dn_next_blksz[txgoff] != 0) {
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT(P2PHASE(dn->dn_next_blksz[txgoff],
|
|
|
|
SPA_MINBLOCKSIZE) == 0);
|
|
|
|
ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
|
2008-12-03 23:09:06 +03:00
|
|
|
dn->dn_maxblkid == 0 || list_head(list) != NULL ||
|
2008-11-20 23:01:55 +03:00
|
|
|
dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT ==
|
2014-04-16 07:40:22 +04:00
|
|
|
dnp->dn_datablkszsec ||
|
2016-12-17 01:11:29 +03:00
|
|
|
!range_tree_is_empty(dn->dn_free_ranges[txgoff]));
|
2008-11-20 23:01:55 +03:00
|
|
|
dnp->dn_datablkszsec =
|
|
|
|
dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT;
|
|
|
|
dn->dn_next_blksz[txgoff] = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-08 21:13:05 +04:00
|
|
|
if (dn->dn_next_bonuslen[txgoff] != 0) {
|
2008-11-20 23:01:55 +03:00
|
|
|
if (dn->dn_next_bonuslen[txgoff] == DN_ZERO_BONUSLEN)
|
|
|
|
dnp->dn_bonuslen = 0;
|
|
|
|
else
|
|
|
|
dnp->dn_bonuslen = dn->dn_next_bonuslen[txgoff];
|
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 04:25:34 +03:00
|
|
|
ASSERT(dnp->dn_bonuslen <=
|
|
|
|
DN_SLOTS_TO_BONUSLEN(dnp->dn_extra_slots + 1));
|
2008-11-20 23:01:55 +03:00
|
|
|
dn->dn_next_bonuslen[txgoff] = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-08 21:13:05 +04:00
|
|
|
if (dn->dn_next_bonustype[txgoff] != 0) {
|
2012-12-14 03:24:15 +04:00
|
|
|
ASSERT(DMU_OT_IS_VALID(dn->dn_next_bonustype[txgoff]));
|
2010-05-29 00:45:14 +04:00
|
|
|
dnp->dn_bonustype = dn->dn_next_bonustype[txgoff];
|
|
|
|
dn->dn_next_bonustype[txgoff] = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
boolean_t freeing_dnode = dn->dn_free_txg > 0 &&
|
|
|
|
dn->dn_free_txg <= tx->tx_txg;
|
2013-12-09 22:37:51 +04:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
2015-05-06 20:24:09 +03:00
|
|
|
* Remove the spill block if we have been explicitly asked to
|
|
|
|
* remove it, or if the object is being removed.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
2015-05-06 20:24:09 +03:00
|
|
|
if (dn->dn_rm_spillblk[txgoff] || freeing_dnode) {
|
|
|
|
if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR)
|
2010-05-29 00:45:14 +04:00
|
|
|
kill_spill = B_TRUE;
|
|
|
|
dn->dn_rm_spillblk[txgoff] = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-08 21:13:05 +04:00
|
|
|
if (dn->dn_next_indblkshift[txgoff] != 0) {
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT(dnp->dn_nlevels == 1);
|
|
|
|
dnp->dn_indblkshift = dn->dn_next_indblkshift[txgoff];
|
|
|
|
dn->dn_next_indblkshift[txgoff] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just take the live (open-context) values for checksum and compress.
|
|
|
|
* Strictly speaking it's a future leak, but nothing bad happens if we
|
|
|
|
* start using the new checksum or compress algorithm a little early.
|
|
|
|
*/
|
|
|
|
dnp->dn_checksum = dn->dn_checksum;
|
|
|
|
dnp->dn_compress = dn->dn_compress;
|
|
|
|
|
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (kill_spill) {
|
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 04:25:34 +03:00
|
|
|
free_blocks(dn, DN_SPILL_BLKPTR(dn->dn_phys), 1, tx);
|
2010-05-29 00:45:14 +04:00
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
dnp->dn_flags &= ~DNODE_FLAG_SPILL_BLKPTR;
|
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/* process all the "freed" ranges in the file */
|
2014-04-16 07:40:22 +04:00
|
|
|
if (dn->dn_free_ranges[txgoff] != NULL) {
|
|
|
|
dnode_sync_free_range_arg_t dsfra;
|
|
|
|
dsfra.dsfra_dnode = dn;
|
|
|
|
dsfra.dsfra_tx = tx;
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
dsfra.dsfra_free_indirects = freeing_dnode;
|
2020-08-27 07:48:29 +03:00
|
|
|
mutex_enter(&dn->dn_mtx);
|
OpenZFS 9438 - Holes can lose birth time info if a block has a mix of birth times
As reported by https://github.com/zfsonlinux/zfs/issues/4996, there is
yet another hole birth issue. In this one, if a block is entirely holes,
but the birth times are not all the same, we lose that information by
creating one hole with the current txg as its birth time.
The ZoL PR's fix approach is incorrect. Ultimately, the problem here is
that when you truncate and write a file in the same transaction group,
the dbuf for the indirect block will be zeroed out to deal with the
truncation, and then written for the write. During this process, we will
lose hole birth time information for any holes in the range. In the case
where a dnode is being freed, we need to determine whether the block
should be converted to a higher-level hole in the zio pipeline, and if
so do it when the dnode is being synced out.
Porting Notes:
* The DMU_OBJECT_END change in zfs_znode.c was already applied.
* Added test cases from #5675 provided by @rincebrain for hole_birth
issues. These test cases should be pushed upstream to OpenZFS.
* Updated mk_files which is used by several rsend tests so the
files created are a little more interesting and may contain holes.
Authored by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/9438
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/738e2a3c
External-issue: DLPX-46861
Closes #7746
2016-09-20 20:02:29 +03:00
|
|
|
if (freeing_dnode) {
|
|
|
|
ASSERT(range_tree_contains(dn->dn_free_ranges[txgoff],
|
|
|
|
0, dn->dn_maxblkid + 1));
|
|
|
|
}
|
2020-08-27 07:48:29 +03:00
|
|
|
/*
|
|
|
|
* Because dnode_sync_free_range() must drop dn_mtx during its
|
|
|
|
* processing, using it as a callback to range_tree_vacate() is
|
|
|
|
* not safe. No other operations (besides destroy) are allowed
|
|
|
|
* once range_tree_vacate() has begun, and dropping dn_mtx
|
|
|
|
* would leave a window open for another thread to observe that
|
|
|
|
* invalid (and unsafe) state.
|
|
|
|
*/
|
|
|
|
range_tree_walk(dn->dn_free_ranges[txgoff],
|
2014-04-16 07:40:22 +04:00
|
|
|
dnode_sync_free_range, &dsfra);
|
2020-08-27 07:48:29 +03:00
|
|
|
range_tree_vacate(dn->dn_free_ranges[txgoff], NULL, NULL);
|
2014-04-16 07:40:22 +04:00
|
|
|
range_tree_destroy(dn->dn_free_ranges[txgoff]);
|
|
|
|
dn->dn_free_ranges[txgoff] = NULL;
|
2008-12-03 23:09:06 +03:00
|
|
|
mutex_exit(&dn->dn_mtx);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2013-12-09 22:37:51 +04:00
|
|
|
if (freeing_dnode) {
|
2016-05-17 04:02:29 +03:00
|
|
|
dn->dn_objset->os_freed_dnodes++;
|
2008-11-20 23:01:55 +03:00
|
|
|
dnode_sync_free(dn, tx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 04:25:34 +03:00
|
|
|
if (dn->dn_num_slots > DNODE_MIN_SLOTS) {
|
|
|
|
dsl_dataset_t *ds = dn->dn_objset->os_dsl_dataset;
|
|
|
|
mutex_enter(&ds->ds_lock);
|
2018-10-16 21:15:04 +03:00
|
|
|
ds->ds_feature_activation[SPA_FEATURE_LARGE_DNODE] =
|
|
|
|
(void *)B_TRUE;
|
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 04:25:34 +03:00
|
|
|
mutex_exit(&ds->ds_lock);
|
|
|
|
}
|
|
|
|
|
2014-09-05 04:50:36 +04:00
|
|
|
if (dn->dn_next_nlevels[txgoff]) {
|
|
|
|
dnode_increase_indirection(dn, tx);
|
|
|
|
dn->dn_next_nlevels[txgoff] = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-08 22:12:59 +03:00
|
|
|
/*
|
|
|
|
* This must be done after dnode_sync_free_range()
|
2019-03-13 20:52:01 +03:00
|
|
|
* and dnode_increase_indirection(). See dnode_new_blkid()
|
|
|
|
* for an explanation of the high bit being set.
|
2017-11-08 22:12:59 +03:00
|
|
|
*/
|
|
|
|
if (dn->dn_next_maxblkid[txgoff]) {
|
|
|
|
mutex_enter(&dn->dn_mtx);
|
2019-03-13 20:52:01 +03:00
|
|
|
dnp->dn_maxblkid =
|
|
|
|
dn->dn_next_maxblkid[txgoff] & ~DMU_NEXT_MAXBLKID_SET;
|
2017-11-08 22:12:59 +03:00
|
|
|
dn->dn_next_maxblkid[txgoff] = 0;
|
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
}
|
|
|
|
|
2009-02-18 23:51:31 +03:00
|
|
|
if (dn->dn_next_nblkptr[txgoff]) {
|
|
|
|
/* this should only happen on a realloc */
|
|
|
|
ASSERT(dn->dn_allocated_txg == tx->tx_txg);
|
|
|
|
if (dn->dn_next_nblkptr[txgoff] > dnp->dn_nblkptr) {
|
|
|
|
/* zero the new blkptrs we are gaining */
|
|
|
|
bzero(dnp->dn_blkptr + dnp->dn_nblkptr,
|
|
|
|
sizeof (blkptr_t) *
|
|
|
|
(dn->dn_next_nblkptr[txgoff] - dnp->dn_nblkptr));
|
|
|
|
#ifdef ZFS_DEBUG
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
ASSERT(dn->dn_next_nblkptr[txgoff] < dnp->dn_nblkptr);
|
|
|
|
/* the blkptrs we are losing better be unallocated */
|
2012-12-27 02:56:41 +04:00
|
|
|
for (i = 0; i < dnp->dn_nblkptr; i++) {
|
|
|
|
if (i >= dn->dn_next_nblkptr[txgoff])
|
|
|
|
ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[i]));
|
|
|
|
}
|
2009-02-18 23:51:31 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
dnp->dn_nblkptr = dn->dn_next_nblkptr[txgoff];
|
|
|
|
dn->dn_next_nblkptr[txgoff] = 0;
|
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
}
|
|
|
|
|
2015-07-02 19:23:20 +03:00
|
|
|
dbuf_sync_list(list, dn->dn_phys->dn_nlevels - 1, tx);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
if (!DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT3P(list_head(list), ==, NULL);
|
|
|
|
dnode_rele(dn, (void *)(uintptr_t)tx->tx_txg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Although we have dropped our reference to the dnode, it
|
|
|
|
* can't be evicted until its written, and we haven't yet
|
|
|
|
* initiated the IO for the dnode's dbuf.
|
|
|
|
*/
|
|
|
|
}
|