Skip to content

Commit 4982943

Browse files
robntonyhutter
authored andcommitted
zfs_debug: specific variant for userspace
Just nice and simple, with room to grow. Reviewed by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Rob Norris <[email protected]> Sponsored-by: https://despairlabs.com/sponsor/ Closes openzfs#16492
1 parent 16266b4 commit 4982943

File tree

5 files changed

+118
-82
lines changed

5 files changed

+118
-82
lines changed

lib/libzpool/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ dist_libzpool_la_SOURCES = \
1717
%D%/taskq.c \
1818
%D%/util.c \
1919
%D%/vdev_label_os.c \
20-
%D%/zfs_racct.c
20+
%D%/zfs_racct.c \
21+
%D%/zfs_debug.c
2122

2223
nodist_libzpool_la_SOURCES = \
2324
module/lua/lapi.c \
@@ -46,7 +47,6 @@ nodist_libzpool_la_SOURCES = \
4647
module/lua/lzio.c \
4748
\
4849
module/os/linux/zfs/vdev_file.c \
49-
module/os/linux/zfs/zfs_debug.c \
5050
module/os/linux/zfs/zio_crypt.c \
5151
\
5252
module/zcommon/cityhash.c \

lib/libzpool/vdev_label_os.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@
3030
#include <sys/vdev_impl.h>
3131

3232
/*
33-
* Check if the reserved boot area is in-use.
33+
* Check if the reserved boot area is in-use. This is called from
34+
* spa_vdev_attach() when adding a device to a raidz vdev, to ensure that the
35+
* reserved area is available as scratch space for raidz expansion.
3436
*
35-
* This function always returns 0, as there are no known external uses
36-
* of the reserved area on Linux.
37+
* This function currently always returns 0. On Linux, there are no known
38+
* external uses of the reserved area. On FreeBSD, the reserved boot area is
39+
* used when booting to a ZFS root from an MBR partition.
40+
*
41+
* Currently nothing using libzpool can add a disk to a pool, so this does
42+
* nothing.
3743
*/
3844
int
3945
vdev_check_boot_reserve(spa_t *spa, vdev_t *childvd)

lib/libzpool/zfs_debug.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or https://opensource.org/licenses/CDDL-1.0.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
/*
22+
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23+
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24+
* Copyright (c) 2024, Rob Norris <[email protected]>
25+
*/
26+
27+
#include <sys/zfs_context.h>
28+
29+
typedef struct zfs_dbgmsg {
30+
list_node_t zdm_node;
31+
uint64_t zdm_timestamp;
32+
uint_t zdm_size;
33+
char zdm_msg[]; /* variable length allocation */
34+
} zfs_dbgmsg_t;
35+
36+
static list_t zfs_dbgmsgs;
37+
static kmutex_t zfs_dbgmsgs_lock;
38+
39+
int zfs_dbgmsg_enable = B_TRUE;
40+
41+
void
42+
zfs_dbgmsg_init(void)
43+
{
44+
list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t),
45+
offsetof(zfs_dbgmsg_t, zdm_node));
46+
mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL);
47+
}
48+
49+
void
50+
zfs_dbgmsg_fini(void)
51+
{
52+
zfs_dbgmsg_t *zdm;
53+
while ((zdm = list_remove_head(&zfs_dbgmsgs)))
54+
umem_free(zdm, zdm->zdm_size);
55+
mutex_destroy(&zfs_dbgmsgs_lock);
56+
}
57+
58+
void
59+
__set_error(const char *file, const char *func, int line, int err)
60+
{
61+
if (zfs_flags & ZFS_DEBUG_SET_ERROR)
62+
__dprintf(B_FALSE, file, func, line, "error %lu",
63+
(ulong_t)err);
64+
}
65+
66+
void
67+
__zfs_dbgmsg(char *buf)
68+
{
69+
uint_t size = sizeof (zfs_dbgmsg_t) + strlen(buf) + 1;
70+
zfs_dbgmsg_t *zdm = umem_zalloc(size, KM_SLEEP);
71+
zdm->zdm_size = size;
72+
zdm->zdm_timestamp = gethrestime_sec();
73+
strcpy(zdm->zdm_msg, buf);
74+
75+
mutex_enter(&zfs_dbgmsgs_lock);
76+
list_insert_tail(&zfs_dbgmsgs, zdm);
77+
mutex_exit(&zfs_dbgmsgs_lock);
78+
}
79+
80+
void
81+
zfs_dbgmsg_print(int fd, const char *tag)
82+
{
83+
ssize_t ret __attribute__((unused));
84+
85+
mutex_enter(&zfs_dbgmsgs_lock);
86+
87+
/*
88+
* We use write() in this function instead of printf()
89+
* so it is safe to call from a signal handler.
90+
*/
91+
ret = write(fd, "ZFS_DBGMSG(", 11);
92+
ret = write(fd, tag, strlen(tag));
93+
ret = write(fd, ") START:\n", 9);
94+
95+
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
96+
zdm = list_next(&zfs_dbgmsgs, zdm)) {
97+
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
98+
ret = write(fd, "\n", 1);
99+
}
100+
101+
ret = write(fd, "ZFS_DBGMSG(", 11);
102+
ret = write(fd, tag, strlen(tag));
103+
ret = write(fd, ") END\n", 6);
104+
105+
mutex_exit(&zfs_dbgmsgs_lock);
106+
}

