Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Notable upstream pull request merges:
 #15940 41ae864 Replace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN
 #16128 5137c13 zpool import output is not formated properly
 #16138 efbef9e FreeBSD: Add zfs_link_create() error handling
 #16146 04bae5e Disable high priority ZIO threads on FreeBSD and Linux
 #16151 cc38691 zfs_ioc_send: use a dedicated taskq thread for send
 #16151 adda768 spa: remove spa_taskq_dispatch_sync()
 #16151 515c4dd spa: flatten spa_taskq_dispatch_ent()
 #16151 0a543db spa_taskq_dispatch_ent: simplify arguments
 #16153 975a132 Add support for parallel pool exports
 #16153 89acef9 Simplified the scope of the namespace lock
 #16159 136c053 ZAP: Fix leaf references on zap_expand_leaf() errors
 #16162 af5dbed Fix scn_queue races on very old pools
 #16165 3400127 Fix ZIL clone records for legacy holes
 #16167 414acbd Unbreak FreeBSD cross-build on MacOS broken in 051460b
 #16172 eced2e2 libzfs: Fix mounting datasets under thread limit pressure
 #16178 b64afa4 Better control the thread pool size when mounting datasets
 #16181 fa99d9c zfs_dbgmsg_print: make FreeBSD and Linux consistent
 #16191 e675852 dbuf: separate refcount calls for dbuf and dbuf_user
 #16198 a043b60 Correct level handling in zstream recompress
 #16204 34906f8 zap: reuse zap_leaf_t on dbuf reuse after shrink
 #16206 d0aa9db Use memset to zero stack allocations containing unions
 #16207 8865dfb Fix assertion in Persistent L2ARC
 #16208 08648cf Allow block cloning to be interrupted by a signal
 #16210 e235756 FreeBSD: Add const qualifier to members of struct
        opensolaris_utsname
 #16214 800d59d Some improvements to metaslabs eviction
 #16216 02c5aa9 Destroy ARC buffer in case of fill error
 #16225 01c8efd Simplify issig()

Obtained from:	OpenZFS
OpenZFS commit:	e235756
  • Loading branch information
mmatuska committed May 31, 2024
2 parents d28bbfa + e235756 commit aca928a
Show file tree
Hide file tree
Showing 89 changed files with 1,694 additions and 610 deletions.
1 change: 1 addition & 0 deletions cddl/lib/libspl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PACKAGE= zfs

SRCS = \
assert.c \
backtrace.c \
list.c \
mkdirp.c \
os/freebsd/zone.c \
Expand Down
132 changes: 101 additions & 31 deletions sys/contrib/openzfs/cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include <sys/brt_impl.h>
#include <zfs_comutil.h>
#include <sys/zstd/zstd.h>
#include <sys/backtrace.h>

#include <libnvpair.h>
#include <libzutil.h>
Expand Down Expand Up @@ -120,6 +121,9 @@ static int flagbits[256];
static uint64_t max_inflight_bytes = 256 * 1024 * 1024; /* 256MB */
static int leaked_objects = 0;
static range_tree_t *mos_refd_objs;
static spa_t *spa;
static objset_t *os;
static boolean_t kernel_init_done;

