-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 1 in trying to slowly rip the zdb functions out of zdb.c to allow people to play with more flexible things to leverage zdb's functionality. No promises on any functions or structs being stable, now or probably in general unless someone builds a more polished abstraction, the goal at the moment is to slowly untangle the global state usage in zdb... Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rich Ercolani <rincebrain@gmail.com> Closes #15804
- Loading branch information
1 parent
06e25f9
commit a0d3fe7
Showing
7 changed files
with
184 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ zdb_SOURCES = \ | |
%D%/zdb_il.c | ||
|
||
zdb_LDADD = \ | ||
libzdb.la \ | ||
libzpool.la \ | ||
libzfs_core.la \ | ||
libnvpair.la | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \ | ||
zio_compress_table[(idx)].ci_name : "UNKNOWN") | ||
#define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \ | ||
zio_checksum_table[(idx)].ci_name : "UNKNOWN") | ||
#define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : \ | ||
(idx) == DMU_OTN_ZAP_DATA || (idx) == DMU_OTN_ZAP_METADATA ? \ | ||
DMU_OT_ZAP_OTHER : \ | ||
(idx) == DMU_OTN_UINT64_DATA || (idx) == DMU_OTN_UINT64_METADATA ? \ | ||
DMU_OT_UINT64_OTHER : DMU_OT_NUMTYPES) | ||
|
||
/* Some platforms require part of inode IDs to be remapped */ | ||
#ifdef __APPLE__ | ||
#define ZDB_MAP_OBJECT_ID(obj) INO_XNUTOZFS(obj, 2) | ||
#else | ||
#define ZDB_MAP_OBJECT_ID(obj) (obj) | ||
#endif | ||
|
||
#define ZOR_FLAG_PLAIN_FILE 0x0001 | ||
#define ZOR_FLAG_DIRECTORY 0x0002 | ||
#define ZOR_FLAG_SPACE_MAP 0x0004 | ||
#define ZOR_FLAG_ZAP 0x0008 | ||
#define ZOR_FLAG_ALL_TYPES -1 | ||
#define ZOR_SUPPORTED_FLAGS (ZOR_FLAG_PLAIN_FILE | \ | ||
ZOR_FLAG_DIRECTORY | \ | ||
ZOR_FLAG_SPACE_MAP | \ | ||
ZOR_FLAG_ZAP) | ||
|
||
#define ZDB_FLAG_CHECKSUM 0x0001 | ||
#define ZDB_FLAG_DECOMPRESS 0x0002 | ||
#define ZDB_FLAG_BSWAP 0x0004 | ||
#define ZDB_FLAG_GBH 0x0008 | ||
#define ZDB_FLAG_INDIRECT 0x0010 | ||
#define ZDB_FLAG_RAW 0x0020 | ||
#define ZDB_FLAG_PRINT_BLKPTR 0x0040 | ||
#define ZDB_FLAG_VERBOSE 0x0080 | ||
|
||
|
||
typedef struct zdb_ctx { | ||
} zdb_ctx_t; | ||
|
||
typedef struct zopt_object_range { | ||
uint64_t zor_obj_start; | ||
uint64_t zor_obj_end; | ||
uint64_t zor_flags; | ||
} zopt_object_range_t; | ||
|
||
|
||
typedef struct sublivelist_verify { | ||
/* FREE's that haven't yet matched to an ALLOC, in one sub-livelist */ | ||
zfs_btree_t sv_pair; | ||
|
||
/* ALLOC's without a matching FREE, accumulates across sub-livelists */ | ||
zfs_btree_t sv_leftover; | ||
} sublivelist_verify_t; | ||
|
||
typedef struct sublivelist_verify_block { | ||
dva_t svb_dva; | ||
|
||
/* | ||
* We need this to check if the block marked as allocated | ||
* in the livelist was freed (and potentially reallocated) | ||
* in the metaslab spacemaps at a later TXG. | ||
*/ | ||
uint64_t svb_allocated_txg; | ||
} sublivelist_verify_block_t; | ||
|
||
const char *zdb_ot_name(dmu_object_type_t type); | ||
int livelist_compare(const void *larg, const void *rarg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
libzdb_la_CFLAGS = $(AM_CFLAGS) $(LIBRARY_CFLAGS) | ||
libzdb_la_CFLAGS += -fvisibility=hidden | ||
|
||
noinst_LTLIBRARIES += libzdb.la | ||
|
||
libzdb_la_SOURCES = \ | ||
%D%/libzdb.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#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 (l->blk_birth < r->blk_birth) { | ||
return (-1); | ||
} else if (l->blk_birth > r->blk_birth) { | ||
return (+1); | ||
} | ||
return (0); | ||
} |