spa.c revision bb8b5132cbf0e1d3fd47148d13c12ace41e302bb
/*
* 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
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains all the routines used when modifying on-disk SPA state.
* This includes opening, importing, destroying, exporting a pool, and syncing a
* pool.
*/
#include <sys/zfs_context.h>
#include <sys/spa_impl.h>
#include <sys/zio_checksum.h>
#include <sys/zio_compress.h>
#include <sys/vdev_impl.h>
#include <sys/metaslab.h>
#include <sys/uberblock_impl.h>
#include <sys/dmu_traverse.h>
#include <sys/dmu_objset.h>
#include <sys/dsl_pool.h>
#include <sys/dsl_dataset.h>
#include <sys/dsl_prop.h>
#include <sys/dsl_synctask.h>
#include <sys/systeminfo.h>
int zio_taskq_threads = 8;
/*
* ==========================================================================
* ==========================================================================
*/
static int
spa_error_entry_compare(const void *a, const void *b)
{
int ret;
sizeof (zbookmark_t));
if (ret < 0)
return (-1);
else if (ret > 0)
return (1);
else
return (0);
}
/*
* Utility function which retrieves copies of the current logs and
* re-initializes them in the process.
*/
void
{
spa_error_entry_compare, sizeof (spa_error_entry_t),
spa_error_entry_compare, sizeof (spa_error_entry_t),
}
/*
* Activate an uninitialized pool.
*/
static void
{
int t;
for (t = 0; t < ZIO_TYPES; t++) {
}
spa_error_entry_compare, sizeof (spa_error_entry_t),
spa_error_entry_compare, sizeof (spa_error_entry_t),
}
/*
* Opposite of spa_activate().
*/
static void
{
int t;
for (t = 0; t < ZIO_TYPES; t++) {
}
/*
* If this was part of an import or the open otherwise failed, we may
* still have errors left in the queues. Empty them just in case.
*/
}
/*
* Verify a pool configuration, and construct the vdev tree appropriately. This
* will create all the necessary vdevs in the appropriate layout, with each vdev
* All vdev validation is done by the vdev_alloc() routine.
*/
static int
{
int error;
return (error);
return (0);
return (EINVAL);
}
for (c = 0; c < children; c++) {
atype)) != 0) {
return (error);
}
}
return (0);
}
/*
* Opposite of spa_load().
*/
static void
{
int i;
/*
* Stop async tasks.
*/
/*
* Stop syncing.
*/
if (spa->spa_sync_on) {
}
/*
* Wait for any outstanding prefetch I/O to complete.
*/
/*
* Close the dsl pool.
*/
if (spa->spa_dsl_pool) {
}
/*
* Close all vdevs.
*/
if (spa->spa_root_vdev)
for (i = 0; i < spa->spa_nspares; i++)
if (spa->spa_spares) {
}
if (spa->spa_sparelist) {
}
spa->spa_async_suspended = 0;
}
/*
* Load (or re-load) the current list of vdevs describing the active spares for
* this pool. When this is called, we have some form of basic information in
* 'spa_sparelist'. We parse this into vdevs, try to open them, and then
* re-generate a more complete list including status information.
*/
static void
{
int i;
/*
* First, close and free any existing spare vdevs.
*/
for (i = 0; i < spa->spa_nspares; i++) {
/* Undo the call to spa_activate() below */
vdev_close(vd);
}
if (spa->spa_spares)
nspares = 0;
else
if (nspares == 0)
return;
/*
* Construct the array of vdevs, opening them to get status in the
* process. For each spare, there is potentially two different vdev_t
* structures associated with it: one in the list of spares (used only
* for basic validation purposes) and one in the active vdev
* configuration (if it's spared in). During this phase we open and
* validate each vdev on the spare list. If the vdev also exists in the
* active configuration, then we also mark this vdev as an active spare.
*/
for (i = 0; i < spa->spa_nspares; i++) {
VDEV_ALLOC_SPARE) == 0);
if (!tvd->vdev_isspare)
/*
* We only mark the spare active if we were successfully
* able to load the vdev. Otherwise, importing a pool
* with a bad active spare would result in strange
* behavior, because multiple pool would think the spare
* is actively in use.
*
* There is a vulnerability here to an equally bizarre
* circumstance, where a dead active spare is later
* brought back to life (onlined or otherwise). Given
* the rarity of this scenario, and the extra complexity
* it adds, we ignore the possibility.
*/
if (!vdev_is_dead(tvd))
}
continue;
(void) vdev_validate_spare(vd);
}
/*
* Recompute the stashed list of spares, with status information
* this time.
*/
DATA_TYPE_NVLIST_ARRAY) == 0);
for (i = 0; i < spa->spa_nspares; i++)
for (i = 0; i < spa->spa_nspares; i++)
nvlist_free(spares[i]);
}
static int
{
int error;
if (error == 0)
return (error);
}
/*
* Checks to see if the given vdev could not be opened, in which case we post a
* sysevent to notify the autoreplace code that the device has been removed.
*/
static void
{
int c;
for (c = 0; c < vd->vdev_children; c++)
}
}
/*
* Load an existing storage pool, using the pool's builtin spa_config as a
* source of configuration information.
*/
static int
{
int error = 0;
uint64_t autoreplace = 0;
goto out;
}
/*
* Versioning wasn't explicitly added to the label until later, so if
* it's not present treat it as the initial version.
*/
&spa->spa_config_txg);
spa_guid_exists(pool_guid, 0)) {
goto out;
}
/*
* Parse the configuration into a vdev tree. We explicitly set the
* value that will be returned by spa_version() since parsing the
* configuration requires knowing the version number.
*/
if (error != 0)
goto out;
/*
* Try to open all vdevs, loading each label in the process.
*/
if (error != 0)
goto out;
/*
* Validate the labels for all leaf vdevs. We need to grab the config
* lock because all label I/O is done with the ZIO_FLAG_CONFIG_HELD
* flag.
*/
if (error != 0)
goto out;
goto out;
}
/*
* Find the best uberblock.
*/
/*
* If we weren't able to find a single valid uberblock, return failure.
*/
goto out;
}
/*
* If the pool is newer than the code, we can't open it.
*/
goto out;
}
/*
* If the vdev guid sum doesn't match the uberblock, we have an
* incomplete configuration.
*/
goto out;
}
/*
* Initialize internal SPA structures.
*/
if (error) {
goto out;
}
goto out;
}
if (!mosconfig) {
goto out;
}
&hostid) == 0) {
char *hostname;
unsigned long myhostid = 0;
ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
"loaded as it was last accessed by "
"another system (host: %s hostid: 0x%lx). "
(unsigned long)hostid);
goto out;
}
}
}
goto out;
}
/*
* Load the bit that tells us to use the new accounting function
* (raid-z deflation). If we have an older pool, this will not
* be present.
*/
goto out;
}
/*
* Load the persistent error log. If we have an older pool, this will
* not be present.
*/
goto out;
}
goto out;
}
/*
* Load the history object. If we have an older pool, this
* will not be present.
*/
goto out;
}
/*
* Load any hot spares for this pool.
*/
goto out;
}
if (error == 0) {
&spa->spa_sparelist) != 0) {
goto out;
}
}
goto out;
}
if (error == 0) {
}
/*
* If the 'autoreplace' property is set, then post a resource notifying
* the ZFS DE that it should not issue any faults for unopenable
* devices. We also iterate over the vdevs, and post a sysevent for any
* unopenable vdevs so that the normal autoreplace handler can take
* over.
*/
if (autoreplace)
/*
* Load the vdev state for all toplevel vdevs.
*/
/*
* Propagate the leaf DTLs we just loaded all the way up the tree.
*/
/*
* Check the state of the root vdev. If it can't be opened, it
* indicates one or more toplevel vdevs are faulted.
*/
goto out;
}
int need_update = B_FALSE;
int c;
/*
* Claim log blocks that haven't been committed yet.
* This must all happen in a single txg.
*/
spa_first_txg(spa));
/*
* Wait for all claims to sync.
*/
/*
* If the config cache is stale, or we have uninitialized
* metaslabs (see spa_vdev_add()), then update the config.
*/
state == SPA_LOAD_IMPORT)
for (c = 0; c < rvd->vdev_children; c++)
/*
* Update the config cache asychronously in case we're the
* root pool, in which case the config cache isn't writable yet.
*/
if (need_update)
}
error = 0;
out:
return (error);
}
/*
*
* The import case is identical to an open except that the configuration is sent
* down from userland, instead of grabbed from the configuration cache. For the
* case of an open, the pool configuration will exist in the
* POOL_STATE_UNINITIALIZED state.
*
* the same time open the pool, without having to keep around the spa_t in some
* ambiguous state.
*/
static int
{
int error;
/*
* As disgusting as this is, we need to support recursive calls to this
* function because dsl_dir_open() is called during spa_load(), and ends
* up calling spa_open() again. The real fix is to figure out how to
* avoid dsl_dir_open() calling this in the first place.
*/
}
if (locked)
return (ENOENT);
}
/*
* If vdev_validate() returns failure (indicated by
* EBADF), it indicates that one of the vdevs indicates
* that the pool has been exported or destroyed. If
* this is the case, the config cache is out of sync and
* we should remove the pool from the namespace.
*/
if (locked)
return (ENOENT);
}
if (error) {
/*
* We can't open the pool, but we still have useful
* information: the state of each vdev after the
* attempted vdev_open(). Return this to the user.
*/
B_TRUE);
}
if (locked)
return (error);
} else {
}
}
/*
* If we just loaded the pool, resilver anything that's out of date.
*/
if (locked)
}
return (0);
}
int
{
}
/*
* Lookup the given spa_t, incrementing the inject count in the process,
* preventing it from being exported or destroyed.
*/
spa_t *
spa_inject_addref(char *name)
{
return (NULL);
}
spa->spa_inject_ref++;
return (spa);
}
void
{
spa->spa_inject_ref--;
}
static void
{
if (spa->spa_nspares == 0)
return;
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
if (nspares != 0) {
/*
* Go through and find any spares which have since been
* repurposed as an active spare. If this is the case, update
* their status appropriately.
*/
for (i = 0; i < nspares; i++) {
ZPOOL_CONFIG_GUID, &guid) == 0);
spares[i], ZPOOL_CONFIG_STATS,
}
}
}
}
int
{
int error;
spa_get_errlog_size(spa)) == 0);
}
/*
* We want to get the alternate root even for faulted pools, so we cheat
* and call spa_lookup() directly.
*/
if (altroot) {
if (spa)
else
altroot[0] = '\0';
} else {
}
}
return (error);
}
/*
* Validate that the 'spares' array is well formed. We must have an array of
* nvlists, each which describes a valid leaf vdev. If this is an import (mode
* is VDEV_ALLOC_SPARE), then we allow corrupted spares to be specified, as long
* as they are well-formed.
*/
static int
{
int error;
/*
* It's acceptable to have no spares specified.
*/
return (0);
if (nspares == 0)
return (EINVAL);
/*
* Make sure the pool is formatted with a version that supports hot
* spares.
*/
return (ENOTSUP);
/*
* Set the pending spare list so we correctly handle device in-use
* checking.
*/
for (i = 0; i < nspares; i++) {
mode)) != 0)
goto out;
goto out;
}
VDEV_LABEL_SPARE)) == 0) {
}
goto out;
else
error = 0;
}
out:
spa->spa_pending_nspares = 0;
return (error);
}
/*
* Pool Creation
*/
int
const char *history_str)
{
dsl_pool_t *dp;
int c, error = 0;
/*
* If this pool already exists, return failure.
*/
return (EEXIST);
}
/*
* Allocate a new spa_t structure.
*/
/*
* Create the root vdev.
*/
if (error == 0 &&
VDEV_ALLOC_ADD)) == 0) {
for (c = 0; c < rvd->vdev_children; c++)
}
if (error != 0) {
return (error);
}
/*
* Get the list of spares, if specified.
*/
KM_SLEEP) == 0);
}
/*
* Create the pool config object.
*/
}
/* Newly created pools are always deflated. */
}
/*
* Create the deferred-free bplist object. Turn off compression
* because sync-to-convergence takes longer if the blocksize
* keeps changing.
*/
}
/*
* Create the pool's history object.
*/
/*
* We explicitly wait for the first transaction to complete so that our
* bean counters are appropriately updated.
*/
if (history_str != NULL)
return (0);
}
/*
* Import the given pool into the system. We set up the necessary spa_t and
* then call spa_load() to do the dirty work.
*/
int
{
int error;
/*
* If a pool with this name exists, return failure.
*/
return (EEXIST);
}
/*
* Create and initialize the spa structure.
*/
/*
* Pass off the heavy lifting to spa_load().
* Pass TRUE for mosconfig because the user-supplied config
* is actually the one to trust when doing an import.
*/
/*
* Toss any existing sparelist, as it doesn't have any validity anymore,
* and conflicts with spa_has_spare().
*/
if (spa->spa_sparelist) {
}
&nvroot) == 0);
if (error == 0)
if (error != 0) {
return (error);
}
/*
* Override any spares as specified by the user, as these may have
*/
if (spa->spa_sparelist)
else
NV_UNIQUE_NAME, KM_SLEEP) == 0);
}
/*
* Update the config cache to include the newly-imported pool.
*/
/*
* Resilver anything that's out of date.
*/
return (0);
}
/*
* This (illegal) pool name is used when temporarily importing a spa_t in order
* to get the vdev stats associated with the imported devices.
*/
#define TRYIMPORT_NAME "$import"
nvlist_t *
{
char *poolname;
return (NULL);
return (NULL);
/*
* Create and initialize the spa structure.
*/
/*
* Pass off the heavy lifting to spa_load().
* Pass TRUE for mosconfig because the user-supplied config
* is actually the one to trust when doing an import.
*/
/*
* If 'tryconfig' was at least parsable, return the current config.
*/
poolname) == 0);
state) == 0);
/*
* Add the list of hot spares.
*/
}
return (config);
}
/*
*
* The act of destroying or exporting a pool is very simple. We make sure there
* is no more pending I/O and any references to the pool are gone. Then, we
* update the pool state and sync all the labels to disk, removing the
* configuration from the cache afterwards.
*/
static int
{
if (oldconfig)
return (EROFS);
return (ENOENT);
}
/*
* Put a hold on the pool, drop the namespace lock, stop async tasks,
* reacquire the namespace lock, and see if we can export.
*/
/*
* The pool will be in core if it's openable,
* in which case we can modify its state.
*/
/*
* Objsets may be open only because they're dirty, so we
* have to force it to sync before checking spa_refcnt.
*/
/*
* A pool cannot be exported or destroyed if there are active
* references. If we are resetting a pool, allow references by
* fault injection handlers.
*/
if (!spa_refcount_zero(spa) ||
(spa->spa_inject_ref != 0 &&
return (EBUSY);
}
/*
* We want this to be reflected on every label,
* so mark them all dirty. spa_unload() will do the
* final sync that pushes these changes out.
*/
if (new_state != POOL_STATE_UNINITIALIZED) {
}
}
}
if (new_state != POOL_STATE_UNINITIALIZED) {
}
return (0);
}
/*
* Destroy a storage pool.
*/
int
spa_destroy(char *pool)
{
}
/*
* Export a storage pool.
*/
int
{
}
/*
* Similar to spa_export(), this unloads the spa_t without actually removing it
* from the namespace in any way.
*/
int
{
}
/*
* ==========================================================================
* Device manipulation
* ==========================================================================
*/
/*
* Add a device to a storage pool.
*/
int
{
int c, error;
VDEV_ALLOC_ADD)) != 0)
nspares = 0;
}
if (vd->vdev_children != 0) {
}
}
/*
* We must validate the spares after checking the children. Otherwise,
* vdev_inuse() will blindly overwrite the spare.
*/
VDEV_ALLOC_ADD)) != 0) {
}
/*
* Transfer each new top-level vdev from vd to rvd.
*/
for (c = 0; c < vd->vdev_children; c++) {
}
if (nspares != 0) {
newspares = kmem_alloc(sizeof (void *) *
for (i = 0; i < oldnspares; i++)
for (i = 0; i < nspares; i++)
&newspares[i + oldnspares],
KM_SLEEP) == 0);
nspares + oldnspares) == 0);
for (i = 0; i < oldnspares + nspares; i++)
nvlist_free(newspares[i]);
sizeof (void *));
} else {
NV_UNIQUE_NAME, KM_SLEEP) == 0);
}
}
/*
* We have to be careful when adding new vdevs to an existing pool.
* If other threads start allocating from these vdevs before we
* sync the config cache, and we lose power, then upon reboot we may
* fail to open the pool because there are DVAs that the config cache
* can't translate. Therefore, we first add the vdevs without
* initializing metaslabs; sync the config cache (via spa_vdev_exit());
* and then let spa_config_update() initialize the new metaslabs.
*
* spa_load() checks for added-but-not-initialized vdevs, so that
* if we lose power at any point in this sequence, the remaining
* steps will be completed the next time we load the pool.
*/
return (0);
}
/*
* Attach a device to a mirror. The arguments are the path to any device
* in the mirror, and the nvroot for the new device. If the path specifies
* a device that is not mirrored, we automatically insert the mirror vdev.
*
* If 'replacing' is specified, the new device is intended to replace the
* existing device; in this case the two devices are made into their own
* mirror using the 'replacing' vdev, which is functionally identical to
* the mirror vdev (it actually reuses all the same ops) but has a few
* extra rules: you can't attach to it after it's been created, and upon
* completion of resilvering, the first disk (the one being replaced)
* is automatically detached.
*/
int
{
int error;
int is_log;
VDEV_ALLOC_ADD)) != 0)
/*
* Spares can't replace logs
*/
if (!replacing) {
/*
* For attach, the only allowable parent is a mirror or the root
* vdev.
*/
pvops = &vdev_mirror_ops;
} else {
/*
* Active hot spares can only be replaced by inactive hot
* spares.
*/
/*
* If the source is a hot spare, and the parent isn't already a
* spare, then we want to create a new hot spare. Otherwise, we
* want to create a replacing vdev. The user is not allowed to
* attach to a spared vdev child unless the 'isspare' state is
* the same (spare replaces spare, non-spare replaces
* non-spare).
*/
pvops = &vdev_spare_ops;
else
}
/*
* Compare the new device size with the replaceable/attachable
* device size.
*/
/*
* The new device cannot have a higher alignment requirement
* than the top-level vdev.
*/
/*
* If this is an in-place replacement, update oldvd's path and devid
* to make it distinguishable from newvd, and unopenable from now on.
*/
KM_SLEEP);
}
}
/*
* If the parent is not a mirror, or if we're replacing, insert the new
*/
/*
* Extract the new device from its root and add it to pvd.
*/
/*
* If newvd is smaller than oldvd, but larger than its rsize,
* the addition of newvd may have decreased our parent's asize.
*/
/*
* Set newvd's DTL to [TXG_INITIAL, open_txg]. It will propagate
* upward when spa_vdev_exit() calls vdev_dtl_reassess().
*/
if (newvd->vdev_isspare)
/*
* Mark newvd's DTL dirty in this txg.
*/
/*
* Kick off a resilver to update newvd. We need to grab the namespace
* lock because spa_scrub() needs to post a sysevent with the pool name.
*/
return (0);
}
/*
* Detach a device from a mirror or replacing vdev.
* If 'replace_done' is specified, only detach if the parent
* is a replacing vdev.
*/
int
{
int c, t, error;
/*
* If replace_done is specified, only remove this device if it's
* the first child of a replacing vdev. For the 'spare' vdev, either
* disk can be removed.
*/
if (replace_done) {
}
}
/*
* Only mirror, replacing, and spare vdevs support detach.
*/
/*
* If there's only one replica, you can't detach it.
*/
/*
* If all siblings have non-empty DTLs, this device may have the only
* valid copy of the data, which means we cannot safely detach it.
*
* XXX -- as in the vdev_offline() case, we really want a more
* precise DTL check.
*/
for (c = 0; c < pvd->vdev_children; c++) {
continue;
if (vdev_is_dead(cvd))
continue;
if (!dirty)
break;
}
/*
* If we are a replacing or spare vdev, then we can always detach the
* latter child, as that is how one cancels the operation.
*/
c == pvd->vdev_children)
/*
* If we are detaching the original disk from a spare, then it implies
* that the spare should become a real disk, and be removed from the
* active spare list for the pool.
*/
/*
* Erase the disk labels so the disk can be used for other things.
* This must be done after all other error cases are handled,
* but before we disembowel vd (so we can still do I/O to it).
* But if we can't do it, don't treat the error as fatal --
* it may be that the unwritability of the disk is the reason
* it's being detached!
*/
/*
* Remove vd from its parent and compact the parent's children.
*/
/*
* Remember one of the remaining children so we can get tvd below.
*/
/*
* If we need to remove the remaining child from the list of hot spares,
* do it now, marking the vdev as no longer a spare in the process. We
* must do this before vdev_remove_parent(), because that can change the
* GUID if it creates a new toplevel GUID.
*/
if (unspare) {
}
/*
* the parent is no longer needed. Remove it from the tree.
*/
/*
* We don't set tvd until now because the parent we just removed
* may have been the previous top-level vdev.
*/
/*
* Reevaluate the parent vdev state.
*/
/*
* If the device we just detached was smaller than the others, it may be
* possible to add metaslabs (i.e. grow the pool). vdev_metaslab_init()
* can't fail because the existing metaslabs are already in core, so
* there's nothing to read from disk.
*/
/*
* Mark vd's DTL as dirty in this txg. vdev_dtl_sync() will see that
* vd->vdev_detached is set and free vd's DTL object in syncing context.
* But first make sure we're not on any *other* txg's DTL list, to
* prevent vd from being accessed after it's freed.
*/
for (t = 0; t < TXG_SIZE; t++)
/*
* If this was the removal of the original device in a hot spare vdev,
* then we want to go through and remove the device from the hot spare
* list of every other pool.
*/
if (unspare) {
continue;
}
}
return (error);
}
/*
* Remove a device from the pool. Currently, this supports removing only hot
* spares.
*/
int
{
int ret = 0;
for (i = 0; i < nspares; i++) {
ZPOOL_CONFIG_GUID, &theguid) == 0);
break;
}
}
}
/*
* We only support removing a hot spare, and only if it's not currently
* in use in this pool.
*/
goto out;
}
goto out;
}
goto out;
}
if (nspares == 1) {
} else {
KM_SLEEP);
for (i = 0, j = 0; i < nspares; i++) {
}
}
DATA_TYPE_NVLIST_ARRAY) == 0);
for (i = 0; i < nspares - 1; i++)
nvlist_free(newspares[i]);
out:
return (ret);
}
/*
* Find any device that's done replacing, or a vdev marked 'unspare' that's
* current spared, so we can detach it.
*/
static vdev_t *
{
int c;
for (c = 0; c < vd->vdev_children; c++) {
return (oldvd);
}
/*
* Check for a completed replacement.
*/
return (oldvd);
}
}
/*
* Check for a completed resilver with the 'unspare' flag set.
*/
if (newvd->vdev_unspare &&
newvd->vdev_unspare = 0;
return (oldvd);
}
}
return (NULL);
}
static void
{
/*
* If we have just finished replacing a hot spared device, then
* we need to detach the parent's first child (the original hot
* spare) as well.
*/
}
return;
return;
}
}
/*
* Update the stored path for this vdev. Dirty the vdev configuration, relying
* on spa_vdev_enter/exit() to synchronize the labels and cache.
*/
int
{
/*
* Determine if this is a reference to a hot spare. In that
* case, update the path as stored in the spare list.
*/
for (i = 0; i < nspares; i++) {
ZPOOL_CONFIG_GUID, &theguid) == 0);
break;
}
if (i == nspares)
ZPOOL_CONFIG_PATH, newpath) == 0);
} else {
}
}
}
/*
* ==========================================================================
* SPA Scrubbing
* ==========================================================================
*/
static void
{
spa->spa_scrub_errors++;
}
}
static void
{
void *data;
/*
* Do not give too much work to vdev(s).
*/
}
}
/* ARGSUSED */
static int
{
int needs_resilver = B_FALSE;
int d;
/*
* We can't scrub this block, but we can continue to scrub
* the rest of the pool. Note the error and move along.
*/
spa->spa_scrub_errors++;
return (ERESTART);
}
for (d = 0; d < BP_GET_NDVAS(bp); d++) {
/*
* Keep track of how much data we've examined so that
* zpool(1M) status can make useful progress reports.
*/
if (DVA_GET_GANG(&dva[d])) {
/*
* Gang members may be spread across multiple
* vdevs, so the best we can do is look at the
* pool-wide DTL.
* XXX -- it would be better to change our
* allocation policy to ensure that this can't
* happen.
*/
}
}
}
else if (needs_resilver)
return (0);
}
static void
{
int error = 0;
/*
* wait for that to complete.
*/
dprintf("start %s mintxg=%llu maxtxg=%llu\n",
spa->spa_scrub_errors = 0;
while (!spa->spa_scrub_stop) {
while (spa->spa_scrub_suspended) {
spa->spa_scrub_active = 0;
}
if (spa->spa_scrub_restart_txg != 0)
break;
break;
}
while (spa->spa_scrub_inflight)
spa->spa_scrub_active = 0;
/*
* Note: we check spa_scrub_restart_txg under both spa_scrub_lock
* AND the spa config lock to synchronize with any config changes
* that revise the DTLs under spa_vdev_enter() / spa_vdev_exit().
*/
if (spa->spa_scrub_restart_txg != 0)
if (spa->spa_scrub_stop)
/*
* Even if there were uncorrectable errors, we consider the scrub
* completed. The downside is that if there is a transient error during
* a resilver, we won't resilver the data properly to the target. But
* if the damage is permanent (more likely) we will resilver forever,
* which isn't really acceptable. Since there is enough information for
* the user to know what has failed and why, this seems like a more
* tractable approach.
*/
dprintf("end %s to maxtxg=%llu %s, traverse=%d, %llu errors, stop=%u\n",
/*
* Whether it succeeded or not, vacate all temporary scrub DTLs.
*/
/*
* We may have finished replacing a device.
* Let the async thread assess this and handle the detach.
*/
/*
* If we were told to restart, our final act is to start a new scrub.
*/
spa->spa_scrub_active = 0;
thread_exit();
}
void
{
while (spa->spa_scrub_active) {
}
while (spa->spa_scrub_inflight)
}
void
{
if (--spa->spa_scrub_suspended == 0)
}
void
{
/*
* we must restart any in-progress scrubs. The itinerary will
* fix this properly.
*/
}
int
{
return (ENOTSUP);
/*
* If there's a scrub or resilver already in progress, stop it.
*/
/*
* Don't stop a resilver unless forced.
*/
return (EBUSY);
}
}
/*
* Terminate the previous traverse.
*/
}
return (0);
}
/*
* The pool-wide DTL is empty.
* If this is a resilver, there's nothing to do except
* check whether any in-progress replacements have completed.
*/
if (type == POOL_SCRUB_RESILVER) {
}
} else {
/*
* The pool-wide DTL is non-empty.
* If this is a normal scrub, upgrade to a resilver instead.
*/
if (type == POOL_SCRUB_EVERYTHING)
}
if (type == POOL_SCRUB_RESILVER) {
/*
* Determine the resilvering boundaries.
*
* Note: (mintxg, maxtxg) is an open interval,
* i.e. mintxg and maxtxg themselves are not included.
*
* Note: for maxtxg, we MIN with spa_last_synced_txg(spa) + 1
* so we don't claim to resilver a txg that's still changing.
*/
}
spa->spa_scrub_stop = 0;
spa->spa_scrub_restart_txg = 0;
if (type != POOL_SCRUB_NONE) {
}
return (0);
}
/*
* ==========================================================================
* SPA async task processing
* ==========================================================================
*/
static void
{
int c;
for (c = 0; c < vd->vdev_children; c++) {
if (tvd->vdev_remove_wanted) {
tvd->vdev_remove_wanted = 0;
}
}
}
static void
{
int tasks;
spa->spa_async_tasks = 0;
/*
* See if the config needs to be updated.
*/
if (tasks & SPA_ASYNC_CONFIG_UPDATE) {
}
/*
* See if any devices need to be marked REMOVED.
*/
if (tasks & SPA_ASYNC_REMOVE) {
}
/*
* If any devices are done replacing, detach them.
*/
if (tasks & SPA_ASYNC_RESILVER_DONE)
/*
* Kick off a scrub. When starting a RESILVER scrub (or an EVERYTHING
* scrub which can become a resilver), we need to hold
* spa_namespace_lock() because the sysevent we post via
* spa_event_notify() needs to get the name of the pool.
*/
if (tasks & SPA_ASYNC_SCRUB) {
}
/*
* Kick off a resilver.
*/
if (tasks & SPA_ASYNC_RESILVER) {
}
/*
* Let the world know that we're done.
*/
thread_exit();
}
void
{
}
void
{
}
static void
{
}
void
{
}
/*
* ==========================================================================
* SPA syncing routines
* ==========================================================================
*/
static void
{
int error;
uint8_t c = 1;
/*
* Pre-dirty the first block so we sync to convergence faster.
* (Usually only the first block is needed.)
*/
}
static void
{
KM_SLEEP) == 0);
}
static void
{
int i;
if (!spa->spa_sync_spares)
return;
/*
* Update the MOS nvlist describing the list of available spares.
* spa_validate_spares() will have already made sure this nvlist is
* valid and the vdevs are labeled appropriately.
*/
if (spa->spa_spares_object == 0) {
}
if (spa->spa_nspares == 0) {
NULL, 0) == 0);
} else {
KM_SLEEP);
for (i = 0; i < spa->spa_nspares; i++)
for (i = 0; i < spa->spa_nspares; i++)
nvlist_free(spares[i]);
}
}
static void
{
return;
if (spa->spa_config_syncing)
}
static void
{
if (spa->spa_pool_props_object == 0) {
}
case ZPOOL_PROP_DELEGATION:
break;
case ZPOOL_PROP_BOOTFS:
break;
case ZPOOL_PROP_AUTOREPLACE:
break;
}
}
}
/*
* Sync the specified transaction group. New blocks may be dirtied as
* part of the process, so we iterate until it converges.
*/
void
{
int dirty_vdevs;
/*
* Lock out configuration changes.
*/
spa->spa_sync_pass = 0;
/*
* If we are upgrading to SPA_VERSION_RAIDZ_DEFLATE this txg,
* set spa_deflate if we have no raid-z vdevs.
*/
int i;
for (i = 0; i < rvd->vdev_children; i++) {
break;
}
if (i == rvd->vdev_children) {
}
}
/*
* If anything has changed in this txg, push the deferred frees
* from the previous txg. If not, leave them alone so that we
* don't generate work on an otherwise idle system.
*/
/*
* Iterate to convergence.
*/
do {
spa->spa_sync_pass++;
dirty_vdevs = 0;
dirty_vdevs++;
}
} while (dirty_vdevs);
/*
* Rewrite the vdev configuration (which includes the uberblock)
* to commit the transaction group.
*
* If there are any dirty vdevs, sync the uberblock to all vdevs.
* Otherwise, pick a random top-level vdev that's known to be
* visible in the config cache (see spa_vdev_add() for details).
* If the write fails, try the next vdev until we're tried them all.
*/
} else {
int c;
for (c = 0; c < children; c++) {
if (vd->vdev_ms_array == 0)
continue;
break;
}
if (c == children)
}
/*
* Clear the dirty config list.
*/
/*
* Now that the new config has synced transactionally,
* let it become visible to the config cache.
*/
}
/*
* Make a stable copy of the fully synced uberblock.
* We use this as the root for pool traversals.
*/
spa->spa_traverse_wanted = 0;
/*
* Clean up the ZIL records for the synced txg.
*/
/*
* Update usable space statistics.
*/
/*
* It had better be the case that we didn't dirty anything
* since vdev_config_sync().
*/
/*
* If any async tasks have been requested, kick them off.
*/
}
/*
* Sync all pools. We don't want to hold the namespace lock across these
* operations, so we take a reference on the spa_t and drop the lock during the
* sync.
*/
void
spa_sync_allpools(void)
{
continue;
}
}
/*
* ==========================================================================
* Miscellaneous routines
* ==========================================================================
*/
/*
* Remove all pools in the system.
*/
void
spa_evict_all(void)
{
/*
* Remove all cached state. All pools should be closed now,
* so every spa in the AVL tree should be unreferenced.
*/
/*
* Stop async tasks. The async thread may need to detach
* a device that's been replaced, which requires grabbing
* spa_namespace_lock, so we must drop it here.
*/
}
}
}
vdev_t *
{
}
void
{
/*
* This should only be called for a non-faulted pool, and since a
* future version would result in an unopenable pool, this shouldn't be
* possible.
*/
}
{
int i;
for (i = 0; i < spa->spa_nspares; i++)
return (B_TRUE);
for (i = 0; i < spa->spa_pending_nspares; i++) {
ZPOOL_CONFIG_GUID, &spareguid) == 0 &&
return (B_TRUE);
}
return (B_FALSE);
}
int
{
}
int
{
int err;
/* If no props object, then just return empty nvlist */
if (spa->spa_pool_props_object == 0) {
return (0);
}
zap_cursor_advance(&zc)) {
continue;
switch (za.za_integer_length) {
case 8:
if (zpool_prop_default_numeric(prop) ==
else
src = ZFS_SRC_LOCAL;
if (prop == ZPOOL_PROP_BOOTFS) {
dsl_pool_t *dp;
char strval[MAXPATHLEN];
break;
}
ZFS_PROP_SOURCE, src) == 0);
ZFS_PROP_VALUE, strval) == 0);
} else {
ZFS_PROP_SOURCE, src) == 0);
ZFS_PROP_VALUE, value) == 0);
}
propval) == 0);
break;
}
}
nvlist_free(*nvp);
return (err);
}
return (0);
}
/*
* If the bootfs property value is dsobj, clear it.
*/
void
{
spa->spa_bootfs = 0;
}
}
/*
* Post a sysevent corresponding to the given event. The 'name' must be one of
* the event definitions in sys/sysevent/eventdefs.h. The payload will be
* filled in from the spa and (optionally) the vdev. This doesn't do anything
* in the userland libzpool, as we don't want consumers to misinterpret ztest
* or zdb as real changes.
*/
void
{
#ifdef _KERNEL
sysevent_t *ev;
SE_SLEEP);
goto done;
goto done;
if (vd) {
SE_SLEEP) != 0)
goto done;
goto done;
}
}
done:
if (attr)
#endif
}