static void snprintf_blkptr_compact(char *, size_t, const blkptr_t *,
boolean_t);
Expand All @@ -131,6 +135,7 @@ static int dump_bpobj_cb(void *arg, const blkptr_t *bp, boolean_t free,


static void zdb_print_blkptr(const blkptr_t *bp, int flags);
static void zdb_exit(int reason);

typedef struct sublivelist_verify_block_refcnt {
/* block pointer entry in livelist being verified */
Expand Down Expand Up @@ -818,17 +823,40 @@ usage(void)
(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
"to make only that option verbose\n");
(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
exit(1);
zdb_exit(1);
}

static void
dump_debug_buffer(void)
{
if (dump_opt['G']) {
(void) printf("\n");
(void) fflush(stdout);
zfs_dbgmsg_print("zdb");
}
ssize_t ret __attribute__((unused));

if (!dump_opt['G'])
return;
/*
* We use write() instead of printf() so that this function
* is safe to call from a signal handler.
*/
ret = write(STDERR_FILENO, "\n", 1);
zfs_dbgmsg_print(STDERR_FILENO, "zdb");
}

static void sig_handler(int signo)
{
struct sigaction action;

libspl_backtrace(STDERR_FILENO);
dump_debug_buffer();

/*
* Restore default action and re-raise signal so SIGSEGV and
* SIGABRT can trigger a core dump.
*/
action.sa_handler = SIG_DFL;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
(void) sigaction(signo, &action, NULL);
raise(signo);
}

/*
Expand All @@ -849,7 +877,7 @@ fatal(const char *fmt, ...)

dump_debug_buffer();

exit(1);
zdb_exit(1);
}

static void
Expand Down Expand Up @@ -2276,7 +2304,7 @@ snprintf_zstd_header(spa_t *spa, char *blkbuf, size_t buflen,
buf = malloc(SPA_MAXBLOCKSIZE);
if (buf == NULL) {
(void) fprintf(stderr, "out of memory\n");
exit(1);
zdb_exit(1);
}
decode_embedded_bp_compressed(bp, buf);
memcpy(&zstd_hdr, buf, sizeof (zstd_hdr));
Expand Down Expand Up @@ -3231,6 +3259,23 @@ fuid_table_destroy(void)
}
}

static void
zdb_exit(int reason)
{
if (os != NULL) {
close_objset(os, FTAG);
} else if (spa != NULL) {
spa_close(spa, FTAG);
}

fuid_table_destroy();

if (kernel_init_done)
kernel_fini();

exit(reason);
}

/*
* print uid or gid information.
* For normal POSIX id just the id is printed in decimal format.
Expand Down Expand Up @@ -4161,32 +4206,32 @@ dump_cachefile(const char *cachefile)
if ((fd = open64(cachefile, O_RDONLY)) < 0) {
(void) printf("cannot open '%s': %s\n", cachefile,
strerror(errno));
exit(1);
zdb_exit(1);
}

if (fstat64(fd, &statbuf) != 0) {
(void) printf("failed to stat '%s': %s\n", cachefile,
strerror(errno));
exit(1);
zdb_exit(1);
}

if ((buf = malloc(statbuf.st_size)) == NULL) {
(void) fprintf(stderr, "failed to allocate %llu bytes\n",
(u_longlong_t)statbuf.st_size);
exit(1);
zdb_exit(1);
}

if (read(fd, buf, statbuf.st_size) != statbuf.st_size) {
(void) fprintf(stderr, "failed to read %llu bytes\n",
(u_longlong_t)statbuf.st_size);
exit(1);
zdb_exit(1);
}

(void) close(fd);

if (nvlist_unpack(buf, statbuf.st_size, &config, 0) != 0) {
(void) fprintf(stderr, "failed to unpack nvlist\n");
exit(1);
zdb_exit(1);
}

free(buf);
Expand Down Expand Up @@ -5102,14 +5147,14 @@ dump_label(const char *dev)

if ((fd = open64(path, O_RDONLY)) < 0) {
(void) printf("cannot open '%s': %s\n", path, strerror(errno));
exit(1);
zdb_exit(1);
}

if (fstat64_blk(fd, &statbuf) != 0) {
(void) printf("failed to stat '%s': %s\n", path,
strerror(errno));
(void) close(fd);
exit(1);
zdb_exit(1);
}

if (S_ISBLK(statbuf.st_mode) && zfs_dev_flush(fd) != 0)
Expand All @@ -5122,7 +5167,7 @@ dump_label(const char *dev)
sizeof (cksum_record_t), offsetof(cksum_record_t, link));

psize = statbuf.st_size;
psize = P2ALIGN(psize, (uint64_t)sizeof (vdev_label_t));
psize = P2ALIGN_TYPED(psize, sizeof (vdev_label_t), uint64_t);
ashift = SPA_MINBLOCKSHIFT;

/*
Expand Down Expand Up @@ -8221,7 +8266,7 @@ dump_zpool(spa_t *spa)

if (rc != 0) {
dump_debug_buffer();
exit(rc);
zdb_exit(rc);
}
}

Expand Down Expand Up @@ -8825,18 +8870,18 @@ zdb_embedded_block(char *thing)
words + 12, words + 13, words + 14, words + 15);
if (err != 16) {
(void) fprintf(stderr, "invalid input format\n");
exit(1);
zdb_exit(1);
}
ASSERT3U(BPE_GET_LSIZE(&bp), <=, SPA_MAXBLOCKSIZE);
buf = malloc(SPA_MAXBLOCKSIZE);
if (buf == NULL) {
(void) fprintf(stderr, "out of memory\n");
exit(1);
zdb_exit(1);
}
err = decode_embedded_bp(&bp, buf, BPE_GET_LSIZE(&bp));
if (err != 0) {
(void) fprintf(stderr, "decode failed: %u\n", err);
exit(1);
zdb_exit(1);
}
zdb_dump_block_raw(buf, BPE_GET_LSIZE(&bp), 0);
free(buf);
Expand All @@ -8863,8 +8908,6 @@ int
main(int argc, char **argv)
{
int c;
spa_t *spa = NULL;
objset_t *os = NULL;
int dump_all = 1;
int verbose = 0;
int error = 0;
Expand All @@ -8880,9 +8923,27 @@ main(int argc, char **argv)
char *spa_config_path_env, *objset_str;
boolean_t target_is_spa = B_TRUE, dataset_lookup = B_FALSE;
nvlist_t *cfg = NULL;
struct sigaction action;

dprintf_setup(&argc, argv);

/*
* Set up signal handlers, so if we crash due to bad on-disk data we
* can get more info. Unlike ztest, we don't bail out if we can't set
* up signal handlers, because zdb is very useful without them.
*/
action.sa_handler = sig_handler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGSEGV, &action, NULL) < 0) {
(void) fprintf(stderr, "zdb: cannot catch SIGSEGV: %s\n",
strerror(errno));
}
if (sigaction(SIGABRT, &action, NULL) < 0) {
(void) fprintf(stderr, "zdb: cannot catch SIGABRT: %s\n",
strerror(errno));
}

