2016-09-01 00:46:58 +03: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.
|
2016-09-01 00:46:58 +03: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
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
|
2016-11-08 02:01:38 +03:00
|
|
|
*
|
|
|
|
* Copyright (c) 2016, Intel Corporation.
|
2018-09-19 00:45:52 +03:00
|
|
|
* Copyright (c) 2018, loli10K <ezomori.nozomu@gmail.com>
|
2016-11-08 02:01:38 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ZFS retire agent is responsible for managing hot spares across all pools.
|
|
|
|
* When we see a device fault or a device removal, we try to open the associated
|
|
|
|
* pool and look for any hot spares. We iterate over any available hot spares
|
|
|
|
* and attempt a 'zpool replace' for each one.
|
|
|
|
*
|
|
|
|
* For vdevs diagnosed as faulty, the agent is also responsible for proactively
|
|
|
|
* marking the vdev FAULTY (for I/O errors) or DEGRADED (for checksum errors).
|
2016-09-01 00:46:58 +03:00
|
|
|
*/
|
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/fm/protocol.h>
|
|
|
|
#include <sys/fm/fs/zfs.h>
|
2021-05-22 18:19:14 +03:00
|
|
|
#include <libzutil.h>
|
2016-11-08 02:01:38 +03:00
|
|
|
#include <libzfs.h>
|
|
|
|
#include <string.h>
|
2021-09-09 20:44:21 +03:00
|
|
|
#include <libgen.h>
|
2016-11-08 02:01:38 +03:00
|
|
|
|
2016-09-01 00:46:58 +03:00
|
|
|
#include "zfs_agents.h"
|
2016-11-08 02:01:38 +03:00
|
|
|
#include "fmd_api.h"
|
2016-09-01 00:46:58 +03:00
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
|
|
|
|
typedef struct zfs_retire_repaired {
|
|
|
|
struct zfs_retire_repaired *zrr_next;
|
|
|
|
uint64_t zrr_pool;
|
|
|
|
uint64_t zrr_vdev;
|
|
|
|
} zfs_retire_repaired_t;
|
|
|
|
|
|
|
|
typedef struct zfs_retire_data {
|
|
|
|
libzfs_handle_t *zrd_hdl;
|
|
|
|
zfs_retire_repaired_t *zrd_repaired;
|
|
|
|
} zfs_retire_data_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
zfs_retire_clear_data(fmd_hdl_t *hdl, zfs_retire_data_t *zdp)
|
2016-09-01 00:46:58 +03:00
|
|
|
{
|
2016-11-08 02:01:38 +03:00
|
|
|
zfs_retire_repaired_t *zrp;
|
|
|
|
|
|
|
|
while ((zrp = zdp->zrd_repaired) != NULL) {
|
|
|
|
zdp->zrd_repaired = zrp->zrr_next;
|
|
|
|
fmd_hdl_free(hdl, zrp, sizeof (zfs_retire_repaired_t));
|
|
|
|
}
|
2016-09-01 00:46:58 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
/*
|
|
|
|
* Find a pool with a matching GUID.
|
|
|
|
*/
|
|
|
|
typedef struct find_cbdata {
|
|
|
|
uint64_t cb_guid;
|
|
|
|
zpool_handle_t *cb_zhp;
|
|
|
|
nvlist_t *cb_vdev;
|
|
|
|
} find_cbdata_t;
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_pool(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
find_cbdata_t *cbp = data;
|
|
|
|
|
|
|
|
if (cbp->cb_guid ==
|
|
|
|
zpool_get_prop_int(zhp, ZPOOL_PROP_GUID, NULL)) {
|
|
|
|
cbp->cb_zhp = zhp;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a vdev within a tree with a matching GUID.
|
|
|
|
*/
|
|
|
|
static nvlist_t *
|
2017-09-19 03:06:40 +03:00
|
|
|
find_vdev(libzfs_handle_t *zhdl, nvlist_t *nv, uint64_t search_guid)
|
2016-11-08 02:01:38 +03:00
|
|
|
{
|
|
|
|
uint64_t guid;
|
|
|
|
nvlist_t **child;
|
|
|
|
uint_t c, children;
|
|
|
|
nvlist_t *ret;
|
2017-09-19 03:06:40 +03:00
|
|
|
|
|
|
|
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) == 0 &&
|
|
|
|
guid == search_guid) {
|
|
|
|
fmd_hdl_debug(fmd_module_hdl("zfs-retire"),
|
|
|
|
"matched vdev %llu", guid);
|
|
|
|
return (nv);
|
2016-11-08 02:01:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&child, &children) != 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
2017-09-19 03:06:40 +03:00
|
|
|
if ((ret = find_vdev(zhdl, child[c], search_guid)) != NULL)
|
2016-11-08 02:01:38 +03:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
|
|
|
|
&child, &children) != 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
2017-09-19 03:06:40 +03:00
|
|
|
if ((ret = find_vdev(zhdl, child[c], search_guid)) != NULL)
|
2016-11-08 02:01:38 +03:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:45:52 +03:00
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
|
|
|
|
&child, &children) != 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
|
|
|
if ((ret = find_vdev(zhdl, child[c], search_guid)) != NULL)
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a (pool, vdev) GUID pair, find the matching pool and vdev.
|
|
|
|
*/
|
|
|
|
static zpool_handle_t *
|
|
|
|
find_by_guid(libzfs_handle_t *zhdl, uint64_t pool_guid, uint64_t vdev_guid,
|
|
|
|
nvlist_t **vdevp)
|
|
|
|
{
|
|
|
|
find_cbdata_t cb;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
nvlist_t *config, *nvroot;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the corresponding pool and make sure the vdev still exists.
|
|
|
|
*/
|
|
|
|
cb.cb_guid = pool_guid;
|
|
|
|
if (zpool_iter(zhdl, find_pool, &cb) != 1)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
zhp = cb.cb_zhp;
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
|
|
|
if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&nvroot) != 0) {
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vdev_guid != 0) {
|
2017-09-19 03:06:40 +03:00
|
|
|
if ((*vdevp = find_vdev(zhdl, nvroot, vdev_guid)) == NULL) {
|
2016-11-08 02:01:38 +03:00
|
|
|
zpool_close(zhp);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (zhp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a vdev, attempt to replace it with every known spare until one
|
2018-09-19 00:45:52 +03:00
|
|
|
* succeeds or we run out of devices to try.
|
|
|
|
* Return whether we were successful or not in replacing the device.
|
2016-11-08 02:01:38 +03:00
|
|
|
*/
|
2018-09-19 00:45:52 +03:00
|
|
|
static boolean_t
|
2016-11-08 02:01:38 +03:00
|
|
|
replace_with_spare(fmd_hdl_t *hdl, zpool_handle_t *zhp, nvlist_t *vdev)
|
|
|
|
{
|
|
|
|
nvlist_t *config, *nvroot, *replacement;
|
|
|
|
nvlist_t **spares;
|
|
|
|
uint_t s, nspares;
|
|
|
|
char *dev_name;
|
2017-12-09 03:58:41 +03:00
|
|
|
zprop_source_t source;
|
|
|
|
int ashift;
|
2016-11-08 02:01:38 +03:00
|
|
|
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
|
|
|
if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&nvroot) != 0)
|
2018-09-19 00:45:52 +03:00
|
|
|
return (B_FALSE);
|
2016-11-08 02:01:38 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find out if there are any hot spares available in the pool.
|
|
|
|
*/
|
|
|
|
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
|
|
|
|
&spares, &nspares) != 0)
|
2018-09-19 00:45:52 +03:00
|
|
|
return (B_FALSE);
|
2016-11-08 02:01:38 +03:00
|
|
|
|
2017-12-09 03:58:41 +03:00
|
|
|
/*
|
|
|
|
* lookup "ashift" pool property, we may need it for the replacement
|
|
|
|
*/
|
|
|
|
ashift = zpool_get_prop_int(zhp, ZPOOL_PROP_ASHIFT, &source);
|
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
replacement = fmd_nvl_alloc(hdl, FMD_SLEEP);
|
|
|
|
|
|
|
|
(void) nvlist_add_string(replacement, ZPOOL_CONFIG_TYPE,
|
|
|
|
VDEV_TYPE_ROOT);
|
|
|
|
|
|
|
|
dev_name = zpool_vdev_name(NULL, zhp, vdev, B_FALSE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to replace each spare, ending when we successfully
|
|
|
|
* replace it.
|
|
|
|
*/
|
|
|
|
for (s = 0; s < nspares; s++) {
|
Distributed Spare (dRAID) Feature
This patch adds a new top-level vdev type called dRAID, which stands
for Distributed parity RAID. This pool configuration allows all dRAID
vdevs to participate when rebuilding to a distributed hot spare device.
This can substantially reduce the total time required to restore full
parity to pool with a failed device.
A dRAID pool can be created using the new top-level `draid` type.
Like `raidz`, the desired redundancy is specified after the type:
`draid[1,2,3]`. No additional information is required to create the
pool and reasonable default values will be chosen based on the number
of child vdevs in the dRAID vdev.
zpool create <pool> draid[1,2,3] <vdevs...>
Unlike raidz, additional optional dRAID configuration values can be
provided as part of the draid type as colon separated values. This
allows administrators to fully specify a layout for either performance
or capacity reasons. The supported options include:
zpool create <pool> \
draid[<parity>][:<data>d][:<children>c][:<spares>s] \
<vdevs...>
- draid[parity] - Parity level (default 1)
- draid[:<data>d] - Data devices per group (default 8)
- draid[:<children>c] - Expected number of child vdevs
- draid[:<spares>s] - Distributed hot spares (default 0)
Abbreviated example `zpool status` output for a 68 disk dRAID pool
with two distributed spares using special allocation classes.
```
pool: tank
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
slag7 ONLINE 0 0 0
draid2:8d:68c:2s-0 ONLINE 0 0 0
L0 ONLINE 0 0 0
L1 ONLINE 0 0 0
...
U25 ONLINE 0 0 0
U26 ONLINE 0 0 0
spare-53 ONLINE 0 0 0
U27 ONLINE 0 0 0
draid2-0-0 ONLINE 0 0 0
U28 ONLINE 0 0 0
U29 ONLINE 0 0 0
...
U42 ONLINE 0 0 0
U43 ONLINE 0 0 0
special
mirror-1 ONLINE 0 0 0
L5 ONLINE 0 0 0
U5 ONLINE 0 0 0
mirror-2 ONLINE 0 0 0
L6 ONLINE 0 0 0
U6 ONLINE 0 0 0
spares
draid2-0-0 INUSE currently in use
draid2-0-1 AVAIL
```
When adding test coverage for the new dRAID vdev type the following
options were added to the ztest command. These options are leverages
by zloop.sh to test a wide range of dRAID configurations.
-K draid|raidz|random - kind of RAID to test
-D <value> - dRAID data drives per group
-S <value> - dRAID distributed hot spares
-R <value> - RAID parity (raidz or dRAID)
The zpool_create, zpool_import, redundancy, replacement and fault
test groups have all been updated provide test coverage for the
dRAID feature.
Co-authored-by: Isaac Huang <he.huang@intel.com>
Co-authored-by: Mark Maybee <mmaybee@cray.com>
Co-authored-by: Don Brady <don.brady@delphix.com>
Co-authored-by: Matthew Ahrens <mahrens@delphix.com>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mark Maybee <mmaybee@cray.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #10102
2020-11-14 00:51:51 +03:00
|
|
|
boolean_t rebuild = B_FALSE;
|
|
|
|
char *spare_name, *type;
|
2016-11-08 02:01:38 +03:00
|
|
|
|
|
|
|
if (nvlist_lookup_string(spares[s], ZPOOL_CONFIG_PATH,
|
|
|
|
&spare_name) != 0)
|
|
|
|
continue;
|
|
|
|
|
Distributed Spare (dRAID) Feature
This patch adds a new top-level vdev type called dRAID, which stands
for Distributed parity RAID. This pool configuration allows all dRAID
vdevs to participate when rebuilding to a distributed hot spare device.
This can substantially reduce the total time required to restore full
parity to pool with a failed device.
A dRAID pool can be created using the new top-level `draid` type.
Like `raidz`, the desired redundancy is specified after the type:
`draid[1,2,3]`. No additional information is required to create the
pool and reasonable default values will be chosen based on the number
of child vdevs in the dRAID vdev.
zpool create <pool> draid[1,2,3] <vdevs...>
Unlike raidz, additional optional dRAID configuration values can be
provided as part of the draid type as colon separated values. This
allows administrators to fully specify a layout for either performance
or capacity reasons. The supported options include:
zpool create <pool> \
draid[<parity>][:<data>d][:<children>c][:<spares>s] \
<vdevs...>
- draid[parity] - Parity level (default 1)
- draid[:<data>d] - Data devices per group (default 8)
- draid[:<children>c] - Expected number of child vdevs
- draid[:<spares>s] - Distributed hot spares (default 0)
Abbreviated example `zpool status` output for a 68 disk dRAID pool
with two distributed spares using special allocation classes.
```
pool: tank
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
slag7 ONLINE 0 0 0
draid2:8d:68c:2s-0 ONLINE 0 0 0
L0 ONLINE 0 0 0
L1 ONLINE 0 0 0
...
U25 ONLINE 0 0 0
U26 ONLINE 0 0 0
spare-53 ONLINE 0 0 0
U27 ONLINE 0 0 0
draid2-0-0 ONLINE 0 0 0
U28 ONLINE 0 0 0
U29 ONLINE 0 0 0
...
U42 ONLINE 0 0 0
U43 ONLINE 0 0 0
special
mirror-1 ONLINE 0 0 0
L5 ONLINE 0 0 0
U5 ONLINE 0 0 0
mirror-2 ONLINE 0 0 0
L6 ONLINE 0 0 0
U6 ONLINE 0 0 0
spares
draid2-0-0 INUSE currently in use
draid2-0-1 AVAIL
```
When adding test coverage for the new dRAID vdev type the following
options were added to the ztest command. These options are leverages
by zloop.sh to test a wide range of dRAID configurations.
-K draid|raidz|random - kind of RAID to test
-D <value> - dRAID data drives per group
-S <value> - dRAID distributed hot spares
-R <value> - RAID parity (raidz or dRAID)
The zpool_create, zpool_import, redundancy, replacement and fault
test groups have all been updated provide test coverage for the
dRAID feature.
Co-authored-by: Isaac Huang <he.huang@intel.com>
Co-authored-by: Mark Maybee <mmaybee@cray.com>
Co-authored-by: Don Brady <don.brady@delphix.com>
Co-authored-by: Matthew Ahrens <mahrens@delphix.com>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mark Maybee <mmaybee@cray.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #10102
2020-11-14 00:51:51 +03:00
|
|
|
/* prefer sequential resilvering for distributed spares */
|
|
|
|
if ((nvlist_lookup_string(spares[s], ZPOOL_CONFIG_TYPE,
|
|
|
|
&type) == 0) && strcmp(type, VDEV_TYPE_DRAID_SPARE) == 0)
|
|
|
|
rebuild = B_TRUE;
|
|
|
|
|
2017-12-09 03:58:41 +03:00
|
|
|
/* if set, add the "ashift" pool property to the spare nvlist */
|
|
|
|
if (source != ZPROP_SRC_DEFAULT)
|
|
|
|
(void) nvlist_add_uint64(spares[s],
|
|
|
|
ZPOOL_CONFIG_ASHIFT, ashift);
|
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
(void) nvlist_add_nvlist_array(replacement,
|
2021-12-07 04:19:13 +03:00
|
|
|
ZPOOL_CONFIG_CHILDREN, (const nvlist_t **)&spares[s], 1);
|
2016-11-08 02:01:38 +03:00
|
|
|
|
|
|
|
fmd_hdl_debug(hdl, "zpool_vdev_replace '%s' with spare '%s'",
|
2021-05-22 18:19:14 +03:00
|
|
|
dev_name, zfs_basename(spare_name));
|
2016-11-08 02:01:38 +03:00
|
|
|
|
|
|
|
if (zpool_vdev_attach(zhp, dev_name, spare_name,
|
Distributed Spare (dRAID) Feature
This patch adds a new top-level vdev type called dRAID, which stands
for Distributed parity RAID. This pool configuration allows all dRAID
vdevs to participate when rebuilding to a distributed hot spare device.
This can substantially reduce the total time required to restore full
parity to pool with a failed device.
A dRAID pool can be created using the new top-level `draid` type.
Like `raidz`, the desired redundancy is specified after the type:
`draid[1,2,3]`. No additional information is required to create the
pool and reasonable default values will be chosen based on the number
of child vdevs in the dRAID vdev.
zpool create <pool> draid[1,2,3] <vdevs...>
Unlike raidz, additional optional dRAID configuration values can be
provided as part of the draid type as colon separated values. This
allows administrators to fully specify a layout for either performance
or capacity reasons. The supported options include:
zpool create <pool> \
draid[<parity>][:<data>d][:<children>c][:<spares>s] \
<vdevs...>
- draid[parity] - Parity level (default 1)
- draid[:<data>d] - Data devices per group (default 8)
- draid[:<children>c] - Expected number of child vdevs
- draid[:<spares>s] - Distributed hot spares (default 0)
Abbreviated example `zpool status` output for a 68 disk dRAID pool
with two distributed spares using special allocation classes.
```
pool: tank
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
slag7 ONLINE 0 0 0
draid2:8d:68c:2s-0 ONLINE 0 0 0
L0 ONLINE 0 0 0
L1 ONLINE 0 0 0
...
U25 ONLINE 0 0 0
U26 ONLINE 0 0 0
spare-53 ONLINE 0 0 0
U27 ONLINE 0 0 0
draid2-0-0 ONLINE 0 0 0
U28 ONLINE 0 0 0
U29 ONLINE 0 0 0
...
U42 ONLINE 0 0 0
U43 ONLINE 0 0 0
special
mirror-1 ONLINE 0 0 0
L5 ONLINE 0 0 0
U5 ONLINE 0 0 0
mirror-2 ONLINE 0 0 0
L6 ONLINE 0 0 0
U6 ONLINE 0 0 0
spares
draid2-0-0 INUSE currently in use
draid2-0-1 AVAIL
```
When adding test coverage for the new dRAID vdev type the following
options were added to the ztest command. These options are leverages
by zloop.sh to test a wide range of dRAID configurations.
-K draid|raidz|random - kind of RAID to test
-D <value> - dRAID data drives per group
-S <value> - dRAID distributed hot spares
-R <value> - RAID parity (raidz or dRAID)
The zpool_create, zpool_import, redundancy, replacement and fault
test groups have all been updated provide test coverage for the
dRAID feature.
Co-authored-by: Isaac Huang <he.huang@intel.com>
Co-authored-by: Mark Maybee <mmaybee@cray.com>
Co-authored-by: Don Brady <don.brady@delphix.com>
Co-authored-by: Matthew Ahrens <mahrens@delphix.com>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mark Maybee <mmaybee@cray.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #10102
2020-11-14 00:51:51 +03:00
|
|
|
replacement, B_TRUE, rebuild) == 0) {
|
2018-09-19 00:45:52 +03:00
|
|
|
free(dev_name);
|
|
|
|
nvlist_free(replacement);
|
|
|
|
return (B_TRUE);
|
|
|
|
}
|
2016-11-08 02:01:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
free(dev_name);
|
|
|
|
nvlist_free(replacement);
|
2018-09-19 00:45:52 +03:00
|
|
|
|
|
|
|
return (B_FALSE);
|
2016-11-08 02:01:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Repair this vdev if we had diagnosed a 'fault.fs.zfs.device' and
|
|
|
|
* ASRU is now usable. ZFS has found the device to be present and
|
|
|
|
* functioning.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
zfs_vdev_repair(fmd_hdl_t *hdl, nvlist_t *nvl)
|
|
|
|
{
|
|
|
|
zfs_retire_data_t *zdp = fmd_hdl_getspecific(hdl);
|
|
|
|
zfs_retire_repaired_t *zrp;
|
|
|
|
uint64_t pool_guid, vdev_guid;
|
|
|
|
if (nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
|
|
|
|
&pool_guid) != 0 || nvlist_lookup_uint64(nvl,
|
|
|
|
FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, &vdev_guid) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before checking the state of the ASRU, go through and see if we've
|
|
|
|
* already made an attempt to repair this ASRU. This list is cleared
|
|
|
|
* whenever we receive any kind of list event, and is designed to
|
|
|
|
* prevent us from generating a feedback loop when we attempt repairs
|
|
|
|
* against a faulted pool. The problem is that checking the unusable
|
|
|
|
* state of the ASRU can involve opening the pool, which can post
|
|
|
|
* statechange events but otherwise leave the pool in the faulted
|
|
|
|
* state. This list allows us to detect when a statechange event is
|
|
|
|
* due to our own request.
|
|
|
|
*/
|
|
|
|
for (zrp = zdp->zrd_repaired; zrp != NULL; zrp = zrp->zrr_next) {
|
|
|
|
if (zrp->zrr_pool == pool_guid &&
|
|
|
|
zrp->zrr_vdev == vdev_guid)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
zrp = fmd_hdl_alloc(hdl, sizeof (zfs_retire_repaired_t), FMD_SLEEP);
|
|
|
|
zrp->zrr_next = zdp->zrd_repaired;
|
|
|
|
zrp->zrr_pool = pool_guid;
|
|
|
|
zrp->zrr_vdev = vdev_guid;
|
|
|
|
zdp->zrd_repaired = zrp;
|
|
|
|
|
|
|
|
fmd_hdl_debug(hdl, "marking repaired vdev %llu on pool %llu",
|
|
|
|
vdev_guid, pool_guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zfs_retire_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl,
|
|
|
|
const char *class)
|
|
|
|
{
|
2021-12-11 03:21:46 +03:00
|
|
|
(void) ep;
|
2016-11-08 02:01:38 +03:00
|
|
|
uint64_t pool_guid, vdev_guid;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
nvlist_t *resource, *fault;
|
|
|
|
nvlist_t **faults;
|
|
|
|
uint_t f, nfaults;
|
|
|
|
zfs_retire_data_t *zdp = fmd_hdl_getspecific(hdl);
|
|
|
|
libzfs_handle_t *zhdl = zdp->zrd_hdl;
|
|
|
|
boolean_t fault_device, degrade_device;
|
|
|
|
boolean_t is_repair;
|
|
|
|
char *scheme;
|
|
|
|
nvlist_t *vdev = NULL;
|
|
|
|
char *uuid;
|
|
|
|
int repair_done = 0;
|
|
|
|
boolean_t retire;
|
|
|
|
boolean_t is_disk;
|
|
|
|
vdev_aux_t aux;
|
|
|
|
uint64_t state = 0;
|
2022-09-28 19:48:46 +03:00
|
|
|
int l2arc;
|
|
|
|
vdev_stat_t *vs;
|
|
|
|
unsigned int c;
|
2016-11-08 02:01:38 +03:00
|
|
|
|
|
|
|
fmd_hdl_debug(hdl, "zfs_retire_recv: '%s'", class);
|
|
|
|
|
2022-09-24 02:52:03 +03:00
|
|
|
(void) nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE,
|
|
|
|
&state);
|
2020-07-03 21:05:50 +03:00
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
/*
|
2018-09-19 00:45:52 +03:00
|
|
|
* If this is a resource notifying us of device removal then simply
|
|
|
|
* check for an available spare and continue unless the device is a
|
|
|
|
* l2arc vdev, in which case we just offline it.
|
2016-11-08 02:01:38 +03:00
|
|
|
*/
|
2020-07-03 21:05:50 +03:00
|
|
|
if (strcmp(class, "resource.fs.zfs.removed") == 0 ||
|
|
|
|
(strcmp(class, "resource.fs.zfs.statechange") == 0 &&
|
2021-01-29 04:00:26 +03:00
|
|
|
(state == VDEV_STATE_REMOVED || state == VDEV_STATE_FAULTED))) {
|
2018-09-19 00:45:52 +03:00
|
|
|
char *devtype;
|
|
|
|
char *devname;
|
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
if (nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
|
|
|
|
&pool_guid) != 0 ||
|
|
|
|
nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
|
|
|
|
&vdev_guid) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((zhp = find_by_guid(zhdl, pool_guid, vdev_guid,
|
|
|
|
&vdev)) == NULL)
|
|
|
|
return;
|
|
|
|
|
2018-09-19 00:45:52 +03:00
|
|
|
devname = zpool_vdev_name(NULL, zhp, vdev, B_FALSE);
|
|
|
|
|
2022-09-28 19:48:46 +03:00
|
|
|
nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS,
|
|
|
|
(uint64_t **)&vs, &c);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If state removed is requested for already removed vdev,
|
|
|
|
* its a loopback event from spa_async_remove(). Just
|
|
|
|
* ignore it.
|
|
|
|
*/
|
|
|
|
if (vs->vs_state == VDEV_STATE_REMOVED &&
|
|
|
|
state == VDEV_STATE_REMOVED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
l2arc = (nvlist_lookup_string(nvl,
|
|
|
|
FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE, &devtype) == 0 &&
|
|
|
|
strcmp(devtype, VDEV_TYPE_L2CACHE) == 0);
|
|
|
|
|
|
|
|
/* Remove the vdev since device is unplugged */
|
|
|
|
if (l2arc || (strcmp(class, "resource.fs.zfs.removed") == 0)) {
|
|
|
|
int status = zpool_vdev_remove_wanted(zhp, devname);
|
|
|
|
fmd_hdl_debug(hdl, "zpool_vdev_remove_wanted '%s'"
|
|
|
|
", ret:%d", devname, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replace the vdev with a spare if its not a l2arc */
|
|
|
|
if (!l2arc && (!fmd_prop_get_int32(hdl, "spare_on_remove") ||
|
|
|
|
replace_with_spare(hdl, zhp, vdev) == B_FALSE)) {
|
2020-08-19 08:13:17 +03:00
|
|
|
/* Could not handle with spare */
|
|
|
|
fmd_hdl_debug(hdl, "no spare for '%s'", devname);
|
2018-09-19 00:45:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
free(devname);
|
2016-11-08 02:01:38 +03:00
|
|
|
zpool_close(zhp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(class, FM_LIST_RESOLVED_CLASS) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2020-10-09 06:10:13 +03:00
|
|
|
* Note: on Linux statechange events are more than just
|
2016-12-12 21:46:26 +03:00
|
|
|
* healthy ones so we need to confirm the actual state value.
|
2016-11-08 02:01:38 +03:00
|
|
|
*/
|
|
|
|
if (strcmp(class, "resource.fs.zfs.statechange") == 0 &&
|
2020-07-03 21:05:50 +03:00
|
|
|
state == VDEV_STATE_HEALTHY) {
|
2016-11-08 02:01:38 +03:00
|
|
|
zfs_vdev_repair(hdl, nvl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strcmp(class, "sysevent.fs.zfs.vdev_remove") == 0) {
|
|
|
|
zfs_vdev_repair(hdl, nvl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_retire_clear_data(hdl, zdp);
|
|
|
|
|
|
|
|
if (strcmp(class, FM_LIST_REPAIRED_CLASS) == 0)
|
|
|
|
is_repair = B_TRUE;
|
|
|
|
else
|
|
|
|
is_repair = B_FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We subscribe to zfs faults as well as all repair events.
|
|
|
|
*/
|
|
|
|
if (nvlist_lookup_nvlist_array(nvl, FM_SUSPECT_FAULT_LIST,
|
|
|
|
&faults, &nfaults) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (f = 0; f < nfaults; f++) {
|
|
|
|
fault = faults[f];
|
|
|
|
|
|
|
|
fault_device = B_FALSE;
|
|
|
|
degrade_device = B_FALSE;
|
|
|
|
is_disk = B_FALSE;
|
|
|
|
|
|
|
|
if (nvlist_lookup_boolean_value(fault, FM_SUSPECT_RETIRE,
|
|
|
|
&retire) == 0 && retire == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* While we subscribe to fault.fs.zfs.*, we only take action
|
|
|
|
* for faults targeting a specific vdev (open failure or SERD
|
|
|
|
* failure). We also subscribe to fault.io.* events, so that
|
|
|
|
* faulty disks will be faulted in the ZFS configuration.
|
|
|
|
*/
|
|
|
|
if (fmd_nvl_class_match(hdl, fault, "fault.fs.zfs.vdev.io")) {
|
|
|
|
fault_device = B_TRUE;
|
|
|
|
} else if (fmd_nvl_class_match(hdl, fault,
|
|
|
|
"fault.fs.zfs.vdev.checksum")) {
|
|
|
|
degrade_device = B_TRUE;
|
|
|
|
} else if (fmd_nvl_class_match(hdl, fault,
|
|
|
|
"fault.fs.zfs.device")) {
|
|
|
|
fault_device = B_FALSE;
|
|
|
|
} else if (fmd_nvl_class_match(hdl, fault, "fault.io.*")) {
|
|
|
|
is_disk = B_TRUE;
|
|
|
|
fault_device = B_TRUE;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_disk) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This is a ZFS fault. Lookup the resource, and
|
|
|
|
* attempt to find the matching vdev.
|
|
|
|
*/
|
|
|
|
if (nvlist_lookup_nvlist(fault, FM_FAULT_RESOURCE,
|
|
|
|
&resource) != 0 ||
|
|
|
|
nvlist_lookup_string(resource, FM_FMRI_SCHEME,
|
|
|
|
&scheme) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(scheme, FM_FMRI_SCHEME_ZFS) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nvlist_lookup_uint64(resource, FM_FMRI_ZFS_POOL,
|
|
|
|
&pool_guid) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nvlist_lookup_uint64(resource, FM_FMRI_ZFS_VDEV,
|
|
|
|
&vdev_guid) != 0) {
|
|
|
|
if (is_repair)
|
|
|
|
vdev_guid = 0;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((zhp = find_by_guid(zhdl, pool_guid, vdev_guid,
|
|
|
|
&vdev)) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
aux = VDEV_AUX_ERR_EXCEEDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vdev_guid == 0) {
|
|
|
|
/*
|
|
|
|
* For pool-level repair events, clear the entire pool.
|
|
|
|
*/
|
|
|
|
fmd_hdl_debug(hdl, "zpool_clear of pool '%s'",
|
|
|
|
zpool_get_name(zhp));
|
|
|
|
(void) zpool_clear(zhp, NULL, NULL);
|
|
|
|
zpool_close(zhp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is a repair event, then mark the vdev as repaired and
|
|
|
|
* continue.
|
|
|
|
*/
|
|
|
|
if (is_repair) {
|
|
|
|
repair_done = 1;
|
|
|
|
fmd_hdl_debug(hdl, "zpool_clear of pool '%s' vdev %llu",
|
|
|
|
zpool_get_name(zhp), vdev_guid);
|
|
|
|
(void) zpool_vdev_clear(zhp, vdev_guid);
|
|
|
|
zpool_close(zhp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actively fault the device if needed.
|
|
|
|
*/
|
|
|
|
if (fault_device)
|
|
|
|
(void) zpool_vdev_fault(zhp, vdev_guid, aux);
|
|
|
|
if (degrade_device)
|
|
|
|
(void) zpool_vdev_degrade(zhp, vdev_guid, aux);
|
|
|
|
|
|
|
|
if (fault_device || degrade_device)
|
|
|
|
fmd_hdl_debug(hdl, "zpool_vdev_%s: vdev %llu on '%s'",
|
|
|
|
fault_device ? "fault" : "degrade", vdev_guid,
|
|
|
|
zpool_get_name(zhp));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to substitute a hot spare.
|
|
|
|
*/
|
2018-09-19 00:45:52 +03:00
|
|
|
(void) replace_with_spare(hdl, zhp, vdev);
|
Distributed Spare (dRAID) Feature
This patch adds a new top-level vdev type called dRAID, which stands
for Distributed parity RAID. This pool configuration allows all dRAID
vdevs to participate when rebuilding to a distributed hot spare device.
This can substantially reduce the total time required to restore full
parity to pool with a failed device.
A dRAID pool can be created using the new top-level `draid` type.
Like `raidz`, the desired redundancy is specified after the type:
`draid[1,2,3]`. No additional information is required to create the
pool and reasonable default values will be chosen based on the number
of child vdevs in the dRAID vdev.
zpool create <pool> draid[1,2,3] <vdevs...>
Unlike raidz, additional optional dRAID configuration values can be
provided as part of the draid type as colon separated values. This
allows administrators to fully specify a layout for either performance
or capacity reasons. The supported options include:
zpool create <pool> \
draid[<parity>][:<data>d][:<children>c][:<spares>s] \
<vdevs...>
- draid[parity] - Parity level (default 1)
- draid[:<data>d] - Data devices per group (default 8)
- draid[:<children>c] - Expected number of child vdevs
- draid[:<spares>s] - Distributed hot spares (default 0)
Abbreviated example `zpool status` output for a 68 disk dRAID pool
with two distributed spares using special allocation classes.
```
pool: tank
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
slag7 ONLINE 0 0 0
draid2:8d:68c:2s-0 ONLINE 0 0 0
L0 ONLINE 0 0 0
L1 ONLINE 0 0 0
...
U25 ONLINE 0 0 0
U26 ONLINE 0 0 0
spare-53 ONLINE 0 0 0
U27 ONLINE 0 0 0
draid2-0-0 ONLINE 0 0 0
U28 ONLINE 0 0 0
U29 ONLINE 0 0 0
...
U42 ONLINE 0 0 0
U43 ONLINE 0 0 0
special
mirror-1 ONLINE 0 0 0
L5 ONLINE 0 0 0
U5 ONLINE 0 0 0
mirror-2 ONLINE 0 0 0
L6 ONLINE 0 0 0
U6 ONLINE 0 0 0
spares
draid2-0-0 INUSE currently in use
draid2-0-1 AVAIL
```
When adding test coverage for the new dRAID vdev type the following
options were added to the ztest command. These options are leverages
by zloop.sh to test a wide range of dRAID configurations.
-K draid|raidz|random - kind of RAID to test
-D <value> - dRAID data drives per group
-S <value> - dRAID distributed hot spares
-R <value> - RAID parity (raidz or dRAID)
The zpool_create, zpool_import, redundancy, replacement and fault
test groups have all been updated provide test coverage for the
dRAID feature.
Co-authored-by: Isaac Huang <he.huang@intel.com>
Co-authored-by: Mark Maybee <mmaybee@cray.com>
Co-authored-by: Don Brady <don.brady@delphix.com>
Co-authored-by: Matthew Ahrens <mahrens@delphix.com>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mark Maybee <mmaybee@cray.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #10102
2020-11-14 00:51:51 +03:00
|
|
|
|
2016-11-08 02:01:38 +03:00
|
|
|
zpool_close(zhp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(class, FM_LIST_REPAIRED_CLASS) == 0 && repair_done &&
|
|
|
|
nvlist_lookup_string(nvl, FM_SUSPECT_UUID, &uuid) == 0)
|
|
|
|
fmd_case_uuresolved(hdl, uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const fmd_hdl_ops_t fmd_ops = {
|
|
|
|
zfs_retire_recv, /* fmdo_recv */
|
|
|
|
NULL, /* fmdo_timeout */
|
|
|
|
NULL, /* fmdo_close */
|
|
|
|
NULL, /* fmdo_stats */
|
|
|
|
NULL, /* fmdo_gc */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const fmd_prop_t fmd_props[] = {
|
|
|
|
{ "spare_on_remove", FMD_TYPE_BOOL, "true" },
|
|
|
|
{ NULL, 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const fmd_hdl_info_t fmd_info = {
|
|
|
|
"ZFS Retire Agent", "1.0", &fmd_ops, fmd_props
|
|
|
|
};
|
|
|
|
|
2016-09-01 00:46:58 +03:00
|
|
|
void
|
2016-11-08 02:01:38 +03:00
|
|
|
_zfs_retire_init(fmd_hdl_t *hdl)
|
2016-09-01 00:46:58 +03:00
|
|
|
{
|
2016-11-08 02:01:38 +03:00
|
|
|
zfs_retire_data_t *zdp;
|
|
|
|
libzfs_handle_t *zhdl;
|
|
|
|
|
2017-12-09 03:58:41 +03:00
|
|
|
if ((zhdl = libzfs_init()) == NULL)
|
2016-11-08 02:01:38 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0) {
|
|
|
|
libzfs_fini(zhdl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
zdp = fmd_hdl_zalloc(hdl, sizeof (zfs_retire_data_t), FMD_SLEEP);
|
|
|
|
zdp->zrd_hdl = zhdl;
|
|
|
|
|
|
|
|
fmd_hdl_setspecific(hdl, zdp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_zfs_retire_fini(fmd_hdl_t *hdl)
|
|
|
|
{
|
|
|
|
zfs_retire_data_t *zdp = fmd_hdl_getspecific(hdl);
|
|
|
|
|
|
|
|
if (zdp != NULL) {
|
|
|
|
zfs_retire_clear_data(hdl, zdp);
|
2017-12-09 03:58:41 +03:00
|
|
|
libzfs_fini(zdp->zrd_hdl);
|
2016-11-08 02:01:38 +03:00
|
|
|
fmd_hdl_free(hdl, zdp, sizeof (zfs_retire_data_t));
|
|
|
|
}
|
2016-09-01 00:46:58 +03:00
|
|
|
}
|