mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 02:44:41 +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:
+47
-4
@@ -142,6 +142,7 @@
|
||||
#include <sys/zap.h>
|
||||
#include <sys/vdev.h>
|
||||
#include <sys/vdev_impl.h>
|
||||
#include <sys/vdev_raidz.h>
|
||||
#include <sys/vdev_draid.h>
|
||||
#include <sys/uberblock_impl.h>
|
||||
#include <sys/metaslab.h>
|
||||
@@ -423,6 +424,13 @@ root_vdev_actions_getprogress(vdev_t *vd, nvlist_t *nvl)
|
||||
ZPOOL_CONFIG_CHECKPOINT_STATS, (uint64_t *)&pcs,
|
||||
sizeof (pcs) / sizeof (uint64_t));
|
||||
}
|
||||
|
||||
pool_raidz_expand_stat_t pres;
|
||||
if (spa_raidz_expand_get_stats(spa, &pres) == 0) {
|
||||
fnvlist_add_uint64_array(nvl,
|
||||
ZPOOL_CONFIG_RAIDZ_EXPAND_STATS, (uint64_t *)&pres,
|
||||
sizeof (pres) / sizeof (uint64_t));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1504,7 +1512,8 @@ vdev_uberblock_compare(const uberblock_t *ub1, const uberblock_t *ub2)
|
||||
}
|
||||
|
||||
struct ubl_cbdata {
|
||||
uberblock_t *ubl_ubbest; /* Best uberblock */
|
||||
uberblock_t ubl_latest; /* Most recent uberblock */
|
||||
uberblock_t *ubl_ubbest; /* Best uberblock (w/r/t max_txg) */
|
||||
vdev_t *ubl_vd; /* vdev associated with the above */
|
||||
};
|
||||
|
||||
@@ -1521,6 +1530,9 @@ vdev_uberblock_load_done(zio_t *zio)
|
||||
|
||||
if (zio->io_error == 0 && uberblock_verify(ub) == 0) {
|
||||
mutex_enter(&rio->io_lock);
|
||||
if (vdev_uberblock_compare(ub, &cbp->ubl_latest) > 0) {
|
||||
cbp->ubl_latest = *ub;
|
||||
}
|
||||
if (ub->ub_txg <= spa->spa_load_max_txg &&
|
||||
vdev_uberblock_compare(ub, cbp->ubl_ubbest) > 0) {
|
||||
/*
|
||||
@@ -1578,10 +1590,10 @@ vdev_uberblock_load(vdev_t *rvd, uberblock_t *ub, nvlist_t **config)
|
||||
ASSERT(config);
|
||||
|
||||
memset(ub, 0, sizeof (uberblock_t));
|
||||
memset(&cb, 0, sizeof (cb));
|
||||
*config = NULL;
|
||||
|
||||
cb.ubl_ubbest = ub;
|
||||
cb.ubl_vd = NULL;
|
||||
|
||||
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
||||
zio = zio_root(spa, NULL, &cb, flags);
|
||||
@@ -1598,6 +1610,22 @@ vdev_uberblock_load(vdev_t *rvd, uberblock_t *ub, nvlist_t **config)
|
||||
vdev_dbgmsg(cb.ubl_vd, "best uberblock found for spa %s. "
|
||||
"txg %llu", spa->spa_name, (u_longlong_t)ub->ub_txg);
|
||||
|
||||
if (ub->ub_raidz_reflow_info !=
|
||||
cb.ubl_latest.ub_raidz_reflow_info) {
|
||||
vdev_dbgmsg(cb.ubl_vd,
|
||||
"spa=%s best uberblock (txg=%llu info=0x%llx) "
|
||||
"has different raidz_reflow_info than latest "
|
||||
"uberblock (txg=%llu info=0x%llx)",
|
||||
spa->spa_name,
|
||||
(u_longlong_t)ub->ub_txg,
|
||||
(u_longlong_t)ub->ub_raidz_reflow_info,
|
||||
(u_longlong_t)cb.ubl_latest.ub_txg,
|
||||
(u_longlong_t)cb.ubl_latest.ub_raidz_reflow_info);
|
||||
memset(ub, 0, sizeof (uberblock_t));
|
||||
spa_config_exit(spa, SCL_ALL, FTAG);
|
||||
return;
|
||||
}
|
||||
|
||||
*config = vdev_label_read_config(cb.ubl_vd, ub->ub_txg);
|
||||
if (*config == NULL && spa->spa_extreme_rewind) {
|
||||
vdev_dbgmsg(cb.ubl_vd, "failed to read label config. "
|
||||
@@ -1719,8 +1747,23 @@ vdev_uberblock_sync(zio_t *zio, uint64_t *good_writes,
|
||||
vd->vdev_copy_uberblocks = B_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* We chose a slot based on the txg. If this uberblock has a special
|
||||
* RAIDZ expansion state, then it is essentially an update of the
|
||||
* current uberblock (it has the same txg). However, the current
|
||||
* state is committed, so we want to write it to a different slot. If
|
||||
* we overwrote the same slot, and we lose power during the uberblock
|
||||
* write, and the disk does not do single-sector overwrites
|
||||
* atomically (even though it is required to - i.e. we should see
|
||||
* either the old or the new uberblock), then we could lose this
|
||||
* txg's uberblock. Rewinding to the previous txg's uberblock may not
|
||||
* be possible because RAIDZ expansion may have already overwritten
|
||||
* some of the data, so we need the progress indicator in the
|
||||
* uberblock.
|
||||
*/
|
||||
int m = spa_multihost(vd->vdev_spa) ? MMP_BLOCKS_PER_LABEL : 0;
|
||||
int n = ub->ub_txg % (VDEV_UBERBLOCK_COUNT(vd) - m);
|
||||
int n = (ub->ub_txg - (RRSS_GET_STATE(ub) == RRSS_SCRATCH_VALID)) %
|
||||
(VDEV_UBERBLOCK_COUNT(vd) - m);
|
||||
|
||||
/* Copy the uberblock_t into the ABD */
|
||||
abd_t *ub_abd = abd_alloc_for_io(VDEV_UBERBLOCK_SIZE(vd), B_TRUE);
|
||||
@@ -1737,7 +1780,7 @@ vdev_uberblock_sync(zio_t *zio, uint64_t *good_writes,
|
||||
}
|
||||
|
||||
/* Sync the uberblocks to all vdevs in svd[] */
|
||||
static int
|
||||
int
|
||||
vdev_uberblock_sync_list(vdev_t **svd, int svdcount, uberblock_t *ub, int flags)
|
||||
{
|
||||
spa_t *spa = svd[0]->vdev_spa;
|
||||
|
||||
Reference in New Issue
Block a user