-
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.
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 #16492
- Loading branch information
1 parent
c22d56e
commit e8ede2b
Showing
5 changed files
with
118 additions
and
82 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
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,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 <[email protected]> | ||
*/ | ||
|
||
#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); | ||
} |
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