mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-01-30 20:04:22 +03:00
zfs_debug: specific variant for userspace
Just nice and simple, with room to grow. Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Signed-off-by: Rob Norris <robn@despairlabs.com> Sponsored-by: https://despairlabs.com/sponsor/ Closes #16492
This commit is contained in:
parent
16266b47a1
commit
4982943d25
@ -17,7 +17,8 @@ dist_libzpool_la_SOURCES = \
|
|||||||
%D%/taskq.c \
|
%D%/taskq.c \
|
||||||
%D%/util.c \
|
%D%/util.c \
|
||||||
%D%/vdev_label_os.c \
|
%D%/vdev_label_os.c \
|
||||||
%D%/zfs_racct.c
|
%D%/zfs_racct.c \
|
||||||
|
%D%/zfs_debug.c
|
||||||
|
|
||||||
nodist_libzpool_la_SOURCES = \
|
nodist_libzpool_la_SOURCES = \
|
||||||
module/lua/lapi.c \
|
module/lua/lapi.c \
|
||||||
@ -46,7 +47,6 @@ nodist_libzpool_la_SOURCES = \
|
|||||||
module/lua/lzio.c \
|
module/lua/lzio.c \
|
||||||
\
|
\
|
||||||
module/os/linux/zfs/vdev_file.c \
|
module/os/linux/zfs/vdev_file.c \
|
||||||
module/os/linux/zfs/zfs_debug.c \
|
|
||||||
module/os/linux/zfs/zio_crypt.c \
|
module/os/linux/zfs/zio_crypt.c \
|
||||||
\
|
\
|
||||||
module/zcommon/cityhash.c \
|
module/zcommon/cityhash.c \
|
||||||
|
@ -30,10 +30,16 @@
|
|||||||
#include <sys/vdev_impl.h>
|
#include <sys/vdev_impl.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the reserved boot area is in-use.
|
* Check if the reserved boot area is in-use. This is called from
|
||||||
|
* spa_vdev_attach() when adding a device to a raidz vdev, to ensure that the
|
||||||
|
* reserved area is available as scratch space for raidz expansion.
|
||||||
*
|
*
|
||||||
* This function always returns 0, as there are no known external uses
|
* This function currently always returns 0. On Linux, there are no known
|
||||||
* of the reserved area on Linux.
|
* external uses of the reserved area. On FreeBSD, the reserved boot area is
|
||||||
|
* used when booting to a ZFS root from an MBR partition.
|
||||||
|
*
|
||||||
|
* Currently nothing using libzpool can add a disk to a pool, so this does
|
||||||
|
* nothing.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
vdev_check_boot_reserve(spa_t *spa, vdev_t *childvd)
|
vdev_check_boot_reserve(spa_t *spa, vdev_t *childvd)
|
||||||
|
106
lib/libzpool/zfs_debug.c
Normal file
106
lib/libzpool/zfs_debug.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* 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 https://opensource.org/licenses/CDDL-1.0.
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
|
||||||
|
* Copyright (c) 2024, Rob Norris <robn@despairlabs.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/zfs_context.h>
|
||||||
|
|
||||||
|
typedef struct zfs_dbgmsg {
|
||||||
|
list_node_t zdm_node;
|
||||||
|
uint64_t zdm_timestamp;
|
||||||
|
uint_t zdm_size;
|
||||||
|
char zdm_msg[]; /* variable length allocation */
|
||||||
|
} zfs_dbgmsg_t;
|
||||||
|
|
||||||
|
static list_t zfs_dbgmsgs;
|
||||||
|
static kmutex_t zfs_dbgmsgs_lock;
|
||||||
|
|
||||||
|
int zfs_dbgmsg_enable = B_TRUE;
|
||||||
|
|
||||||
|
void
|
||||||
|
zfs_dbgmsg_init(void)
|
||||||
|
{
|
||||||
|
list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t),
|
||||||
|
offsetof(zfs_dbgmsg_t, zdm_node));
|
||||||
|
mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
zfs_dbgmsg_fini(void)
|
||||||
|
{
|
||||||
|
zfs_dbgmsg_t *zdm;
|
||||||
|
while ((zdm = list_remove_head(&zfs_dbgmsgs)))
|
||||||
|
umem_free(zdm, zdm->zdm_size);
|
||||||
|
mutex_destroy(&zfs_dbgmsgs_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
__set_error(const char *file, const char *func, int line, int err)
|
||||||
|
{
|
||||||
|
if (zfs_flags & ZFS_DEBUG_SET_ERROR)
|
||||||
|
__dprintf(B_FALSE, file, func, line, "error %lu",
|
||||||
|
(ulong_t)err);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
__zfs_dbgmsg(char *buf)
|
||||||
|
{
|
||||||
|
uint_t size = sizeof (zfs_dbgmsg_t) + strlen(buf) + 1;
|
||||||
|
zfs_dbgmsg_t *zdm = umem_zalloc(size, KM_SLEEP);
|
||||||
|
zdm->zdm_size = size;
|
||||||
|
zdm->zdm_timestamp = gethrestime_sec();
|
||||||
|
strcpy(zdm->zdm_msg, buf);
|
||||||
|
|
||||||
|
mutex_enter(&zfs_dbgmsgs_lock);
|
||||||
|
list_insert_tail(&zfs_dbgmsgs, zdm);
|
||||||
|
mutex_exit(&zfs_dbgmsgs_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
zfs_dbgmsg_print(int fd, const char *tag)
|
||||||
|
{
|
||||||
|
ssize_t ret __attribute__((unused));
|
||||||
|
|
||||||
|
mutex_enter(&zfs_dbgmsgs_lock);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We use write() in this function instead of printf()
|
||||||
|
* so it is safe to call from a signal handler.
|
||||||
|
*/
|
||||||
|
ret = write(fd, "ZFS_DBGMSG(", 11);
|
||||||
|
ret = write(fd, tag, strlen(tag));
|
||||||
|
ret = write(fd, ") START:\n", 9);
|
||||||
|
|
||||||
|
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
|
||||||
|
zdm = list_next(&zfs_dbgmsgs, zdm)) {
|
||||||
|
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
|
||||||
|
ret = write(fd, "\n", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = write(fd, "ZFS_DBGMSG(", 11);
|
||||||
|
ret = write(fd, tag, strlen(tag));
|
||||||
|
ret = write(fd, ") END\n", 6);
|
||||||
|
|
||||||
|
mutex_exit(&zfs_dbgmsgs_lock);
|
||||||
|
}
|
@ -140,15 +140,11 @@ zfs_dbgmsg_fini(void)
|
|||||||
{
|
{
|
||||||
if (zfs_dbgmsg_kstat)
|
if (zfs_dbgmsg_kstat)
|
||||||
kstat_delete(zfs_dbgmsg_kstat);
|
kstat_delete(zfs_dbgmsg_kstat);
|
||||||
/*
|
|
||||||
* TODO - decide how to make this permanent
|
|
||||||
*/
|
|
||||||
#ifdef _KERNEL
|
|
||||||
mutex_enter(&zfs_dbgmsgs_lock);
|
mutex_enter(&zfs_dbgmsgs_lock);
|
||||||
zfs_dbgmsg_purge(0);
|
zfs_dbgmsg_purge(0);
|
||||||
mutex_exit(&zfs_dbgmsgs_lock);
|
mutex_exit(&zfs_dbgmsgs_lock);
|
||||||
mutex_destroy(&zfs_dbgmsgs_lock);
|
mutex_destroy(&zfs_dbgmsgs_lock);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -184,7 +180,6 @@ __set_error(const char *file, const char *func, int line, int err)
|
|||||||
__dprintf(B_FALSE, file, func, line, "error %lu", (ulong_t)err);
|
__dprintf(B_FALSE, file, func, line, "error %lu", (ulong_t)err);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _KERNEL
|
|
||||||
void
|
void
|
||||||
__dprintf(boolean_t dprint, const char *file, const char *func,
|
__dprintf(boolean_t dprint, const char *file, const char *func,
|
||||||
int line, const char *fmt, ...)
|
int line, const char *fmt, ...)
|
||||||
@ -229,37 +224,6 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
|
|||||||
kmem_free(buf, size);
|
kmem_free(buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void
|
|
||||||
zfs_dbgmsg_print(int fd, const char *tag)
|
|
||||||
{
|
|
||||||
ssize_t ret __attribute__((unused));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We use write() in this function instead of printf()
|
|
||||||
* so it is safe to call from a signal handler.
|
|
||||||
*/
|
|
||||||
ret = write(fd, "ZFS_DBGMSG(", 11);
|
|
||||||
ret = write(fd, tag, strlen(tag));
|
|
||||||
ret = write(fd, ") START:\n", 9);
|
|
||||||
|
|
||||||
mutex_enter(&zfs_dbgmsgs_lock);
|
|
||||||
|
|
||||||
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
|
|
||||||
zdm = list_next(&zfs_dbgmsgs, zdm))
|
|
||||||
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
|
|
||||||
ret = write(fd, "\n", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = write(fd, "ZFS_DBGMSG(", 11);
|
|
||||||
ret = write(fd, tag, strlen(tag));
|
|
||||||
ret = write(fd, ") END\n", 6);
|
|
||||||
|
|
||||||
mutex_exit(&zfs_dbgmsgs_lock);
|
|
||||||
}
|
|
||||||
#endif /* _KERNEL */
|
|
||||||
|
|
||||||
ZFS_MODULE_PARAM(zfs, zfs_, dbgmsg_enable, INT, ZMOD_RW,
|
ZFS_MODULE_PARAM(zfs, zfs_, dbgmsg_enable, INT, ZMOD_RW,
|
||||||
"Enable ZFS debug message log");
|
"Enable ZFS debug message log");
|
||||||
|
|
||||||
|
@ -111,12 +111,7 @@ zfs_dbgmsg_fini(void)
|
|||||||
procfs_list_uninstall(&zfs_dbgmsgs);
|
procfs_list_uninstall(&zfs_dbgmsgs);
|
||||||
zfs_dbgmsg_purge(0);
|
zfs_dbgmsg_purge(0);
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO - decide how to make this permanent
|
|
||||||
*/
|
|
||||||
#ifdef _KERNEL
|
|
||||||
procfs_list_destroy(&zfs_dbgmsgs);
|
procfs_list_destroy(&zfs_dbgmsgs);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -148,8 +143,6 @@ __zfs_dbgmsg(char *buf)
|
|||||||
mutex_exit(&zfs_dbgmsgs.pl_lock);
|
mutex_exit(&zfs_dbgmsgs.pl_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _KERNEL
|
|
||||||
|
|
||||||
void
|
void
|
||||||
__dprintf(boolean_t dprint, const char *file, const char *func,
|
__dprintf(boolean_t dprint, const char *file, const char *func,
|
||||||
int line, const char *fmt, ...)
|
int line, const char *fmt, ...)
|
||||||
@ -217,38 +210,6 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
|
|||||||
kmem_free(buf, size);
|
kmem_free(buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void
|
|
||||||
zfs_dbgmsg_print(int fd, const char *tag)
|
|
||||||
{
|
|
||||||
ssize_t ret __attribute__((unused));
|
|
||||||
|
|
||||||
mutex_enter(&zfs_dbgmsgs.pl_lock);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We use write() in this function instead of printf()
|
|
||||||
* so it is safe to call from a signal handler.
|
|
||||||
*/
|
|
||||||
ret = write(fd, "ZFS_DBGMSG(", 11);
|
|
||||||
ret = write(fd, tag, strlen(tag));
|
|
||||||
ret = write(fd, ") START:\n", 9);
|
|
||||||
|
|
||||||
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs.pl_list); zdm != NULL;
|
|
||||||
zdm = list_next(&zfs_dbgmsgs.pl_list, zdm)) {
|
|
||||||
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
|
|
||||||
ret = write(fd, "\n", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = write(fd, "ZFS_DBGMSG(", 11);
|
|
||||||
ret = write(fd, tag, strlen(tag));
|
|
||||||
ret = write(fd, ") END\n", 6);
|
|
||||||
|
|
||||||
mutex_exit(&zfs_dbgmsgs.pl_lock);
|
|
||||||
}
|
|
||||||
#endif /* _KERNEL */
|
|
||||||
|
|
||||||
#ifdef _KERNEL
|
|
||||||
module_param(zfs_dbgmsg_enable, int, 0644);
|
module_param(zfs_dbgmsg_enable, int, 0644);
|
||||||
MODULE_PARM_DESC(zfs_dbgmsg_enable, "Enable ZFS debug message log");
|
MODULE_PARM_DESC(zfs_dbgmsg_enable, "Enable ZFS debug message log");
|
||||||
|
|
||||||
@ -256,4 +217,3 @@ MODULE_PARM_DESC(zfs_dbgmsg_enable, "Enable ZFS debug message log");
|
|||||||
module_param(zfs_dbgmsg_maxsize, uint, 0644);
|
module_param(zfs_dbgmsg_maxsize, uint, 0644);
|
||||||
/* END CSTYLED */
|
/* END CSTYLED */
|
||||||
MODULE_PARM_DESC(zfs_dbgmsg_maxsize, "Maximum ZFS debug log size");
|
MODULE_PARM_DESC(zfs_dbgmsg_maxsize, "Maximum ZFS debug log size");
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user