vdev_mirror.c revision ea8dc4b6d2251b437950c0056bc626b311c73c27
/*
* 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/vdev_impl.h>
/*
* Virtual device vector for mirroring.
*/
typedef struct mirror_map {
int mm_error;
short mm_tried;
short mm_skipped;
} mirror_map_t;
static mirror_map_t *
{
sizeof (mirror_map_t), KM_SLEEP);
}
static void
{
}
static int
{
uint64_t c;
int numerrors = 0;
if (vd->vdev_children == 0) {
return (EINVAL);
}
for (c = 0; c < vd->vdev_children; c++) {
numerrors++;
continue;
}
}
return (lasterror);
}
return (0);
}
static void
{
uint64_t c;
for (c = 0; c < vd->vdev_children; c++)
}
static void
{
mm->mm_skipped = 0;
}
static void
{
}
mm->mm_skipped = 0;
}
/*
* Try to find a child whose DTL doesn't contain the block we want to read.
* If we can't, try the read on any vdev we haven't already tried.
*/
static int
{
int i, c;
/*
* Select the child we'd like to read from absent any errors.
* The current policy is to alternate sides at 8M granularity.
* XXX -- investigate other policies for read distribution.
*/
/*
* If this is a replacing vdev, always try child 0 (the source) first.
*/
c = 0;
/*
* Try to find a child whose DTL doesn't contain the block to read.
* If a child is known to be completely inaccessible (indicated by
* vdev_is_dead() returning B_TRUE), don't even try.
*/
for (i = 0; i < vd->vdev_children; i++, c++) {
if (c >= vd->vdev_children)
c = 0;
continue;
if (vdev_is_dead(cvd)) {
continue;
}
return (c);
}
/*
* Every device is either missing or has this txg in its DTL.
* If we don't have any sibling replicas to consult, look for
* any child we haven't already tried before giving up.
*/
for (c = 0; c < vd->vdev_children; c++) {
return (c);
}
}
/*
* Every child failed. There's no place left to look.
*/
return (-1);
}
static void
{
int c, children;
/*
* For scrubbing reads we need to allocate a read
* buffer for each child and issue reads to all
* children. If any child succeeds, it will copy its
* data into zio->io_data in vdev_mirror_scrub_done.
*/
for (c = 0; c < vd->vdev_children; c++) {
&mm[c]));
}
return;
}
/*
* For normal reads just pick one child.
*/
c = vdev_mirror_child_select(zio);
children = (c >= 0);
} else {
/*
* If this is a resilvering I/O to a replacing vdev,
* only the last child should be written -- unless the
* first child happens to have a DTL entry here as well.
* All other writes go to all children.
*/
children = 1;
} else {
c = 0;
}
}
while (children--) {
c++;
}
}
static void
{
int c;
int good_copies = 0;
int unexpected_errors = 0;
zio->io_numerrors = 0;
for (c = 0; c < vd->vdev_children; c++) {
good_copies++;
continue;
}
/*
* We preserve any EIOs because those may be worth retrying;
* whereas ECKSUM and ENXIO are more likely to be persistent.
*/
if (!mm[c].mm_skipped)
zio->io_numerrors++;
}
}
/*
* XXX -- for now, treat partial writes as success.
*/
/* XXPOLICY */
if (good_copies != 0)
return;
}
/*
* If we don't have a good copy yet, keep trying other children.
*/
/* XXPOLICY */
dprintf("%s: retrying i/o (err=%d) on child %s\n",
vdev_mirror_child_done, &mm[c]));
return;
}
/* XXPOLICY */
if (good_copies)
else
/*
* Use the good data we have in hand to repair damaged children.
*/
for (c = 0; c < vd->vdev_children; c++) {
/*
* Don't rewrite known good children.
* Not only is it unnecessary, it could
* actually be harmful: if the system lost
* power while rewriting the only good copy,
* there would be no good copies left!
*/
continue;
continue;
}
dprintf("%s resilvered %s @ 0x%llx error %d\n",
}
}
}
static void
{
else
}
VDEV_TYPE_MIRROR, /* name of this vdev type */
B_FALSE /* not a leaf vdev */
};
VDEV_TYPE_REPLACING, /* name of this vdev type */
B_FALSE /* not a leaf vdev */
};