2004-03-04 05:49:58 +03:00
|
|
|
/* $NetBSD: rf_copyback.c,v 1.28 2004/03/04 02:49:58 oster Exp $ */
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Mark Holland
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
2003-12-31 00:59:03 +03:00
|
|
|
/*****************************************************************************
|
1998-11-13 07:20:26 +03:00
|
|
|
*
|
|
|
|
* copyback.c -- code to copy reconstructed data back from spare space to
|
|
|
|
* the replaced disk.
|
|
|
|
*
|
2003-12-31 00:59:03 +03:00
|
|
|
* the code operates using callbacks on the I/Os to continue with the
|
|
|
|
* next unit to be copied back. We do this because a simple loop
|
|
|
|
* containing blocking I/Os will not work in the simulator.
|
1998-11-13 07:20:26 +03:00
|
|
|
*
|
2003-12-31 00:59:03 +03:00
|
|
|
****************************************************************************/
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2001-11-13 10:11:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-03-04 05:49:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: rf_copyback.c,v 1.28 2004/03/04 02:49:58 oster Exp $");
|
2001-11-13 10:11:12 +03:00
|
|
|
|
2001-10-04 19:58:51 +04:00
|
|
|
#include <dev/raidframe/raidframevar.h>
|
1999-01-26 05:33:49 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include "rf_raid.h"
|
|
|
|
#include "rf_mcpair.h"
|
|
|
|
#include "rf_acctrace.h"
|
|
|
|
#include "rf_etimer.h"
|
|
|
|
#include "rf_general.h"
|
|
|
|
#include "rf_utils.h"
|
|
|
|
#include "rf_copyback.h"
|
|
|
|
#include "rf_decluster.h"
|
|
|
|
#include "rf_driver.h"
|
|
|
|
#include "rf_shutdown.h"
|
2000-01-09 04:29:27 +03:00
|
|
|
#include "rf_kintf.h"
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
#define RF_COPYBACK_DATA 0
|
|
|
|
#define RF_COPYBACK_PARITY 1
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int rf_copyback_in_progress;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static int rf_CopybackReadDoneProc(RF_CopybackDesc_t * desc, int status);
|
|
|
|
static int rf_CopybackWriteDoneProc(RF_CopybackDesc_t * desc, int status);
|
2000-01-09 04:29:27 +03:00
|
|
|
static void rf_CopybackOne(RF_CopybackDesc_t * desc, int typ,
|
2003-12-29 05:38:17 +03:00
|
|
|
RF_RaidAddr_t addr, RF_RowCol_t testCol,
|
2000-01-09 04:29:27 +03:00
|
|
|
RF_SectorNum_t testOffs);
|
1999-02-05 03:06:06 +03:00
|
|
|
static void rf_CopybackComplete(RF_CopybackDesc_t * desc, int status);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_ConfigureCopyback(listp)
|
|
|
|
RF_ShutdownList_t **listp;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
rf_copyback_in_progress = 0;
|
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
2001-11-15 12:47:59 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
/* do a complete copyback */
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_CopybackReconstructedData(RF_Raid_t *raidPtr)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-03-02 06:18:48 +03:00
|
|
|
RF_ComponentLabel_t c_label;
|
2003-12-29 05:38:17 +03:00
|
|
|
int found, retcode;
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_CopybackDesc_t *desc;
|
2003-12-29 05:38:17 +03:00
|
|
|
RF_RowCol_t fcol;
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_RaidDisk_t *badDisk;
|
|
|
|
char *databuf;
|
|
|
|
|
|
|
|
struct partinfo dpart;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vattr va;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *proc;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2000-03-07 05:59:50 +03:00
|
|
|
int ac;
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
fcol = 0;
|
2003-12-29 05:38:17 +03:00
|
|
|
found = 0;
|
|
|
|
for (fcol = 0; fcol < raidPtr->numCol; fcol++) {
|
|
|
|
if (raidPtr->Disks[fcol].status == rf_ds_dist_spared
|
|
|
|
|| raidPtr->Disks[fcol].status == rf_ds_spared) {
|
|
|
|
found = 1;
|
1999-02-05 03:06:06 +03:00
|
|
|
break;
|
2003-12-29 05:38:17 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
if (!found) {
|
2002-11-16 19:49:46 +03:00
|
|
|
printf("raid%d: no disks need copyback\n", raidPtr->raidid);
|
1999-02-05 03:06:06 +03:00
|
|
|
return;
|
|
|
|
}
|
2003-12-29 05:38:17 +03:00
|
|
|
|
|
|
|
badDisk = &raidPtr->Disks[fcol];
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
proc = raidPtr->engine_thread;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
/* This device may have been opened successfully the first time. Close
|
|
|
|
* it before trying to open it again.. */
|
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
if (raidPtr->raid_cinfo[fcol].ci_vp != NULL) {
|
1999-02-05 03:06:06 +03:00
|
|
|
printf("Closed the open device: %s\n",
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[fcol].devname);
|
|
|
|
vp = raidPtr->raid_cinfo[fcol].ci_vp;
|
|
|
|
ac = raidPtr->Disks[fcol].auto_configured;
|
2000-03-07 05:59:50 +03:00
|
|
|
rf_close_component(raidPtr, vp, ac);
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->raid_cinfo[fcol].ci_vp = NULL;
|
2000-02-23 05:03:03 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
2000-02-23 05:03:03 +03:00
|
|
|
/* note that this disk was *not* auto_configured (any longer) */
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[fcol].auto_configured = 0;
|
2000-02-23 05:03:03 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
printf("About to (re-)open the device: %s\n",
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[fcol].devname);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
retcode = raidlookup(raidPtr->Disks[fcol].devname, proc, &vp);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
if (retcode) {
|
2002-11-16 19:49:46 +03:00
|
|
|
printf("raid%d: copyback: raidlookup on device: %s failed: %d!\n",
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->raidid, raidPtr->Disks[fcol].devname,
|
2002-11-16 19:49:46 +03:00
|
|
|
retcode);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
/* XXX the component isn't responding properly... must be
|
|
|
|
* still dead :-( */
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Ok, so we can at least do a lookup... How about actually
|
|
|
|
* getting a vp for it? */
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((retcode = VOP_GETATTR(vp, &va, proc->p_ucred, proc)) != 0) {
|
1999-02-05 03:06:06 +03:00
|
|
|
return;
|
|
|
|
}
|
2003-03-22 02:11:19 +03:00
|
|
|
retcode = VOP_IOCTL(vp, DIOCGPART, &dpart,
|
2003-06-30 02:28:00 +04:00
|
|
|
FREAD, proc->p_ucred, proc);
|
1999-02-05 03:06:06 +03:00
|
|
|
if (retcode) {
|
|
|
|
return;
|
|
|
|
}
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[fcol].blockSize = dpart.disklab->d_secsize;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[fcol].numBlocks = dpart.part->p_size -
|
1999-02-05 03:06:06 +03:00
|
|
|
rf_protectedSectors;
|
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->raid_cinfo[fcol].ci_vp = vp;
|
|
|
|
raidPtr->raid_cinfo[fcol].ci_dev = va.va_rdev;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[fcol].dev = va.va_rdev; /* XXX or the above? */
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
/* we allow the user to specify that only a fraction of the
|
|
|
|
* disks should be used this is just for debug: it speeds up
|
|
|
|
* the parity scan */
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[fcol].numBlocks =
|
|
|
|
raidPtr->Disks[fcol].numBlocks *
|
1999-02-05 03:06:06 +03:00
|
|
|
rf_sizePercentage / 100;
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
if (retcode) {
|
2002-11-16 19:49:46 +03:00
|
|
|
printf("raid%d: copyback: target disk failed TUR\n",
|
|
|
|
raidPtr->raidid);
|
1999-02-05 03:06:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* get a buffer to hold one SU */
|
|
|
|
RF_Malloc(databuf, rf_RaidAddressToByte(raidPtr, raidPtr->Layout.sectorsPerStripeUnit), (char *));
|
|
|
|
|
|
|
|
/* create a descriptor */
|
|
|
|
RF_Malloc(desc, sizeof(*desc), (RF_CopybackDesc_t *));
|
|
|
|
desc->raidPtr = raidPtr;
|
|
|
|
desc->status = 0;
|
|
|
|
desc->fcol = fcol;
|
|
|
|
desc->spCol = badDisk->spareCol;
|
|
|
|
desc->stripeAddr = 0;
|
|
|
|
desc->sectPerSU = raidPtr->Layout.sectorsPerStripeUnit;
|
|
|
|
desc->sectPerStripe = raidPtr->Layout.sectorsPerStripeUnit * raidPtr->Layout.numDataCol;
|
|
|
|
desc->databuf = databuf;
|
|
|
|
desc->mcpair = rf_AllocMCPair();
|
|
|
|
|
|
|
|
/* quiesce the array, since we don't want to code support for user
|
|
|
|
* accs here */
|
|
|
|
rf_SuspendNewRequestsAndWait(raidPtr);
|
|
|
|
|
|
|
|
/* adjust state of the array and of the disks */
|
|
|
|
RF_LOCK_MUTEX(raidPtr->mutex);
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[desc->fcol].status = rf_ds_optimal;
|
|
|
|
raidPtr->status = rf_rs_optimal;
|
1999-02-05 03:06:06 +03:00
|
|
|
rf_copyback_in_progress = 1; /* debug only */
|
|
|
|
RF_UNLOCK_MUTEX(raidPtr->mutex);
|
|
|
|
|
|
|
|
RF_GETTIME(desc->starttime);
|
|
|
|
rf_ContinueCopyback(desc);
|
1999-03-02 06:18:48 +03:00
|
|
|
|
|
|
|
/* Data has been restored. Fix up the component label. */
|
|
|
|
/* Don't actually need the read here.. */
|
2003-12-29 05:38:17 +03:00
|
|
|
raidread_component_label( raidPtr->raid_cinfo[fcol].ci_dev,
|
|
|
|
raidPtr->raid_cinfo[fcol].ci_vp,
|
1999-03-02 06:18:48 +03:00
|
|
|
&c_label);
|
2000-02-23 05:03:03 +03:00
|
|
|
|
|
|
|
raid_init_component_label( raidPtr, &c_label );
|
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
c_label.row = 0;
|
1999-03-02 06:18:48 +03:00
|
|
|
c_label.column = fcol;
|
2003-12-29 05:38:17 +03:00
|
|
|
c_label.partitionSize = raidPtr->Disks[fcol].partitionSize;
|
2000-02-23 05:03:03 +03:00
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
raidwrite_component_label( raidPtr->raid_cinfo[fcol].ci_dev,
|
|
|
|
raidPtr->raid_cinfo[fcol].ci_vp,
|
1999-03-02 06:18:48 +03:00
|
|
|
&c_label);
|
2002-11-15 06:57:48 +03:00
|
|
|
rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* invoked via callback after a copyback I/O has completed to
|
|
|
|
* continue on with the next one
|
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_ContinueCopyback(RF_CopybackDesc_t *desc)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_SectorNum_t testOffs, stripeAddr;
|
|
|
|
RF_Raid_t *raidPtr = desc->raidPtr;
|
|
|
|
RF_RaidAddr_t addr;
|
2003-12-29 05:38:17 +03:00
|
|
|
RF_RowCol_t testCol;
|
2002-09-17 07:30:33 +04:00
|
|
|
#if RF_DEBUG_RECON
|
|
|
|
int old_pctg, new_pctg;
|
1999-02-05 03:06:06 +03:00
|
|
|
struct timeval t, diff;
|
2002-09-17 07:30:33 +04:00
|
|
|
#endif
|
|
|
|
int done;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2002-09-17 07:30:33 +04:00
|
|
|
#if RF_DEBUG_RECON
|
1999-02-05 03:06:06 +03:00
|
|
|
old_pctg = (-1);
|
2002-09-17 07:30:33 +04:00
|
|
|
#endif
|
1999-02-05 03:06:06 +03:00
|
|
|
while (1) {
|
|
|
|
stripeAddr = desc->stripeAddr;
|
2000-01-05 05:57:28 +03:00
|
|
|
desc->raidPtr->copyback_stripes_done = stripeAddr
|
|
|
|
/ desc->sectPerStripe;
|
2002-09-17 07:30:33 +04:00
|
|
|
#if RF_DEBUG_RECON
|
1999-02-05 03:06:06 +03:00
|
|
|
if (rf_prReconSched) {
|
|
|
|
old_pctg = 100 * desc->stripeAddr / raidPtr->totalSectors;
|
|
|
|
}
|
2002-09-17 07:30:33 +04:00
|
|
|
#endif
|
1999-02-05 03:06:06 +03:00
|
|
|
desc->stripeAddr += desc->sectPerStripe;
|
2002-09-17 07:30:33 +04:00
|
|
|
#if RF_DEBUG_RECON
|
1999-02-05 03:06:06 +03:00
|
|
|
if (rf_prReconSched) {
|
|
|
|
new_pctg = 100 * desc->stripeAddr / raidPtr->totalSectors;
|
|
|
|
if (new_pctg != old_pctg) {
|
|
|
|
RF_GETTIME(t);
|
|
|
|
RF_TIMEVAL_DIFF(&desc->starttime, &t, &diff);
|
|
|
|
printf("%d %d.%06d\n", new_pctg, (int) diff.tv_sec, (int) diff.tv_usec);
|
|
|
|
}
|
|
|
|
}
|
2002-09-17 07:30:33 +04:00
|
|
|
#endif
|
1999-02-05 03:06:06 +03:00
|
|
|
if (stripeAddr >= raidPtr->totalSectors) {
|
|
|
|
rf_CopybackComplete(desc, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* walk through the current stripe, su-by-su */
|
|
|
|
for (done = 0, addr = stripeAddr; addr < stripeAddr + desc->sectPerStripe; addr += desc->sectPerSU) {
|
|
|
|
|
|
|
|
/* map the SU, disallowing remap to spare space */
|
2003-12-29 05:38:17 +03:00
|
|
|
(raidPtr->Layout.map->MapSector) (raidPtr, addr, &testCol, &testOffs, RF_DONT_REMAP);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
if (testCol == desc->fcol) {
|
|
|
|
rf_CopybackOne(desc, RF_COPYBACK_DATA, addr, testCol, testOffs);
|
1999-02-05 03:06:06 +03:00
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
/* we didn't find the failed disk in the data part.
|
|
|
|
* check parity. */
|
|
|
|
|
|
|
|
/* map the parity for this stripe, disallowing remap
|
|
|
|
* to spare space */
|
2003-12-29 05:38:17 +03:00
|
|
|
(raidPtr->Layout.map->MapParity) (raidPtr, stripeAddr, &testCol, &testOffs, RF_DONT_REMAP);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
if (testCol == desc->fcol) {
|
|
|
|
rf_CopybackOne(desc, RF_COPYBACK_PARITY, stripeAddr, testCol, testOffs);
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* check to see if the last read/write pair failed */
|
|
|
|
if (desc->status) {
|
|
|
|
rf_CopybackComplete(desc, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* we didn't find any units to copy back in this stripe.
|
|
|
|
* Continue with the next one */
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* copyback one unit */
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_CopybackOne(RF_CopybackDesc_t *desc, int typ, RF_RaidAddr_t addr,
|
|
|
|
RF_RowCol_t testCol, RF_SectorNum_t testOffs)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_SectorCount_t sectPerSU = desc->sectPerSU;
|
|
|
|
RF_Raid_t *raidPtr = desc->raidPtr;
|
|
|
|
RF_RowCol_t spCol = desc->spCol;
|
|
|
|
RF_SectorNum_t spOffs;
|
|
|
|
|
|
|
|
/* find the spare spare location for this SU */
|
|
|
|
if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
|
|
|
|
if (typ == RF_COPYBACK_DATA)
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Layout.map->MapSector(raidPtr, addr, &spCol, &spOffs, RF_REMAP);
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Layout.map->MapParity(raidPtr, addr, &spCol, &spOffs, RF_REMAP);
|
1999-02-05 03:06:06 +03:00
|
|
|
} else {
|
|
|
|
spOffs = testOffs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create reqs to read the old location & write the new */
|
|
|
|
desc->readreq = rf_CreateDiskQueueData(RF_IO_TYPE_READ, spOffs,
|
|
|
|
sectPerSU, desc->databuf, 0L, 0,
|
|
|
|
(int (*) (void *, int)) rf_CopybackReadDoneProc, desc,
|
|
|
|
NULL, NULL, (void *) raidPtr, RF_DISKQUEUE_DATA_FLAGS_NONE, NULL);
|
|
|
|
desc->writereq = rf_CreateDiskQueueData(RF_IO_TYPE_WRITE, testOffs,
|
|
|
|
sectPerSU, desc->databuf, 0L, 0,
|
|
|
|
(int (*) (void *, int)) rf_CopybackWriteDoneProc, desc,
|
|
|
|
NULL, NULL, (void *) raidPtr, RF_DISKQUEUE_DATA_FLAGS_NONE, NULL);
|
|
|
|
desc->fcol = testCol;
|
|
|
|
|
|
|
|
/* enqueue the read. the write will go out as part of the callback on
|
|
|
|
* the read. at user-level & in the kernel, wait for the read-write
|
|
|
|
* pair to complete. in the simulator, just return, since everything
|
|
|
|
* will happen as callbacks */
|
|
|
|
|
|
|
|
RF_LOCK_MUTEX(desc->mcpair->mutex);
|
|
|
|
desc->mcpair->flag = 0;
|
2004-03-04 05:49:58 +03:00
|
|
|
RF_UNLOCK_MUTEX(desc->mcpair->mutex);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2003-12-29 05:38:17 +03:00
|
|
|
rf_DiskIOEnqueue(&raidPtr->Queues[spCol], desc->readreq, RF_IO_NORMAL_PRIORITY);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2004-03-04 05:49:58 +03:00
|
|
|
RF_LOCK_MUTEX(desc->mcpair->mutex);
|
1999-02-05 03:06:06 +03:00
|
|
|
while (!desc->mcpair->flag) {
|
|
|
|
RF_WAIT_MCPAIR(desc->mcpair);
|
|
|
|
}
|
|
|
|
RF_UNLOCK_MUTEX(desc->mcpair->mutex);
|
|
|
|
rf_FreeDiskQueueData(desc->readreq);
|
|
|
|
rf_FreeDiskQueueData(desc->writereq);
|
1999-01-26 05:33:49 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* called at interrupt context when the read has completed. just send out the write */
|
1999-02-05 03:06:06 +03:00
|
|
|
static int
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_CopybackReadDoneProc(RF_CopybackDesc_t *desc, int status)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
if (status) { /* invoke the callback with bad status */
|
2002-11-16 19:49:46 +03:00
|
|
|
printf("raid%d: copyback read failed. Aborting.\n",
|
|
|
|
desc->raidPtr->raidid);
|
1999-02-05 03:06:06 +03:00
|
|
|
(desc->writereq->CompleteFunc) (desc, -100);
|
|
|
|
} else {
|
2003-12-29 05:38:17 +03:00
|
|
|
rf_DiskIOEnqueue(&(desc->raidPtr->Queues[desc->fcol]), desc->writereq, RF_IO_NORMAL_PRIORITY);
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
/* called at interrupt context when the write has completed.
|
1998-11-13 07:20:26 +03:00
|
|
|
* at user level & in the kernel, wake up the copyback thread.
|
|
|
|
* in the simulator, invoke the next copyback directly.
|
|
|
|
* can't free diskqueuedata structs in the kernel b/c we're at interrupt context.
|
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
static int
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_CopybackWriteDoneProc(RF_CopybackDesc_t *desc, int status)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
if (status && status != -100) {
|
2002-11-16 19:49:46 +03:00
|
|
|
printf("raid%d: copyback write failed. Aborting.\n",
|
|
|
|
desc->raidPtr->raidid);
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
desc->status = status;
|
|
|
|
rf_MCPairWakeupFunc(desc->mcpair);
|
|
|
|
return (0);
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
/* invoked when the copyback has completed */
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_CopybackComplete(RF_CopybackDesc_t *desc, int status)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Raid_t *raidPtr = desc->raidPtr;
|
|
|
|
struct timeval t, diff;
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
RF_LOCK_MUTEX(raidPtr->mutex);
|
|
|
|
if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
|
|
|
|
RF_ASSERT(raidPtr->Layout.map->parityConfig == 'D');
|
|
|
|
rf_FreeSpareTable(raidPtr);
|
|
|
|
} else {
|
2003-12-29 05:38:17 +03:00
|
|
|
raidPtr->Disks[desc->spCol].status = rf_ds_spare;
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
|
|
|
RF_UNLOCK_MUTEX(raidPtr->mutex);
|
|
|
|
|
|
|
|
RF_GETTIME(t);
|
|
|
|
RF_TIMEVAL_DIFF(&desc->starttime, &t, &diff);
|
2002-11-16 19:49:46 +03:00
|
|
|
#if 0
|
1999-02-05 03:06:06 +03:00
|
|
|
printf("Copyback time was %d.%06d seconds\n",
|
|
|
|
(int) diff.tv_sec, (int) diff.tv_usec);
|
2002-11-16 19:49:46 +03:00
|
|
|
#endif
|
1999-02-05 03:06:06 +03:00
|
|
|
} else
|
2002-11-16 19:49:46 +03:00
|
|
|
printf("raid%d: Copyback failure. Status: %d\n",
|
|
|
|
raidPtr->raidid, status);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
RF_Free(desc->databuf, rf_RaidAddressToByte(raidPtr, desc->sectPerSU));
|
|
|
|
rf_FreeMCPair(desc->mcpair);
|
|
|
|
RF_Free(desc, sizeof(*desc));
|
|
|
|
|
|
|
|
rf_copyback_in_progress = 0;
|
|
|
|
rf_ResumeNewRequests(raidPtr);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|