mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-24 11:18:52 +03:00
RAID-Z expansion feature
This feature allows disks to be added one at a time to a RAID-Z group, expanding its capacity incrementally. This feature is especially useful for small pools (typically with only one RAID-Z group), where there isn't sufficient hardware to add capacity by adding a whole new RAID-Z group (typically doubling the number of disks). == Initiating expansion == A new device (disk) can be attached to an existing RAIDZ vdev, by running `zpool attach POOL raidzP-N NEW_DEVICE`, e.g. `zpool attach tank raidz2-0 sda`. The new device will become part of the RAIDZ group. A "raidz expansion" will be initiated, and the new device will contribute additional space to the RAIDZ group once the expansion completes. The `feature@raidz_expansion` on-disk feature flag must be `enabled` to initiate an expansion, and it remains `active` for the life of the pool. In other words, pools with expanded RAIDZ vdevs can not be imported by older releases of the ZFS software. == During expansion == The expansion entails reading all allocated space from existing disks in the RAIDZ group, and rewriting it to the new disks in the RAIDZ group (including the newly added device). The expansion progress can be monitored with `zpool status`. Data redundancy is maintained during (and after) the expansion. If a disk fails while the expansion is in progress, the expansion pauses until the health of the RAIDZ vdev is restored (e.g. by replacing the failed disk and waiting for reconstruction to complete). The pool remains accessible during expansion. Following a reboot or export/import, the expansion resumes where it left off. == After expansion == When the expansion completes, the additional space is available for use, and is reflected in the `available` zfs property (as seen in `zfs list`, `df`, etc). Expansion does not change the number of failures that can be tolerated without data loss (e.g. a RAIDZ2 is still a RAIDZ2 even after expansion). A RAIDZ vdev can be expanded multiple times. After the expansion completes, old blocks remain with their old data-to-parity ratio (e.g. 5-wide RAIDZ2, has 3 data to 2 parity), but distributed among the larger set of disks. New blocks will be written with the new data-to-parity ratio (e.g. a 5-wide RAIDZ2 which has been expanded once to 6-wide, has 4 data to 2 parity). However, the RAIDZ vdev's "assumed parity ratio" does not change, so slightly less space than is expected may be reported for newly-written blocks, according to `zfs list`, `df`, `ls -s`, and similar tools. Sponsored-by: The FreeBSD Foundation Sponsored-by: iXsystems, Inc. Sponsored-by: vStack Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Mark Maybee <mark.maybee@delphix.com> Authored-by: Matthew Ahrens <mahrens@delphix.com> Contributions-by: Fedor Uporov <fuporov.vstack@gmail.com> Contributions-by: Stuart Maybee <stuart.maybee@comcast.net> Contributions-by: Thorsten Behrens <tbehrens@outlook.com> Contributions-by: Fmstrat <nospam@nowsci.com> Contributions-by: Don Brady <dev.fs.zfs@gmail.com> Signed-off-by: Don Brady <dev.fs.zfs@gmail.com> Closes #15022
This commit is contained in:
+79
-35
@@ -58,6 +58,7 @@
|
||||
#include <sys/abd.h>
|
||||
#include <sys/vdev_initialize.h>
|
||||
#include <sys/vdev_trim.h>
|
||||
#include <sys/vdev_raidz.h>
|
||||
#include <sys/zvol.h>
|
||||
#include <sys/zfs_ratelimit.h>
|
||||
#include "zfs_prop.h"
|
||||
@@ -305,13 +306,13 @@ vdev_derive_alloc_bias(const char *bias)
|
||||
* all children. This is what's used by anything other than RAID-Z.
|
||||
*/
|
||||
uint64_t
|
||||
vdev_default_asize(vdev_t *vd, uint64_t psize)
|
||||
vdev_default_asize(vdev_t *vd, uint64_t psize, uint64_t txg)
|
||||
{
|
||||
uint64_t asize = P2ROUNDUP(psize, 1ULL << vd->vdev_top->vdev_ashift);
|
||||
uint64_t csize;
|
||||
|
||||
for (int c = 0; c < vd->vdev_children; c++) {
|
||||
csize = vdev_psize_to_asize(vd->vdev_child[c], psize);
|
||||
csize = vdev_psize_to_asize_txg(vd->vdev_child[c], psize, txg);
|
||||
asize = MAX(asize, csize);
|
||||
}
|
||||
|
||||
@@ -930,6 +931,8 @@ vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, uint_t id,
|
||||
&vd->vdev_removing);
|
||||
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_VDEV_TOP_ZAP,
|
||||
&vd->vdev_top_zap);
|
||||
vd->vdev_rz_expanding = nvlist_exists(nv,
|
||||
ZPOOL_CONFIG_RAIDZ_EXPANDING);
|
||||
} else {
|
||||
ASSERT0(vd->vdev_top_zap);
|
||||
}
|
||||
@@ -1692,6 +1695,8 @@ vdev_probe_done(zio_t *zio)
|
||||
|
||||
vd->vdev_cant_read |= !vps->vps_readable;
|
||||
vd->vdev_cant_write |= !vps->vps_writeable;
|
||||
vdev_dbgmsg(vd, "probe done, cant_read=%u cant_write=%u",
|
||||
vd->vdev_cant_read, vd->vdev_cant_write);
|
||||
|
||||
if (vdev_readable(vd) &&
|
||||
(vdev_writeable(vd) || !spa_writeable(spa))) {
|
||||
@@ -1913,17 +1918,20 @@ vdev_open_children_subset(vdev_t *vd, vdev_open_children_func_t *open_func)
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the raidz-deflation ratio. Note, we hard-code
|
||||
* in 128k (1 << 17) because it is the "typical" blocksize.
|
||||
* Even though SPA_MAXBLOCKSIZE changed, this algorithm can not change,
|
||||
* otherwise it would inconsistently account for existing bp's.
|
||||
* Compute the raidz-deflation ratio. Note, we hard-code 128k (1 << 17)
|
||||
* because it is the "typical" blocksize. Even though SPA_MAXBLOCKSIZE
|
||||
* changed, this algorithm can not change, otherwise it would inconsistently
|
||||
* account for existing bp's. We also hard-code txg 0 for the same reason
|
||||
* since expanded RAIDZ vdevs can use a different asize for different birth
|
||||
* txg's.
|
||||
*/
|
||||
static void
|
||||
vdev_set_deflate_ratio(vdev_t *vd)
|
||||
{
|
||||
if (vd == vd->vdev_top && !vd->vdev_ishole && vd->vdev_ashift != 0) {
|
||||
vd->vdev_deflate_ratio = (1 << 17) /
|
||||
(vdev_psize_to_asize(vd, 1 << 17) >> SPA_MINBLOCKSHIFT);
|
||||
(vdev_psize_to_asize_txg(vd, 1 << 17, 0) >>
|
||||
SPA_MINBLOCKSHIFT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3228,32 +3236,43 @@ vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
|
||||
|
||||
if (txg != 0)
|
||||
vdev_dirty(vd->vdev_top, VDD_DTL, vd, txg);
|
||||
return;
|
||||
} else {
|
||||
mutex_enter(&vd->vdev_dtl_lock);
|
||||
for (int t = 0; t < DTL_TYPES; t++) {
|
||||
/* account for child's outage in parent's missing map */
|
||||
int s = (t == DTL_MISSING) ? DTL_OUTAGE: t;
|
||||
if (t == DTL_SCRUB) {
|
||||
/* leaf vdevs only */
|
||||
continue;
|
||||
}
|
||||
if (t == DTL_PARTIAL) {
|
||||
/* i.e. non-zero */
|
||||
minref = 1;
|
||||
} else if (vdev_get_nparity(vd) != 0) {
|
||||
/* RAIDZ, DRAID */
|
||||
minref = vdev_get_nparity(vd) + 1;
|
||||
} else {
|
||||
/* any kind of mirror */
|
||||
minref = vd->vdev_children;
|
||||
}
|
||||
space_reftree_create(&reftree);
|
||||
for (int c = 0; c < vd->vdev_children; c++) {
|
||||
vdev_t *cvd = vd->vdev_child[c];
|
||||
mutex_enter(&cvd->vdev_dtl_lock);
|
||||
space_reftree_add_map(&reftree,
|
||||
cvd->vdev_dtl[s], 1);
|
||||
mutex_exit(&cvd->vdev_dtl_lock);
|
||||
}
|
||||
space_reftree_generate_map(&reftree,
|
||||
vd->vdev_dtl[t], minref);
|
||||
space_reftree_destroy(&reftree);
|
||||
}
|
||||
mutex_exit(&vd->vdev_dtl_lock);
|
||||
}
|
||||
|
||||
mutex_enter(&vd->vdev_dtl_lock);
|
||||
for (int t = 0; t < DTL_TYPES; t++) {
|
||||
/* account for child's outage in parent's missing map */
|
||||
int s = (t == DTL_MISSING) ? DTL_OUTAGE: t;
|
||||
if (t == DTL_SCRUB)
|
||||
continue; /* leaf vdevs only */
|
||||
if (t == DTL_PARTIAL)
|
||||
minref = 1; /* i.e. non-zero */
|
||||
else if (vdev_get_nparity(vd) != 0)
|
||||
minref = vdev_get_nparity(vd) + 1; /* RAID-Z, dRAID */
|
||||
else
|
||||
minref = vd->vdev_children; /* any kind of mirror */
|
||||
space_reftree_create(&reftree);
|
||||
for (int c = 0; c < vd->vdev_children; c++) {
|
||||
vdev_t *cvd = vd->vdev_child[c];
|
||||
mutex_enter(&cvd->vdev_dtl_lock);
|
||||
space_reftree_add_map(&reftree, cvd->vdev_dtl[s], 1);
|
||||
mutex_exit(&cvd->vdev_dtl_lock);
|
||||
}
|
||||
space_reftree_generate_map(&reftree, vd->vdev_dtl[t], minref);
|
||||
space_reftree_destroy(&reftree);
|
||||
if (vd->vdev_top->vdev_ops == &vdev_raidz_ops) {
|
||||
raidz_dtl_reassessed(vd);
|
||||
}
|
||||
mutex_exit(&vd->vdev_dtl_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3628,6 +3647,12 @@ vdev_load(vdev_t *vd)
|
||||
|
||||
vdev_set_deflate_ratio(vd);
|
||||
|
||||
if (vd->vdev_ops == &vdev_raidz_ops) {
|
||||
error = vdev_raidz_load(vd);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* On spa_load path, grab the allocation bias from our zap
|
||||
*/
|
||||
@@ -4005,10 +4030,22 @@ vdev_sync(vdev_t *vd, uint64_t txg)
|
||||
dmu_tx_commit(tx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the amount of space that should be (or was) allocated for the given
|
||||
* psize (compressed block size) in the given TXG. Note that for expanded
|
||||
* RAIDZ vdevs, the size allocated for older BP's may be larger. See
|
||||
* vdev_raidz_asize().
|
||||
*/
|
||||
uint64_t
|
||||
vdev_psize_to_asize_txg(vdev_t *vd, uint64_t psize, uint64_t txg)
|
||||
{
|
||||
return (vd->vdev_ops->vdev_op_asize(vd, psize, txg));
|
||||
}
|
||||
|
||||
uint64_t
|
||||
vdev_psize_to_asize(vdev_t *vd, uint64_t psize)
|
||||
{
|
||||
return (vd->vdev_ops->vdev_op_asize(vd, psize));
|
||||
return (vdev_psize_to_asize_txg(vd, psize, 0));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4174,9 +4211,6 @@ vdev_online(spa_t *spa, uint64_t guid, uint64_t flags, vdev_state_t *newstate)
|
||||
if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
|
||||
return (spa_vdev_state_exit(spa, NULL, SET_ERROR(ENODEV)));
|
||||
|
||||
if (!vd->vdev_ops->vdev_op_leaf)
|
||||
return (spa_vdev_state_exit(spa, NULL, SET_ERROR(ENOTSUP)));
|
||||
|
||||
wasoffline = (vd->vdev_offline || vd->vdev_tmpoffline);
|
||||
oldstate = vd->vdev_state;
|
||||
|
||||
@@ -5457,7 +5491,9 @@ vdev_expand(vdev_t *vd, uint64_t txg)
|
||||
|
||||
vdev_set_deflate_ratio(vd);
|
||||
|
||||
if ((vd->vdev_asize >> vd->vdev_ms_shift) > vd->vdev_ms_count &&
|
||||
if ((vd->vdev_spa->spa_raidz_expand == NULL ||
|
||||
vd->vdev_spa->spa_raidz_expand->vre_vdev_id != vd->vdev_id) &&
|
||||
(vd->vdev_asize >> vd->vdev_ms_shift) > vd->vdev_ms_count &&
|
||||
vdev_is_concrete(vd)) {
|
||||
vdev_metaslab_group_create(vd);
|
||||
VERIFY(vdev_metaslab_init(vd, txg) == 0);
|
||||
@@ -6209,6 +6245,14 @@ vdev_prop_get(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
|
||||
vdev_prop_add_list(outnvl, propname, NULL,
|
||||
vd->vdev_removing, ZPROP_SRC_NONE);
|
||||
continue;
|
||||
case VDEV_PROP_RAIDZ_EXPANDING:
|
||||
/* Only expose this for raidz */
|
||||
if (vd->vdev_ops == &vdev_raidz_ops) {
|
||||
vdev_prop_add_list(outnvl, propname,
|
||||
NULL, vd->vdev_rz_expanding,
|
||||
ZPROP_SRC_NONE);
|
||||
}
|
||||
continue;
|
||||
/* Numeric Properites */
|
||||
case VDEV_PROP_ALLOCATING:
|
||||
/* Leaf vdevs cannot have this property */
|
||||
|
||||
Reference in New Issue
Block a user