zio_inject.c revision 9b3f6b4237fa1168168cca4bdc5c2a8045642bb4
/*
* 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.
*/
/*
* ZFS fault injection
*
* To handle fault injection, we keep track of a series of zinject_record_t
* structures which describe which logical block(s) should be injected with a
* fault. These are kept in a global list. Each record corresponds to a given
* spa_t and maintains a special hold on the spa_t so that it cannot be deleted
* or exported while the injection record exists.
*
* Device level injection is done using the 'zi_guid' field. If this is set, it
* means that the error is destined for a particular device, not a piece of
* data.
*
* This is a rather poor data structure and algorithm, but we don't expect more
* than a few faults at any one time, so it should be sufficient for our needs.
*/
#include <sys/zio_impl.h>
#include <sys/zfs_ioctl.h>
#include <sys/spa_impl.h>
#include <sys/vdev_impl.h>
typedef struct inject_handler {
int zi_id;
static list_t inject_handlers;
static krwlock_t inject_lock;
static int inject_next_id = 1;
/*
* Returns true if the given record matches the I/O in progress.
*/
static boolean_t
{
/*
* Check for a match against the MOS, which is based on type
*/
else
return (B_FALSE);
}
/*
* Check for an exact match.
*/
return (B_FALSE);
}
/*
* Determine if the I/O in question should return failure. Returns the errno
* to be returned to the caller.
*/
int
{
int ret = 0;
/*
* Ignore I/O not associated with any logical data.
*/
return (0);
/*
* Currently, we only support fault injection on reads.
*/
return (0);
/* Ignore errors not destined for this pool */
continue;
/* Ignore device errors */
continue;
/* If this handler matches, return EIO */
break;
}
}
return (ret);
}
/*
* Determine if the zio is part of a label update and has an injection
* handler associated with that portion of the label. Currently, we
* allow error injection in either the nvlist or the uberblock region of
* of the vdev label.
*/
int
{
int label;
int ret = 0;
/*
*/
return (0);
return (0);
/* Ignore device only faults */
continue;
/*
* The injection region is the relative offsets within a
* vdev label. We must determine the label which is being
* updated and adjust our region accordingly.
*/
break;
}
}
return (ret);
}
int
{
int ret = 0;
/* Ignore label specific faults */
continue;
/*
* For a failed open, pretend like the device
* has gone away.
*/
break;
}
break;
}
}
}
return (ret);
}
/*
* Create a new handler for the given record. We add it to the list, adding
* a reference to the spa_t in the process. We increment zio_injection_enabled,
* which is the switch to trigger all fault injection.
*/
int
{
int error;
/*
* If this is pool-wide metadata, make sure we unload the corresponding
* spa_t, so that the next attempt to load it will trigger the fault.
* We call spa_reset() to unload the pool appropriately.
*/
if (flags & ZINJECT_UNLOAD_SPA)
return (error);
if (!(flags & ZINJECT_NULL)) {
/*
* spa_inject_ref() will add an injection reference, which will
* prevent the pool from being removed from the namespace while
* still allowing it to be unloaded.
*/
return (ENOENT);
}
/*
* Flush the ARC, so that any attempts to read this data will end up
* going to the ZIO layer. Note that this is a little overkill, but
* we don't have the necessary ARC interfaces to do anything else, and
* fault injection isn't a performance critical path.
*/
if (flags & ZINJECT_FLUSH_ARC)
return (0);
}
/*
* Returns the next record with an ID greater than that supplied to the
* function. Used to iterate over all handlers in the system.
*/
int
{
int ret;
break;
if (handler) {
ret = 0;
} else {
}
return (ret);
}
/*
* Clear the fault handler with the given identifier, or return ENOENT if none
* exists.
*/
int
zio_clear_fault(int id)
{
int ret;
break;
} else {
ret = 0;
}
return (ret);
}
void
zio_inject_init(void)
{
}
void
zio_inject_fini(void)
{
}