xref: /freebsd/sys/contrib/openzfs/include/sys/fm/util.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 
13 /*
14  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
15  */
16 
17 #ifndef	_SYS_FM_UTIL_H
18 #define	_SYS_FM_UTIL_H
19 
20 #ifdef	__cplusplus
21 extern "C" {
22 #endif
23 
24 #include <sys/nvpair.h>
25 #include <sys/zfs_file.h>
26 
27 /*
28  * Shared user/kernel definitions for class length, error channel name,
29  * and kernel event publisher string.
30  */
31 #define	FM_MAX_CLASS 100
32 #define	FM_ERROR_CHAN	"com.sun:fm:error"
33 #define	FM_PUB		"fm"
34 
35 /*
36  * ereport dump device transport support
37  *
38  * Ereports are written out to the dump device at a proscribed offset from the
39  * end, similar to in-transit log messages.  The ereports are represented as a
40  * erpt_dump_t header followed by ed_size bytes of packed native nvlist data.
41  *
42  * NOTE: All of these constants and the header must be defined so they have the
43  * same representation for *both* 32-bit and 64-bit producers and consumers.
44  */
45 #define	ERPT_MAGIC	0xf00d4eddU
46 #define	ERPT_MAX_ERRS	16
47 #define	ERPT_DATA_SZ	(6 * 1024)
48 #define	ERPT_EVCH_MAX	256
49 #define	ERPT_HIWAT	64
50 
51 typedef struct erpt_dump {
52 	uint32_t ed_magic;	/* ERPT_MAGIC or zero to indicate end */
53 	uint32_t ed_chksum;	/* checksum32() of packed nvlist data */
54 	uint32_t ed_size;	/* ereport (nvl) fixed buf size */
55 	uint32_t ed_pad;	/* reserved for future use */
56 	hrtime_t ed_hrt_nsec;	/* hrtime of this ereport */
57 	hrtime_t ed_hrt_base;	/* hrtime sample corresponding to ed_tod_base */
58 	struct {
59 		uint64_t sec;	/* seconds since gettimeofday() Epoch */
60 		uint64_t nsec;	/* nanoseconds past ed_tod_base.sec */
61 	} ed_tod_base;
62 } erpt_dump_t;
63 
64 #ifdef _KERNEL
65 
66 #define	ZEVENT_SHUTDOWN		0x1
67 
68 typedef void zevent_cb_t(nvlist_t *, nvlist_t *);
69 
70 typedef struct zevent_s {
71 	nvlist_t	*ev_nvl;	/* protected by the zevent_lock */
72 	nvlist_t	*ev_detector;	/* " */
73 	list_t		ev_ze_list;	/* " */
74 	list_node_t	ev_node;	/* " */
75 	zevent_cb_t	*ev_cb;		/* " */
76 	uint64_t	ev_eid;
77 } zevent_t;
78 
79 typedef struct zfs_zevent {
80 	zevent_t	*ze_zevent;	/* protected by the zevent_lock */
81 	list_node_t	ze_node;	/* " */
82 	uint64_t	ze_dropped;	/* " */
83 } zfs_zevent_t;
84 
85 extern void fm_init(void);
86 extern void fm_fini(void);
87 extern void zfs_zevent_post_cb(nvlist_t *nvl, nvlist_t *detector);
88 extern int zfs_zevent_post(nvlist_t *, nvlist_t *, zevent_cb_t *);
89 extern void zfs_zevent_drain_all(uint_t *);
90 extern zfs_file_t *zfs_zevent_fd_hold(int, minor_t *, zfs_zevent_t **);
91 extern void zfs_zevent_fd_rele(zfs_file_t *);
92 extern int zfs_zevent_next(zfs_zevent_t *, nvlist_t **, uint64_t *, uint64_t *);
93 extern int zfs_zevent_wait(zfs_zevent_t *);
94 extern int zfs_zevent_seek(zfs_zevent_t *, uint64_t);
95 extern void zfs_zevent_init(zfs_zevent_t **);
96 extern void zfs_zevent_destroy(zfs_zevent_t *);
97 
98 extern void zfs_zevent_track_duplicate(void);
99 extern void zfs_ereport_init(void);
100 extern void zfs_ereport_fini(void);
101 #else
102 
fm_init(void)103 static inline void fm_init(void) { }
fm_fini(void)104 static inline void fm_fini(void) { }
105 
106 #endif  /* _KERNEL */
107 
108 #ifdef	__cplusplus
109 }
110 #endif
111 
112 #endif /* _SYS_FM_UTIL_H */
113