2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
Illumos 6370 - ZFS send fails to transmit some holes
6370 ZFS send fails to transmit some holes
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Chris Williamson <chris.williamson@delphix.com>
Reviewed by: Stefan Ring <stefanrin@gmail.com>
Reviewed by: Steven Burgess <sburgess@datto.com>
Reviewed by: Arne Jansen <sensille@gmx.net>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
https://www.illumos.org/issues/6370
https://github.com/illumos/illumos-gate/commit/286ef71
In certain circumstances, "zfs send -i" (incremental send) can produce
a stream which will result in incorrect sparse file contents on the
target.
The problem manifests as regions of the received file that should be
sparse (and read a zero-filled) actually contain data from a file that
was deleted (and which happened to share this file's object ID).
Note: this can happen only with filesystems (not zvols, because they do
not free (and thus can not reuse) object IDs).
Note: This can happen only if, since the incremental source (FromSnap),
a file was deleted and then another file was created, and the new file
is sparse (i.e. has areas that were never written to and should be
implicitly zero-filled).
We suspect that this was introduced by 4370 (applies only if hole_birth
feature is enabled), and made worse by 5243 (applies if hole_birth
feature is disabled, and we never send any holes).
The bug is caused by the hole birth feature. When an object is deleted
and replaced, all the holes in the object have birth time zero. However,
zfs send cannot tell that the holes are new since the file was replaced,
so it doesn't send them in an incremental. As a result, you can end up
with invalid data when you receive incremental send streams. As a
short-term fix, we can always send holes with birth time 0 (unless it's
a zvol or a dataset where we can guarantee that no objects have been
reused).
Ported-by: Steven Burgess <sburgess@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4369
Closes #4050
2016-02-26 01:45:19 +00:00
|
|
|
* Copyright (c) 2013, 2015 by Delphix. All rights reserved.
|
2014-09-12 03:28:35 +00:00
|
|
|
* Copyright 2014 HybridCluster. All rights reserved.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
#include <sys/dmu_objset.h>
|
|
|
|
#include <sys/dmu_tx.h>
|
|
|
|
#include <sys/dnode.h>
|
2013-10-08 17:13:05 +00:00
|
|
|
#include <sys/zap.h>
|
|
|
|
#include <sys/zfeature.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
uint64_t
|
|
|
|
dmu_object_alloc(objset_t *os, dmu_object_type_t ot, int blocksize,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
uint64_t object;
|
2016-05-17 01:02:29 +00:00
|
|
|
uint64_t L1_dnode_count = DNODES_PER_BLOCK <<
|
2010-08-26 21:24:34 +00:00
|
|
|
(DMU_META_DNODE(os)->dn_indblkshift - SPA_BLKPTRSHIFT);
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_t *dn = NULL;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_enter(&os->os_obj_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
for (;;) {
|
2010-05-28 20:45:14 +00:00
|
|
|
object = os->os_obj_next;
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
2016-05-17 01:02:29 +00:00
|
|
|
* Each time we polish off a L1 bp worth of dnodes (2^12
|
|
|
|
* objects), move to another L1 bp that's still reasonably
|
|
|
|
* sparse (at most 1/4 full). Look from the beginning at most
|
|
|
|
* once per txg, but after that keep looking from here.
|
|
|
|
* os_scan_dnodes is set during txg sync if enough objects
|
|
|
|
* have been freed since the previous rescan to justify
|
|
|
|
* backfilling again. If we can't find a suitable block, just
|
|
|
|
* keep going from here.
|
Illumos 6370 - ZFS send fails to transmit some holes
6370 ZFS send fails to transmit some holes
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Chris Williamson <chris.williamson@delphix.com>
Reviewed by: Stefan Ring <stefanrin@gmail.com>
Reviewed by: Steven Burgess <sburgess@datto.com>
Reviewed by: Arne Jansen <sensille@gmx.net>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
https://www.illumos.org/issues/6370
https://github.com/illumos/illumos-gate/commit/286ef71
In certain circumstances, "zfs send -i" (incremental send) can produce
a stream which will result in incorrect sparse file contents on the
target.
The problem manifests as regions of the received file that should be
sparse (and read a zero-filled) actually contain data from a file that
was deleted (and which happened to share this file's object ID).
Note: this can happen only with filesystems (not zvols, because they do
not free (and thus can not reuse) object IDs).
Note: This can happen only if, since the incremental source (FromSnap),
a file was deleted and then another file was created, and the new file
is sparse (i.e. has areas that were never written to and should be
implicitly zero-filled).
We suspect that this was introduced by 4370 (applies only if hole_birth
feature is enabled), and made worse by 5243 (applies if hole_birth
feature is disabled, and we never send any holes).
The bug is caused by the hole birth feature. When an object is deleted
and replaced, all the holes in the object have birth time zero. However,
zfs send cannot tell that the holes are new since the file was replaced,
so it doesn't send them in an incremental. As a result, you can end up
with invalid data when you receive incremental send streams. As a
short-term fix, we can always send holes with birth time 0 (unless it's
a zvol or a dataset where we can guarantee that no objects have been
reused).
Ported-by: Steven Burgess <sburgess@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4369
Closes #4050
2016-02-26 01:45:19 +00:00
|
|
|
*
|
|
|
|
* Note that dmu_traverse depends on the behavior that we use
|
|
|
|
* multiple blocks of the dnode object before going back to
|
|
|
|
* reuse objects. Any change to this algorithm should preserve
|
|
|
|
* that property or find another solution to the issues
|
|
|
|
* described in traverse_visitbp.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2016-05-17 01:02:29 +00:00
|
|
|
|
|
|
|
if (P2PHASE(object, L1_dnode_count) == 0) {
|
|
|
|
uint64_t offset;
|
|
|
|
int error;
|
|
|
|
if (os->os_rescan_dnodes) {
|
|
|
|
offset = 0;
|
|
|
|
os->os_rescan_dnodes = B_FALSE;
|
|
|
|
} else {
|
|
|
|
offset = object << DNODE_SHIFT;
|
|
|
|
}
|
|
|
|
error = dnode_next_offset(DMU_META_DNODE(os),
|
2008-12-03 20:09:06 +00:00
|
|
|
DNODE_FIND_HOLE,
|
|
|
|
&offset, 2, DNODES_PER_BLOCK >> 2, 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error == 0)
|
|
|
|
object = offset >> DNODE_SHIFT;
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_obj_next = ++object;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX We should check for an i/o error here and return
|
|
|
|
* up to our caller. Actually we should pre-read it in
|
|
|
|
* dmu_tx_assign(), but there is currently no mechanism
|
|
|
|
* to do so.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) dnode_hold_impl(os, object, DNODE_MUST_BE_FREE,
|
2008-11-20 20:01:55 +00:00
|
|
|
FTAG, &dn);
|
|
|
|
if (dn)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (dmu_object_next(os, &object, B_TRUE, 0) == 0)
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_obj_next = object - 1;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx);
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_exit(&os->os_obj_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
dmu_tx_add_new_object(tx, os, object);
|
|
|
|
return (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
|
|
|
|
int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (object == DMU_META_DNODE_OBJECT && !dmu_tx_private_ok(tx))
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EBADF));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dnode_hold_impl(os, object, DNODE_MUST_BE_FREE, FTAG, &dn);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx);
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
|
|
|
|
dmu_tx_add_new_object(tx, os, object);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot,
|
2014-09-12 03:28:35 +00:00
|
|
|
int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
int err;
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
if (object == DMU_META_DNODE_OBJECT)
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EBADF));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED,
|
2008-11-20 20:01:55 +00:00
|
|
|
FTAG, &dn);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_reallocate(dn, ot, blocksize, bonustype, bonuslen, tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_rele(dn, FTAG);
|
2009-07-02 22:44:48 +00:00
|
|
|
return (err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ASSERT(object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED,
|
2008-11-20 20:01:55 +00:00
|
|
|
FTAG, &dn);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
ASSERT(dn->dn_type != DMU_OT_NONE);
|
2008-12-03 20:09:06 +00:00
|
|
|
dnode_free_range(dn, 0, DMU_OBJECT_END, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_free(dn, tx);
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2015-12-22 01:31:57 +00:00
|
|
|
/*
|
|
|
|
* Return (in *objectp) the next object which is allocated (or a hole)
|
|
|
|
* after *object, taking into account only objects that may have been modified
|
|
|
|
* after the specified txg.
|
|
|
|
*/
|
2008-11-20 20:01:55 +00:00
|
|
|
int
|
|
|
|
dmu_object_next(objset_t *os, uint64_t *objectp, boolean_t hole, uint64_t txg)
|
|
|
|
{
|
|
|
|
uint64_t offset = (*objectp + 1) << DNODE_SHIFT;
|
|
|
|
int error;
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
error = dnode_next_offset(DMU_META_DNODE(os),
|
2008-12-03 20:09:06 +00:00
|
|
|
(hole ? DNODE_FIND_HOLE : 0), &offset, 0, DNODES_PER_BLOCK, txg);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
*objectp = offset >> DNODE_SHIFT;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
2010-08-26 18:49:16 +00:00
|
|
|
|
2013-10-08 17:13:05 +00:00
|
|
|
/*
|
|
|
|
* Turn this object from old_type into DMU_OTN_ZAP_METADATA, and bump the
|
|
|
|
* refcount on SPA_FEATURE_EXTENSIBLE_DATASET.
|
|
|
|
*
|
|
|
|
* Only for use from syncing context, on MOS objects.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dmu_object_zapify(objset_t *mos, uint64_t object, dmu_object_type_t old_type,
|
|
|
|
dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
|
|
|
|
VERIFY0(dnode_hold(mos, object, FTAG, &dn));
|
|
|
|
if (dn->dn_type == DMU_OTN_ZAP_METADATA) {
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSERT3U(dn->dn_type, ==, old_type);
|
|
|
|
ASSERT0(dn->dn_maxblkid);
|
|
|
|
dn->dn_next_type[tx->tx_txg & TXG_MASK] = dn->dn_type =
|
|
|
|
DMU_OTN_ZAP_METADATA;
|
|
|
|
dnode_setdirty(dn, tx);
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
|
|
|
|
mzap_create_impl(mos, object, 0, 0, tx);
|
|
|
|
|
|
|
|
spa_feature_incr(dmu_objset_spa(mos),
|
|
|
|
SPA_FEATURE_EXTENSIBLE_DATASET, tx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dmu_object_free_zapified(objset_t *mos, uint64_t object, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
dmu_object_type_t t;
|
|
|
|
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
|
|
|
|
VERIFY0(dnode_hold(mos, object, FTAG, &dn));
|
|
|
|
t = dn->dn_type;
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
|
|
|
|
if (t == DMU_OTN_ZAP_METADATA) {
|
|
|
|
spa_feature_decr(dmu_objset_spa(mos),
|
|
|
|
SPA_FEATURE_EXTENSIBLE_DATASET, tx);
|
|
|
|
}
|
|
|
|
VERIFY0(dmu_object_free(mos, object, tx));
|
|
|
|
}
|
|
|
|
|
2010-08-26 18:49:16 +00:00
|
|
|
#if defined(_KERNEL) && defined(HAVE_SPL)
|
|
|
|
EXPORT_SYMBOL(dmu_object_alloc);
|
|
|
|
EXPORT_SYMBOL(dmu_object_claim);
|
|
|
|
EXPORT_SYMBOL(dmu_object_reclaim);
|
|
|
|
EXPORT_SYMBOL(dmu_object_free);
|
|
|
|
EXPORT_SYMBOL(dmu_object_next);
|
2013-10-08 17:13:05 +00:00
|
|
|
EXPORT_SYMBOL(dmu_object_zapify);
|
|
|
|
EXPORT_SYMBOL(dmu_object_free_zapified);
|
2010-08-26 18:49:16 +00:00
|
|
|
#endif
|