module/os/freebsd/zfs/zfs_debug.c

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,11 @@ zfs_dbgmsg_fini(void)
140140
{
141141
if (zfs_dbgmsg_kstat)
142142
kstat_delete(zfs_dbgmsg_kstat);
143-
/*
144-
* TODO - decide how to make this permanent
145-
*/
146-
#ifdef _KERNEL
143+
147144
mutex_enter(&zfs_dbgmsgs_lock);
148145
zfs_dbgmsg_purge(0);
149146
mutex_exit(&zfs_dbgmsgs_lock);
150147
mutex_destroy(&zfs_dbgmsgs_lock);
151-
#endif
152148
}
153149

154150
void
@@ -184,7 +180,6 @@ __set_error(const char *file, const char *func, int line, int err)
184180
__dprintf(B_FALSE, file, func, line, "error %lu", (ulong_t)err);
185181
}
186182

187-
#ifdef _KERNEL
188183
void
189184
__dprintf(boolean_t dprint, const char *file, const char *func,
190185
int line, const char *fmt, ...)
@@ -229,37 +224,6 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
229224
kmem_free(buf, size);
230225
}
231226

232-
#else
233-
234-
void
235-
zfs_dbgmsg_print(int fd, const char *tag)
236-
{
237-
ssize_t ret __attribute__((unused));
238-
239-
/*
240-
* We use write() in this function instead of printf()
241-
* so it is safe to call from a signal handler.
242-
*/
243-
ret = write(fd, "ZFS_DBGMSG(", 11);
244-
ret = write(fd, tag, strlen(tag));
245-
ret = write(fd, ") START:\n", 9);
246-
247-
mutex_enter(&zfs_dbgmsgs_lock);
248-
249-
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
250-
zdm = list_next(&zfs_dbgmsgs, zdm))
251-
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
252-
ret = write(fd, "\n", 1);
253-
}
254-
255-
ret = write(fd, "ZFS_DBGMSG(", 11);
256-
ret = write(fd, tag, strlen(tag));
257-
ret = write(fd, ") END\n", 6);
258-
259-
mutex_exit(&zfs_dbgmsgs_lock);
260-
}
261-
#endif /* _KERNEL */
262-
263227
ZFS_MODULE_PARAM(zfs, zfs_, dbgmsg_enable, INT, ZMOD_RW,
264228
"Enable ZFS debug message log");
265229

module/os/linux/zfs/zfs_debug.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,7 @@ zfs_dbgmsg_fini(void)
111111
procfs_list_uninstall(&zfs_dbgmsgs);
112112
zfs_dbgmsg_purge(0);
113113

114-
/*
115-
* TODO - decide how to make this permanent
116-
*/
117-
#ifdef _KERNEL
118114
procfs_list_destroy(&zfs_dbgmsgs);
119-
#endif
120115
}
121116

122117
void
@@ -148,8 +143,6 @@ __zfs_dbgmsg(char *buf)
148143
mutex_exit(&zfs_dbgmsgs.pl_lock);
149144
}
150145

151-
#ifdef _KERNEL
152-
153146
void
154147
__dprintf(boolean_t dprint, const char *file, const char *func,
155148
int line, const char *fmt, ...)
@@ -217,43 +210,10 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
217210
kmem_free(buf, size);
218211
}
219212

220-
#else
221-
222-
void
223-
zfs_dbgmsg_print(int fd, const char *tag)
224-
{
225-
ssize_t ret __attribute__((unused));
226-
227-
mutex_enter(&zfs_dbgmsgs.pl_lock);
228-
229-
/*
230-
* We use write() in this function instead of printf()
231-
* so it is safe to call from a signal handler.
232-
*/
233-
ret = write(fd, "ZFS_DBGMSG(", 11);
234-
ret = write(fd, tag, strlen(tag));
235-
ret = write(fd, ") START:\n", 9);
236-
237-
for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs.pl_list); zdm != NULL;
238-
zdm = list_next(&zfs_dbgmsgs.pl_list, zdm)) {
239-
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
240-
ret = write(fd, "\n", 1);
241-
}
242-
243-
ret = write(fd, "ZFS_DBGMSG(", 11);
244-
ret = write(fd, tag, strlen(tag));
245-
ret = write(fd, ") END\n", 6);
246-
247-
mutex_exit(&zfs_dbgmsgs.pl_lock);
248-
}
249-
#endif /* _KERNEL */
250-
251-
#ifdef _KERNEL
252213
module_param(zfs_dbgmsg_enable, int, 0644);
253214
MODULE_PARM_DESC(zfs_dbgmsg_enable, "Enable ZFS debug message log");
254215

255216
/* BEGIN CSTYLED */
256217
module_param(zfs_dbgmsg_maxsize, uint, 0644);
257218
/* END CSTYLED */
258219
MODULE_PARM_DESC(zfs_dbgmsg_maxsize, "Maximum ZFS debug log size");
259-
#endif

0 commit comments

Comments
 (0)