a1d477c24c
OpenZFS 7614 - zfs device evacuation/removal OpenZFS 9064 - remove_mirror should wait for device removal to complete This project allows top-level vdevs to be removed from the storage pool with "zpool remove", reducing the total amount of storage in the pool. This operation copies all allocated regions of the device to be removed onto other devices, recording the mapping from old to new location. After the removal is complete, read and free operations to the removed (now "indirect") vdev must be remapped and performed at the new location on disk. The indirect mapping table is kept in memory whenever the pool is loaded, so there is minimal performance overhead when doing operations on the indirect vdev. The size of the in-memory mapping table will be reduced when its entries become "obsolete" because they are no longer used by any block pointers in the pool. An entry becomes obsolete when all the blocks that use it are freed. An entry can also become obsolete when all the snapshots that reference it are deleted, and the block pointers that reference it have been "remapped" in all filesystems/zvols (and clones). Whenever an indirect block is written, all the block pointers in it will be "remapped" to their new (concrete) locations if possible. This process can be accelerated by using the "zfs remap" command to proactively rewrite all indirect blocks that reference indirect (removed) vdevs. Note that when a device is removed, we do not verify the checksum of the data that is copied. This makes the process much faster, but if it were used on redundant vdevs (i.e. mirror or raidz vdevs), it would be possible to copy the wrong data, when we have the correct data on e.g. the other side of the mirror. At the moment, only mirrors and simple top-level vdevs can be removed and no removal is allowed if any of the top-level vdevs are raidz. Porting Notes: * Avoid zero-sized kmem_alloc() in vdev_compact_children(). The device evacuation code adds a dependency that vdev_compact_children() be able to properly empty the vdev_child array by setting it to NULL and zeroing vdev_children. Under Linux, kmem_alloc() and related functions return a sentinel pointer rather than NULL for zero-sized allocations. * Remove comment regarding "mpt" driver where zfs_remove_max_segment is initialized to SPA_MAXBLOCKSIZE. Change zfs_condense_indirect_commit_entry_delay_ticks to zfs_condense_indirect_commit_entry_delay_ms for consistency with most other tunables in which delays are specified in ms. * ZTS changes: Use set_tunable rather than mdb Use zpool sync as appropriate Use sync_pool instead of sync Kill jobs during test_removal_with_operation to allow unmount/export Don't add non-disk names such as "mirror" or "raidz" to $DISKS Use $TEST_BASE_DIR instead of /tmp Increase HZ from 100 to 1000 which is more common on Linux removal_multiple_indirection.ksh Reduce iterations in order to not time out on the code coverage builders. removal_resume_export: Functionally, the test case is correct but there exists a race where the kernel thread hasn't been fully started yet and is not visible. Wait for up to 1 second for the removal thread to be started before giving up on it. Also, increase the amount of data copied in order that the removal not finish before the export has a chance to fail. * MMP compatibility, the concept of concrete versus non-concrete devices has slightly changed the semantics of vdev_writeable(). Update mmp_random_leaf_impl() accordingly. * Updated dbuf_remap() to handle the org.zfsonlinux:large_dnode pool feature which is not supported by OpenZFS. * Added support for new vdev removal tracepoints. * Test cases removal_with_zdb and removal_condense_export have been intentionally disabled. When run manually they pass as intended, but when running in the automated test environment they produce unreliable results on the latest Fedora release. They may work better once the upstream pool import refectoring is merged into ZoL at which point they will be re-enabled. Authored by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Alex Reece <alex@delphix.com> Reviewed-by: George Wilson <george.wilson@delphix.com> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Reviewed-by: Prakash Surya <prakash.surya@delphix.com> Reviewed by: Richard Laager <rlaager@wiktel.com> Reviewed by: Tim Chase <tim@chase2k.com> Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Approved by: Garrett D'Amore <garrett@damore.org> Ported-by: Tim Chase <tim@chase2k.com> Signed-off-by: Tim Chase <tim@chase2k.com> OpenZFS-issue: https://www.illumos.org/issues/7614 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/f539f1eb Closes #6900
227 lines
5.9 KiB
C
227 lines
5.9 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* This file and its contents are supplied under the terms of the
|
|
* Common Development and Distribution License ("CDDL"), version 1.0.
|
|
* You may only use this file in accordance with the terms of version
|
|
* 1.0 of the CDDL.
|
|
*
|
|
* A full copy of the text of the CDDL should have accompanied this
|
|
* source. A copy of the CDDL is also available via the Internet at
|
|
* http://www.illumos.org/license/CDDL.
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2015 by Delphix. All rights reserved.
|
|
*/
|
|
|
|
#include <sys/dmu_tx.h>
|
|
#include <sys/spa.h>
|
|
#include <sys/dmu.h>
|
|
#include <sys/dsl_pool.h>
|
|
#include <sys/vdev_indirect_births.h>
|
|
|
|
#ifdef ZFS_DEBUG
|
|
static boolean_t
|
|
vdev_indirect_births_verify(vdev_indirect_births_t *vib)
|
|
{
|
|
ASSERT(vib != NULL);
|
|
|
|
ASSERT(vib->vib_object != 0);
|
|
ASSERT(vib->vib_objset != NULL);
|
|
ASSERT(vib->vib_phys != NULL);
|
|
ASSERT(vib->vib_dbuf != NULL);
|
|
|
|
EQUIV(vib->vib_phys->vib_count > 0, vib->vib_entries != NULL);
|
|
|
|
return (B_TRUE);
|
|
}
|
|
#endif
|
|
|
|
uint64_t
|
|
vdev_indirect_births_count(vdev_indirect_births_t *vib)
|
|
{
|
|
ASSERT(vdev_indirect_births_verify(vib));
|
|
|
|
return (vib->vib_phys->vib_count);
|
|
}
|
|
|
|
uint64_t
|
|
vdev_indirect_births_object(vdev_indirect_births_t *vib)
|
|
{
|
|
ASSERT(vdev_indirect_births_verify(vib));
|
|
|
|
return (vib->vib_object);
|
|
}
|
|
|
|
static uint64_t
|
|
vdev_indirect_births_size_impl(vdev_indirect_births_t *vib)
|
|
{
|
|
return (vib->vib_phys->vib_count * sizeof (*vib->vib_entries));
|
|
}
|
|
|
|
void
|
|
vdev_indirect_births_close(vdev_indirect_births_t *vib)
|
|
{
|
|
ASSERT(vdev_indirect_births_verify(vib));
|
|
|
|
if (vib->vib_phys->vib_count > 0) {
|
|
uint64_t births_size = vdev_indirect_births_size_impl(vib);
|
|
|
|
kmem_free(vib->vib_entries, births_size);
|
|
vib->vib_entries = NULL;
|
|
}
|
|
|
|
dmu_buf_rele(vib->vib_dbuf, vib);
|
|
|
|
vib->vib_objset = NULL;
|
|
vib->vib_object = 0;
|
|
vib->vib_dbuf = NULL;
|
|
vib->vib_phys = NULL;
|
|
|
|
kmem_free(vib, sizeof (*vib));
|
|
}
|
|
|
|
uint64_t
|
|
vdev_indirect_births_alloc(objset_t *os, dmu_tx_t *tx)
|
|
{
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
return (dmu_object_alloc(os,
|
|
DMU_OTN_UINT64_METADATA, SPA_OLD_MAXBLOCKSIZE,
|
|
DMU_OTN_UINT64_METADATA, sizeof (vdev_indirect_birth_phys_t),
|
|
tx));
|
|
}
|
|
|
|
vdev_indirect_births_t *
|
|
vdev_indirect_births_open(objset_t *os, uint64_t births_object)
|
|
{
|
|
vdev_indirect_births_t *vib = kmem_zalloc(sizeof (*vib), KM_SLEEP);
|
|
|
|
vib->vib_objset = os;
|
|
vib->vib_object = births_object;
|
|
|
|
VERIFY0(dmu_bonus_hold(os, vib->vib_object, vib, &vib->vib_dbuf));
|
|
vib->vib_phys = vib->vib_dbuf->db_data;
|
|
|
|
if (vib->vib_phys->vib_count > 0) {
|
|
uint64_t births_size = vdev_indirect_births_size_impl(vib);
|
|
vib->vib_entries = kmem_alloc(births_size, KM_SLEEP);
|
|
VERIFY0(dmu_read(vib->vib_objset, vib->vib_object, 0,
|
|
births_size, vib->vib_entries, DMU_READ_PREFETCH));
|
|
}
|
|
|
|
ASSERT(vdev_indirect_births_verify(vib));
|
|
|
|
return (vib);
|
|
}
|
|
|
|
void
|
|
vdev_indirect_births_free(objset_t *os, uint64_t object, dmu_tx_t *tx)
|
|
{
|
|
VERIFY0(dmu_object_free(os, object, tx));
|
|
}
|
|
|
|
void
|
|
vdev_indirect_births_add_entry(vdev_indirect_births_t *vib,
|
|
uint64_t max_offset, uint64_t txg, dmu_tx_t *tx)
|
|
{
|
|
vdev_indirect_birth_entry_phys_t vibe;
|
|
uint64_t old_size;
|
|
uint64_t new_size;
|
|
vdev_indirect_birth_entry_phys_t *new_entries;
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
ASSERT(dsl_pool_sync_context(dmu_tx_pool(tx)));
|
|
ASSERT(vdev_indirect_births_verify(vib));
|
|
|
|
dmu_buf_will_dirty(vib->vib_dbuf, tx);
|
|
|
|
vibe.vibe_offset = max_offset;
|
|
vibe.vibe_phys_birth_txg = txg;
|
|
|
|
old_size = vdev_indirect_births_size_impl(vib);
|
|
dmu_write(vib->vib_objset, vib->vib_object, old_size, sizeof (vibe),
|
|
&vibe, tx);
|
|
vib->vib_phys->vib_count++;
|
|
new_size = vdev_indirect_births_size_impl(vib);
|
|
|
|
new_entries = kmem_alloc(new_size, KM_SLEEP);
|
|
if (old_size > 0) {
|
|
bcopy(vib->vib_entries, new_entries, old_size);
|
|
kmem_free(vib->vib_entries, old_size);
|
|
}
|
|
new_entries[vib->vib_phys->vib_count - 1] = vibe;
|
|
vib->vib_entries = new_entries;
|
|
}
|
|
|
|
uint64_t
|
|
vdev_indirect_births_last_entry_txg(vdev_indirect_births_t *vib)
|
|
{
|
|
ASSERT(vdev_indirect_births_verify(vib));
|
|
ASSERT(vib->vib_phys->vib_count > 0);
|
|
|
|
vdev_indirect_birth_entry_phys_t *last =
|
|
&vib->vib_entries[vib->vib_phys->vib_count - 1];
|
|
return (last->vibe_phys_birth_txg);
|
|
}
|
|
|
|
/*
|
|
* Return the txg in which the given range was copied (i.e. its physical
|
|
* birth txg). The specified offset+asize must be contiguously mapped
|
|
* (i.e. not a split block).
|
|
*
|
|
* The entries are sorted by increasing phys_birth, and also by increasing
|
|
* offset. We find the specified offset by binary search. Note that we
|
|
* can not use bsearch() because looking at each entry independently is
|
|
* insufficient to find the correct entry. Each entry implicitly relies
|
|
* on the previous entry: an entry indicates that the offsets from the
|
|
* end of the previous entry to the end of this entry were written in the
|
|
* specified txg.
|
|
*/
|
|
uint64_t
|
|
vdev_indirect_births_physbirth(vdev_indirect_births_t *vib, uint64_t offset,
|
|
uint64_t asize)
|
|
{
|
|
vdev_indirect_birth_entry_phys_t *base;
|
|
vdev_indirect_birth_entry_phys_t *last;
|
|
|
|
ASSERT(vdev_indirect_births_verify(vib));
|
|
ASSERT(vib->vib_phys->vib_count > 0);
|
|
|
|
base = vib->vib_entries;
|
|
last = base + vib->vib_phys->vib_count - 1;
|
|
|
|
ASSERT3U(offset, <, last->vibe_offset);
|
|
|
|
while (last >= base) {
|
|
vdev_indirect_birth_entry_phys_t *p =
|
|
base + ((last - base) / 2);
|
|
if (offset >= p->vibe_offset) {
|
|
base = p + 1;
|
|
} else if (p == vib->vib_entries ||
|
|
offset >= (p - 1)->vibe_offset) {
|
|
ASSERT3U(offset + asize, <=, p->vibe_offset);
|
|
return (p->vibe_phys_birth_txg);
|
|
} else {
|
|
last = p - 1;
|
|
}
|
|
}
|
|
ASSERT(!"offset not found");
|
|
return (-1);
|
|
}
|
|
|
|
#if defined(_KERNEL) && defined(HAVE_SPL)
|
|
EXPORT_SYMBOL(vdev_indirect_births_add_entry);
|
|
EXPORT_SYMBOL(vdev_indirect_births_alloc);
|
|
EXPORT_SYMBOL(vdev_indirect_births_close);
|
|
EXPORT_SYMBOL(vdev_indirect_births_count);
|
|
EXPORT_SYMBOL(vdev_indirect_births_free);
|
|
EXPORT_SYMBOL(vdev_indirect_births_last_entry_txg);
|
|
EXPORT_SYMBOL(vdev_indirect_births_object);
|
|
EXPORT_SYMBOL(vdev_indirect_births_open);
|
|
EXPORT_SYMBOL(vdev_indirect_births_physbirth);
|
|
#endif
|