4 * This file and its contents are supplied under the terms of the
5 * Common Development and Distribution License ("CDDL"), version 1.0.
6 * You may only use this file in accordance with the terms of version
9 * A full copy of the text of the CDDL should have accompanied this
10 * source. A copy of the CDDL is also available via the Internet at
11 * http://www.illumos.org/license/CDDL.
17 * Copyright (c) 2020 by Delphix. All rights reserved.
24 #include <sys/zfs_ioctl.h>
25 #include <sys/nvpair.h>
26 #include <sys/fm/protocol.h>
27 #include <sys/fm/fs/zfs.h>
30 * Command to output io and checksum ereport values, one per line.
31 * Used by zpool_events_duplicates.ksh to check for duplicate events.
33 * example output line:
35 * checksum "error_pool" 0x856dd01ce52e336 0x000034 0x000400 0x000a402c00
36 * 0x000004 0x000000 0x000000 0x000000 0x000001
40 * Our ereport duplicate criteria
42 * When the class and all of these values match, then an ereport is
43 * considered to be a duplicate.
45 static const char *const criteria_name
[] = {
46 FM_EREPORT_PAYLOAD_ZFS_POOL
,
47 FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID
,
48 FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR
,
49 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE
,
50 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET
,
51 FM_EREPORT_PAYLOAD_ZFS_ZIO_PRIORITY
,
53 /* logical zio criteriai (optional) */
54 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET
,
55 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT
,
56 FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID
,
57 FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL
,
60 #define CRITERIA_NAMES_COUNT ARRAY_SIZE(criteria_name)
63 print_ereport_line(nvlist_t
*nvl
)
66 int last
= CRITERIA_NAMES_COUNT
- 1;
69 * For the test case context, we only want to see 'io' and
70 * 'checksum' subclass. We skip 'data' to minimize the output.
72 if (nvlist_lookup_string(nvl
, FM_CLASS
, &class) != 0 ||
73 strstr(class, "ereport.fs.zfs.") == NULL
||
74 strcmp(class, "ereport.fs.zfs.data") == 0) {
78 (void) printf("%s\t", class + strlen("ereport.fs.zfs."));
80 for (int i
= 0; i
< CRITERIA_NAMES_COUNT
; i
++) {
84 const char *str
= NULL
;
86 if (nvlist_lookup_nvpair(nvl
, criteria_name
[i
], &nvp
) != 0) {
87 /* print a proxy for optional criteria */
88 (void) printf("--------");
89 (void) printf("%c", i
== last
? '\n' : '\t');
93 switch (nvpair_type(nvp
)) {
94 case DATA_TYPE_STRING
:
95 (void) nvpair_value_string(nvp
, &str
);
96 (void) printf("\"%s\"", str
? str
: "<NULL>");
100 (void) nvpair_value_int32(nvp
, (void *)&i32
);
101 (void) printf("0x%06x", i32
);
104 case DATA_TYPE_UINT32
:
105 (void) nvpair_value_uint32(nvp
, &i32
);
106 (void) printf("0x%06x", i32
);
109 case DATA_TYPE_INT64
:
110 (void) nvpair_value_int64(nvp
, (void *)&i64
);
111 (void) printf("0x%06llx", (u_longlong_t
)i64
);
114 case DATA_TYPE_UINT64
:
115 (void) nvpair_value_uint64(nvp
, &i64
);
116 if (strcmp(FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET
,
117 criteria_name
[i
]) == 0)
118 (void) printf("0x%010llx", (u_longlong_t
)i64
);
120 (void) printf("0x%06llx", (u_longlong_t
)i64
);
123 (void) printf("<unknown>");
126 (void) printf("%c", i
== last
? '\n' : '\t');
131 ereports_dump(libzfs_handle_t
*zhdl
, int zevent_fd
)
137 ret
= zpool_events_next(zhdl
, &nvl
, &dropped
, ZEVENT_NONBLOCK
,
139 if (ret
|| nvl
== NULL
)
142 (void) fprintf(stdout
, "dropped %d events\n", dropped
);
143 print_ereport_line(nvl
);
144 (void) fflush(stdout
);
152 libzfs_handle_t
*hdl
;
157 (void) fprintf(stderr
, "libzfs_init: %s\n", strerror(errno
));
160 fd
= open(ZFS_DEV
, O_RDWR
);
162 (void) fprintf(stderr
, "open: %s\n", strerror(errno
));
167 ereports_dump(hdl
, fd
);