/*
* If there is an environment variable SPA_CONFIG_PATH it overrides
* default spa_config_path setting. If -U flag is specified it will
Expand Down Expand Up @@ -9093,6 +9154,7 @@ main(int argc, char **argv)
spa_mode_readable_spacemaps = B_TRUE;

kernel_init(SPA_MODE_READ);
kernel_init_done = B_TRUE;

if (dump_all)
verbose = MAX(verbose, 1);
Expand All @@ -9116,19 +9178,23 @@ main(int argc, char **argv)
if (argc != 1)
usage();
zdb_embedded_block(argv[0]);
return (0);
error = 0;
goto fini;
}

if (argc < 1) {
if (!dump_opt['e'] && dump_opt['C']) {
dump_cachefile(spa_config_path);
return (0);
error = 0;
goto fini;
}
usage();
}

if (dump_opt['l'])
return (dump_label(argv[0]));
if (dump_opt['l']) {
error = dump_label(argv[0]);
goto fini;
}

if (dump_opt['X'] || dump_opt['F'])
rewind = ZPOOL_DO_REWIND |
Expand Down Expand Up @@ -9183,7 +9249,8 @@ main(int argc, char **argv)
} else if (objset_str && !zdb_numeric(objset_str + 1) &&
dump_opt['N']) {
printf("Supply a numeric objset ID with -N\n");
exit(1);
error = 1;
goto fini;
}
} else {
target_pool = target;
Expand Down Expand Up @@ -9240,7 +9307,8 @@ main(int argc, char **argv)
if (argc != 2)
usage();
dump_opt['v'] = verbose + 3;
return (dump_path(argv[0], argv[1], NULL));
error = dump_path(argv[0], argv[1], NULL);
goto fini;
}

if (dump_opt['r']) {
Expand Down Expand Up @@ -9328,7 +9396,7 @@ main(int argc, char **argv)
fatal("can't dump '%s': %s", target,
strerror(error));
}
return (error);
goto fini;
} else {
target_pool = strdup(target);
if (strpbrk(target, "/@") != NULL)
Expand Down Expand Up @@ -9458,17 +9526,19 @@ main(int argc, char **argv)
free(checkpoint_target);
}

fini:
if (os != NULL) {
close_objset(os, FTAG);
} else {
} else if (spa != NULL) {
spa_close(spa, FTAG);
}

fuid_table_destroy();

dump_debug_buffer();

kernel_fini();
if (kernel_init_done)
kernel_fini();

return (error);
}
2 changes: 1 addition & 1 deletion sys/contrib/openzfs/cmd/zed/agents/zfs_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ zfs_enable_ds(void *arg)
{
unavailpool_t *pool = (unavailpool_t *)arg;

(void) zpool_enable_datasets(pool->uap_zhp, NULL, 0);
(void) zpool_enable_datasets(pool->uap_zhp, NULL, 0, 512);
zpool_close(pool->uap_zhp);
free(pool);
}
Expand Down
2 changes: 2 additions & 0 deletions sys/contrib/openzfs/cmd/zed/zed.d/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dist_zedexec_SCRIPTS = \
%D%/all-debug.sh \
%D%/all-syslog.sh \
%D%/data-notify.sh \
%D%/deadman-slot_off.sh \
%D%/generic-notify.sh \
%D%/pool_import-led.sh \
%D%/resilver_finish-notify.sh \
Expand All @@ -29,6 +30,7 @@ SUBSTFILES += $(nodist_zedexec_SCRIPTS)
zedconfdefaults = \
all-syslog.sh \
data-notify.sh \
deadman-slot_off.sh \
history_event-zfs-list-cacher.sh \
pool_import-led.sh \
resilver_finish-notify.sh \
Expand Down
Loading

0 comments on commit aca928a

Please sign in to comment.