mirror of
https://github.com/openzfs/zfs.git
synced 2025-10-01 02:46:29 +00:00

During regular block writes ZFS sets both logical and physical birth times equal to the current TXG. During dedup and block cloning logical birth time is still set to the current TXG, but physical may be copied from the original block that was used. This represents the fact that logically user data has changed, but the physically it is the same old block. But block rewrite introduces a new situation, when block is not changed logically, but stored in a different place of the pool. From ARC, scrub and some other perspectives this is a new block, but for example for user applications or incremental replication it is not. Somewhat similar thing happen during remap phase of device removal, but in that case space blocks are still acounted as allocated at their logical birth times. This patch introduces a new "rewrite" flag in the block pointer structure, allowing to differentiate physical rewrite (when the block is actually reallocated at the physical birth time) from the device reval case (when the logical birth time is used). The new functionality is not used at this point, and the only expected change is that error log is now kept in terms of physical physical birth times, rather than logical, since if a block with logged error was somehow rewritten, then the previous error does not matter any more. This change also introduces a new TRAVERSE_LOGICAL flag to the traverse code, allowing zfs send, redact and diff to work in context of logical birth times, ignoring physical-only rewrites. It also changes nothing at this point due to lack of those writes, but they will come in a following patch. Reviewed-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Alexander Motin <alexander.motin@TrueNAS.com> Closes #17565
103 lines
2.4 KiB
C
103 lines
2.4 KiB
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <getopt.h>
|
|
#include <openssl/evp.h>
|
|
#include <sys/zfs_context.h>
|
|
#include <sys/spa.h>
|
|
#include <sys/spa_impl.h>
|
|
#include <sys/dmu.h>
|
|
#include <sys/zap.h>
|
|
#include <sys/fs/zfs.h>
|
|
#include <sys/zfs_znode.h>
|
|
#include <sys/zfs_sa.h>
|
|
#include <sys/sa.h>
|
|
#include <sys/sa_impl.h>
|
|
#include <sys/vdev.h>
|
|
#include <sys/vdev_impl.h>
|
|
#include <sys/metaslab_impl.h>
|
|
#include <sys/dmu_objset.h>
|
|
#include <sys/dsl_dir.h>
|
|
#include <sys/dsl_dataset.h>
|
|
#include <sys/dsl_pool.h>
|
|
#include <sys/dsl_bookmark.h>
|
|
#include <sys/dbuf.h>
|
|
#include <sys/zil.h>
|
|
#include <sys/zil_impl.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/resource.h>
|
|
#include <sys/dmu_send.h>
|
|
#include <sys/dmu_traverse.h>
|
|
#include <sys/zio_checksum.h>
|
|
#include <sys/zio_compress.h>
|
|
#include <sys/zfs_fuid.h>
|
|
#include <sys/arc.h>
|
|
#include <sys/arc_impl.h>
|
|
#include <sys/ddt.h>
|
|
#include <sys/zfeature.h>
|
|
#include <sys/abd.h>
|
|
#include <sys/blkptr.h>
|
|
#include <sys/dsl_crypt.h>
|
|
#include <sys/dsl_scan.h>
|
|
#include <sys/btree.h>
|
|
#include <sys/brt.h>
|
|
#include <sys/brt_impl.h>
|
|
#include <zfs_comutil.h>
|
|
#include <sys/zstd/zstd.h>
|
|
|
|
#include <libnvpair.h>
|
|
#include <libzutil.h>
|
|
|
|
#include <libzdb.h>
|
|
|
|
const char *
|
|
zdb_ot_name(dmu_object_type_t type)
|
|
{
|
|
if (type < DMU_OT_NUMTYPES)
|
|
return (dmu_ot[type].ot_name);
|
|
else if ((type & DMU_OT_NEWTYPE) &&
|
|
((type & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS))
|
|
return (dmu_ot_byteswap[type & DMU_OT_BYTESWAP_MASK].ob_name);
|
|
else
|
|
return ("UNKNOWN");
|
|
}
|
|
|
|
int
|
|
livelist_compare(const void *larg, const void *rarg)
|
|
{
|
|
const blkptr_t *l = larg;
|
|
const blkptr_t *r = rarg;
|
|
|
|
/* Sort them according to dva[0] */
|
|
uint64_t l_dva0_vdev, r_dva0_vdev;
|
|
l_dva0_vdev = DVA_GET_VDEV(&l->blk_dva[0]);
|
|
r_dva0_vdev = DVA_GET_VDEV(&r->blk_dva[0]);
|
|
if (l_dva0_vdev < r_dva0_vdev)
|
|
return (-1);
|
|
else if (l_dva0_vdev > r_dva0_vdev)
|
|
return (+1);
|
|
|
|
/* if vdevs are equal, sort by offsets. */
|
|
uint64_t l_dva0_offset;
|
|
uint64_t r_dva0_offset;
|
|
l_dva0_offset = DVA_GET_OFFSET(&l->blk_dva[0]);
|
|
r_dva0_offset = DVA_GET_OFFSET(&r->blk_dva[0]);
|
|
if (l_dva0_offset < r_dva0_offset) {
|
|
return (-1);
|
|
} else if (l_dva0_offset > r_dva0_offset) {
|
|
return (+1);
|
|
}
|
|
|
|
/*
|
|
* Since we're storing blkptrs without cancelling FREE/ALLOC pairs,
|
|
* it's possible the offsets are equal. In that case, sort by txg
|
|
*/
|
|
if (BP_GET_BIRTH(l) < BP_GET_BIRTH(r)) {
|
|
return (-1);
|
|
} else if (BP_GET_BIRTH(l) > BP_GET_BIRTH(r)) {
|
|
return (+1);
|
|
}
|
|
return (0);
|
|
}
|