aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Norris <robn@despairlabs.com>2024-08-28 12:28:58 +0000
committerTony Hutter <hutter2@llnl.gov>2024-11-15 18:15:01 +0000
commit4982943d253b45d55b9043bdb6ba3a3c1aa59d7b (patch)
tree538fb106c6f7f79c0b3dc8911a22a76e95bebfcb
parent16266b47a13a2f9796ad3fba567315d66f8850f5 (diff)
-rw-r--r--lib/libzpool/Makefile.am4
-rw-r--r--lib/libzpool/vdev_label_os.c12
-rw-r--r--lib/libzpool/zfs_debug.c106
-rw-r--r--module/os/freebsd/zfs/zfs_debug.c38
-rw-r--r--module/os/linux/zfs/zfs_debug.c40
5 files changed, 118 insertions, 82 deletions
diff --git a/lib/libzpool/Makefile.am b/lib/libzpool/Makefile.am
index a353583eb430..edac1f1b2707 100644
--- a/lib/libzpool/Makefile.am
+++ b/lib/libzpool/Makefile.am
@@ -17,7 +17,8 @@ dist_libzpool_la_SOURCES = \
%D%/taskq.c \
%D%/util.c \
%D%/vdev_label_os.c \
- %D%/zfs_racct.c
+ %D%/zfs_racct.c \
+ %D%/zfs_debug.c
nodist_libzpool_la_SOURCES = \
module/lua/lapi.c \
@@ -46,7 +47,6 @@ nodist_libzpool_la_SOURCES = \
module/lua/lzio.c \
\
module/os/linux/zfs/vdev_file.c \
- module/os/linux/zfs/zfs_debug.c \
module/os/linux/zfs/zio_crypt.c \
\
module/zcommon/cityhash.c \
diff --git a/lib/libzpool/vdev_label_os.c b/lib/libzpool/vdev_label_os.c
index 3d965b89a962..c303cba6dc09 100644
--- a/lib/libzpool/vdev_label_os.c
+++ b/lib/libzpool/vdev_label_os.c
@@ -30,10 +30,16 @@
#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
- * of the reserved area on Linux.
+ * This function currently always returns 0. On Linux, there are no known
+ * 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
vdev_check_boot_reserve(spa_t *spa, vdev_t *childvd)
diff --git a/lib/libzpool/zfs_debug.c b/lib/libzpool/zfs_debug.c
new file mode 100644
index 000000000000..df49a9a33fe8
--- /dev/null
+++ b/lib/libzpool/zfs_debug.c
@@ -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);
+}
diff --git a/module/os/freebsd/zfs/zfs_debug.c b/module/os/freebsd/zfs/zfs_debug.c
index c4cebe102075..a7ddd3c2f5eb 100644
--- a/module/os/freebsd/zfs/zfs_debug.c
+++ b/module/os/freebsd/zfs/zfs_debug.c
@@ -140,15 +140,11 @@ zfs_dbgmsg_fini(void)
{
if (zfs_dbgmsg_kstat)
kstat_delete(zfs_dbgmsg_kstat);
- /*
- * TODO - decide how to make this permanent
- */
-#ifdef _KERNEL
+
mutex_enter(&zfs_dbgmsgs_lock);
zfs_dbgmsg_purge(0);
mutex_exit(&zfs_dbgmsgs_lock);
mutex_destroy(&zfs_dbgmsgs_lock);
-#endif
}
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);
}
-#ifdef _KERNEL
void
__dprintf(boolean_t dprint, const char *file, const char *func,
int line, const char *fmt, ...)
@@ -229,37 +224,6 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
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,
"Enable ZFS debug message log");
diff --git a/module/os/linux/zfs/zfs_debug.c b/module/os/linux/zfs/zfs_debug.c
index 733b4a574bf5..92e2d69ee06b 100644
--- a/module/os/linux/zfs/zfs_debug.c
+++ b/module/os/linux/zfs/zfs_debug.c
@@ -111,12 +111,7 @@ zfs_dbgmsg_fini(void)
procfs_list_uninstall(&zfs_dbgmsgs);
zfs_dbgmsg_purge(0);
- /*
- * TODO - decide how to make this permanent
- */
-#ifdef _KERNEL
procfs_list_destroy(&zfs_dbgmsgs);
-#endif
}
void
@@ -148,8 +143,6 @@ __zfs_dbgmsg(char *buf)
mutex_exit(&zfs_dbgmsgs.pl_lock);
}
-#ifdef _KERNEL
-
void
__dprintf(boolean_t dprint, const char *file, const char *func,
int line, const char *fmt, ...)
@@ -217,38 +210,6 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
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_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);
/* END CSTYLED */
MODULE_PARM_DESC(zfs_dbgmsg_maxsize, "Maximum ZFS debug log size");
-#endif