2010-04-29 21:37:15 +04:00
|
|
|
/*
|
|
|
|
* 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 http://www.opensolaris.org/os/licensing.
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
|
2010-04-29 21:37:15 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fault Management Architecture (FMA) Resource and Protocol Support
|
|
|
|
*
|
|
|
|
* The routines contained herein provide services to support kernel subsystems
|
|
|
|
* in publishing fault management telemetry (see PSARC 2002/412 and 2003/089).
|
|
|
|
*
|
|
|
|
* Name-Value Pair Lists
|
|
|
|
*
|
|
|
|
* The embodiment of an FMA protocol element (event, fmri or authority) is a
|
2019-09-03 03:56:41 +03:00
|
|
|
* name-value pair list (nvlist_t). FMA-specific nvlist constructor and
|
2010-04-29 21:37:15 +04:00
|
|
|
* destructor functions, fm_nvlist_create() and fm_nvlist_destroy(), are used
|
|
|
|
* to create an nvpair list using custom allocators. Callers may choose to
|
|
|
|
* allocate either from the kernel memory allocator, or from a preallocated
|
|
|
|
* buffer, useful in constrained contexts like high-level interrupt routines.
|
|
|
|
*
|
|
|
|
* Protocol Event and FMRI Construction
|
|
|
|
*
|
|
|
|
* Convenience routines are provided to construct nvlist events according to
|
|
|
|
* the FMA Event Protocol and Naming Schema specification for ereports and
|
|
|
|
* FMRIs for the dev, cpu, hc, mem, legacy hc and de schemes.
|
|
|
|
*
|
|
|
|
* ENA Manipulation
|
|
|
|
*
|
|
|
|
* Routines to generate ENA formats 0, 1 and 2 are available as well as
|
|
|
|
* routines to increment formats 1 and 2. Individual fields within the
|
|
|
|
* ENA are extractable via fm_ena_time_get(), fm_ena_id_get(),
|
|
|
|
* fm_ena_format_get() and fm_ena_gen_get().
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
2010-08-26 22:42:43 +04:00
|
|
|
#include <sys/list.h>
|
2010-04-29 21:37:15 +04:00
|
|
|
#include <sys/nvpair.h>
|
|
|
|
#include <sys/cmn_err.h>
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#include <sys/sunddi.h>
|
|
|
|
#include <sys/systeminfo.h>
|
|
|
|
#include <sys/fm/util.h>
|
|
|
|
#include <sys/fm/protocol.h>
|
2010-08-26 22:42:43 +04:00
|
|
|
#include <sys/kstat.h>
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/atomic.h>
|
|
|
|
#include <sys/condvar.h>
|
|
|
|
#include <sys/console.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2011-05-04 02:09:28 +04:00
|
|
|
int zfs_zevent_len_max = 0;
|
|
|
|
int zfs_zevent_cols = 80;
|
|
|
|
int zfs_zevent_console = 0;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
static int zevent_len_cur = 0;
|
|
|
|
static int zevent_waiters = 0;
|
|
|
|
static int zevent_flags = 0;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2016-10-19 22:55:59 +03:00
|
|
|
/* Num events rate limited since the last time zfs_zevent_next() was called */
|
|
|
|
static uint64_t ratelimit_dropped = 0;
|
|
|
|
|
2013-11-22 23:20:41 +04:00
|
|
|
/*
|
|
|
|
* The EID (Event IDentifier) is used to uniquely tag a zevent when it is
|
|
|
|
* posted. The posted EIDs are monotonically increasing but not persistent.
|
|
|
|
* They will be reset to the initial value (1) each time the kernel module is
|
|
|
|
* loaded.
|
|
|
|
*/
|
|
|
|
static uint64_t zevent_eid = 0;
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
static kmutex_t zevent_lock;
|
|
|
|
static list_t zevent_list;
|
|
|
|
static kcondvar_t zevent_cv;
|
|
|
|
#endif /* _KERNEL */
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
/*
|
2010-08-26 22:42:43 +04:00
|
|
|
* Common fault management kstats to record event generation failures
|
2010-04-29 21:37:15 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct erpt_kstat {
|
|
|
|
kstat_named_t erpt_dropped; /* num erpts dropped on post */
|
|
|
|
kstat_named_t erpt_set_failed; /* num erpt set failures */
|
|
|
|
kstat_named_t fmri_set_failed; /* num fmri set failures */
|
|
|
|
kstat_named_t payload_set_failed; /* num payload set failures */
|
2020-09-04 20:34:28 +03:00
|
|
|
kstat_named_t erpt_duplicates; /* num duplicate erpts */
|
2010-04-29 21:37:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct erpt_kstat erpt_kstat_data = {
|
|
|
|
{ "erpt-dropped", KSTAT_DATA_UINT64 },
|
|
|
|
{ "erpt-set-failed", KSTAT_DATA_UINT64 },
|
|
|
|
{ "fmri-set-failed", KSTAT_DATA_UINT64 },
|
2020-09-04 20:34:28 +03:00
|
|
|
{ "payload-set-failed", KSTAT_DATA_UINT64 },
|
|
|
|
{ "erpt-duplicates", KSTAT_DATA_UINT64 }
|
2010-04-29 21:37:15 +04:00
|
|
|
};
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
kstat_t *fm_ksp;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
#ifdef _KERNEL
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Formatting utility function for fm_nvprintr. We attempt to wrap chunks of
|
|
|
|
* output so they aren't split across console lines, and return the end column.
|
|
|
|
*/
|
|
|
|
/*PRINTFLIKE4*/
|
|
|
|
static int
|
|
|
|
fm_printf(int depth, int c, int cols, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int width;
|
|
|
|
char c1;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
width = vsnprintf(&c1, sizeof (c1), format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (c + width >= cols) {
|
2010-08-26 22:42:43 +04:00
|
|
|
console_printf("\n");
|
2010-04-29 21:37:15 +04:00
|
|
|
c = 0;
|
|
|
|
if (format[0] != ' ' && depth > 0) {
|
|
|
|
console_printf(" ");
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
console_vprintf(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return ((c + width) % cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-08-08 11:00:08 +03:00
|
|
|
* Recursively print an nvlist in the specified column width and return the
|
2010-04-29 21:37:15 +04:00
|
|
|
* column we end up in. This function is called recursively by fm_nvprint(),
|
|
|
|
* below. We generically format the entire nvpair using hexadecimal
|
|
|
|
* integers and strings, and elide any integer arrays. Arrays are basically
|
|
|
|
* used for cache dumps right now, so we suppress them so as not to overwhelm
|
|
|
|
* the amount of console output we produce at panic time. This can be further
|
|
|
|
* enhanced as FMA technology grows based upon the needs of consumers. All
|
|
|
|
* FMA telemetry is logged using the dump device transport, so the console
|
|
|
|
* output serves only as a fallback in case this procedure is unsuccessful.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fm_nvprintr(nvlist_t *nvl, int d, int c, int cols)
|
|
|
|
{
|
|
|
|
nvpair_t *nvp;
|
|
|
|
|
|
|
|
for (nvp = nvlist_next_nvpair(nvl, NULL);
|
|
|
|
nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) {
|
|
|
|
|
|
|
|
data_type_t type = nvpair_type(nvp);
|
|
|
|
const char *name = nvpair_name(nvp);
|
|
|
|
|
|
|
|
boolean_t b;
|
|
|
|
uint8_t i8;
|
|
|
|
uint16_t i16;
|
|
|
|
uint32_t i32;
|
|
|
|
uint64_t i64;
|
|
|
|
char *str;
|
|
|
|
nvlist_t *cnv;
|
|
|
|
|
|
|
|
if (strcmp(name, FM_CLASS) == 0)
|
|
|
|
continue; /* already printed by caller */
|
|
|
|
|
|
|
|
c = fm_printf(d, c, cols, " %s=", name);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DATA_TYPE_BOOLEAN:
|
|
|
|
c = fm_printf(d + 1, c, cols, " 1");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
(void) nvpair_value_boolean_value(nvp, &b);
|
|
|
|
c = fm_printf(d + 1, c, cols, b ? "1" : "0");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BYTE:
|
|
|
|
(void) nvpair_value_byte(nvp, &i8);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%x", i8);
|
2010-04-29 21:37:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT8:
|
|
|
|
(void) nvpair_value_int8(nvp, (void *)&i8);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%x", i8);
|
2010-04-29 21:37:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT8:
|
|
|
|
(void) nvpair_value_uint8(nvp, &i8);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%x", i8);
|
2010-04-29 21:37:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT16:
|
|
|
|
(void) nvpair_value_int16(nvp, (void *)&i16);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%x", i16);
|
2010-04-29 21:37:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT16:
|
|
|
|
(void) nvpair_value_uint16(nvp, &i16);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%x", i16);
|
2010-04-29 21:37:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT32:
|
|
|
|
(void) nvpair_value_int32(nvp, (void *)&i32);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%x", i32);
|
2010-04-29 21:37:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT32:
|
|
|
|
(void) nvpair_value_uint32(nvp, &i32);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%x", i32);
|
2010-04-29 21:37:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT64:
|
|
|
|
(void) nvpair_value_int64(nvp, (void *)&i64);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx",
|
2010-04-29 21:37:15 +04:00
|
|
|
(u_longlong_t)i64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT64:
|
|
|
|
(void) nvpair_value_uint64(nvp, &i64);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx",
|
2010-04-29 21:37:15 +04:00
|
|
|
(u_longlong_t)i64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_HRTIME:
|
|
|
|
(void) nvpair_value_hrtime(nvp, (void *)&i64);
|
2010-08-26 22:42:43 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx",
|
2010-04-29 21:37:15 +04:00
|
|
|
(u_longlong_t)i64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_STRING:
|
|
|
|
(void) nvpair_value_string(nvp, &str);
|
|
|
|
c = fm_printf(d + 1, c, cols, "\"%s\"",
|
|
|
|
str ? str : "<NULL>");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_NVLIST:
|
|
|
|
c = fm_printf(d + 1, c, cols, "[");
|
|
|
|
(void) nvpair_value_nvlist(nvp, &cnv);
|
|
|
|
c = fm_nvprintr(cnv, d + 1, c, cols);
|
|
|
|
c = fm_printf(d + 1, c, cols, " ]");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_NVLIST_ARRAY: {
|
|
|
|
nvlist_t **val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[");
|
|
|
|
(void) nvpair_value_nvlist_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++) {
|
|
|
|
c = fm_nvprintr(val[i], d + 1, c, cols);
|
|
|
|
}
|
|
|
|
c = fm_printf(d + 1, c, cols, " ]");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
case DATA_TYPE_INT8_ARRAY: {
|
|
|
|
int8_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_int8_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT8_ARRAY: {
|
|
|
|
uint8_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_uint8_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_INT16_ARRAY: {
|
|
|
|
int16_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_int16_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT16_ARRAY: {
|
|
|
|
uint16_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_uint16_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_INT32_ARRAY: {
|
|
|
|
int32_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_int32_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT32_ARRAY: {
|
|
|
|
uint32_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_uint32_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_INT64_ARRAY: {
|
|
|
|
int64_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_int64_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT64_ARRAY: {
|
|
|
|
uint64_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "[ ");
|
|
|
|
(void) nvpair_value_uint64_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 23:26:11 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "0x%llx ",
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
c = fm_printf(d + 1, c, cols, "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_STRING_ARRAY:
|
2010-04-29 21:37:15 +04:00
|
|
|
case DATA_TYPE_BOOLEAN_ARRAY:
|
|
|
|
case DATA_TYPE_BYTE_ARRAY:
|
|
|
|
c = fm_printf(d + 1, c, cols, "[...]");
|
|
|
|
break;
|
2010-08-26 22:42:43 +04:00
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
case DATA_TYPE_UNKNOWN:
|
2017-12-05 20:57:42 +03:00
|
|
|
case DATA_TYPE_DONTCARE:
|
2010-04-29 21:37:15 +04:00
|
|
|
c = fm_printf(d + 1, c, cols, "<unknown>");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fm_nvprint(nvlist_t *nvl)
|
|
|
|
{
|
|
|
|
char *class;
|
|
|
|
int c = 0;
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
console_printf("\n");
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
if (nvlist_lookup_string(nvl, FM_CLASS, &class) == 0)
|
2011-05-04 02:09:28 +04:00
|
|
|
c = fm_printf(0, c, zfs_zevent_cols, "%s", class);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2011-05-04 02:09:28 +04:00
|
|
|
if (fm_nvprintr(nvl, 0, c, zfs_zevent_cols) != 0)
|
2010-04-29 21:37:15 +04:00
|
|
|
console_printf("\n");
|
|
|
|
|
|
|
|
console_printf("\n");
|
|
|
|
}
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
static zevent_t *
|
|
|
|
zfs_zevent_alloc(void)
|
|
|
|
{
|
|
|
|
zevent_t *ev;
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
ev = kmem_zalloc(sizeof (zevent_t), KM_SLEEP);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
list_create(&ev->ev_ze_list, sizeof (zfs_zevent_t),
|
2016-12-12 21:46:26 +03:00
|
|
|
offsetof(zfs_zevent_t, ze_node));
|
2010-08-26 22:42:43 +04:00
|
|
|
list_link_init(&ev->ev_node);
|
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
return (ev);
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zfs_zevent_free(zevent_t *ev)
|
|
|
|
{
|
|
|
|
/* Run provided cleanup callback */
|
|
|
|
ev->ev_cb(ev->ev_nvl, ev->ev_detector);
|
|
|
|
|
|
|
|
list_destroy(&ev->ev_ze_list);
|
2013-11-01 23:26:11 +04:00
|
|
|
kmem_free(ev, sizeof (zevent_t));
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zfs_zevent_drain(zevent_t *ev)
|
|
|
|
{
|
|
|
|
zfs_zevent_t *ze;
|
|
|
|
|
|
|
|
ASSERT(MUTEX_HELD(&zevent_lock));
|
|
|
|
list_remove(&zevent_list, ev);
|
|
|
|
|
|
|
|
/* Remove references to this event in all private file data */
|
|
|
|
while ((ze = list_head(&ev->ev_ze_list)) != NULL) {
|
|
|
|
list_remove(&ev->ev_ze_list, ze);
|
|
|
|
ze->ze_zevent = NULL;
|
|
|
|
ze->ze_dropped++;
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_zevent_free(ev);
|
|
|
|
}
|
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
void
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_drain_all(int *count)
|
2010-04-29 21:37:15 +04:00
|
|
|
{
|
2010-08-26 22:42:43 +04:00
|
|
|
zevent_t *ev;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
mutex_enter(&zevent_lock);
|
|
|
|
while ((ev = list_head(&zevent_list)) != NULL)
|
|
|
|
zfs_zevent_drain(ev);
|
|
|
|
|
|
|
|
*count = zevent_len_cur;
|
|
|
|
zevent_len_cur = 0;
|
|
|
|
mutex_exit(&zevent_lock);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
/*
|
2010-08-26 22:42:43 +04:00
|
|
|
* New zevents are inserted at the head. If the maximum queue
|
|
|
|
* length is exceeded a zevent will be drained from the tail.
|
|
|
|
* As part of this any user space processes which currently have
|
|
|
|
* a reference to this zevent_t in their private data will have
|
|
|
|
* this reference set to NULL.
|
2010-08-27 01:24:34 +04:00
|
|
|
*/
|
2010-08-26 22:42:43 +04:00
|
|
|
static void
|
|
|
|
zfs_zevent_insert(zevent_t *ev)
|
2010-08-27 01:24:34 +04:00
|
|
|
{
|
2012-10-16 00:36:26 +04:00
|
|
|
ASSERT(MUTEX_HELD(&zevent_lock));
|
2010-08-26 22:42:43 +04:00
|
|
|
list_insert_head(&zevent_list, ev);
|
2012-10-16 00:36:26 +04:00
|
|
|
|
2011-05-04 02:09:28 +04:00
|
|
|
if (zevent_len_cur >= zfs_zevent_len_max)
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_drain(list_tail(&zevent_list));
|
2010-08-27 01:24:34 +04:00
|
|
|
else
|
2010-08-26 22:42:43 +04:00
|
|
|
zevent_len_cur++;
|
2010-08-27 01:24:34 +04:00
|
|
|
}
|
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
/*
|
2014-03-04 07:00:11 +04:00
|
|
|
* Post a zevent. The cb will be called when nvl and detector are no longer
|
|
|
|
* needed, i.e.:
|
|
|
|
* - An error happened and a zevent can't be posted. In this case, cb is called
|
|
|
|
* before zfs_zevent_post() returns.
|
|
|
|
* - The event is being drained and freed.
|
2010-04-29 21:37:15 +04:00
|
|
|
*/
|
2014-03-04 07:00:11 +04:00
|
|
|
int
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_post(nvlist_t *nvl, nvlist_t *detector, zevent_cb_t *cb)
|
2010-04-29 21:37:15 +04:00
|
|
|
{
|
2018-06-20 07:51:18 +03:00
|
|
|
inode_timespec_t tv;
|
2010-08-26 22:42:43 +04:00
|
|
|
int64_t tv_array[2];
|
2013-11-22 23:20:41 +04:00
|
|
|
uint64_t eid;
|
2010-08-26 22:42:43 +04:00
|
|
|
size_t nvl_size = 0;
|
|
|
|
zevent_t *ev;
|
2014-03-04 07:00:11 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
ASSERT(cb != NULL);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
gethrestime(&tv);
|
|
|
|
tv_array[0] = tv.tv_sec;
|
|
|
|
tv_array[1] = tv.tv_nsec;
|
2014-03-04 07:00:11 +04:00
|
|
|
|
|
|
|
error = nvlist_add_int64_array(nvl, FM_EREPORT_TIME, tv_array, 2);
|
|
|
|
if (error) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
|
2014-03-04 07:00:11 +04:00
|
|
|
goto out;
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2013-11-22 23:20:41 +04:00
|
|
|
eid = atomic_inc_64_nv(&zevent_eid);
|
2014-03-04 07:00:11 +04:00
|
|
|
error = nvlist_add_uint64(nvl, FM_EREPORT_EID, eid);
|
|
|
|
if (error) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
|
2014-03-04 07:00:11 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = nvlist_size(nvl, &nvl_size, NV_ENCODE_NATIVE);
|
|
|
|
if (error) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64);
|
2014-03-04 07:00:11 +04:00
|
|
|
goto out;
|
2013-11-22 23:20:41 +04:00
|
|
|
}
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
if (nvl_size > ERPT_DATA_SZ || nvl_size == 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64);
|
2014-03-04 07:00:11 +04:00
|
|
|
error = EOVERFLOW;
|
|
|
|
goto out;
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
2011-05-04 02:09:28 +04:00
|
|
|
if (zfs_zevent_console)
|
2010-08-26 22:42:43 +04:00
|
|
|
fm_nvprint(nvl);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
ev = zfs_zevent_alloc();
|
|
|
|
if (ev == NULL) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64);
|
2014-03-04 07:00:11 +04:00
|
|
|
error = ENOMEM;
|
|
|
|
goto out;
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
ev->ev_nvl = nvl;
|
2010-08-26 22:42:43 +04:00
|
|
|
ev->ev_detector = detector;
|
|
|
|
ev->ev_cb = cb;
|
2013-11-22 23:20:41 +04:00
|
|
|
ev->ev_eid = eid;
|
2012-10-16 00:36:26 +04:00
|
|
|
|
|
|
|
mutex_enter(&zevent_lock);
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_insert(ev);
|
|
|
|
cv_broadcast(&zevent_cv);
|
2012-10-16 00:36:26 +04:00
|
|
|
mutex_exit(&zevent_lock);
|
2014-03-04 07:00:11 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (error)
|
|
|
|
cb(nvl, detector);
|
|
|
|
|
|
|
|
return (error);
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2020-09-04 20:34:28 +03:00
|
|
|
void
|
|
|
|
zfs_zevent_track_duplicate(void)
|
|
|
|
{
|
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_duplicates.value.ui64);
|
|
|
|
}
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
static int
|
|
|
|
zfs_zevent_minor_to_state(minor_t minor, zfs_zevent_t **ze)
|
|
|
|
{
|
|
|
|
*ze = zfsdev_get_state(minor, ZST_ZEVENT);
|
|
|
|
if (*ze == NULL)
|
2017-08-03 07:16:12 +03:00
|
|
|
return (SET_ERROR(EBADF));
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
return (0);
|
|
|
|
}
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
int
|
|
|
|
zfs_zevent_fd_hold(int fd, minor_t *minorp, zfs_zevent_t **ze)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2019-10-17 04:43:52 +03:00
|
|
|
error = zfsdev_getminor(fd, minorp);
|
2015-04-16 16:20:02 +03:00
|
|
|
if (error == 0)
|
|
|
|
error = zfs_zevent_minor_to_state(*minorp, ze);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
zfs_zevent_fd_rele(fd);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zfs_zevent_fd_rele(int fd)
|
|
|
|
{
|
2019-11-21 20:32:57 +03:00
|
|
|
zfs_file_put(fd);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-05 03:21:04 +04:00
|
|
|
* Get the next zevent in the stream and place a copy in 'event'. This
|
|
|
|
* may fail with ENOMEM if the encoded nvlist size exceeds the passed
|
|
|
|
* 'event_size'. In this case the stream pointer is not advanced and
|
|
|
|
* and 'event_size' is set to the minimum required buffer size.
|
2010-04-29 21:37:15 +04:00
|
|
|
*/
|
2010-08-26 22:42:43 +04:00
|
|
|
int
|
2010-10-05 03:21:04 +04:00
|
|
|
zfs_zevent_next(zfs_zevent_t *ze, nvlist_t **event, uint64_t *event_size,
|
2013-11-01 23:26:11 +04:00
|
|
|
uint64_t *dropped)
|
2010-04-29 21:37:15 +04:00
|
|
|
{
|
2010-08-26 22:42:43 +04:00
|
|
|
zevent_t *ev;
|
2010-10-05 03:21:04 +04:00
|
|
|
size_t size;
|
|
|
|
int error = 0;
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
mutex_enter(&zevent_lock);
|
|
|
|
if (ze->ze_zevent == NULL) {
|
|
|
|
/* New stream start at the beginning/tail */
|
|
|
|
ev = list_tail(&zevent_list);
|
|
|
|
if (ev == NULL) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-29 21:37:15 +04:00
|
|
|
} else {
|
2013-11-01 23:26:11 +04:00
|
|
|
/*
|
|
|
|
* Existing stream continue with the next element and remove
|
|
|
|
* ourselves from the wait queue for the previous element
|
|
|
|
*/
|
2010-08-26 22:42:43 +04:00
|
|
|
ev = list_prev(&zevent_list, ze->ze_zevent);
|
|
|
|
if (ev == NULL) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-10-05 03:21:04 +04:00
|
|
|
}
|
2010-08-26 22:42:43 +04:00
|
|
|
|
2010-10-05 03:21:04 +04:00
|
|
|
VERIFY(nvlist_size(ev->ev_nvl, &size, NV_ENCODE_NATIVE) == 0);
|
|
|
|
if (size > *event_size) {
|
|
|
|
*event_size = size;
|
|
|
|
error = ENOMEM;
|
|
|
|
goto out;
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 03:21:04 +04:00
|
|
|
if (ze->ze_zevent)
|
|
|
|
list_remove(&ze->ze_zevent->ev_ze_list, ze);
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
ze->ze_zevent = ev;
|
|
|
|
list_insert_head(&ev->ev_ze_list, ze);
|
2016-10-02 21:24:54 +03:00
|
|
|
(void) nvlist_dup(ev->ev_nvl, event, KM_SLEEP);
|
2010-08-26 22:42:43 +04:00
|
|
|
*dropped = ze->ze_dropped;
|
2016-10-19 22:55:59 +03:00
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
/* Include events dropped due to rate limiting */
|
|
|
|
*dropped += ratelimit_dropped;
|
|
|
|
ratelimit_dropped = 0;
|
|
|
|
#endif
|
2010-08-26 22:42:43 +04:00
|
|
|
ze->ze_dropped = 0;
|
|
|
|
out:
|
|
|
|
mutex_exit(&zevent_lock);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
return (error);
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
|
|
|
|
Add support for autoexpand property
While the autoexpand property may seem like a small feature it
depends on a significant amount of system infrastructure. Enough
of that infrastructure is now in place that with a few modifications
for Linux it can be supported.
Auto-expand works as follows; when a block device is modified
(re-sized, closed after being open r/w, etc) a change uevent is
generated for udev. The ZED, which is monitoring udev events,
passes the change event along to zfs_deliver_dle() if the disk
or partition contains a zfs_member as identified by blkid.
From here the device is matched against all imported pool vdevs
using the vdev_guid which was read from the label by blkid. If
a match is found the ZED reopens the pool vdev. This re-opening
is important because it allows the vdev to be briefly closed so
the disk partition table can be re-read. Otherwise, it wouldn't
be possible to report the maximum possible expansion size.
Finally, if the property autoexpand=on a vdev expansion will be
attempted. After performing some sanity checks on the disk to
verify that it is safe to expand, the primary partition (-part1)
will be expanded and the partition table updated. The partition
is then re-opened (again) to detect the updated size which allows
the new capacity to be used.
In order to make all of the above possible the following changes
were required:
* Updated the zpool_expand_001_pos and zpool_expand_003_pos tests.
These tests now create a pool which is layered on a loopback,
scsi_debug, and file vdev. This allows for testing of non-
partitioned block device (loopback), a partition block device
(scsi_debug), and a file which does not receive udev change
events. This provided for better test coverage, and by removing
the layering on ZFS volumes there issues surrounding layering
one pool on another are avoided.
* zpool_find_vdev_by_physpath() updated to accept a vdev guid.
This allows for matching by guid rather than path which is a
more reliable way for the ZED to reference a vdev.
* Fixed zfs_zevent_wait() signal handling which could result
in the ZED spinning when a signal was not handled.
* Removed vdev_disk_rrpart() functionality which can be abandoned
in favor of kernel provided blkdev_reread_part() function.
* Added a rwlock which is held as a writer while a disk is being
reopened. This is important to prevent errors from occurring
for any configuration related IOs which bypass the SCL_ZIO lock.
The zpool_reopen_007_pos.ksh test case was added to verify IO
error are never observed when reopening. This is not expected
to impact IO performance.
Additional fixes which aren't critical but were discovered and
resolved in the course of developing this functionality.
* Added PHYS_PATH="/dev/zvol/dataset" to the vdev configuration for
ZFS volumes. This is as good as a unique physical path, while the
volumes are not used in the test cases anymore for other reasons
this improvement was included.
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Signed-off-by: Sara Hartse <sara.hartse@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #120
Closes #2437
Closes #5771
Closes #7366
Closes #7582
Closes #7629
2018-07-24 01:40:15 +03:00
|
|
|
/*
|
|
|
|
* Wait in an interruptible state for any new events.
|
|
|
|
*/
|
2010-08-26 22:42:43 +04:00
|
|
|
int
|
|
|
|
zfs_zevent_wait(zfs_zevent_t *ze)
|
|
|
|
{
|
Add support for autoexpand property
While the autoexpand property may seem like a small feature it
depends on a significant amount of system infrastructure. Enough
of that infrastructure is now in place that with a few modifications
for Linux it can be supported.
Auto-expand works as follows; when a block device is modified
(re-sized, closed after being open r/w, etc) a change uevent is
generated for udev. The ZED, which is monitoring udev events,
passes the change event along to zfs_deliver_dle() if the disk
or partition contains a zfs_member as identified by blkid.
From here the device is matched against all imported pool vdevs
using the vdev_guid which was read from the label by blkid. If
a match is found the ZED reopens the pool vdev. This re-opening
is important because it allows the vdev to be briefly closed so
the disk partition table can be re-read. Otherwise, it wouldn't
be possible to report the maximum possible expansion size.
Finally, if the property autoexpand=on a vdev expansion will be
attempted. After performing some sanity checks on the disk to
verify that it is safe to expand, the primary partition (-part1)
will be expanded and the partition table updated. The partition
is then re-opened (again) to detect the updated size which allows
the new capacity to be used.
In order to make all of the above possible the following changes
were required:
* Updated the zpool_expand_001_pos and zpool_expand_003_pos tests.
These tests now create a pool which is layered on a loopback,
scsi_debug, and file vdev. This allows for testing of non-
partitioned block device (loopback), a partition block device
(scsi_debug), and a file which does not receive udev change
events. This provided for better test coverage, and by removing
the layering on ZFS volumes there issues surrounding layering
one pool on another are avoided.
* zpool_find_vdev_by_physpath() updated to accept a vdev guid.
This allows for matching by guid rather than path which is a
more reliable way for the ZED to reference a vdev.
* Fixed zfs_zevent_wait() signal handling which could result
in the ZED spinning when a signal was not handled.
* Removed vdev_disk_rrpart() functionality which can be abandoned
in favor of kernel provided blkdev_reread_part() function.
* Added a rwlock which is held as a writer while a disk is being
reopened. This is important to prevent errors from occurring
for any configuration related IOs which bypass the SCL_ZIO lock.
The zpool_reopen_007_pos.ksh test case was added to verify IO
error are never observed when reopening. This is not expected
to impact IO performance.
Additional fixes which aren't critical but were discovered and
resolved in the course of developing this functionality.
* Added PHYS_PATH="/dev/zvol/dataset" to the vdev configuration for
ZFS volumes. This is as good as a unique physical path, while the
volumes are not used in the test cases anymore for other reasons
this improvement was included.
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Signed-off-by: Sara Hartse <sara.hartse@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #120
Closes #2437
Closes #5771
Closes #7366
Closes #7582
Closes #7629
2018-07-24 01:40:15 +03:00
|
|
|
int error = EAGAIN;
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
mutex_enter(&zevent_lock);
|
Add support for autoexpand property
While the autoexpand property may seem like a small feature it
depends on a significant amount of system infrastructure. Enough
of that infrastructure is now in place that with a few modifications
for Linux it can be supported.
Auto-expand works as follows; when a block device is modified
(re-sized, closed after being open r/w, etc) a change uevent is
generated for udev. The ZED, which is monitoring udev events,
passes the change event along to zfs_deliver_dle() if the disk
or partition contains a zfs_member as identified by blkid.
From here the device is matched against all imported pool vdevs
using the vdev_guid which was read from the label by blkid. If
a match is found the ZED reopens the pool vdev. This re-opening
is important because it allows the vdev to be briefly closed so
the disk partition table can be re-read. Otherwise, it wouldn't
be possible to report the maximum possible expansion size.
Finally, if the property autoexpand=on a vdev expansion will be
attempted. After performing some sanity checks on the disk to
verify that it is safe to expand, the primary partition (-part1)
will be expanded and the partition table updated. The partition
is then re-opened (again) to detect the updated size which allows
the new capacity to be used.
In order to make all of the above possible the following changes
were required:
* Updated the zpool_expand_001_pos and zpool_expand_003_pos tests.
These tests now create a pool which is layered on a loopback,
scsi_debug, and file vdev. This allows for testing of non-
partitioned block device (loopback), a partition block device
(scsi_debug), and a file which does not receive udev change
events. This provided for better test coverage, and by removing
the layering on ZFS volumes there issues surrounding layering
one pool on another are avoided.
* zpool_find_vdev_by_physpath() updated to accept a vdev guid.
This allows for matching by guid rather than path which is a
more reliable way for the ZED to reference a vdev.
* Fixed zfs_zevent_wait() signal handling which could result
in the ZED spinning when a signal was not handled.
* Removed vdev_disk_rrpart() functionality which can be abandoned
in favor of kernel provided blkdev_reread_part() function.
* Added a rwlock which is held as a writer while a disk is being
reopened. This is important to prevent errors from occurring
for any configuration related IOs which bypass the SCL_ZIO lock.
The zpool_reopen_007_pos.ksh test case was added to verify IO
error are never observed when reopening. This is not expected
to impact IO performance.
Additional fixes which aren't critical but were discovered and
resolved in the course of developing this functionality.
* Added PHYS_PATH="/dev/zvol/dataset" to the vdev configuration for
ZFS volumes. This is as good as a unique physical path, while the
volumes are not used in the test cases anymore for other reasons
this improvement was included.
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Signed-off-by: Sara Hartse <sara.hartse@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #120
Closes #2437
Closes #5771
Closes #7366
Closes #7582
Closes #7629
2018-07-24 01:40:15 +03:00
|
|
|
zevent_waiters++;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
Add support for autoexpand property
While the autoexpand property may seem like a small feature it
depends on a significant amount of system infrastructure. Enough
of that infrastructure is now in place that with a few modifications
for Linux it can be supported.
Auto-expand works as follows; when a block device is modified
(re-sized, closed after being open r/w, etc) a change uevent is
generated for udev. The ZED, which is monitoring udev events,
passes the change event along to zfs_deliver_dle() if the disk
or partition contains a zfs_member as identified by blkid.
From here the device is matched against all imported pool vdevs
using the vdev_guid which was read from the label by blkid. If
a match is found the ZED reopens the pool vdev. This re-opening
is important because it allows the vdev to be briefly closed so
the disk partition table can be re-read. Otherwise, it wouldn't
be possible to report the maximum possible expansion size.
Finally, if the property autoexpand=on a vdev expansion will be
attempted. After performing some sanity checks on the disk to
verify that it is safe to expand, the primary partition (-part1)
will be expanded and the partition table updated. The partition
is then re-opened (again) to detect the updated size which allows
the new capacity to be used.
In order to make all of the above possible the following changes
were required:
* Updated the zpool_expand_001_pos and zpool_expand_003_pos tests.
These tests now create a pool which is layered on a loopback,
scsi_debug, and file vdev. This allows for testing of non-
partitioned block device (loopback), a partition block device
(scsi_debug), and a file which does not receive udev change
events. This provided for better test coverage, and by removing
the layering on ZFS volumes there issues surrounding layering
one pool on another are avoided.
* zpool_find_vdev_by_physpath() updated to accept a vdev guid.
This allows for matching by guid rather than path which is a
more reliable way for the ZED to reference a vdev.
* Fixed zfs_zevent_wait() signal handling which could result
in the ZED spinning when a signal was not handled.
* Removed vdev_disk_rrpart() functionality which can be abandoned
in favor of kernel provided blkdev_reread_part() function.
* Added a rwlock which is held as a writer while a disk is being
reopened. This is important to prevent errors from occurring
for any configuration related IOs which bypass the SCL_ZIO lock.
The zpool_reopen_007_pos.ksh test case was added to verify IO
error are never observed when reopening. This is not expected
to impact IO performance.
Additional fixes which aren't critical but were discovered and
resolved in the course of developing this functionality.
* Added PHYS_PATH="/dev/zvol/dataset" to the vdev configuration for
ZFS volumes. This is as good as a unique physical path, while the
volumes are not used in the test cases anymore for other reasons
this improvement was included.
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Signed-off-by: Sara Hartse <sara.hartse@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #120
Closes #2437
Closes #5771
Closes #7366
Closes #7582
Closes #7629
2018-07-24 01:40:15 +03:00
|
|
|
while (error == EAGAIN) {
|
|
|
|
if (zevent_flags & ZEVENT_SHUTDOWN) {
|
|
|
|
error = SET_ERROR(ESHUTDOWN);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2019-08-05 21:35:47 +03:00
|
|
|
error = cv_wait_sig(&zevent_cv, &zevent_lock);
|
Add support for autoexpand property
While the autoexpand property may seem like a small feature it
depends on a significant amount of system infrastructure. Enough
of that infrastructure is now in place that with a few modifications
for Linux it can be supported.
Auto-expand works as follows; when a block device is modified
(re-sized, closed after being open r/w, etc) a change uevent is
generated for udev. The ZED, which is monitoring udev events,
passes the change event along to zfs_deliver_dle() if the disk
or partition contains a zfs_member as identified by blkid.
From here the device is matched against all imported pool vdevs
using the vdev_guid which was read from the label by blkid. If
a match is found the ZED reopens the pool vdev. This re-opening
is important because it allows the vdev to be briefly closed so
the disk partition table can be re-read. Otherwise, it wouldn't
be possible to report the maximum possible expansion size.
Finally, if the property autoexpand=on a vdev expansion will be
attempted. After performing some sanity checks on the disk to
verify that it is safe to expand, the primary partition (-part1)
will be expanded and the partition table updated. The partition
is then re-opened (again) to detect the updated size which allows
the new capacity to be used.
In order to make all of the above possible the following changes
were required:
* Updated the zpool_expand_001_pos and zpool_expand_003_pos tests.
These tests now create a pool which is layered on a loopback,
scsi_debug, and file vdev. This allows for testing of non-
partitioned block device (loopback), a partition block device
(scsi_debug), and a file which does not receive udev change
events. This provided for better test coverage, and by removing
the layering on ZFS volumes there issues surrounding layering
one pool on another are avoided.
* zpool_find_vdev_by_physpath() updated to accept a vdev guid.
This allows for matching by guid rather than path which is a
more reliable way for the ZED to reference a vdev.
* Fixed zfs_zevent_wait() signal handling which could result
in the ZED spinning when a signal was not handled.
* Removed vdev_disk_rrpart() functionality which can be abandoned
in favor of kernel provided blkdev_reread_part() function.
* Added a rwlock which is held as a writer while a disk is being
reopened. This is important to prevent errors from occurring
for any configuration related IOs which bypass the SCL_ZIO lock.
The zpool_reopen_007_pos.ksh test case was added to verify IO
error are never observed when reopening. This is not expected
to impact IO performance.
Additional fixes which aren't critical but were discovered and
resolved in the course of developing this functionality.
* Added PHYS_PATH="/dev/zvol/dataset" to the vdev configuration for
ZFS volumes. This is as good as a unique physical path, while the
volumes are not used in the test cases anymore for other reasons
this improvement was included.
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Signed-off-by: Sara Hartse <sara.hartse@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #120
Closes #2437
Closes #5771
Closes #7366
Closes #7582
Closes #7629
2018-07-24 01:40:15 +03:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
error = SET_ERROR(EINTR);
|
|
|
|
break;
|
|
|
|
} else if (!list_is_empty(&zevent_list)) {
|
|
|
|
error = 0;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
error = EAGAIN;
|
|
|
|
}
|
|
|
|
}
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
zevent_waiters--;
|
|
|
|
mutex_exit(&zevent_lock);
|
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
return (error);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
2013-11-23 02:52:16 +04:00
|
|
|
/*
|
|
|
|
* The caller may seek to a specific EID by passing that EID. If the EID
|
|
|
|
* is still available in the posted list of events the cursor is positioned
|
|
|
|
* there. Otherwise ENOENT is returned and the cursor is not moved.
|
|
|
|
*
|
|
|
|
* There are two reserved EIDs which may be passed and will never fail.
|
|
|
|
* ZEVENT_SEEK_START positions the cursor at the start of the list, and
|
|
|
|
* ZEVENT_SEEK_END positions the cursor at the end of the list.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_zevent_seek(zfs_zevent_t *ze, uint64_t eid)
|
|
|
|
{
|
|
|
|
zevent_t *ev;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
mutex_enter(&zevent_lock);
|
|
|
|
|
|
|
|
if (eid == ZEVENT_SEEK_START) {
|
|
|
|
if (ze->ze_zevent)
|
|
|
|
list_remove(&ze->ze_zevent->ev_ze_list, ze);
|
|
|
|
|
|
|
|
ze->ze_zevent = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eid == ZEVENT_SEEK_END) {
|
|
|
|
if (ze->ze_zevent)
|
|
|
|
list_remove(&ze->ze_zevent->ev_ze_list, ze);
|
|
|
|
|
|
|
|
ev = list_head(&zevent_list);
|
|
|
|
if (ev) {
|
|
|
|
ze->ze_zevent = ev;
|
|
|
|
list_insert_head(&ev->ev_ze_list, ze);
|
|
|
|
} else {
|
|
|
|
ze->ze_zevent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ev = list_tail(&zevent_list); ev != NULL;
|
|
|
|
ev = list_prev(&zevent_list, ev)) {
|
|
|
|
if (ev->ev_eid == eid) {
|
|
|
|
if (ze->ze_zevent)
|
|
|
|
list_remove(&ze->ze_zevent->ev_ze_list, ze);
|
|
|
|
|
|
|
|
ze->ze_zevent = ev;
|
|
|
|
list_insert_head(&ev->ev_ze_list, ze);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev == NULL)
|
|
|
|
error = ENOENT;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_exit(&zevent_lock);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
void
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_init(zfs_zevent_t **zep)
|
2010-04-29 21:37:15 +04:00
|
|
|
{
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_t *ze;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
ze = *zep = kmem_zalloc(sizeof (zfs_zevent_t), KM_SLEEP);
|
|
|
|
list_link_init(&ze->ze_node);
|
|
|
|
}
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
void
|
|
|
|
zfs_zevent_destroy(zfs_zevent_t *ze)
|
|
|
|
{
|
|
|
|
mutex_enter(&zevent_lock);
|
|
|
|
if (ze->ze_zevent)
|
|
|
|
list_remove(&ze->ze_zevent->ev_ze_list, ze);
|
|
|
|
mutex_exit(&zevent_lock);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
kmem_free(ze, sizeof (zfs_zevent_t));
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
2010-08-26 22:42:43 +04:00
|
|
|
#endif /* _KERNEL */
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
/*
|
2019-09-03 03:56:41 +03:00
|
|
|
* Wrappers for FM nvlist allocators
|
2010-04-29 21:37:15 +04:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void *
|
|
|
|
i_fm_alloc(nv_alloc_t *nva, size_t size)
|
|
|
|
{
|
2014-11-21 03:09:39 +03:00
|
|
|
return (kmem_zalloc(size, KM_SLEEP));
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
|
|
|
i_fm_free(nv_alloc_t *nva, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
kmem_free(buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nv_alloc_ops_t fm_mem_alloc_ops = {
|
2017-11-29 02:33:48 +03:00
|
|
|
.nv_ao_init = NULL,
|
|
|
|
.nv_ao_fini = NULL,
|
|
|
|
.nv_ao_alloc = i_fm_alloc,
|
|
|
|
.nv_ao_free = i_fm_free,
|
|
|
|
.nv_ao_reset = NULL
|
2010-04-29 21:37:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create and initialize a new nv_alloc_t for a fixed buffer, buf. A pointer
|
|
|
|
* to the newly allocated nv_alloc_t structure is returned upon success or NULL
|
|
|
|
* is returned to indicate that the nv_alloc structure could not be created.
|
|
|
|
*/
|
|
|
|
nv_alloc_t *
|
|
|
|
fm_nva_xcreate(char *buf, size_t bufsz)
|
|
|
|
{
|
|
|
|
nv_alloc_t *nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP);
|
|
|
|
|
|
|
|
if (bufsz == 0 || nv_alloc_init(nvhdl, nv_fixed_ops, buf, bufsz) != 0) {
|
|
|
|
kmem_free(nvhdl, sizeof (nv_alloc_t));
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (nvhdl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy a previously allocated nv_alloc structure. The fixed buffer
|
|
|
|
* associated with nva must be freed by the caller.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fm_nva_xdestroy(nv_alloc_t *nva)
|
|
|
|
{
|
|
|
|
nv_alloc_fini(nva);
|
|
|
|
kmem_free(nva, sizeof (nv_alloc_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new nv list. A pointer to a new nv list structure is returned
|
|
|
|
* upon success or NULL is returned to indicate that the structure could
|
|
|
|
* not be created. The newly created nv list is created and managed by the
|
|
|
|
* operations installed in nva. If nva is NULL, the default FMA nva
|
|
|
|
* operations are installed and used.
|
|
|
|
*
|
|
|
|
* When called from the kernel and nva == NULL, this function must be called
|
|
|
|
* from passive kernel context with no locks held that can prevent a
|
|
|
|
* sleeping memory allocation from occurring. Otherwise, this function may
|
|
|
|
* be called from other kernel contexts as long a valid nva created via
|
|
|
|
* fm_nva_create() is supplied.
|
|
|
|
*/
|
|
|
|
nvlist_t *
|
|
|
|
fm_nvlist_create(nv_alloc_t *nva)
|
|
|
|
{
|
|
|
|
int hdl_alloced = 0;
|
|
|
|
nvlist_t *nvl;
|
|
|
|
nv_alloc_t *nvhdl;
|
|
|
|
|
|
|
|
if (nva == NULL) {
|
2014-11-21 03:09:39 +03:00
|
|
|
nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
if (nv_alloc_init(nvhdl, &fm_mem_alloc_ops, NULL, 0) != 0) {
|
|
|
|
kmem_free(nvhdl, sizeof (nv_alloc_t));
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
hdl_alloced = 1;
|
|
|
|
} else {
|
|
|
|
nvhdl = nva;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nvhdl) != 0) {
|
|
|
|
if (hdl_alloced) {
|
|
|
|
nv_alloc_fini(nvhdl);
|
2010-08-27 01:24:34 +04:00
|
|
|
kmem_free(nvhdl, sizeof (nv_alloc_t));
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (nvl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy a previously allocated nvlist structure. flag indicates whether
|
|
|
|
* or not the associated nva structure should be freed (FM_NVA_FREE) or
|
|
|
|
* retained (FM_NVA_RETAIN). Retaining the nv alloc structure allows
|
|
|
|
* it to be re-used for future nvlist creation operations.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fm_nvlist_destroy(nvlist_t *nvl, int flag)
|
|
|
|
{
|
|
|
|
nv_alloc_t *nva = nvlist_lookup_nv_alloc(nvl);
|
|
|
|
|
|
|
|
nvlist_free(nvl);
|
|
|
|
|
|
|
|
if (nva != NULL) {
|
|
|
|
if (flag == FM_NVA_FREE)
|
|
|
|
fm_nva_xdestroy(nva);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
i_fm_payload_set(nvlist_t *payload, const char *name, va_list ap)
|
|
|
|
{
|
|
|
|
int nelem, ret = 0;
|
|
|
|
data_type_t type;
|
|
|
|
|
|
|
|
while (ret == 0 && name != NULL) {
|
|
|
|
type = va_arg(ap, data_type_t);
|
|
|
|
switch (type) {
|
|
|
|
case DATA_TYPE_BYTE:
|
|
|
|
ret = nvlist_add_byte(payload, name,
|
|
|
|
va_arg(ap, uint_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_BYTE_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_byte_array(payload, name,
|
|
|
|
va_arg(ap, uchar_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
ret = nvlist_add_boolean_value(payload, name,
|
|
|
|
va_arg(ap, boolean_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_BOOLEAN_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_boolean_array(payload, name,
|
|
|
|
va_arg(ap, boolean_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT8:
|
|
|
|
ret = nvlist_add_int8(payload, name,
|
|
|
|
va_arg(ap, int));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT8_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_int8_array(payload, name,
|
|
|
|
va_arg(ap, int8_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT8:
|
|
|
|
ret = nvlist_add_uint8(payload, name,
|
|
|
|
va_arg(ap, uint_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT8_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_uint8_array(payload, name,
|
|
|
|
va_arg(ap, uint8_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT16:
|
|
|
|
ret = nvlist_add_int16(payload, name,
|
|
|
|
va_arg(ap, int));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT16_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_int16_array(payload, name,
|
|
|
|
va_arg(ap, int16_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT16:
|
|
|
|
ret = nvlist_add_uint16(payload, name,
|
|
|
|
va_arg(ap, uint_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT16_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_uint16_array(payload, name,
|
|
|
|
va_arg(ap, uint16_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT32:
|
|
|
|
ret = nvlist_add_int32(payload, name,
|
|
|
|
va_arg(ap, int32_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT32_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_int32_array(payload, name,
|
|
|
|
va_arg(ap, int32_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT32:
|
|
|
|
ret = nvlist_add_uint32(payload, name,
|
|
|
|
va_arg(ap, uint32_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT32_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_uint32_array(payload, name,
|
|
|
|
va_arg(ap, uint32_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT64:
|
|
|
|
ret = nvlist_add_int64(payload, name,
|
|
|
|
va_arg(ap, int64_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT64_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_int64_array(payload, name,
|
|
|
|
va_arg(ap, int64_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT64:
|
|
|
|
ret = nvlist_add_uint64(payload, name,
|
|
|
|
va_arg(ap, uint64_t));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_UINT64_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_uint64_array(payload, name,
|
|
|
|
va_arg(ap, uint64_t *), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_STRING:
|
|
|
|
ret = nvlist_add_string(payload, name,
|
|
|
|
va_arg(ap, char *));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_STRING_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_string_array(payload, name,
|
|
|
|
va_arg(ap, char **), nelem);
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_NVLIST:
|
|
|
|
ret = nvlist_add_nvlist(payload, name,
|
|
|
|
va_arg(ap, nvlist_t *));
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_NVLIST_ARRAY:
|
|
|
|
nelem = va_arg(ap, int);
|
|
|
|
ret = nvlist_add_nvlist_array(payload, name,
|
|
|
|
va_arg(ap, nvlist_t **), nelem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = va_arg(ap, char *);
|
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fm_payload_set(nvlist_t *payload, ...)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const char *name;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, payload);
|
|
|
|
name = va_arg(ap, char *);
|
|
|
|
ret = i_fm_payload_set(payload, name, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (ret)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.payload_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set-up and validate the members of an ereport event according to:
|
|
|
|
*
|
|
|
|
* Member name Type Value
|
|
|
|
* ====================================================
|
|
|
|
* class string ereport
|
|
|
|
* version uint8_t 0
|
|
|
|
* ena uint64_t <ena>
|
|
|
|
* detector nvlist_t <detector>
|
|
|
|
* ereport-payload nvlist_t <var args>
|
|
|
|
*
|
2010-05-29 00:45:14 +04:00
|
|
|
* We don't actually add a 'version' member to the payload. Really,
|
|
|
|
* the version quoted to us by our caller is that of the category 1
|
|
|
|
* "ereport" event class (and we require FM_EREPORT_VERS0) but
|
|
|
|
* the payload version of the actual leaf class event under construction
|
|
|
|
* may be something else. Callers should supply a version in the varargs,
|
|
|
|
* or (better) we could take two version arguments - one for the
|
|
|
|
* ereport category 1 classification (expect FM_EREPORT_VERS0) and one
|
|
|
|
* for the leaf class.
|
2010-04-29 21:37:15 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class,
|
|
|
|
uint64_t ena, const nvlist_t *detector, ...)
|
|
|
|
{
|
|
|
|
char ereport_class[FM_MAX_CLASS];
|
|
|
|
const char *name;
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (version != FM_EREPORT_VERS0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) snprintf(ereport_class, FM_MAX_CLASS, "%s.%s",
|
|
|
|
FM_EREPORT_CLASS, erpt_class);
|
|
|
|
if (nvlist_add_string(ereport, FM_CLASS, ereport_class) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_uint64(ereport, FM_EREPORT_ENA, ena)) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_nvlist(ereport, FM_EREPORT_DETECTOR,
|
|
|
|
(nvlist_t *)detector) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
va_start(ap, detector);
|
|
|
|
name = va_arg(ap, const char *);
|
|
|
|
ret = i_fm_payload_set(ereport, name, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (ret)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set-up and validate the members of an hc fmri according to;
|
|
|
|
*
|
|
|
|
* Member name Type Value
|
|
|
|
* ===================================================
|
|
|
|
* version uint8_t 0
|
|
|
|
* auth nvlist_t <auth>
|
|
|
|
* hc-name string <name>
|
|
|
|
* hc-id string <id>
|
|
|
|
*
|
|
|
|
* Note that auth and hc-id are optional members.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define HC_MAXPAIRS 20
|
|
|
|
#define HC_MAXNAMELEN 50
|
|
|
|
|
|
|
|
static int
|
|
|
|
fm_fmri_hc_set_common(nvlist_t *fmri, int version, const nvlist_t *auth)
|
|
|
|
{
|
|
|
|
if (version != FM_HC_SCHEME_VERSION) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0 ||
|
|
|
|
nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth != NULL && nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY,
|
|
|
|
(nvlist_t *)auth) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fm_fmri_hc_set(nvlist_t *fmri, int version, const nvlist_t *auth,
|
|
|
|
nvlist_t *snvl, int npairs, ...)
|
|
|
|
{
|
|
|
|
nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri);
|
|
|
|
nvlist_t *pairs[HC_MAXPAIRS];
|
|
|
|
va_list ap;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!fm_fmri_hc_set_common(fmri, version, auth))
|
|
|
|
return;
|
|
|
|
|
|
|
|
npairs = MIN(npairs, HC_MAXPAIRS);
|
|
|
|
|
|
|
|
va_start(ap, npairs);
|
|
|
|
for (i = 0; i < npairs; i++) {
|
|
|
|
const char *name = va_arg(ap, const char *);
|
|
|
|
uint32_t id = va_arg(ap, uint32_t);
|
|
|
|
char idstr[11];
|
|
|
|
|
|
|
|
(void) snprintf(idstr, sizeof (idstr), "%u", id);
|
|
|
|
|
|
|
|
pairs[i] = fm_nvlist_create(nva);
|
|
|
|
if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 ||
|
|
|
|
nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs) != 0)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
for (i = 0; i < npairs; i++)
|
|
|
|
fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN);
|
|
|
|
|
|
|
|
if (snvl != NULL) {
|
|
|
|
if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
void
|
|
|
|
fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth,
|
|
|
|
nvlist_t *snvl, nvlist_t *bboard, int npairs, ...)
|
|
|
|
{
|
|
|
|
nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri);
|
|
|
|
nvlist_t *pairs[HC_MAXPAIRS];
|
|
|
|
nvlist_t **hcl;
|
|
|
|
uint_t n;
|
|
|
|
int i, j;
|
|
|
|
va_list ap;
|
|
|
|
char *hcname, *hcid;
|
|
|
|
|
|
|
|
if (!fm_fmri_hc_set_common(fmri, version, auth))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy the bboard nvpairs to the pairs array
|
|
|
|
*/
|
|
|
|
if (nvlist_lookup_nvlist_array(bboard, FM_FMRI_HC_LIST, &hcl, &n)
|
|
|
|
!= 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME,
|
|
|
|
&hcname) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &hcid) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pairs[i] = fm_nvlist_create(nva);
|
|
|
|
if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, hcname) != 0 ||
|
|
|
|
nvlist_add_string(pairs[i], FM_FMRI_HC_ID, hcid) != 0) {
|
|
|
|
for (j = 0; j <= i; j++) {
|
|
|
|
if (pairs[j] != NULL)
|
|
|
|
fm_nvlist_destroy(pairs[j],
|
|
|
|
FM_NVA_RETAIN);
|
|
|
|
}
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create the pairs from passed in pairs
|
|
|
|
*/
|
|
|
|
npairs = MIN(npairs, HC_MAXPAIRS);
|
|
|
|
|
|
|
|
va_start(ap, npairs);
|
|
|
|
for (i = n; i < npairs + n; i++) {
|
|
|
|
const char *name = va_arg(ap, const char *);
|
|
|
|
uint32_t id = va_arg(ap, uint32_t);
|
|
|
|
char idstr[11];
|
|
|
|
(void) snprintf(idstr, sizeof (idstr), "%u", id);
|
|
|
|
pairs[i] = fm_nvlist_create(nva);
|
|
|
|
if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 ||
|
|
|
|
nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) {
|
|
|
|
for (j = 0; j <= i; j++) {
|
|
|
|
if (pairs[j] != NULL)
|
|
|
|
fm_nvlist_destroy(pairs[j],
|
|
|
|
FM_NVA_RETAIN);
|
|
|
|
}
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the fmri hc list
|
|
|
|
*/
|
|
|
|
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs,
|
|
|
|
npairs + n) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < npairs + n; i++) {
|
|
|
|
fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (snvl != NULL) {
|
|
|
|
if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
/*
|
|
|
|
* Set-up and validate the members of an dev fmri according to:
|
|
|
|
*
|
|
|
|
* Member name Type Value
|
|
|
|
* ====================================================
|
|
|
|
* version uint8_t 0
|
|
|
|
* auth nvlist_t <auth>
|
|
|
|
* devpath string <devpath>
|
2010-05-29 00:45:14 +04:00
|
|
|
* [devid] string <devid>
|
|
|
|
* [target-port-l0id] string <target-port-lun0-id>
|
2010-04-29 21:37:15 +04:00
|
|
|
*
|
|
|
|
* Note that auth and devid are optional members.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth,
|
2010-05-29 00:45:14 +04:00
|
|
|
const char *devpath, const char *devid, const char *tpl0)
|
2010-04-29 21:37:15 +04:00
|
|
|
{
|
2010-05-29 00:45:14 +04:00
|
|
|
int err = 0;
|
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
if (version != DEV_SCHEME_VERSION0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
err |= nvlist_add_uint8(fmri_dev, FM_VERSION, version);
|
|
|
|
err |= nvlist_add_string(fmri_dev, FM_FMRI_SCHEME, FM_FMRI_SCHEME_DEV);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
if (auth != NULL) {
|
2010-05-29 00:45:14 +04:00
|
|
|
err |= nvlist_add_nvlist(fmri_dev, FM_FMRI_AUTHORITY,
|
|
|
|
(nvlist_t *)auth);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_PATH, devpath);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
if (devid != NULL)
|
2010-05-29 00:45:14 +04:00
|
|
|
err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_ID, devid);
|
|
|
|
|
|
|
|
if (tpl0 != NULL)
|
|
|
|
err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_TGTPTLUN0, tpl0);
|
|
|
|
|
|
|
|
if (err)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set-up and validate the members of an cpu fmri according to:
|
|
|
|
*
|
|
|
|
* Member name Type Value
|
|
|
|
* ====================================================
|
|
|
|
* version uint8_t 0
|
|
|
|
* auth nvlist_t <auth>
|
|
|
|
* cpuid uint32_t <cpu_id>
|
|
|
|
* cpumask uint8_t <cpu_mask>
|
|
|
|
* serial uint64_t <serial_id>
|
|
|
|
*
|
|
|
|
* Note that auth, cpumask, serial are optional members.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fm_fmri_cpu_set(nvlist_t *fmri_cpu, int version, const nvlist_t *auth,
|
|
|
|
uint32_t cpu_id, uint8_t *cpu_maskp, const char *serial_idp)
|
|
|
|
{
|
|
|
|
uint64_t *failedp = &erpt_kstat_data.fmri_set_failed.value.ui64;
|
|
|
|
|
|
|
|
if (version < CPU_SCHEME_VERSION1) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(failedp);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_uint8(fmri_cpu, FM_VERSION, version) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(failedp);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_string(fmri_cpu, FM_FMRI_SCHEME,
|
|
|
|
FM_FMRI_SCHEME_CPU) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(failedp);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth != NULL && nvlist_add_nvlist(fmri_cpu, FM_FMRI_AUTHORITY,
|
|
|
|
(nvlist_t *)auth) != 0)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(failedp);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
if (nvlist_add_uint32(fmri_cpu, FM_FMRI_CPU_ID, cpu_id) != 0)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(failedp);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
if (cpu_maskp != NULL && nvlist_add_uint8(fmri_cpu, FM_FMRI_CPU_MASK,
|
|
|
|
*cpu_maskp) != 0)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(failedp);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
|
|
|
if (serial_idp == NULL || nvlist_add_string(fmri_cpu,
|
|
|
|
FM_FMRI_CPU_SERIAL_ID, (char *)serial_idp) != 0)
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(failedp);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set-up and validate the members of a mem according to:
|
|
|
|
*
|
|
|
|
* Member name Type Value
|
|
|
|
* ====================================================
|
|
|
|
* version uint8_t 0
|
|
|
|
* auth nvlist_t <auth> [optional]
|
|
|
|
* unum string <unum>
|
|
|
|
* serial string <serial> [optional*]
|
|
|
|
* offset uint64_t <offset> [optional]
|
|
|
|
*
|
|
|
|
* * serial is required if offset is present
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth,
|
|
|
|
const char *unum, const char *serial, uint64_t offset)
|
|
|
|
{
|
|
|
|
if (version != MEM_SCHEME_VERSION0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!serial && (offset != (uint64_t)-1)) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth != NULL) {
|
|
|
|
if (nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY,
|
|
|
|
(nvlist_t *)auth) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_string(fmri, FM_FMRI_MEM_UNUM, unum) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (serial != NULL) {
|
|
|
|
if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID,
|
|
|
|
(char **)&serial, 1) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
2016-01-14 03:37:41 +03:00
|
|
|
if (offset != (uint64_t)-1 && nvlist_add_uint64(fmri,
|
|
|
|
FM_FMRI_MEM_OFFSET, offset) != 0) {
|
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fm_fmri_zfs_set(nvlist_t *fmri, int version, uint64_t pool_guid,
|
|
|
|
uint64_t vdev_guid)
|
|
|
|
{
|
|
|
|
if (version != ZFS_SCHEME_VERSION0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_ZFS) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_POOL, pool_guid) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vdev_guid != 0) {
|
|
|
|
if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_VDEV, vdev_guid) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(
|
|
|
|
&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
fm_ena_increment(uint64_t ena)
|
|
|
|
{
|
|
|
|
uint64_t new_ena;
|
|
|
|
|
|
|
|
switch (ENA_FORMAT(ena)) {
|
|
|
|
case FM_ENA_FMT1:
|
|
|
|
new_ena = ena + (1 << ENA_FMT1_GEN_SHFT);
|
|
|
|
break;
|
|
|
|
case FM_ENA_FMT2:
|
|
|
|
new_ena = ena + (1 << ENA_FMT2_GEN_SHFT);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new_ena = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (new_ena);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
fm_ena_generate_cpu(uint64_t timestamp, processorid_t cpuid, uchar_t format)
|
|
|
|
{
|
|
|
|
uint64_t ena = 0;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case FM_ENA_FMT1:
|
|
|
|
if (timestamp) {
|
|
|
|
ena = (uint64_t)((format & ENA_FORMAT_MASK) |
|
|
|
|
((cpuid << ENA_FMT1_CPUID_SHFT) &
|
|
|
|
ENA_FMT1_CPUID_MASK) |
|
|
|
|
((timestamp << ENA_FMT1_TIME_SHFT) &
|
|
|
|
ENA_FMT1_TIME_MASK));
|
|
|
|
} else {
|
|
|
|
ena = (uint64_t)((format & ENA_FORMAT_MASK) |
|
|
|
|
((cpuid << ENA_FMT1_CPUID_SHFT) &
|
|
|
|
ENA_FMT1_CPUID_MASK) |
|
2010-08-26 22:42:43 +04:00
|
|
|
((gethrtime() << ENA_FMT1_TIME_SHFT) &
|
2010-04-29 21:37:15 +04:00
|
|
|
ENA_FMT1_TIME_MASK));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FM_ENA_FMT2:
|
|
|
|
ena = (uint64_t)((format & ENA_FORMAT_MASK) |
|
|
|
|
((timestamp << ENA_FMT2_TIME_SHFT) & ENA_FMT2_TIME_MASK));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ena);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
fm_ena_generate(uint64_t timestamp, uchar_t format)
|
|
|
|
{
|
2012-08-24 04:45:31 +04:00
|
|
|
uint64_t ena;
|
|
|
|
|
|
|
|
kpreempt_disable();
|
|
|
|
ena = fm_ena_generate_cpu(timestamp, getcpuid(), format);
|
|
|
|
kpreempt_enable();
|
|
|
|
|
|
|
|
return (ena);
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
fm_ena_generation_get(uint64_t ena)
|
|
|
|
{
|
|
|
|
uint64_t gen;
|
|
|
|
|
|
|
|
switch (ENA_FORMAT(ena)) {
|
|
|
|
case FM_ENA_FMT1:
|
|
|
|
gen = (ena & ENA_FMT1_GEN_MASK) >> ENA_FMT1_GEN_SHFT;
|
|
|
|
break;
|
|
|
|
case FM_ENA_FMT2:
|
|
|
|
gen = (ena & ENA_FMT2_GEN_MASK) >> ENA_FMT2_GEN_SHFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gen = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (gen);
|
|
|
|
}
|
|
|
|
|
|
|
|
uchar_t
|
|
|
|
fm_ena_format_get(uint64_t ena)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ENA_FORMAT(ena));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
fm_ena_id_get(uint64_t ena)
|
|
|
|
{
|
|
|
|
uint64_t id;
|
|
|
|
|
|
|
|
switch (ENA_FORMAT(ena)) {
|
|
|
|
case FM_ENA_FMT1:
|
|
|
|
id = (ena & ENA_FMT1_ID_MASK) >> ENA_FMT1_ID_SHFT;
|
|
|
|
break;
|
|
|
|
case FM_ENA_FMT2:
|
|
|
|
id = (ena & ENA_FMT2_ID_MASK) >> ENA_FMT2_ID_SHFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (id);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
fm_ena_time_get(uint64_t ena)
|
|
|
|
{
|
|
|
|
uint64_t time;
|
|
|
|
|
|
|
|
switch (ENA_FORMAT(ena)) {
|
|
|
|
case FM_ENA_FMT1:
|
|
|
|
time = (ena & ENA_FMT1_TIME_MASK) >> ENA_FMT1_TIME_SHFT;
|
|
|
|
break;
|
|
|
|
case FM_ENA_FMT2:
|
|
|
|
time = (ena & ENA_FMT2_TIME_MASK) >> ENA_FMT2_TIME_SHFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (time);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:55:59 +03:00
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
|
|
|
* Helper function to increment ereport dropped count. Used by the event
|
|
|
|
* rate limiting code to give feedback to the user about how many events were
|
|
|
|
* rate limited by including them in the 'dropped' count.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fm_erpt_dropped_increment(void)
|
|
|
|
{
|
|
|
|
atomic_inc_64(&ratelimit_dropped);
|
|
|
|
}
|
|
|
|
|
2010-04-29 21:37:15 +04:00
|
|
|
void
|
2010-08-26 22:42:43 +04:00
|
|
|
fm_init(void)
|
2010-04-29 21:37:15 +04:00
|
|
|
{
|
2010-08-26 22:42:43 +04:00
|
|
|
zevent_len_cur = 0;
|
|
|
|
zevent_flags = 0;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2011-05-04 02:09:28 +04:00
|
|
|
if (zfs_zevent_len_max == 0)
|
|
|
|
zfs_zevent_len_max = ERPT_MAX_ERRS * MAX(max_ncpus, 4);
|
2010-04-29 21:37:15 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
/* Initialize zevent allocation and generation kstats */
|
|
|
|
fm_ksp = kstat_create("zfs", 0, "fm", "misc", KSTAT_TYPE_NAMED,
|
|
|
|
sizeof (struct erpt_kstat) / sizeof (kstat_named_t),
|
|
|
|
KSTAT_FLAG_VIRTUAL);
|
|
|
|
|
|
|
|
if (fm_ksp != NULL) {
|
|
|
|
fm_ksp->ks_data = &erpt_kstat_data;
|
|
|
|
kstat_install(fm_ksp);
|
|
|
|
} else {
|
|
|
|
cmn_err(CE_NOTE, "failed to create fm/misc kstat\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_init(&zevent_lock, NULL, MUTEX_DEFAULT, NULL);
|
2013-11-01 23:26:11 +04:00
|
|
|
list_create(&zevent_list, sizeof (zevent_t),
|
|
|
|
offsetof(zevent_t, ev_node));
|
2010-08-26 22:42:43 +04:00
|
|
|
cv_init(&zevent_cv, NULL, CV_DEFAULT, NULL);
|
2020-09-04 20:34:28 +03:00
|
|
|
|
|
|
|
zfs_ereport_init();
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
void
|
2010-08-26 22:42:43 +04:00
|
|
|
fm_fini(void)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
2010-08-26 22:42:43 +04:00
|
|
|
int count;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2020-09-04 20:34:28 +03:00
|
|
|
zfs_ereport_fini();
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_drain_all(&count);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
mutex_enter(&zevent_lock);
|
2012-10-16 00:36:26 +04:00
|
|
|
cv_broadcast(&zevent_cv);
|
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
zevent_flags |= ZEVENT_SHUTDOWN;
|
|
|
|
while (zevent_waiters > 0) {
|
|
|
|
mutex_exit(&zevent_lock);
|
|
|
|
schedule();
|
|
|
|
mutex_enter(&zevent_lock);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2010-08-26 22:42:43 +04:00
|
|
|
mutex_exit(&zevent_lock);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
cv_destroy(&zevent_cv);
|
|
|
|
list_destroy(&zevent_list);
|
|
|
|
mutex_destroy(&zevent_lock);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2010-08-26 22:42:43 +04:00
|
|
|
if (fm_ksp != NULL) {
|
|
|
|
kstat_delete(fm_ksp);
|
|
|
|
fm_ksp = NULL;
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
2020-02-18 22:22:56 +03:00
|
|
|
#endif /* _KERNEL */
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2020-02-18 22:22:56 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs_zevent, zfs_zevent_, len_max, INT, ZMOD_RW,
|
|
|
|
"Max event queue length");
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2020-02-18 22:22:56 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs_zevent, zfs_zevent_, cols, INT, ZMOD_RW,
|
|
|
|
"Max event column width");
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2020-02-18 22:22:56 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs_zevent, zfs_zevent_, console, INT, ZMOD_RW,
|
|
|
|
"Log events to the console");
|