vdev_mirror.c revision 44f6db2a0fe79c85c9bc27afe1cbf5f7c12006e0
/*
* 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.
*/
#include <sys/zfs_context.h>
#include <sys/vdev_impl.h>
/*
* Virtual device vector for mirroring.
*/
typedef struct mirror_child {
int mc_error;
short mc_tried;
short mc_skipped;
typedef struct mirror_map {
int mm_children;
int mm_replacing;
int mm_preferred;
int mm_root;
} mirror_map_t;
int vdev_mirror_shift = 21;
static mirror_map_t *
{
int c, d;
mm->mm_children = c;
/*
* Check the other, lower-index DVAs to see if they're on
* the same vdev as the child we picked. If they are, use
* them since they are likely to have been allocated from
* the primary metaslab in use at the time, and hence are
* more likely to have locality with single-copy data.
*/
mm->mm_preferred = d;
}
for (c = 0; c < mm->mm_children; c++) {
}
} else {
c = vd->vdev_children;
mm->mm_children = c;
for (c = 0; c < mm->mm_children; c++) {
}
}
return (mm);
}
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
{
mc->mc_skipped = 0;
}
static void
{
}
mc->mc_skipped = 0;
}
static void
{
}
/*
* 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;
/*
* 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_readable() returning B_FALSE), don't even try.
*/
if (c >= mm->mm_children)
c = 0;
continue;
continue;
}
return (c);
}
/*
* Every device is either missing or has this txg in its DTL.
* Look for any child we haven't already tried before giving up.
*/
for (c = 0; c < mm->mm_children; c++)
return (c);
/*
* Every child failed. There's no place left to look.
*/
return (-1);
}
static int
{
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 < mm->mm_children; c++) {
}
return (zio_wait_for_children_done(zio));
}
/*
* 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++;
}
return (zio_wait_for_children_done(zio));
}
static int
{
int c;
int good_copies = 0;
int unexpected_errors = 0;
zio->io_numerrors = 0;
for (c = 0; c < mm->mm_children; c++) {
good_copies++;
continue;
}
/*
* There's a hierachy of errors:
* EIO > other errors > ENXIO > 0
*
* We preserve any EIOs because those may be worth retrying;
* whereas ECKSUM and ENXIO are more likely to be persistent.
*
* ENXIO should only be reported as an error in a mirror
* if all children report ENXIO;
*/
}
if (!mc->mc_skipped)
zio->io_numerrors++;
}
}
/*
* XXX -- for now, treat partial writes as success.
* XXX -- For a replacing vdev, we need to make sure the
* new child succeeds.
*/
/* XXPOLICY */
if (good_copies != 0)
return (ZIO_PIPELINE_CONTINUE);
}
/*
* If we don't have a good copy yet, keep trying other children.
*/
/* XXPOLICY */
dprintf("retrying i/o (err=%d) on child %s\n",
return (zio_wait_for_children_done(zio));
}
/* XXPOLICY */
if (good_copies)
else
/*
* Use the good data we have in hand to repair damaged children.
*
* that vdev_mirror_map_free(zio) will be invoked after all
* repairs complete, but before we advance to the next stage.
*/
for (c = 0; c < mm->mm_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("resilvered %s @ 0x%llx error %d\n",
}
return (zio_wait_for_children_done(zio));
}
return (ZIO_PIPELINE_CONTINUE);
}
static void
{
else
}
NULL,
VDEV_TYPE_MIRROR, /* name of this vdev type */
B_FALSE /* not a leaf vdev */
};
NULL,
VDEV_TYPE_REPLACING, /* name of this vdev type */
B_FALSE /* not a leaf vdev */
};
NULL,
VDEV_TYPE_SPARE, /* name of this vdev type */
B_FALSE /* not a leaf vdev */
};