spa.c revision f4565e39fe75b2c28258c16bc697741760935002
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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>
#include <sys/spa_boot.h>
#include "zfs_prop.h"
#include "zfs_comutil.h"
int zio_taskq_threads = 8;
/*
* ==========================================================================
* SPA properties routines
* ==========================================================================
*/
/*
* Add a (source=src, propname=propval) list to an nvlist.
*/
static void
{
else
}
/*
* Get property values from the spa configuration.
*/
static void
{
/*
* readonly properties
*/
/*
* settable properties that are not stored in the pool property object.
*/
else
0, ZPROP_SRC_LOCAL);
"none", 0, ZPROP_SRC_LOCAL);
}
}
}
/*
* Get zpool property values.
*/
int
{
int err;
/*
* Get properties from the spa config.
*/
/* If no pool property object, no more prop to get. */
if (spa->spa_pool_props_object == 0) {
return (0);
}
/*
* Get properties from the MOS pool property object.
*/
zap_cursor_advance(&zc)) {
continue;
switch (za.za_integer_length) {
case 8:
/* integer property */
if (za.za_first_integer !=
if (prop == ZPOOL_PROP_BOOTFS) {
dsl_pool_t *dp;
break;
}
strval = kmem_alloc(
KM_SLEEP);
} else {
}
break;
case 1:
/* string property */
if (err) {
break;
}
break;
default:
break;
}
}
out:
nvlist_free(*nvp);
return (err);
}
return (0);
}
/*
* Validate the given pool properties nvlist and modify the list
* for the property values to be set.
*/
static int
{
int error = 0, reset_bootfs = 0;
char *slash;
return (EINVAL);
switch (prop) {
case ZPOOL_PROP_VERSION:
if (!error &&
break;
case ZPOOL_PROP_DELEGATION:
case ZPOOL_PROP_AUTOREPLACE:
case ZPOOL_PROP_LISTSNAPS:
break;
case ZPOOL_PROP_BOOTFS:
break;
}
/*
* Make sure the vdev config is bootable
*/
break;
}
reset_bootfs = 1;
if (!error) {
break;
}
break;
/* We don't support gzip bootable datasets */
} else {
}
}
break;
case ZPOOL_PROP_FAILUREMODE:
/*
* This is a special case which only occurs when
* the pool has completely failed. This allows
* the user to change the in-core failmode property
* currently be blocked). We do this by returning
* EIO to the caller (spa_prop_set) to trick it
* into thinking we encountered a property validation
* error.
*/
}
break;
case ZPOOL_PROP_CACHEFILE:
break;
if (strval[0] == '\0')
break;
break;
if (strval[0] != '/') {
break;
}
break;
}
if (error)
break;
}
if (!error && reset_bootfs) {
if (!error) {
}
}
return (error);
}
int
{
int error;
return (error);
}
/*
* If the bootfs property value is dsobj, clear it.
*/
void
{
spa->spa_bootfs = 0;
}
}
/*
* ==========================================================================
* ==========================================================================
*/
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.
*/
/*
* Drop and purge level 2 cache
*/
/*
* Close the dsl pool.
*/
if (spa->spa_dsl_pool) {
}
/*
* Close all vdevs.
*/
if (spa->spa_root_vdev)
}
}
}
}
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_spares.sav_config'. 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.
*/
/* Undo the call to spa_activate() below */
vdev_close(vd);
}
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.
*/
KM_SLEEP);
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;
if (vdev_validate_aux(vd) == 0)
}
/*
* Recompute the stashed list of spares, with status information
* this time.
*/
DATA_TYPE_NVLIST_ARRAY) == 0);
KM_SLEEP);
nvlist_free(spares[i]);
}
/*
* Load (or re-load) the current list of vdevs describing the active l2cache for
* this pool. When this is called, we have some form of basic information in
* 'spa_l2cache.sav_config'. We parse this into vdevs, try to open them, and
* then re-generate a more complete list including status information.
* Devices which are already active have their details maintained, and are
* not re-opened.
*/
static void
{
int i, j, oldnvdevs;
} else {
nl2cache = 0;
}
/*
* Process new nvlist of vdevs.
*/
for (i = 0; i < nl2cache; i++) {
&guid) == 0);
for (j = 0; j < oldnvdevs; j++) {
/*
*/
break;
}
}
/*
* Create new vdev
*/
VDEV_ALLOC_L2CACHE) == 0);
/*
* Commit this vdev as an l2cache device,
* even if it fails to open.
*/
continue;
(void) vdev_validate_aux(vd);
if (!vdev_is_dead(vd)) {
}
}
}
/*
* Purge vdevs that were dropped
*/
for (i = 0; i < oldnvdevs; i++) {
l2arc_vdev_present(vd)) {
}
(void) vdev_close(vd);
}
}
if (oldvdevs)
goto out;
/*
* Recompute the stashed list of l2cache devices, with status
* information this time.
*/
DATA_TYPE_NVLIST_ARRAY) == 0);
out:
nvlist_free(l2cache[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++)
}
}
/*
* Check for missing log devices
*/
int
{
switch (spa->spa_log_state) {
case SPA_LOG_MISSING:
/* need to recheck in case slog has been restored */
case SPA_LOG_UNKNOWN:
DS_FIND_CHILDREN)) {
return (1);
}
break;
case SPA_LOG_CLEAR:
break;
}
return (0);
}
/*
* 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;
char *ereport = FM_EREPORT_ZFS_POOL;
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) {
goto out;
}
}
/*
* Load any level 2 ARC devices for this pool.
*/
goto out;
}
if (error == 0) {
goto out;
}
}
if (spa_check_logs(spa)) {
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.
*/
/*
* 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 (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--;
}
/*
* Add spares device information to the nvlist.
*/
static void
{
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,
}
}
}
}
/*
* Add l2cache device information to the nvlist, including vdev stats.
*/
static void
{
return;
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
if (nl2cache != 0) {
/*
* Update level 2 cache device stats.
*/
for (i = 0; i < nl2cache; i++) {
ZPOOL_CONFIG_GUID, &guid) == 0);
if (guid ==
break;
}
}
}
}
}
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 auxiliary device 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 devs specified.
*/
return (0);
if (ndev == 0)
return (EINVAL);
/*
* Make sure the pool is formatted with a version that supports this
* device type.
*/
return (ENOTSUP);
/*
* Set the pending device list so we correctly handle device in-use
* checking.
*/
for (i = 0; i < ndev; i++) {
mode)) != 0)
goto out;
goto out;
}
/*
* The L2ARC currently only supports disk devices.
*/
goto out;
}
}
if (error &&
goto out;
else
error = 0;
}
out:
sav->sav_npending = 0;
return (error);
}
static int
{
int error;
VDEV_LABEL_SPARE)) != 0) {
return (error);
}
}
static void
const char *config)
{
int i;
/*
* Generate new dev list by concatentating with the
* current dev list.
*/
newdevs = kmem_alloc(sizeof (void *) *
for (i = 0; i < oldndevs; i++)
KM_SLEEP) == 0);
for (i = 0; i < ndevs; i++)
KM_SLEEP) == 0);
DATA_TYPE_NVLIST_ARRAY) == 0);
nvlist_free(newdevs[i]);
} else {
/*
* Generate a new dev list.
*/
KM_SLEEP) == 0);
}
}
/*
* Stop and drop level 2 ARC devices
*/
void
{
int i;
l2arc_vdev_present(vd)) {
}
if (vd->vdev_isl2cache)
(void) vdev_close(vd);
}
}
/*
* Pool Creation
*/
int
{
dsl_pool_t *dp;
int c, error = 0;
/*
* If this pool already exists, return failure.
*/
return (EEXIST);
}
/*
* Allocate a new spa_t structure.
*/
(void) nvlist_lookup_string(props,
return (error);
}
&version) != 0)
/*
* 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);
}
/*
* Get the list of level 2 cache devices, if specified.
*/
NV_UNIQUE_NAME, KM_SLEEP) == 0);
}
/*
* Create the pool config object.
*/
}
/* Newly created pools with the right version are always deflated. */
if (version >= SPA_VERSION_RAIDZ_DEFLATE) {
}
}
/*
* 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.
*/
if (version >= SPA_VERSION_ZPOOL_HISTORY)
/*
* Set pool properties.
*/
if (props)
/*
* We explicitly wait for the first transaction to complete so that our
* bean counters are appropriately updated.
*/
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.
*/
static int
{
/*
* If a pool with this name exists, return failure.
*/
return (EEXIST);
}
/*
* Create and initialize the spa structure.
*/
(void) nvlist_lookup_string(props,
if (allowfaulted)
/*
* Pass off the heavy lifting to spa_load().
* Pass TRUE for mosconfig (unless this is a root pool) 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().
*/
}
}
&nvroot) == 0);
if (error == 0)
if (error == 0)
/*
* If we failed to load the pool, but 'allowfaulted' is
* set, then manually set the config as if the config
* passed in was specified in the cache file.
*/
error = 0;
}
} else {
}
return (error);
}
/*
* Override any spares and level 2 cache devices as specified by
*/
else
NV_UNIQUE_NAME, KM_SLEEP) == 0);
}
else
NV_UNIQUE_NAME, KM_SLEEP) == 0);
}
/*
* Update the config cache to include the newly-imported pool.
*/
}
return (0);
}
#ifdef _KERNEL
/*
* Build a "root" vdev for a top level vdev read in from a rootpool
* device label.
*/
static void
{
/*
* Add this top-level vdev to the child array.
*/
== 0);
== 0);
/*
* Put this pool's top-level vdevs into a root vdev.
*/
== 0);
&nvtop, 1) == 0);
/*
* Replace the existing vdev_tree with the new root vdev in
* this pool's configuration (remove the old, add the new).
*/
}
/*
* Get the root pool information from the root disk, then import the root pool
* during the system boot up time.
*/
extern int vdev_disk_read_rootlabel(char *, char *, nvlist_t **);
int
{
int error;
return (error);
else
return (0);
}
{
return (B_FALSE);
return (B_TRUE);
}
/*
* Given the boot device's physical path or devid, check if the device
* is in a valid state. If so, return the configuration from the vdev
* label.
*/
int
{
char *type;
char *tmp;
int error;
*tmp = '\0';
return (error);
}
if (txg == 0) {
return (EINVAL);
}
&nvtop) == 0);
if (spa_rootdev_validate(nvtop)) {
goto out;
} else {
return (EINVAL);
}
}
/*
* Go thru vdevs in the mirror to see if the given device
* has the most recent txg. Only the device with the most
* recent txg has valid information and should be booted.
*/
for (c = 0; c < children; c++) {
&cpath) != 0)
return (EINVAL);
&cdevid) != 0)
return (EINVAL);
ZPOOL_CONFIG_PATH, &bootpath) == 0);
}
}
/* Does the best device match the one we've booted from? */
if (bootpath) {
return (EINVAL);
}
out:
return (0);
}
/*
* Import a root pool.
*
* The GRUB "findroot" command will return the vdev we should boot.
*
* For Sparc, devpath_list consists the physpath name of the booting device
* no matter the rootpool is a single device pool or a mirrored pool.
* e.g.
*/
int
{
char *pname;
int error;
/*
* Get the vdev pathname and configuation from the most
* recently updated vdev (highest txg).
*/
goto msg_out;
/*
* Add type "root" vdev to the config.
*/
/*
* We specify 'allowfaulted' for this to be treated like spa_open()
* instead of spa_import(). This prevents us from marking vdevs as
* persistently unavailable, and generates FMA ereports as if it were a
* pool open, not import.
*/
error = 0;
return (error);
" *************************************************** \n"
" * This device is not bootable! * \n"
" * It is either offlined or detached or faulted. * \n"
" * Please try to boot from a different device. * \n"
" *************************************************** ");
return (error);
}
#endif
/*
* Import a non-root pool into the system.
*/
int
{
}
int
{
}
/*
* 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);
/*
* If the bootfs property exists on this pool then we
* copy it out so that external consumers can tell which
* pools are bootable.
*/
if (spa->spa_bootfs) {
/*
* We have to play games with the name since the
* pool was opened as TRYIMPORT_NAME.
*/
char *cp;
} else {
}
ZPOOL_CONFIG_BOOTFS, dsname) == 0);
}
}
/*
* Add the list of hot spares and level 2 cache devices.
*/
}
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);
}
/*
* A pool cannot be exported if it has an active shared spare.
* This is to prevent other pools stealing the active spare
* from an exported pool. At user's own will, such pool can
* be forcedly exported.
*/
return (EXDEV);
}
/*
* 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
{
B_FALSE));
}
/*
* ==========================================================================
* Device manipulation
* ==========================================================================
*/
/*
* Add a device to a storage pool.
*/
int
{
int c, error;
VDEV_ALLOC_ADD)) != 0)
&nspares) != 0)
nspares = 0;
&nl2cache) != 0)
nl2cache = 0;
}
if (vd->vdev_children != 0) {
}
}
/*
* We must validate the spares and l2cache devices after checking the
* children. Otherwise, vdev_inuse() will blindly overwrite the spare.
*/
}
/*
* Transfer each new top-level vdev from vd to rvd.
*/
for (c = 0; c < vd->vdev_children; c++) {
}
if (nspares != 0) {
}
if (nl2cache != 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 newvd_isspare;
int error;
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.
*/
CRED(), "%s vdev=%s %s vdev=%s",
} else {
}
/*
* Kick off a resilver to update newvd.
*/
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 second disk from a replacing vdev, then
* check to see if we changed the original vdev's path to have "/old"
* at the end in spa_vdev_attach(). If so, undo that change now.
*/
}
}
/*
* 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 spares vdev from the nvlist config.
*/
static int
{
int i, j;
for (i = 0; i < nspares; i++) {
ZPOOL_CONFIG_GUID, &theguid) == 0);
break;
}
}
/*
* Only remove the hot spare if it's not currently in use in this pool.
*/
return (ENOENT);
return (ENOTSUP);
return (EBUSY);
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]);
return (0);
}
/*
* Remove an l2cache vdev from the nvlist config.
*/
static int
{
int i, j;
for (i = 0; i < nl2cache; i++) {
ZPOOL_CONFIG_GUID, &theguid) == 0);
break;
}
}
for (i = 0; i < nl2cache; i++) {
break;
}
}
}
return (ENOENT);
return (ENOTSUP);
if (nl2cache == 1) {
newl2cache = NULL;
} else {
KM_SLEEP);
for (i = 0, j = 0; i < nl2cache; i++) {
&newl2cache[j++], KM_SLEEP) == 0);
}
}
DATA_TYPE_NVLIST_ARRAY) == 0);
for (i = 0; i < nl2cache - 1; i++)
nvlist_free(newl2cache[i]);
return (0);
}
/*
* Remove a device from the pool. Currently, this supports removing only hot
* spares and level 2 ARC devices.
*/
int
{
int error = 0;
goto cache;
goto out;
}
goto out;
}
out:
return (error);
}
/*
* 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 device. If
* it is, update the path manually as there is no associated
* vdev_t that can be synced to disk.
*/
for (i = 0; i < nspares; i++) {
ZPOOL_CONFIG_GUID, &theguid) == 0);
ZPOOL_CONFIG_PATH, newpath) == 0);
0));
}
}
}
}
}
/*
* ==========================================================================
* SPA Scrubbing
* ==========================================================================
*/
int
{
return (ENOTSUP);
/*
* If a resilver was requested, but there is no DTL on a
* writeable leaf device, we have nothing to do.
*/
if (type == POOL_SCRUB_RESILVER &&
return (0);
}
if (type == POOL_SCRUB_EVERYTHING &&
return (EBUSY);
} else if (type == POOL_SCRUB_NONE) {
} else {
return (EINVAL);
}
}
/*
* ==========================================================================
* SPA async task processing
* ==========================================================================
*/
static void
{
int c;
if (vd->vdev_remove_wanted) {
vd->vdev_remove_wanted = 0;
}
for (c = 0; c < vd->vdev_children; c++)
}
static void
{
int tasks, i;
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.
*
* XXX - We avoid doing this when we are in
* I/O failure state since spa_vdev_enter() grabs
* the namespace lock and would not be able to obtain
* the writer config lock.
*/
if (tasks & SPA_ASYNC_REMOVE &&
}
/*
* If any devices are done replacing, detach them.
*/
if (tasks & SPA_ASYNC_RESILVER_DONE)
/*
* 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
{
/*
* Write full (SPA_CONFIG_BLOCKSIZE) blocks of configuration
* information. This avoids the dbuf_will_dirty() path and
* saves us a pre-read to get data we don't actually care about.
*/
KM_SLEEP) == 0);
}
static void
{
int i;
return;
/*
* Update the MOS nvlist describing the list of available devices.
* spa_validate_aux() will have already made sure this nvlist is
* valid and the vdevs are labeled appropriately.
*/
if (sav->sav_object == 0) {
}
} else {
nvlist_free(list[i]);
}
}
static void
{
return;
if (spa->spa_config_syncing)
}
/*
* Set zpool properties.
*/
static void
{
char *strval;
const char *propname;
case ZPOOL_PROP_VERSION:
/*
* Only set version for non-zpool-creation cases
* for version setting.
*/
&intval) == 0);
}
break;
case ZPOOL_PROP_ALTROOT:
/*
* 'altroot' is a non-persistent property. It should
* have been set temporarily at creation or import time.
*/
break;
case ZPOOL_PROP_CACHEFILE:
/*
* 'cachefile' is a non-persistent property, but note
* an async request that the config cache needs to be
* udpated.
*/
KM_SLEEP);
if (strval[0] == '\0')
else
break;
default:
/*
* Set pool property values in the poolprops mos object.
*/
if (spa->spa_pool_props_object == 0) {
DMU_OT_NONE, 0, tx)) > 0);
== 0);
}
/* normalize the property name */
if (proptype == PROP_TYPE_INDEX) {
const char *unused;
}
} else {
ASSERT(0); /* not allowed */
}
switch (prop) {
case ZPOOL_PROP_DELEGATION:
break;
case ZPOOL_PROP_BOOTFS:
break;
case ZPOOL_PROP_FAILUREMODE:
break;
default:
break;
}
}
/* log internal history if this is not a zpool create */
}
}
}
/*
* 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) {
}
}
/* Keeping the origin open increases spa_minref */
}
}
/*
* 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 no dirty vdevs, we sync the uberblock to a few
* random top-level vdevs that are known to be visible in the
* config cache (see spa_vdev_add() for details). If there *are*
* dirty vdevs -- or if the sync to our random subset fails --
* then sync the uberblock to all vdevs.
*/
int svdcount = 0;
int c;
for (c = 0; c < children; c++) {
continue;
if (svdcount == SPA_DVAS_PER_BP)
break;
}
} else {
}
/*
* Clear the dirty config list.
*/
/*
* Now that the new config has synced transactionally,
* let it become visible to the config cache.
*/
}
/*
* 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 *
{
int i;
return (vd);
if (l2cache) {
return (vd);
}
}
return (NULL);
}
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;
return (B_TRUE);
for (i = 0; i < sav->sav_npending; i++) {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Check if a pool has an active shared spare device.
* Note: reference count of an active spare is 2, as a spare and as a replace
*/
static boolean_t
{
int i, refcnt;
refcnt > 2)
return (B_TRUE);
}
return (B_FALSE);
}
/*
* 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;
}
}
goto done;
done:
if (attr)
#endif
}