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
|
2022-07-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2010-04-29 21:37:15 +04:00
|
|
|
* 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/zfs_ioctl.h>
|
2010-04-29 21:37:15 +04:00
|
|
|
|
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and
zfs_vdev_aggregation_limit being signed was pointed out as a possible
reason not to eliminate an unnecessary MAX(unsigned, 0) since the
unsigned value was assigned from them.
There is no reason for these module parameters to be signed and upon
inspection, it was found that there are a number of other module
parameters that are signed, but should not be, so we make them unsigned.
Making them unsigned made it clear that some other variables in the code
should also be unsigned, so we also make those unsigned. This prevents
users from setting negative values that could potentially cause bad
behaviors. It also makes the code slightly easier to understand.
Mostly module parameters that deal with timeouts, limits, bitshifts and
percentages are made unsigned by this. Any that are boolean are left
signed, since whether booleans should be considered signed or unsigned
does not matter.
Making zfs_arc_lotsfree_percent unsigned caused a
`zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was
removed. Removing the check was also necessary to prevent a compiler
error from -Werror=type-limits.
Several end of line comments had to be moved to their own lines because
replacing int with uint_t caused us to exceed the 80 character limit
enforced by cstyle.pl.
The following were kept signed because they are passed to
taskq_create(), which expects signed values and modifying the
OpenSolaris/Illumos DDI is out of scope of this patch:
* metaslab_load_pct
* zfs_sync_taskq_batch_pct
* zfs_zil_clean_taskq_nthr_pct
* zfs_zil_clean_taskq_minalloc
* zfs_zil_clean_taskq_maxalloc
* zfs_arc_prune_task_threads
Also, negative values in those parameters was found to be harmless.
The following were left signed because either negative values make
sense, or more analysis was needed to determine whether negative values
should be disallowed:
* zfs_metaslab_switch_threshold
* zfs_pd_bytes_max
* zfs_livelist_min_percent_shared
zfs_multihost_history was made static to be consistent with other
parameters.
A number of module parameters were marked as signed, but in reality
referenced unsigned variables. upgrade_errlog_limit is one of the
numerous examples. In the case of zfs_vdev_async_read_max_active, it was
already uint32_t, but zdb had an extern int declaration for it.
Interestingly, the documentation in zfs.4 was right for
upgrade_errlog_limit despite the module parameter being wrongly marked,
while the documentation for zfs_vdev_async_read_max_active (and friends)
was wrong. It was also wrong for zstd_abort_size, which was unsigned,
but was documented as signed.
Also, the documentation in zfs.4 incorrectly described the following
parameters as ulong when they were int:
* zfs_arc_meta_adjust_restarts
* zfs_override_estimate_recordsize
They are now uint_t as of this patch and thus the man page has been
updated to describe them as uint.
dbuf_state_index was left alone since it does nothing and perhaps should
be removed in another patch.
If any module parameters were missed, they were not found by `grep -r
'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed,
but only because they were in files that had hits.
This patch intentionally did not attempt to address whether some of
these module parameters should be elevated to 64-bit parameters, because
the length of a long on 32-bit is 32-bit.
Lastly, it was pointed out during review that uint_t is a better match
for these variables than uint32_t because FreeBSD kernel parameter
definitions are designed for uint_t, whose bit width can change in
future memory models. As a result, we change the existing parameters
that are uint32_t to use uint_t.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13875
2022-09-28 02:42:41 +03:00
|
|
|
static uint_t zfs_zevent_len_max = 512;
|
2010-04-29 21:37:15 +04:00
|
|
|
|
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and
zfs_vdev_aggregation_limit being signed was pointed out as a possible
reason not to eliminate an unnecessary MAX(unsigned, 0) since the
unsigned value was assigned from them.
There is no reason for these module parameters to be signed and upon
inspection, it was found that there are a number of other module
parameters that are signed, but should not be, so we make them unsigned.
Making them unsigned made it clear that some other variables in the code
should also be unsigned, so we also make those unsigned. This prevents
users from setting negative values that could potentially cause bad
behaviors. It also makes the code slightly easier to understand.
Mostly module parameters that deal with timeouts, limits, bitshifts and
percentages are made unsigned by this. Any that are boolean are left
signed, since whether booleans should be considered signed or unsigned
does not matter.
Making zfs_arc_lotsfree_percent unsigned caused a
`zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was
removed. Removing the check was also necessary to prevent a compiler
error from -Werror=type-limits.
Several end of line comments had to be moved to their own lines because
replacing int with uint_t caused us to exceed the 80 character limit
enforced by cstyle.pl.
The following were kept signed because they are passed to
taskq_create(), which expects signed values and modifying the
OpenSolaris/Illumos DDI is out of scope of this patch:
* metaslab_load_pct
* zfs_sync_taskq_batch_pct
* zfs_zil_clean_taskq_nthr_pct
* zfs_zil_clean_taskq_minalloc
* zfs_zil_clean_taskq_maxalloc
* zfs_arc_prune_task_threads
Also, negative values in those parameters was found to be harmless.
The following were left signed because either negative values make
sense, or more analysis was needed to determine whether negative values
should be disallowed:
* zfs_metaslab_switch_threshold
* zfs_pd_bytes_max
* zfs_livelist_min_percent_shared
zfs_multihost_history was made static to be consistent with other
parameters.
A number of module parameters were marked as signed, but in reality
referenced unsigned variables. upgrade_errlog_limit is one of the
numerous examples. In the case of zfs_vdev_async_read_max_active, it was
already uint32_t, but zdb had an extern int declaration for it.
Interestingly, the documentation in zfs.4 was right for
upgrade_errlog_limit despite the module parameter being wrongly marked,
while the documentation for zfs_vdev_async_read_max_active (and friends)
was wrong. It was also wrong for zstd_abort_size, which was unsigned,
but was documented as signed.
Also, the documentation in zfs.4 incorrectly described the following
parameters as ulong when they were int:
* zfs_arc_meta_adjust_restarts
* zfs_override_estimate_recordsize
They are now uint_t as of this patch and thus the man page has been
updated to describe them as uint.
dbuf_state_index was left alone since it does nothing and perhaps should
be removed in another patch.
If any module parameters were missed, they were not found by `grep -r
'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed,
but only because they were in files that had hits.
This patch intentionally did not attempt to address whether some of
these module parameters should be elevated to 64-bit parameters, because
the length of a long on 32-bit is 32-bit.
Lastly, it was pointed out during review that uint_t is a better match
for these variables than uint32_t because FreeBSD kernel parameter
definitions are designed for uint_t, whose bit width can change in
future memory models. As a result, we change the existing parameters
that are uint32_t to use uint_t.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13875
2022-09-28 02:42:41 +03:00
|
|
|
static uint_t zevent_len_cur = 0;
|
2010-08-26 22:42:43 +04:00
|
|
|
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
|
|
|
|
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
|
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and
zfs_vdev_aggregation_limit being signed was pointed out as a possible
reason not to eliminate an unnecessary MAX(unsigned, 0) since the
unsigned value was assigned from them.
There is no reason for these module parameters to be signed and upon
inspection, it was found that there are a number of other module
parameters that are signed, but should not be, so we make them unsigned.
Making them unsigned made it clear that some other variables in the code
should also be unsigned, so we also make those unsigned. This prevents
users from setting negative values that could potentially cause bad
behaviors. It also makes the code slightly easier to understand.
Mostly module parameters that deal with timeouts, limits, bitshifts and
percentages are made unsigned by this. Any that are boolean are left
signed, since whether booleans should be considered signed or unsigned
does not matter.
Making zfs_arc_lotsfree_percent unsigned caused a
`zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was
removed. Removing the check was also necessary to prevent a compiler
error from -Werror=type-limits.
Several end of line comments had to be moved to their own lines because
replacing int with uint_t caused us to exceed the 80 character limit
enforced by cstyle.pl.
The following were kept signed because they are passed to
taskq_create(), which expects signed values and modifying the
OpenSolaris/Illumos DDI is out of scope of this patch:
* metaslab_load_pct
* zfs_sync_taskq_batch_pct
* zfs_zil_clean_taskq_nthr_pct
* zfs_zil_clean_taskq_minalloc
* zfs_zil_clean_taskq_maxalloc
* zfs_arc_prune_task_threads
Also, negative values in those parameters was found to be harmless.
The following were left signed because either negative values make
sense, or more analysis was needed to determine whether negative values
should be disallowed:
* zfs_metaslab_switch_threshold
* zfs_pd_bytes_max
* zfs_livelist_min_percent_shared
zfs_multihost_history was made static to be consistent with other
parameters.
A number of module parameters were marked as signed, but in reality
referenced unsigned variables. upgrade_errlog_limit is one of the
numerous examples. In the case of zfs_vdev_async_read_max_active, it was
already uint32_t, but zdb had an extern int declaration for it.
Interestingly, the documentation in zfs.4 was right for
upgrade_errlog_limit despite the module parameter being wrongly marked,
while the documentation for zfs_vdev_async_read_max_active (and friends)
was wrong. It was also wrong for zstd_abort_size, which was unsigned,
but was documented as signed.
Also, the documentation in zfs.4 incorrectly described the following
parameters as ulong when they were int:
* zfs_arc_meta_adjust_restarts
* zfs_override_estimate_recordsize
They are now uint_t as of this patch and thus the man page has been
updated to describe them as uint.
dbuf_state_index was left alone since it does nothing and perhaps should
be removed in another patch.
If any module parameters were missed, they were not found by `grep -r
'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed,
but only because they were in files that had hits.
This patch intentionally did not attempt to address whether some of
these module parameters should be elevated to 64-bit parameters, because
the length of a long on 32-bit is 32-bit.
Lastly, it was pointed out during review that uint_t is a better match
for these variables than uint32_t because FreeBSD kernel parameter
definitions are designed for uint_t, whose bit width can change in
future memory models. As a result, we change the existing parameters
that are uint32_t to use uint_t.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13875
2022-09-28 02:42:41 +03:00
|
|
|
zfs_zevent_drain_all(uint_t *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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-07-11 04:00:37 +03:00
|
|
|
zfs_file_t *
|
2010-08-26 22:42:43 +04:00
|
|
|
zfs_zevent_fd_hold(int fd, minor_t *minorp, zfs_zevent_t **ze)
|
|
|
|
{
|
2021-07-11 04:00:37 +03:00
|
|
|
zfs_file_t *fp = zfs_file_get(fd);
|
|
|
|
if (fp == NULL)
|
|
|
|
return (NULL);
|
2010-08-26 22:42:43 +04:00
|
|
|
|
2021-07-11 04:00:37 +03:00
|
|
|
int error = zfsdev_getminor(fp, 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
|
|
|
|
2021-07-11 04:00:37 +03:00
|
|
|
if (error) {
|
|
|
|
zfs_zevent_fd_rele(fp);
|
|
|
|
fp = NULL;
|
|
|
|
}
|
2010-08-26 22:42:43 +04:00
|
|
|
|
2021-07-11 04:00:37 +03:00
|
|
|
return (fp);
|
2010-08-26 22:42:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-07-11 04:00:37 +03:00
|
|
|
zfs_zevent_fd_rele(zfs_file_t *fp)
|
2010-08-26 22:42:43 +04:00
|
|
|
{
|
2021-07-11 04:00:37 +03:00
|
|
|
zfs_file_put(fp);
|
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 */
|
2021-03-29 22:44:27 +03:00
|
|
|
*dropped += atomic_swap_64(&ratelimit_dropped, 0);
|
2016-10-19 22:55:59 +03:00
|
|
|
#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
|
|
|
|
Cleanup of dead code suggested by Clang Static Analyzer (#14380)
I recently gained the ability to run Clang's static analyzer on the
linux kernel modules via a few hacks. This extended coverage to code
that was previously missed since Clang's static analyzer only looked at
code that we built in userspace. Running it against the Linux kernel
modules built from my local branch produced a total of 72 reports
against my local branch. Of those, 50 were reports of logic errors and
22 were reports of dead code. Since we already had cleaned up all of
the previous dead code reports, I felt it would be a good next step to
clean up these dead code reports. Clang did a further breakdown of the
dead code reports into:
Dead assignment 15
Dead increment 2
Dead nested assignment 5
The benefit of cleaning these up, especially in the case of dead nested
assignment, is that they can expose places where our error handling is
incorrect. A number of them were fairly straight forward. However
several were not:
In vdev_disk_physio_completion(), not only were we not using the return
value from the static function vdev_disk_dio_put(), but nothing used it,
so I changed it to return void and removed the existing (void) cast in
the other area where we call it in addition to no longer storing it to a
stack value.
In FSE_createDTable(), the function is dead code. Its helper function
FSE_freeDTable() is also dead code, as are the CPP definitions in
`module/zstd/include/zstd_compat_wrapper.h`. We just delete it all.
In zfs_zevent_wait(), we have an optimization opportunity. cv_wait_sig()
returns 0 if there are waiting signals and 1 if there are none. The
Linux SPL version literally returns `signal_pending(current) ? 0 : 1)`
and FreeBSD implements the same semantics, we can just do
`!cv_wait_sig()` in place of `signal_pending(current)` to avoid
unnecessarily calling it again.
zfs_setattr() on FreeBSD version did not have error handling issue
because the code was removed entirely from FreeBSD version. The error is
from updating the attribute directory's files. After some thought, I
decided to propapage errors on it to userspace.
In zfs_secpolicy_tmp_snapshot(), we ignore a lack of permission from the
first check in favor of checking three other permissions. I assume this
is intentional.
In zfs_create_fs(), the return value of zap_update() was not checked
despite setting an important version number. I see no backward
compatibility reason to permit failures, so we add an assertion to catch
failures. Interestingly, Linux is still using ASSERT(error == 0) from
OpenSolaris while FreeBSD has switched to the improved ASSERT0(error)
from illumos, although illumos has yet to adopt it here. ASSERT(error ==
0) was used on Linux while ASSERT0(error) was used on FreeBSD since the
entire file needs conversion and that should be the subject of
another patch.
dnode_move()'s issue was caused by us not having implemented
POINTER_IS_VALID() on Linux. We have a stub in
`include/os/linux/spl/sys/kmem_cache.h` for it, when it really should be
in `include/os/linux/spl/sys/kmem.h` to be consistent with
Illumos/OpenSolaris. FreeBSD put both `POINTER_IS_VALID()` and
`POINTER_INVALIDATE()` in `include/os/freebsd/spl/sys/kmem.h`, so we
copy what it did.
Whenever a report was in platform-specific code, I checked the FreeBSD
version to see if it also applied to FreeBSD, but it was only relevant a
few times.
Lastly, the patch that enabled Clang's static analyzer to be run on the
Linux kernel modules needs more work before it can be put into a PR. I
plan to do that in the future as part of the on-going static analysis
work that I am doing.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14380
2023-01-17 20:57:12 +03:00
|
|
|
if (cv_wait_sig(&zevent_cv, &zevent_lock) == 0) {
|
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
|
|
|
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
|
|
|
*/
|
|
|
|
static void *
|
|
|
|
i_fm_alloc(nv_alloc_t *nva, size_t size)
|
|
|
|
{
|
2021-12-12 18:06:44 +03:00
|
|
|
(void) nva;
|
2022-08-05 02:53:47 +03:00
|
|
|
return (kmem_alloc(size, KM_SLEEP));
|
2010-04-29 21:37:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
i_fm_free(nv_alloc_t *nva, void *buf, size_t size)
|
|
|
|
{
|
2021-12-12 18:06:44 +03:00
|
|
|
(void) nva;
|
2010-04-29 21:37:15 +04:00
|
|
|
kmem_free(buf, size);
|
|
|
|
}
|
|
|
|
|
2022-01-15 02:37:55 +03:00
|
|
|
static 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,
|
2021-12-07 04:19:13 +03:00
|
|
|
va_arg(ap, const char **), nelem);
|
2010-04-29 21:37:15 +04:00
|
|
|
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,
|
2021-12-07 04:19:13 +03:00
|
|
|
va_arg(ap, const nvlist_t **), nelem);
|
2010-04-29 21:37:15 +04:00
|
|
|
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);
|
|
|
|
|
2021-12-07 04:19:13 +03:00
|
|
|
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST,
|
|
|
|
(const nvlist_t **)pairs, npairs) != 0) {
|
2016-01-14 03:37:41 +03:00
|
|
|
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
|
2021-12-07 04:19:13 +03:00
|
|
|
}
|
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;
|
2023-03-11 21:39:24 +03:00
|
|
|
const char *hcname, *hcid;
|
2010-08-26 22:42:43 +04:00
|
|
|
|
|
|
|
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);
|
2022-10-15 05:46:43 +03:00
|
|
|
va_end(ap);
|
2010-08-26 22:42:43 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the fmri hc list
|
|
|
|
*/
|
2021-12-07 04:19:13 +03:00
|
|
|
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST,
|
|
|
|
(const nvlist_t **)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,
|
2021-12-07 04:19:13 +03:00
|
|
|
(const 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
|
|
|
|
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
|
|
|
{
|
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and
zfs_vdev_aggregation_limit being signed was pointed out as a possible
reason not to eliminate an unnecessary MAX(unsigned, 0) since the
unsigned value was assigned from them.
There is no reason for these module parameters to be signed and upon
inspection, it was found that there are a number of other module
parameters that are signed, but should not be, so we make them unsigned.
Making them unsigned made it clear that some other variables in the code
should also be unsigned, so we also make those unsigned. This prevents
users from setting negative values that could potentially cause bad
behaviors. It also makes the code slightly easier to understand.
Mostly module parameters that deal with timeouts, limits, bitshifts and
percentages are made unsigned by this. Any that are boolean are left
signed, since whether booleans should be considered signed or unsigned
does not matter.
Making zfs_arc_lotsfree_percent unsigned caused a
`zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was
removed. Removing the check was also necessary to prevent a compiler
error from -Werror=type-limits.
Several end of line comments had to be moved to their own lines because
replacing int with uint_t caused us to exceed the 80 character limit
enforced by cstyle.pl.
The following were kept signed because they are passed to
taskq_create(), which expects signed values and modifying the
OpenSolaris/Illumos DDI is out of scope of this patch:
* metaslab_load_pct
* zfs_sync_taskq_batch_pct
* zfs_zil_clean_taskq_nthr_pct
* zfs_zil_clean_taskq_minalloc
* zfs_zil_clean_taskq_maxalloc
* zfs_arc_prune_task_threads
Also, negative values in those parameters was found to be harmless.
The following were left signed because either negative values make
sense, or more analysis was needed to determine whether negative values
should be disallowed:
* zfs_metaslab_switch_threshold
* zfs_pd_bytes_max
* zfs_livelist_min_percent_shared
zfs_multihost_history was made static to be consistent with other
parameters.
A number of module parameters were marked as signed, but in reality
referenced unsigned variables. upgrade_errlog_limit is one of the
numerous examples. In the case of zfs_vdev_async_read_max_active, it was
already uint32_t, but zdb had an extern int declaration for it.
Interestingly, the documentation in zfs.4 was right for
upgrade_errlog_limit despite the module parameter being wrongly marked,
while the documentation for zfs_vdev_async_read_max_active (and friends)
was wrong. It was also wrong for zstd_abort_size, which was unsigned,
but was documented as signed.
Also, the documentation in zfs.4 incorrectly described the following
parameters as ulong when they were int:
* zfs_arc_meta_adjust_restarts
* zfs_override_estimate_recordsize
They are now uint_t as of this patch and thus the man page has been
updated to describe them as uint.
dbuf_state_index was left alone since it does nothing and perhaps should
be removed in another patch.
If any module parameters were missed, they were not found by `grep -r
'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed,
but only because they were in files that had hits.
This patch intentionally did not attempt to address whether some of
these module parameters should be elevated to 64-bit parameters, because
the length of a long on 32-bit is 32-bit.
Lastly, it was pointed out during review that uint_t is a better match
for these variables than uint32_t because FreeBSD kernel parameter
definitions are designed for uint_t, whose bit width can change in
future memory models. As a result, we change the existing parameters
that are uint32_t to use uint_t.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13875
2022-09-28 02:42:41 +03:00
|
|
|
uint_t 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);
|
Cleanup: Use OpenSolaris functions to call scheduler
In our codebase, `cond_resched() and `schedule()` are Linux kernel
functions that have replaced the OpenSolaris `kpreempt()` functions in
the codebase to such an extent that `kpreempt()` in zfs_context.h was
broken. Nobody noticed because we did not actually use it. The header
had defined `kpreempt()` as `yield()`, which works on OpenSolaris and
Illumos where `sched_yield()` is a wrapper for `yield()`, but that does
not work on any other platform.
The FreeBSD platform specific code implemented shims for these, but the
shim for `schedule()` forced us to wait, which is different than merely
rescheduling to another thread as the original Linux code does, while
the shim for `cond_resched()` had the same definition as its kernel
kpreempt() shim.
After studying this, I have concluded that we should reintroduce the
kpreempt() function in platform independent code with the following
definitions:
- In the Linux kernel:
kpreempt(unused) -> cond_resched()
- In the FreeBSD kernel:
kpreempt(unused) -> kern_yield(PRI_USER)
- In userspace:
kpreempt(unused) -> sched_yield()
In userspace, nothing changes from this cleanup. In the kernels, the
function `fm_fini()` will now call `kern_yield(PRI_USER)` on FreeBSD and
`cond_resched()` on Linux. This is instead of `pause("schedule", 1)` on
FreeBSD and `schedule()` on Linux. This makes our behavior consistent
across platforms.
Note that Linux's SPL continues to use `cond_resched()` and
`schedule()`. However, those functions have been removed from both the
FreeBSD code and userspace code.
This should have the benefit of making it slightly easier to port the
code to new platforms by making how things should be mapped less
confusing.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13845
2022-09-12 19:55:37 +03:00
|
|
|
kpreempt(KPREEMPT_SYNC);
|
2010-08-26 22:42:43 +04:00
|
|
|
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
|
|
|
|
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and
zfs_vdev_aggregation_limit being signed was pointed out as a possible
reason not to eliminate an unnecessary MAX(unsigned, 0) since the
unsigned value was assigned from them.
There is no reason for these module parameters to be signed and upon
inspection, it was found that there are a number of other module
parameters that are signed, but should not be, so we make them unsigned.
Making them unsigned made it clear that some other variables in the code
should also be unsigned, so we also make those unsigned. This prevents
users from setting negative values that could potentially cause bad
behaviors. It also makes the code slightly easier to understand.
Mostly module parameters that deal with timeouts, limits, bitshifts and
percentages are made unsigned by this. Any that are boolean are left
signed, since whether booleans should be considered signed or unsigned
does not matter.
Making zfs_arc_lotsfree_percent unsigned caused a
`zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was
removed. Removing the check was also necessary to prevent a compiler
error from -Werror=type-limits.
Several end of line comments had to be moved to their own lines because
replacing int with uint_t caused us to exceed the 80 character limit
enforced by cstyle.pl.
The following were kept signed because they are passed to
taskq_create(), which expects signed values and modifying the
OpenSolaris/Illumos DDI is out of scope of this patch:
* metaslab_load_pct
* zfs_sync_taskq_batch_pct
* zfs_zil_clean_taskq_nthr_pct
* zfs_zil_clean_taskq_minalloc
* zfs_zil_clean_taskq_maxalloc
* zfs_arc_prune_task_threads
Also, negative values in those parameters was found to be harmless.
The following were left signed because either negative values make
sense, or more analysis was needed to determine whether negative values
should be disallowed:
* zfs_metaslab_switch_threshold
* zfs_pd_bytes_max
* zfs_livelist_min_percent_shared
zfs_multihost_history was made static to be consistent with other
parameters.
A number of module parameters were marked as signed, but in reality
referenced unsigned variables. upgrade_errlog_limit is one of the
numerous examples. In the case of zfs_vdev_async_read_max_active, it was
already uint32_t, but zdb had an extern int declaration for it.
Interestingly, the documentation in zfs.4 was right for
upgrade_errlog_limit despite the module parameter being wrongly marked,
while the documentation for zfs_vdev_async_read_max_active (and friends)
was wrong. It was also wrong for zstd_abort_size, which was unsigned,
but was documented as signed.
Also, the documentation in zfs.4 incorrectly described the following
parameters as ulong when they were int:
* zfs_arc_meta_adjust_restarts
* zfs_override_estimate_recordsize
They are now uint_t as of this patch and thus the man page has been
updated to describe them as uint.
dbuf_state_index was left alone since it does nothing and perhaps should
be removed in another patch.
If any module parameters were missed, they were not found by `grep -r
'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed,
but only because they were in files that had hits.
This patch intentionally did not attempt to address whether some of
these module parameters should be elevated to 64-bit parameters, because
the length of a long on 32-bit is 32-bit.
Lastly, it was pointed out during review that uint_t is a better match
for these variables than uint32_t because FreeBSD kernel parameter
definitions are designed for uint_t, whose bit width can change in
future memory models. As a result, we change the existing parameters
that are uint32_t to use uint_t.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13875
2022-09-28 02:42:41 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs_zevent, zfs_zevent_, len_max, UINT, ZMOD_RW,
|
2020-02-18 22:22:56 +03:00
|
|
|
"Max event queue length");
|