2008-11-20 23:01:55 +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
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* 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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2011-11-15 23:01:27 +04:00
|
|
|
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
|
2018-06-13 01:34:20 +03:00
|
|
|
* Copyright (c) 2011, 2018 by Delphix. All rights reserved.
|
2017-05-30 21:39:17 +03:00
|
|
|
* Copyright 2017 Joyent, Inc.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/spa.h>
|
2015-12-31 19:38:59 +03:00
|
|
|
#include <sys/fm/fs/zfs.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/spa_impl.h>
|
|
|
|
#include <sys/nvpair.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/vdev_impl.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
|
|
|
#include <sys/systeminfo.h>
|
|
|
|
#include <sys/sunddi.h>
|
2012-12-14 03:24:15 +04:00
|
|
|
#include <sys/zfeature.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/kobj.h>
|
2009-02-18 23:51:31 +03:00
|
|
|
#include <sys/zone.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pool configuration repository.
|
|
|
|
*
|
|
|
|
* Pool configuration is stored as a packed nvlist on the filesystem. By
|
|
|
|
* default, all pools are stored in /etc/zfs/zpool.cache and loaded on boot
|
|
|
|
* (when the ZFS module is loaded). Pools can also have the 'cachefile'
|
|
|
|
* property set that allows them to be stored in an alternate location until
|
|
|
|
* the control of external software.
|
|
|
|
*
|
|
|
|
* For each cache file, we have a single nvlist which holds all the
|
|
|
|
* configuration information. When the module loads, we read this information
|
|
|
|
* from /etc/zfs/zpool.cache and populate the SPA namespace. This namespace is
|
|
|
|
* maintained independently in spa.c. Whenever the namespace is modified, or
|
OpenZFS 7614, 9064 - zfs device evacuation/removal
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
2016-09-22 19:30:13 +03:00
|
|
|
* the configuration of a pool is changed, we call spa_write_cachefile(), which
|
2008-11-20 23:01:55 +03:00
|
|
|
* walks through all the active pools and writes the configuration to disk.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static uint64_t spa_config_generation = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This can be overridden in userland to preserve an alternate namespace for
|
|
|
|
* userland pools when doing testing.
|
|
|
|
*/
|
2010-08-26 22:49:16 +04:00
|
|
|
char *spa_config_path = ZPOOL_CACHE;
|
2014-10-10 00:45:46 +04:00
|
|
|
int zfs_autoimport_disable = 1;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when the module is first loaded, this routine loads the configuration
|
|
|
|
* file into the SPA namespace. It does not actually open or load the pools; it
|
|
|
|
* only populates the namespace.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
spa_config_load(void)
|
|
|
|
{
|
|
|
|
void *buf = NULL;
|
|
|
|
nvlist_t *nvlist, *child;
|
|
|
|
nvpair_t *nvpair;
|
2008-12-03 23:09:06 +03:00
|
|
|
char *pathname;
|
2008-11-20 23:01:55 +03:00
|
|
|
struct _buf *file;
|
|
|
|
uint64_t fsize;
|
|
|
|
|
2014-10-10 00:45:46 +04:00
|
|
|
#ifdef _KERNEL
|
2013-07-03 20:55:39 +04:00
|
|
|
if (zfs_autoimport_disable)
|
|
|
|
return;
|
2014-10-10 00:45:46 +04:00
|
|
|
#endif
|
2013-07-03 20:55:39 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Open the configuration file.
|
|
|
|
*/
|
2014-11-21 03:09:39 +03:00
|
|
|
pathname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
|
2008-12-03 23:09:06 +03:00
|
|
|
|
2019-05-30 02:18:14 +03:00
|
|
|
(void) snprintf(pathname, MAXPATHLEN, "%s", spa_config_path);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
file = kobj_open_file(pathname);
|
2008-12-03 23:09:06 +03:00
|
|
|
|
|
|
|
kmem_free(pathname, MAXPATHLEN);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
if (file == (struct _buf *)-1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (kobj_get_filesize(file, &fsize) != 0)
|
|
|
|
goto out;
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
buf = kmem_alloc(fsize, KM_SLEEP);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the nvlist from the file.
|
|
|
|
*/
|
|
|
|
if (kobj_read_file(file, buf, fsize, 0) < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpack the nvlist.
|
|
|
|
*/
|
2014-11-21 03:09:39 +03:00
|
|
|
if (nvlist_unpack(buf, fsize, &nvlist, KM_SLEEP) != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all elements in the nvlist, creating a new spa_t for
|
|
|
|
* each one with the specified configuration.
|
|
|
|
*/
|
|
|
|
mutex_enter(&spa_namespace_lock);
|
|
|
|
nvpair = NULL;
|
|
|
|
while ((nvpair = nvlist_next_nvpair(nvlist, nvpair)) != NULL) {
|
|
|
|
if (nvpair_type(nvpair) != DATA_TYPE_NVLIST)
|
|
|
|
continue;
|
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
child = fnvpair_value_nvlist(nvpair);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (spa_lookup(nvpair_name(nvpair)) != NULL)
|
|
|
|
continue;
|
2010-05-29 00:45:14 +04:00
|
|
|
(void) spa_add(nvpair_name(nvpair), child, NULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
mutex_exit(&spa_namespace_lock);
|
|
|
|
|
|
|
|
nvlist_free(nvlist);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (buf != NULL)
|
|
|
|
kmem_free(buf, fsize);
|
|
|
|
|
|
|
|
kobj_close_file(file);
|
|
|
|
}
|
|
|
|
|
2017-10-19 20:06:55 +03:00
|
|
|
static int
|
|
|
|
spa_config_remove(spa_config_dirent_t *dp)
|
|
|
|
{
|
|
|
|
#if defined(__linux__) && defined(_KERNEL)
|
|
|
|
int error, flags = FWRITE | FTRUNC;
|
|
|
|
uio_seg_t seg = UIO_SYSSPACE;
|
|
|
|
vnode_t *vp;
|
|
|
|
|
|
|
|
error = vn_open(dp->scd_path, seg, flags, 0644, &vp, 0, 0);
|
|
|
|
if (error == 0) {
|
|
|
|
(void) VOP_FSYNC(vp, FSYNC, kcred, NULL);
|
|
|
|
(void) VOP_CLOSE(vp, 0, 1, 0, kcred, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
#else
|
|
|
|
return (vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-12-31 19:38:59 +03:00
|
|
|
static int
|
2008-12-03 23:09:06 +03:00
|
|
|
spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
size_t buflen;
|
|
|
|
char *buf;
|
|
|
|
vnode_t *vp;
|
|
|
|
int oflags = FWRITE | FTRUNC | FCREAT | FOFFMAX;
|
2008-12-03 23:09:06 +03:00
|
|
|
char *temp;
|
2015-12-31 19:38:59 +03:00
|
|
|
int err;
|
2008-12-03 23:09:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the nvlist is empty (NULL), then remove the old cachefile.
|
|
|
|
*/
|
|
|
|
if (nvl == NULL) {
|
2017-10-19 20:06:55 +03:00
|
|
|
err = spa_config_remove(dp);
|
2017-09-11 20:25:01 +03:00
|
|
|
if (err == ENOENT)
|
|
|
|
err = 0;
|
2017-10-19 20:06:55 +03:00
|
|
|
|
2015-12-31 19:38:59 +03:00
|
|
|
return (err);
|
2008-12-03 23:09:06 +03:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pack the configuration into a buffer.
|
|
|
|
*/
|
2016-04-11 23:16:57 +03:00
|
|
|
buf = fnvlist_pack(nvl, &buflen);
|
2014-11-21 03:09:39 +03:00
|
|
|
temp = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2015-12-22 01:02:22 +03:00
|
|
|
#if defined(__linux__) && defined(_KERNEL)
|
2015-07-29 02:45:17 +03:00
|
|
|
/*
|
|
|
|
* Write the configuration to disk. Due to the complexity involved
|
2017-10-19 20:06:55 +03:00
|
|
|
* in performing a rename and remove from within the kernel the file
|
|
|
|
* is instead truncated and overwritten in place. This way we always
|
|
|
|
* have a consistent view of the data or a zero length file.
|
2015-07-29 02:45:17 +03:00
|
|
|
*/
|
2015-12-31 19:38:59 +03:00
|
|
|
err = vn_open(dp->scd_path, UIO_SYSSPACE, oflags, 0644, &vp, 0, 0);
|
|
|
|
if (err == 0) {
|
|
|
|
err = vn_rdwr(UIO_WRITE, vp, buf, buflen, 0,
|
2015-07-29 02:45:17 +03:00
|
|
|
UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, NULL);
|
2015-12-31 19:38:59 +03:00
|
|
|
if (err == 0)
|
|
|
|
err = VOP_FSYNC(vp, FSYNC, kcred, NULL);
|
2015-07-29 02:45:17 +03:00
|
|
|
|
|
|
|
(void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);
|
2015-12-31 19:38:59 +03:00
|
|
|
if (err)
|
2017-10-19 20:06:55 +03:00
|
|
|
(void) spa_config_remove(dp);
|
2015-07-29 02:45:17 +03:00
|
|
|
}
|
|
|
|
#else
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Write the configuration to disk. We need to do the traditional
|
|
|
|
* 'write to temporary file, sync, move over original' to make sure we
|
|
|
|
* always have a consistent view of the data.
|
|
|
|
*/
|
2008-12-03 23:09:06 +03:00
|
|
|
(void) snprintf(temp, MAXPATHLEN, "%s.tmp", dp->scd_path);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2015-12-31 19:38:59 +03:00
|
|
|
err = vn_open(temp, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0);
|
|
|
|
if (err == 0) {
|
|
|
|
err = vn_rdwr(UIO_WRITE, vp, buf, buflen, 0, UIO_SYSSPACE,
|
|
|
|
0, RLIM64_INFINITY, kcred, NULL);
|
|
|
|
if (err == 0)
|
|
|
|
err = VOP_FSYNC(vp, FSYNC, kcred, NULL);
|
|
|
|
if (err == 0)
|
|
|
|
err = vn_rename(temp, dp->scd_path, UIO_SYSSPACE);
|
2008-12-03 23:09:06 +03:00
|
|
|
(void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
(void) vn_remove(temp, UIO_SYSSPACE, RMFILE);
|
2015-07-29 02:45:17 +03:00
|
|
|
#endif
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_pack_free(buf, buflen);
|
2008-12-03 23:09:06 +03:00
|
|
|
kmem_free(temp, MAXPATHLEN);
|
2015-12-31 19:38:59 +03:00
|
|
|
return (err);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-12-03 23:09:06 +03:00
|
|
|
* Synchronize pool configuration to disk. This must be called with the
|
2013-08-08 00:16:22 +04:00
|
|
|
* namespace lock held. Synchronizing the pool cache is typically done after
|
|
|
|
* the configuration has been synced to the MOS. This exposes a window where
|
|
|
|
* the MOS config will have been updated but the cache file has not. If
|
|
|
|
* the system were to crash at that instant then the cached config may not
|
2017-01-03 20:31:18 +03:00
|
|
|
* contain the correct information to open the pool and an explicit import
|
2013-08-08 00:16:22 +04:00
|
|
|
* would be required.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
void
|
OpenZFS 7614, 9064 - zfs device evacuation/removal
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
2016-09-22 19:30:13 +03:00
|
|
|
spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2008-12-03 23:09:06 +03:00
|
|
|
spa_config_dirent_t *dp, *tdp;
|
|
|
|
nvlist_t *nvl;
|
2013-07-01 18:57:04 +04:00
|
|
|
char *pool_name;
|
2015-12-31 19:38:59 +03:00
|
|
|
boolean_t ccw_failure;
|
|
|
|
int error = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT(MUTEX_HELD(&spa_namespace_lock));
|
|
|
|
|
2009-08-18 22:43:27 +04:00
|
|
|
if (rootdir == NULL || !(spa_mode_global & FWRITE))
|
2009-01-16 00:59:39 +03:00
|
|
|
return;
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
/*
|
|
|
|
* Iterate over all cachefiles for the pool, past or present. When the
|
|
|
|
* cachefile is changed, the new one is pushed onto this list, allowing
|
|
|
|
* us to update previous cachefiles that no longer contain this pool.
|
|
|
|
*/
|
2015-12-31 19:38:59 +03:00
|
|
|
ccw_failure = B_FALSE;
|
2008-12-03 23:09:06 +03:00
|
|
|
for (dp = list_head(&target->spa_config_list); dp != NULL;
|
|
|
|
dp = list_next(&target->spa_config_list, dp)) {
|
|
|
|
spa_t *spa = NULL;
|
|
|
|
if (dp->scd_path == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all pools, adding any matching pools to 'nvl'.
|
|
|
|
*/
|
|
|
|
nvl = NULL;
|
|
|
|
while ((spa = spa_next(spa)) != NULL) {
|
2013-07-05 23:14:17 +04:00
|
|
|
/*
|
|
|
|
* Skip over our own pool if we're about to remove
|
|
|
|
* ourselves from the spa namespace or any pool that
|
|
|
|
* is readonly. Since we cannot guarantee that a
|
|
|
|
* readonly pool would successfully import upon reboot,
|
|
|
|
* we don't allow them to be written to the cache file.
|
|
|
|
*/
|
|
|
|
if ((spa == target && removing) ||
|
|
|
|
!spa_writeable(spa))
|
2008-12-03 23:09:06 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
mutex_enter(&spa->spa_props_lock);
|
|
|
|
tdp = list_head(&spa->spa_config_list);
|
|
|
|
if (spa->spa_config == NULL ||
|
2016-10-07 23:19:43 +03:00
|
|
|
tdp == NULL ||
|
2008-12-03 23:09:06 +03:00
|
|
|
tdp->scd_path == NULL ||
|
|
|
|
strcmp(tdp->scd_path, dp->scd_path) != 0) {
|
|
|
|
mutex_exit(&spa->spa_props_lock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvl == NULL)
|
2016-04-11 23:16:57 +03:00
|
|
|
nvl = fnvlist_alloc();
|
2008-12-03 23:09:06 +03:00
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME)
|
|
|
|
pool_name = fnvlist_lookup_string(
|
|
|
|
spa->spa_config, ZPOOL_CONFIG_POOL_NAME);
|
|
|
|
else
|
2013-07-01 18:57:04 +04:00
|
|
|
pool_name = spa_name(spa);
|
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_nvlist(nvl, pool_name, spa->spa_config);
|
2008-12-03 23:09:06 +03:00
|
|
|
mutex_exit(&spa->spa_props_lock);
|
|
|
|
}
|
|
|
|
|
2015-12-31 19:38:59 +03:00
|
|
|
error = spa_config_write(dp, nvl);
|
|
|
|
if (error != 0)
|
|
|
|
ccw_failure = B_TRUE;
|
2008-12-03 23:09:06 +03:00
|
|
|
nvlist_free(nvl);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2015-12-31 19:38:59 +03:00
|
|
|
if (ccw_failure) {
|
|
|
|
/*
|
|
|
|
* Keep trying so that configuration data is
|
|
|
|
* written if/when any temporary filesystem
|
|
|
|
* resource issues are resolved.
|
|
|
|
*/
|
|
|
|
if (target->spa_ccw_fail_time == 0) {
|
|
|
|
zfs_ereport_post(FM_EREPORT_ZFS_CONFIG_CACHE_WRITE,
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
target, NULL, NULL, NULL, 0, 0);
|
2015-12-31 19:38:59 +03:00
|
|
|
}
|
|
|
|
target->spa_ccw_fail_time = gethrtime();
|
|
|
|
spa_async_request(target, SPA_ASYNC_CONFIG_UPDATE);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Do not rate limit future attempts to update
|
|
|
|
* the config cache.
|
|
|
|
*/
|
|
|
|
target->spa_ccw_fail_time = 0;
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2008-12-03 23:09:06 +03:00
|
|
|
* Remove any config entries older than the current one.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
2008-12-03 23:09:06 +03:00
|
|
|
dp = list_head(&target->spa_config_list);
|
|
|
|
while ((tdp = list_next(&target->spa_config_list, dp)) != NULL) {
|
|
|
|
list_remove(&target->spa_config_list, tdp);
|
|
|
|
if (tdp->scd_path != NULL)
|
|
|
|
spa_strfree(tdp->scd_path);
|
|
|
|
kmem_free(tdp, sizeof (spa_config_dirent_t));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
spa_config_generation++;
|
2008-12-03 23:09:06 +03:00
|
|
|
|
|
|
|
if (postsysevent)
|
2017-05-30 21:39:17 +03:00
|
|
|
spa_event_notify(target, NULL, NULL, ESC_ZFS_CONFIG_SYNC);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sigh. Inside a local zone, we don't have access to /etc/zfs/zpool.cache,
|
|
|
|
* and we don't want to allow the local zone to see all the pools anyway.
|
|
|
|
* So we have to invent the ZFS_IOC_CONFIG ioctl to grab the configuration
|
|
|
|
* information for all pool visible within the zone.
|
|
|
|
*/
|
|
|
|
nvlist_t *
|
|
|
|
spa_all_configs(uint64_t *generation)
|
|
|
|
{
|
|
|
|
nvlist_t *pools;
|
2008-12-03 23:09:06 +03:00
|
|
|
spa_t *spa = NULL;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (*generation == spa_config_generation)
|
|
|
|
return (NULL);
|
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
pools = fnvlist_alloc();
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
mutex_enter(&spa_namespace_lock);
|
|
|
|
while ((spa = spa_next(spa)) != NULL) {
|
|
|
|
if (INGLOBALZONE(curproc) ||
|
|
|
|
zone_dataset_visible(spa_name(spa), NULL)) {
|
2008-12-03 23:09:06 +03:00
|
|
|
mutex_enter(&spa->spa_props_lock);
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_nvlist(pools, spa_name(spa),
|
|
|
|
spa->spa_config);
|
2008-12-03 23:09:06 +03:00
|
|
|
mutex_exit(&spa->spa_props_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*generation = spa_config_generation;
|
2008-12-03 23:09:06 +03:00
|
|
|
mutex_exit(&spa_namespace_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
return (pools);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spa_config_set(spa_t *spa, nvlist_t *config)
|
|
|
|
{
|
2008-12-03 23:09:06 +03:00
|
|
|
mutex_enter(&spa->spa_props_lock);
|
OpenZFS 9075 - Improve ZFS pool import/load process and corrupted pool recovery
Some work has been done lately to improve the debugability of the ZFS pool
load (and import) process. This includes:
7638 Refactor spa_load_impl into several functions
8961 SPA load/import should tell us why it failed
7277 zdb should be able to print zfs_dbgmsg's
To iterate on top of that, there's a few changes that were made to make the
import process more resilient and crash free. One of the first tasks during the
pool load process is to parse a config provided from userland that describes
what devices the pool is composed of. A vdev tree is generated from that config,
and then all the vdevs are opened.
The Meta Object Set (MOS) of the pool is accessed, and several metadata objects
that are necessary to load the pool are read. The exact configuration of the
pool is also stored inside the MOS. Since the configuration provided from
userland is external and might not accurately describe the vdev tree
of the pool at the txg that is being loaded, it cannot be relied upon to safely
operate the pool. For that reason, the configuration in the MOS is read early
on. In the past, the two configurations were compared together and if there was
a mismatch then the load process was aborted and an error was returned.
The latter was a good way to ensure a pool does not get corrupted, however it
made the pool load process needlessly fragile in cases where the vdev
configuration changed or the userland configuration was outdated. Since the MOS
is stored in 3 copies, the configuration provided by userland doesn't have to be
perfect in order to read its contents. Hence, a new approach has been adopted:
The pool is first opened with the untrusted userland configuration just so that
the real configuration can be read from the MOS. The trusted MOS configuration
is then used to generate a new vdev tree and the pool is re-opened.
When the pool is opened with an untrusted configuration, writes are disabled
to avoid accidentally damaging it. During reads, some sanity checks are
performed on block pointers to see if each DVA points to a known vdev;
when the configuration is untrusted, instead of panicking the system if those
checks fail we simply avoid issuing reads to the invalid DVAs.
This new two-step pool load process now allows rewinding pools accross
vdev tree changes such as device replacement, addition, etc. Loading a pool
from an external config file in a clustering environment also becomes much
safer now since the pool will import even if the config is outdated and didn't,
for instance, register a recent device addition.
With this code in place, it became relatively easy to implement a
long-sought-after feature: the ability to import a pool with missing top level
(i.e. non-redundant) devices. Note that since this almost guarantees some loss
of data, this feature is for now restricted to a read-only import.
Porting notes (ZTS):
* Fix 'make dist' target in zpool_import
* The maximum path length allowed by tar is 99 characters. Several
of the new test cases exceeded this limit resulting in them not
being included in the tarball. Shorten the names slightly.
* Set/get tunables using accessor functions.
* Get last synced txg via the "zfs_txg_history" mechanism.
* Clear zinject handlers in cleanup for import_cache_device_replaced
and import_rewind_device_replaced in order that the zpool can be
exported if there is an error.
* Increase FILESIZE to 8G in zfs-test.sh to allow for a larger
ext4 file system to be created on ZFS_DISK2. Also, there's
no need to partition ZFS_DISK2 at all. The partitioning had
already been disabled for multipath devices. Among other things,
the partitioning steals some space from the ext4 file system,
makes it difficult to accurately calculate the paramters to
parted and can make some of the tests fail.
* Increase FS_SIZE and FILE_SIZE in the zpool_import test
configuration now that FILESIZE is larger.
* Write more data in order that device evacuation take lonnger in
a couple tests.
* Use mkdir -p to avoid errors when the directory already exists.
* Remove use of sudo in import_rewind_config_changed.
Authored by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Ported-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Tim Chase <tim@chase2k.com>
OpenZFS-issue: https://illumos.org/issues/9075
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/619c0123
Closes #7459
2016-07-22 17:39:36 +03:00
|
|
|
if (spa->spa_config != NULL && spa->spa_config != config)
|
|
|
|
nvlist_free(spa->spa_config);
|
2008-11-20 23:01:55 +03:00
|
|
|
spa->spa_config = config;
|
2008-12-03 23:09:06 +03:00
|
|
|
mutex_exit(&spa->spa_props_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate the pool's configuration based on the current in-core state.
|
2013-06-11 21:12:34 +04:00
|
|
|
*
|
2008-11-20 23:01:55 +03:00
|
|
|
* We infer whether to generate a complete config or just one top-level config
|
|
|
|
* based on whether vd is the root vdev.
|
|
|
|
*/
|
|
|
|
nvlist_t *
|
|
|
|
spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
|
|
|
|
{
|
|
|
|
nvlist_t *config, *nvroot;
|
|
|
|
vdev_t *rvd = spa->spa_root_vdev;
|
|
|
|
unsigned long hostid = 0;
|
2008-12-03 23:09:06 +03:00
|
|
|
boolean_t locked = B_FALSE;
|
2010-05-29 00:45:14 +04:00
|
|
|
uint64_t split_guid;
|
2013-07-01 18:57:04 +04:00
|
|
|
char *pool_name;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
if (vd == NULL) {
|
2008-11-20 23:01:55 +03:00
|
|
|
vd = rvd;
|
2008-12-03 23:09:06 +03:00
|
|
|
locked = B_TRUE;
|
|
|
|
spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(spa_config_held(spa, SCL_CONFIG | SCL_STATE, RW_READER) ==
|
|
|
|
(SCL_CONFIG | SCL_STATE));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If txg is -1, report the current value of spa->spa_config_txg.
|
|
|
|
*/
|
|
|
|
if (txg == -1ULL)
|
|
|
|
txg = spa->spa_config_txg;
|
|
|
|
|
2013-07-01 18:57:04 +04:00
|
|
|
/*
|
|
|
|
* Originally, users had to handle spa namespace collisions by either
|
|
|
|
* exporting the already imported pool or by specifying a new name for
|
|
|
|
* the pool with a conflicting name. In the case of root pools from
|
|
|
|
* virtual guests, neither approach to collision resolution is
|
|
|
|
* reasonable. This is addressed by extending the new name syntax with
|
|
|
|
* an option to specify that the new name is temporary. When specified,
|
|
|
|
* ZFS_IMPORT_TEMP_NAME will be set in spa->spa_import_flags to tell us
|
|
|
|
* to use the previous name, which we do below.
|
|
|
|
*/
|
|
|
|
if (spa->spa_import_flags & ZFS_IMPORT_TEMP_NAME) {
|
|
|
|
VERIFY0(nvlist_lookup_string(spa->spa_config,
|
2016-12-12 21:46:26 +03:00
|
|
|
ZPOOL_CONFIG_POOL_NAME, &pool_name));
|
2013-07-01 18:57:04 +04:00
|
|
|
} else
|
|
|
|
pool_name = spa_name(spa);
|
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
config = fnvlist_alloc();
|
2011-11-15 23:01:27 +04:00
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_VERSION, spa_version(spa));
|
2016-12-22 21:39:00 +03:00
|
|
|
fnvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, pool_name);
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, spa_state(spa));
|
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_TXG, txg);
|
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_POOL_GUID, spa_guid(spa));
|
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_ERRATA, spa->spa_errata);
|
|
|
|
if (spa->spa_comment != NULL)
|
|
|
|
fnvlist_add_string(config, ZPOOL_CONFIG_COMMENT,
|
|
|
|
spa->spa_comment);
|
2011-11-15 23:01:27 +04:00
|
|
|
|
2019-09-10 23:42:30 +03:00
|
|
|
hostid = spa_get_hostid(spa);
|
2016-04-11 23:16:57 +03:00
|
|
|
if (hostid != 0)
|
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_HOSTID, hostid);
|
|
|
|
fnvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME, utsname()->nodename);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2017-11-04 23:25:13 +03:00
|
|
|
int config_gen_flags = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
if (vd != rvd) {
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_TOP_GUID,
|
|
|
|
vd->vdev_top->vdev_guid);
|
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_GUID,
|
|
|
|
vd->vdev_guid);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (vd->vdev_isspare)
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64(config,
|
|
|
|
ZPOOL_CONFIG_IS_SPARE, 1ULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (vd->vdev_islog)
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64(config,
|
|
|
|
ZPOOL_CONFIG_IS_LOG, 1ULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
vd = vd->vdev_top; /* label contains top config */
|
2010-05-29 00:45:14 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Only add the (potentially large) split information
|
|
|
|
* in the mos config, and not in the vdev labels
|
|
|
|
*/
|
|
|
|
if (spa->spa_config_splitting != NULL)
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_nvlist(config, ZPOOL_CONFIG_SPLIT,
|
|
|
|
spa->spa_config_splitting);
|
|
|
|
|
|
|
|
fnvlist_add_boolean(config, ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS);
|
|
|
|
|
|
|
|
config_gen_flags |= VDEV_CONFIG_MOS;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
|
|
|
* Add the top-level config. We even add this on pools which
|
2010-08-27 01:24:34 +04:00
|
|
|
* don't support holes in the namespace.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
|
|
|
vdev_top_config_generate(spa, config);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're splitting, record the original pool's guid.
|
|
|
|
*/
|
|
|
|
if (spa->spa_config_splitting != NULL &&
|
|
|
|
nvlist_lookup_uint64(spa->spa_config_splitting,
|
|
|
|
ZPOOL_CONFIG_SPLIT_GUID, &split_guid) == 0) {
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64(config, ZPOOL_CONFIG_SPLIT_GUID, split_guid);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:16:57 +03:00
|
|
|
nvroot = vdev_config_generate(spa, vd, getstats, config_gen_flags);
|
|
|
|
fnvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, nvroot);
|
2008-11-20 23:01:55 +03:00
|
|
|
nvlist_free(nvroot);
|
|
|
|
|
2012-12-14 03:24:15 +04:00
|
|
|
/*
|
|
|
|
* Store what's necessary for reading the MOS in the label.
|
|
|
|
*/
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_nvlist(config, ZPOOL_CONFIG_FEATURES_FOR_READ,
|
|
|
|
spa->spa_label_features);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (getstats && spa_load_state(spa) == SPA_LOAD_NONE) {
|
|
|
|
ddt_histogram_t *ddh;
|
|
|
|
ddt_stat_t *dds;
|
|
|
|
ddt_object_t *ddo;
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
ddh = kmem_zalloc(sizeof (ddt_histogram_t), KM_SLEEP);
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_get_dedup_histogram(spa, ddh);
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64_array(config,
|
2010-05-29 00:45:14 +04:00
|
|
|
ZPOOL_CONFIG_DDT_HISTOGRAM,
|
2016-04-11 23:16:57 +03:00
|
|
|
(uint64_t *)ddh, sizeof (*ddh) / sizeof (uint64_t));
|
2010-05-29 00:45:14 +04:00
|
|
|
kmem_free(ddh, sizeof (ddt_histogram_t));
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
ddo = kmem_zalloc(sizeof (ddt_object_t), KM_SLEEP);
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_get_dedup_object_stats(spa, ddo);
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64_array(config,
|
2010-05-29 00:45:14 +04:00
|
|
|
ZPOOL_CONFIG_DDT_OBJ_STATS,
|
2016-04-11 23:16:57 +03:00
|
|
|
(uint64_t *)ddo, sizeof (*ddo) / sizeof (uint64_t));
|
2010-05-29 00:45:14 +04:00
|
|
|
kmem_free(ddo, sizeof (ddt_object_t));
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
dds = kmem_zalloc(sizeof (ddt_stat_t), KM_SLEEP);
|
2010-05-29 00:45:14 +04:00
|
|
|
ddt_get_dedup_stats(spa, dds);
|
2016-04-11 23:16:57 +03:00
|
|
|
fnvlist_add_uint64_array(config,
|
2010-05-29 00:45:14 +04:00
|
|
|
ZPOOL_CONFIG_DDT_STATS,
|
2016-04-11 23:16:57 +03:00
|
|
|
(uint64_t *)dds, sizeof (*dds) / sizeof (uint64_t));
|
2010-05-29 00:45:14 +04:00
|
|
|
kmem_free(dds, sizeof (ddt_stat_t));
|
|
|
|
}
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
if (locked)
|
|
|
|
spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
return (config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update all disk labels, generate a fresh config based on the current
|
|
|
|
* in-core state, and sync the global config cache (do not sync the config
|
|
|
|
* cache if this is a booting rootpool).
|
|
|
|
*/
|
|
|
|
void
|
2009-08-18 22:43:27 +04:00
|
|
|
spa_config_update(spa_t *spa, int what)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
vdev_t *rvd = spa->spa_root_vdev;
|
|
|
|
uint64_t txg;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
ASSERT(MUTEX_HELD(&spa_namespace_lock));
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
2008-11-20 23:01:55 +03:00
|
|
|
txg = spa_last_synced_txg(spa) + 1;
|
|
|
|
if (what == SPA_CONFIG_UPDATE_POOL) {
|
|
|
|
vdev_config_dirty(rvd);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If we have top-level vdevs that were added but have
|
|
|
|
* not yet been prepared for allocation, do that now.
|
|
|
|
* (It's safe now because the config cache is up to date,
|
|
|
|
* so it will be able to translate the new DVAs.)
|
|
|
|
* See comments in spa_vdev_add() for full details.
|
|
|
|
*/
|
|
|
|
for (c = 0; c < rvd->vdev_children; c++) {
|
|
|
|
vdev_t *tvd = rvd->vdev_child[c];
|
2018-06-13 01:34:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Explicitly skip vdevs that are indirect or
|
|
|
|
* log vdevs that are being removed. The reason
|
|
|
|
* is that both of those can have vdev_ms_array
|
|
|
|
* set to 0 and we wouldn't want to change their
|
|
|
|
* metaslab size nor call vdev_expand() on them.
|
|
|
|
*/
|
|
|
|
if (!vdev_is_concrete(tvd) ||
|
|
|
|
(tvd->vdev_islog && tvd->vdev_removing))
|
|
|
|
continue;
|
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
if (tvd->vdev_ms_array == 0)
|
|
|
|
vdev_metaslab_set_size(tvd);
|
|
|
|
vdev_expand(tvd, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-03 23:09:06 +03:00
|
|
|
spa_config_exit(spa, SCL_ALL, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the mosconfig to be regenerated and synced.
|
|
|
|
*/
|
|
|
|
txg_wait_synced(spa->spa_dsl_pool, txg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the global config cache to reflect the new mosconfig.
|
|
|
|
*/
|
OpenZFS 7614, 9064 - zfs device evacuation/removal
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
2016-09-22 19:30:13 +03:00
|
|
|
if (!spa->spa_is_root) {
|
|
|
|
spa_write_cachefile(spa, B_FALSE,
|
|
|
|
what != SPA_CONFIG_UPDATE_POOL);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (what == SPA_CONFIG_UPDATE_POOL)
|
2009-08-18 22:43:27 +04:00
|
|
|
spa_config_update(spa, SPA_CONFIG_UPDATE_VDEVS);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2010-08-26 22:49:16 +04:00
|
|
|
|
2018-02-16 04:53:18 +03:00
|
|
|
#if defined(_KERNEL)
|
2010-08-26 22:49:16 +04:00
|
|
|
EXPORT_SYMBOL(spa_config_load);
|
|
|
|
EXPORT_SYMBOL(spa_all_configs);
|
|
|
|
EXPORT_SYMBOL(spa_config_set);
|
|
|
|
EXPORT_SYMBOL(spa_config_generate);
|
|
|
|
EXPORT_SYMBOL(spa_config_update);
|
|
|
|
|
|
|
|
module_param(spa_config_path, charp, 0444);
|
|
|
|
MODULE_PARM_DESC(spa_config_path, "SPA config file (/etc/zfs/zpool.cache)");
|
2013-07-03 20:55:39 +04:00
|
|
|
|
|
|
|
module_param(zfs_autoimport_disable, int, 0644);
|
|
|
|
MODULE_PARM_DESC(zfs_autoimport_disable, "Disable pool import at module load");
|
|
|
|
|
2010-08-26 22:49:16 +04:00
|
|
|
#endif
|