vdev.c revision 0e34b6a7bff4918432f0aa6b1dfaf73ac9df45b1
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/zfs_context.h>
#include <sys/spa_impl.h>
#include <sys/vdev_impl.h>
#include <sys/uberblock_impl.h>
#include <sys/metaslab.h>
#include <sys/metaslab_impl.h>
#include <sys/space_map.h>
/*
* Virtual device management.
*/
static vdev_ops_t *vdev_ops_table[] = {
};
/*
* Given a vdev type, return the appropriate ops vector.
*/
static vdev_ops_t *
vdev_getops(const char *type)
{
break;
return (ops);
}
/*
* Default asize function: return the MAX of psize with the asize of
* all children. This is what's used by anything other than RAID-Z.
*/
{
uint64_t c;
for (c = 0; c < vd->vdev_children; c++) {
}
return (asize);
}
/*
* Get the replaceable or attachable device size.
* If the parent is a mirror or raidz, the replaceable size is the minimum
* psize of all its children. For the rest, just return our own psize.
*
* e.g.
* psize rsize
* root - -
* disk1 20g 20g
* disk2 40g 20g
* disk3 80g 80g
*/
{
/*
* If our parent is NULL or the root, just return our own psize.
*/
return (vd->vdev_psize);
rsize = 0;
for (c = 0; c < pvd->vdev_children; c++) {
}
return (rsize);
}
vdev_t *
{
return (NULL);
}
vdev_t *
{
int c;
return (vd);
for (c = 0; c < vd->vdev_children; c++)
NULL)
return (mvd);
return (NULL);
}
void
{
return;
}
/*
* Walk up all ancestors to update guid sum.
*/
}
void
{
int c;
return;
for (c = 0; c < pvd->vdev_children; c++)
if (pvd->vdev_child[c])
break;
if (c == pvd->vdev_children) {
pvd->vdev_children = 0;
}
/*
* Walk up all ancestors to update guid sum.
*/
}
/*
* Remove any holes in the child array.
*/
void
{
int newc, c;
if (pvd->vdev_child[c])
newc++;
}
}
}
/*
* Allocate and minimally initialize a vdev_t.
*/
static vdev_t *
{
}
if (guid == 0) {
/*
* The root vdev's guid will also be the pool guid,
* which must be unique among all pools.
*/
} else {
/*
* Any other vdev's guid must be unique within the pool.
*/
while (guid == 0 ||
}
}
return (vd);
}
/*
* Free a vdev_t that has been removed from service.
*/
static void
{
if (vd->vdev_devid)
}
/*
* Allocate a new vdev. The 'alloctype' is used to control whether we are
* creating a new vdev or loading an existing one - the behavior is slightly
* different for each case.
*/
vdev_t *
{
char *type;
return (NULL);
return (NULL);
/*
* If this is a load, get the vdev guid from the nvlist.
* Otherwise, vdev_alloc_common() will generate one for us.
*/
if (alloctype == VDEV_ALLOC_LOAD) {
return (NULL);
return (NULL);
}
/*
* Set the whole_disk property. If it's not specified, leave the value
* as -1.
*/
&vd->vdev_wholedisk) != 0)
/*
* Look for the 'not present' flag. This will only be set if the device
* was not present at the time of import.
*/
&vd->vdev_not_present);
/*
* If we're a top-level vdev, try to load the allocation parameters.
*/
&vd->vdev_ms_array);
&vd->vdev_ms_shift);
&vd->vdev_ashift);
&vd->vdev_asize);
}
/*
* If we're a leaf vdev, try to load the DTL object
* and the offline state.
*/
== 0)
}
/*
* Add ourselves to the parent's list of children.
*/
return (vd);
}
void
{
int c;
/*
* vdev_free() implies closing the vdev first. This is simpler than
* trying to ensure complicated semantics for all callers.
*/
vdev_close(vd);
/*
* It's possible to free a vdev that's been added to the dirty
* list when in the middle of spa_vdev_add(). Handle that case
* correctly here.
*/
if (vd->vdev_is_dirty)
/*
* Free all children.
*/
for (c = 0; c < vd->vdev_children; c++)
/*
* Discard allocation state.
*/
/*
* Remove this vdev from its parent's child list.
*/
}
/*
* Transfer top-level vdev state from svd to tvd.
*/
static void
{
int t;
svd->vdev_ms_array = 0;
svd->vdev_ms_shift = 0;
svd->vdev_ms_count = 0;
for (t = 0; t < TXG_SIZE; t++) {
svd->vdev_dirty[t] = 0;
}
if (svd->vdev_is_dirty) {
}
svd->vdev_reopen_wanted = 0;
}
static void
{
int c;
return;
for (c = 0; c < vd->vdev_children; c++)
}
/*
*/
vdev_t *
{
return (mvd);
}
/*
*/
void
{
}
int
{
uint64_t c;
int ret;
return (0);
if (txg == 0) {
KM_SLEEP);
vd->vdev_ms_array, 0,
goto error;
}
for (c = 0; c < newc; c++) {
if (ms_array[c] == 0)
continue;
if ((ret = dmu_bonus_hold(
goto error;
}
ms_array[c]);
}
}
}
for (c = 0; c < oldc; c++) {
}
if (oldc != 0) {
}
return (0);
/*
* On error, undo any partial progress we may have made, and restore the
* old metaslab values.
*/
return (ret);
}
void
{
uint64_t m;
for (m = 0; m < count; m++)
}
}
}
/*
* Prepare a virtual device for access.
*/
int
{
int error;
int c;
else
}
}
if (vd->vdev_offline) {
return (ENXIO);
}
if (zio_injection_enabled && error == 0)
dprintf("%s = %d, osize %llu, state = %d\n",
if (error) {
return (error);
}
for (c = 0; c < vd->vdev_children; c++)
break;
}
if (vd->vdev_children == 0) {
if (osize < SPA_MINDEVSIZE) {
return (EOVERFLOW);
}
} else {
if (osize < SPA_MINDEVSIZE -
return (EOVERFLOW);
}
psize = 0;
}
if (vd->vdev_asize == 0) {
/*
* This is the first-ever open, so use the computed values.
*/
} else {
/*
* Make sure the alignment requirement hasn't increased.
*/
return (EINVAL);
}
/*
* Make sure the device hasn't shrunk.
*/
return (EINVAL);
}
/*
* If all children are healthy and the asize has increased,
* then we've experienced dynamic LUN growth.
*/
}
}
/*
* If we were able to open a vdev that was marked permanently
* unavailable, clear that state now.
*/
if (vd->vdev_not_present)
vd->vdev_not_present = 0;
/*
* This allows the ZFS DE to close cases appropriately. If a device
* goes away and later returns, we want to close the associated case.
* But it's not enough to simply post this only when a device goes from
* CANT_OPEN -> HEALTHY. If we reboot the system and the device is
* back, we also need to close the case (otherwise we will try to replay
* it). So we have to post this notifier every time. Since this only
* occurs during pool open or error recovery, this should not be an
* issue.
*/
return (0);
}
/*
* Close a virtual device.
*/
void
{
if (vd->vdev_cache_active) {
}
if (vd->vdev_offline)
else
}
void
{
int c;
for (c = 0; c < rvd->vdev_children; c++)
return;
}
/* only valid for top-level vdevs */
vdev_close(vd);
/*
* Reassess root vdev's health.
*/
for (c = 0; c < rvd->vdev_children; c++) {
}
}
int
{
int error;
/*
* Normally, partial opens (e.g. of a mirror) are allowed.
* For a create, however, we want to fail the request if
* there are any components we can't open.
*/
vdev_close(vd);
}
/*
* Recursively initialize all labels.
*/
vdev_close(vd);
return (error);
}
return (0);
}
/*
* The is the latter half of vdev_create(). It is distinct because it
* involves initiating transactions in order to do metaslab creation.
* For creation, we want to try to create all vdevs at once and then undo it
* if anything fails; this is much harder if we have pending transactions.
*/
void
{
/*
* Aim for roughly 200 metaslabs per vdev.
*/
/*
* Initialize the vdev's metaslabs. This can't fail because
* there's nothing to read when creating all new metaslabs.
*/
}
void
{
}
}
void
{
}
int
{
int dirty;
/*
* Quick test without the lock -- covers the common case that
* there are no dirty time segments.
*/
return (0);
return (dirty);
}
/*
* Reassess DTLs after a config change or scrub completion.
*/
void
{
int c;
if (vd->vdev_children == 0) {
/*
* We're successfully scrubbed everything up to scrub_txg.
* Therefore, excise all old DTLs up to that point, then
* fold in the DTLs for everything we couldn't scrub.
*/
if (scrub_txg != 0) {
}
if (scrub_done)
if (txg != 0) {
}
return;
}
/*
* Make sure the DTLs are always correct under the scrub lock.
*/
for (c = 0; c < vd->vdev_children; c++) {
}
}
static int
{
int error;
if (smo->smo_object == 0)
return (0);
return (error);
return (error);
}
void
{
dprintf("%s in txg %llu pass %d\n",
if (vd->vdev_detached) {
if (smo->smo_object != 0) {
smo->smo_object = 0;
}
return;
}
if (smo->smo_object == 0) {
}
&smlock);
smo->smo_objsize = 0;
mutex_exit(&smlock);
}
int
{
int c, error;
/*
* Recursively load all children.
*/
for (c = 0; c < vd->vdev_children; c++)
return (error);
/*
* If this is a leaf vdev, make sure its agrees with its disk labels.
*/
if (vdev_is_dead(vd))
return (0);
/*
* XXX state transitions don't propagate to parent here.
* Also, merely setting the state isn't sufficient because
* it's not persistent; a vdev_reopen() would make us
* forget all about it.
*/
dprintf("can't load label config\n");
return (0);
}
return (0);
}
dprintf("bad or missing vdev guid (%llu != %llu)\n",
return (0);
}
/*
* If we find a vdev with a matching pool guid and vdev guid,
* but the pool state is not active, it indicates that the user
* exported or destroyed the pool without affecting the config
* cache (if / was mounted readonly, for example). In this
* case, immediately return EBADF so the caller can remove it
* from the config.
*/
&state)) {
dprintf("missing pool state\n");
return (0);
}
if (state != POOL_STATE_ACTIVE &&
state != POOL_STATE_EXPORTED)) {
return (EBADF);
}
}
/*
* If this is a top-level vdev, initialize its metaslabs.
*/
return (0);
}
return (0);
}
}
/*
* If this is a leaf vdev, load its DTL.
*/
if (error) {
dprintf("can't load DTL for %s, error %d\n",
return (0);
}
}
return (0);
}
void
{
}
void
{
if (vd->vdev_ms_array == 0)
}
void
{
dprintf("%s txg %llu pass %d\n",
}
{
}
void
{
}
void
{
}
const char *
{
return ("<unknown>");
}
int
{
return (0);
}
int
{
/* vdev is already offlined, do nothing */
if (vd->vdev_offline)
/*
* If this device's top-level vdev has a non-empty DTL,
* don't allow the device to be offlined.
*
* XXX -- we should make this more precise by allowing the offline
* as long as the remaining devices don't have any DTL holes.
*/
/*
* Set this device to offline state and reopen its top-level vdev.
* If this action results in the top-level vdev becoming unusable,
* undo it and fail the request.
*/
}
if (!istmp)
}
/*
* Clear the error counts associated with this vdev. Unlike vdev_online() and
* vdev_offline(), we assume the spa config is locked. We also clear all
* children. If 'vd' is NULL, then the user wants to clear all vdevs.
*/
void
{
int c;
for (c = 0; c < vd->vdev_children; c++)
}
int
{
}
int
{
int error = 0;
return (0);
return (0);
switch (vd->vdev_fault_mode) {
case VDEV_FAULT_RANDOM:
break;
case VDEV_FAULT_COUNT:
break;
}
if (error != 0) {
dprintf("returning %d for type %d on %s state %d offset %llx\n",
}
return (error);
}
/*
* Get statistics for the given vdev.
*/
void
{
int c, t;
/*
* If we're getting stats on the root vdev, aggregate the I/O counts
* over all top-level vdevs (i.e. the direct children of the root).
*/
for (c = 0; c < rvd->vdev_children; c++) {
for (t = 0; t < ZIO_TYPES; t++) {
}
}
}
}
void
{
if (!(flags & ZIO_FLAG_IO_BYPASS)) {
}
if ((flags & ZIO_FLAG_IO_REPAIR) &&
else
}
return;
}
if (flags & ZIO_FLAG_SPECULATIVE)
return;
if (!vdev_is_dead(vd)) {
if (type == ZIO_TYPE_READ) {
vs->vs_checksum_errors++;
else
vs->vs_read_errors++;
}
if (type == ZIO_TYPE_WRITE)
vs->vs_write_errors++;
}
if (type == ZIO_TYPE_WRITE) {
return;
}
if (!(flags & ZIO_FLAG_IO_REPAIR)) {
return;
}
}
}
void
{
int c;
for (c = 0; c < vd->vdev_children; c++)
if (type == POOL_SCRUB_NONE) {
/*
* Update completion and end time. Leave everything else alone
* so we can report what happened during the previous scrub.
*/
} else {
vs->vs_scrub_complete = 0;
vs->vs_scrub_examined = 0;
vs->vs_scrub_repaired = 0;
vs->vs_scrub_errors = 0;
vs->vs_scrub_end = 0;
}
}
/*
* Update the in-core space usage stats for this vdev and the root vdev.
*/
void
{
do {
}
/*
* Various knobs to tune a vdev.
*/
static vdev_knob_t vdev_knob[] = {
{
"cache_size",
"size of the read-ahead cache",
0,
1ULL << 30,
10ULL << 20,
},
{
"cache_bshift",
"log2 of cache blocksize",
16,
},
{
"cache_max",
"largest block size to cache",
0,
1ULL << 14,
},
{
"min_pending",
1,
10000,
2,
},
{
"max_pending",
1,
10000,
35,
},
{
"scrub_limit",
0,
10000,
70,
},
{
"agg_limit",
0,
},
{
"time_shift",
"deadline = pri + (lbolt >> time_shift)",
0,
63,
4,
},
{
"ramp_rate",
"exponential I/O issue ramp-up rate",
1,
10000,
2,
},
};
{
return (vdev_knob);
return (NULL);
return (vk);
}
/*
* Mark a top-level vdev's config as dirty, placing it on the dirty list
* so that it will be written out next time the vdev configuration is synced.
* If the root vdev is specified (vdev_top == NULL), dirty all top-level vdevs.
*/
void
{
int c;
for (c = 0; c < rvd->vdev_children; c++)
} else {
if (!vd->vdev_is_dirty) {
}
}
}
void
{
}
/*
* Set a vdev's state. If this is during an open, we don't update the parent
* state, because we're in the process of opening children depth-first.
* Otherwise, we propagate the change to the parent.
*
* If this routine places a device in a faulted state, an appropriate ereport is
* generated.
*/
void
{
return;
}
if (state == VDEV_STATE_CANT_OPEN) {
/*
* If we fail to open a vdev during an import, we mark it as
* "not available", which signifies that it was never there to
* begin with. Failure to open such a device is not considered
* an error.
*/
if (!vd->vdev_not_present &&
const char *class;
switch (aux) {
case VDEV_AUX_OPEN_FAILED:
break;
case VDEV_AUX_CORRUPT_DATA:
break;
case VDEV_AUX_NO_REPLICAS:
break;
case VDEV_AUX_BAD_GUID_SUM:
break;
case VDEV_AUX_TOO_SMALL:
break;
case VDEV_AUX_BAD_LABEL:
break;
default:
}
}
}
if (isopen)
return;
int c;
int corrupted = 0;
for (c = 0; c < parent->vdev_children; c++) {
faulted++;
degraded++;
corrupted++;
}
/*
* Root special: if this is a toplevel vdev that cannot be
* opened due to corrupted metadata, then propagate the root
* vdev's aux state as 'corrupt' rather than 'insufficient
* replicas'.
*/
}
}