File: zfs_debug_common.c

package info (click to toggle)
zfs-linux 2.4.1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 71,788 kB
  • sloc: ansic: 398,467; sh: 70,894; asm: 48,745; python: 8,163; makefile: 5,220; perl: 859
file content (97 lines) | stat: -rw-r--r-- 2,422 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-License-Identifier: CDDL-1.0
/*
 * 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) 2025 by Lawrence Livermore National Security, LLC.
 */
/*
 * This file contains zfs_dbgmsg() specific functions that are not OS or
 * userspace specific.
 */
#if !defined(_KERNEL)
#include <string.h>
#endif

#include <sys/zfs_context.h>
#include <sys/zfs_debug.h>
#include <sys/nvpair.h>

/*
 * Given a multi-line string, print out one of the lines and return a pointer
 * to the next line. Lines are demarcated by '\n'.  Note: this modifies the
 * input string (buf[]).
 *
 * This function is meant to be used in a loop like:
 * 	while (buf != NULL)
 * 		buf = kernel_print_one_line(buf);
 *
 * This function is useful for printing large, multi-line text buffers.
 *
 * Returns the pointer to the beginning of the next line in buf[], or NULL
 * if it's the last line, or nothing more to print.
 */
static char *
zfs_dbgmsg_one_line(char *buf)
{
	char *nl;
	if (!buf)
		return (NULL);

	nl = strchr(buf, '\n');
	if (nl == NULL) {
		__zfs_dbgmsg(buf);
		return (NULL); /* done */
	}
	*nl = '\0';
	__zfs_dbgmsg(buf);

	return (nl + 1);
}

/*
 * Dump an nvlist tree to dbgmsg.
 *
 * This is the zfs_dbgmsg version of userspace's dump_nvlist() from libnvpair.
 */
void
__zfs_dbgmsg_nvlist(nvlist_t *nv)
{
	int len;
	char *buf;

	len = nvlist_snprintf(NULL, 0, nv, 4);
	len++; /* Add null terminator */

	buf = vmem_alloc(len, KM_SLEEP);
	if (buf == NULL)
		return;

	(void) nvlist_snprintf(buf, len, nv, 4);

	while (buf != NULL)
		buf = zfs_dbgmsg_one_line(buf);

	vmem_free(buf, len);
}

#ifdef _KERNEL
EXPORT_SYMBOL(__zfs_dbgmsg_nvlist);
#endif