⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rf_kintf.c

📁 RAIDFrame是个非常好的磁盘阵列RAID仿真工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. * * Authors: Mark Holland, Jim Zelenka * * 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. *//*********************************************************** * * rf_kintf.c -- the kernel interface routines for RAIDframe * ***********************************************************//* * $Locker:  $ * $Log: rf_kintf.c,v $ * Revision 1.57  1996/07/19  16:12:20  jimz * remove addition of protectedSectors in InitBP- it's already * done in the diskqueue code * * Revision 1.56  1996/07/17  21:00:58  jimz * clean up timer interface, tracing * * Revision 1.55  1996/06/17  03:00:54  jimz * Change RAIDFRAME_GET_INFO interface to do its own copyout() * (because size of device config structure now exceeds 8k) * * Revision 1.54  1996/06/09  02:36:46  jimz * lots of little crufty cleanup- fixup whitespace * issues, comment #ifdefs, improve typing in some * places (esp size-related) * * Revision 1.53  1996/06/07  21:33:04  jimz * begin using consistent types for sector numbers, * stripe numbers, row+col numbers, recon unit numbers * * Revision 1.52  1996/06/06  17:28:08  jimz * track sector number of last I/O dequeued * * Revision 1.51  1996/06/05  18:06:02  jimz * Major code cleanup. The Great Renaming is now done. * Better modularity. Better typing. Fixed a bunch of * synchronization bugs. Made a lot of global stuff * per-desc or per-array. Removed dead code. * * Revision 1.50  1996/06/03  23:28:26  jimz * more bugfixes * check in tree to sync for IPDS runs with current bugfixes * there still may be a problem with threads in the script test * getting I/Os stuck- not trivially reproducible (runs ~50 times * in a row without getting stuck) * * Revision 1.49  1996/06/02  17:31:48  jimz * Moved a lot of global stuff into array structure, where it belongs. * Fixed up paritylogging, pss modules in this manner. Some general * code cleanup. Removed lots of dead code, some dead files. * * Revision 1.48  1996/05/31  22:26:54  jimz * fix a lot of mapping problems, memory allocation problems * found some weird lock issues, fixed 'em * more code cleanup * * Revision 1.47  1996/05/30  12:59:18  jimz * make etimer happier, more portable * * Revision 1.46  1996/05/30  11:29:41  jimz * Numerous bug fixes. Stripe lock release code disagreed with the taking code * about when stripes should be locked (I made it consistent: no parity, no lock) * There was a lot of extra serialization of I/Os which I've removed- a lot of * it was to calculate values for the cache code, which is no longer with us. * More types, function, macro cleanup. Added code to properly quiesce the array * on shutdown. Made a lot of stuff array-specific which was (bogusly) general * before. Fixed memory allocation, freeing bugs. * * Revision 1.45  1996/05/27  18:56:37  jimz * more code cleanup * better typing * compiles in all 3 environments * * Revision 1.44  1996/05/24  22:17:04  jimz * continue code + namespace cleanup * typed a bunch of flags * * Revision 1.43  1996/05/24  01:59:45  jimz * another checkpoint in code cleanup for release * time to sync kernel tree * * Revision 1.42  1996/05/23  22:17:54  jimz * fix sector size hardcoding problems * * Revision 1.41  1996/05/23  21:46:35  jimz * checkpoint in code cleanup (release prep) * lots of types, function names have been fixed * * Revision 1.40  1996/05/23  13:18:07  jimz * tracing_mutex -> rf_tracing_mutex * * Revision 1.39  1996/05/23  00:33:23  jimz * code cleanup: move all debug decls to rf_options.c, all extern * debug decls to rf_options.h, all debug vars preceded by rf_ * * Revision 1.38  1996/05/20  16:15:32  jimz * switch to rf_{mutex,cond}_{init,destroy} * * Revision 1.37  1996/05/10  16:23:47  jimz * RF_offset -> RF_Offset * * Revision 1.36  1996/05/08  21:01:24  jimz * fixed up enum type names that were conflicting with other * enums and function names (ie, "panic") * future naming trends will be towards RF_ and rf_ for * everything raidframe-related * * Revision 1.35  1996/05/03  19:10:48  jimz * change sanity checking for bogus I/Os to return more appropriate * values (to make some user-level utilities happer with RAIDframe) * * Revision 1.34  1996/05/02  22:17:00  jimz * When using DKUSAGE, send a bogus IO after configuring to let DKUSAGE know * that we exist. This will let user-level programs doing group stats on the * RF device function without error before RF gets its first IO * * Changed rf_device_config devs and spares fields to RF_RaidDisk_t * * Inc numOutstanding for the disk queue in rf_DispatchKernelIO if * type is IO_TYPE_NOP. I'm not sure this is right, but it seems to be, * because the disk IO completion routine wants to dec it, and doesn't * care if there was no such IO. * * Revision 1.33  1996/05/02  15:05:44  jimz * for now, rf_DoAccessKernel will reject non-sector-sized I/Os * eventually, it should do something more clever... * (and do it in DoAccess(), not just DoAccessKernel()) * * Revision 1.32  1996/05/01  16:28:39  jimz * get rid of uses of ccmn_ functions * * Revision 1.31  1996/05/01  15:42:17  jimz * ccmn_* memory management is on the way out. This is an archival checkpoint- * both the old and new code are in place (all the ccmn_ calls are #if 0). After * this, the ccmn_ code will no longer appear. * * Revision 1.30  1996/04/22  15:53:13  jimz * MAX_RAIDS -> NRAIDFRAME * * Revision 1.29  1995/12/12  18:10:06  jimz * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT * fix 80-column brain damage in comments * * Revision 1.28  1995/12/01  19:11:01  root * added copyright info * * Revision 1.27  1995/11/28  18:56:40  wvcii * disabled buffer copy in rf_write * * Revision 1.26  1995/10/06  16:37:08  jimz * get struct bufs from ubc, not cam * copy all write data, and operate on copy * (temporary hack to get around dags in PQ that want * to Xor into user write buffers) * * Revision 1.25  1995/09/30  22:23:08  jimz * do not require raid to be active to perform ACCTOTAL ioctl * * Revision 1.24  1995/09/30  20:39:08  jimz * added new ioctls: *   RAIDFRAME_RESET_ACCTOTALS *   RAIDFRAME_GET_ACCTOTALS *   RAIDFRAME_KEEP_ACCTOTALS * * Revision 1.23  1995/09/20  21:11:59  jimz * include dfstrace.h in KERNEL block * (even though it's a kernel-only file, this makes the depend process * at user-level happy. Why the user-level Makefile wants to depend * kintf.c is less clear, but this is a workaround). * * Revision 1.22  1995/09/19  23:19:03  jimz * added DKUSAGE support * */#ifdef KERNEL#include <dkusage.h>#include <dfstrace.h>#include <raidframe.h>#include <raidframe_recon.h>#include <sys/errno.h>#include <kern/task.h>#include <kern/thread.h>#include <io/common/iotypes.h>#include <io/cam/cam_debug.h>#include <io/cam/cam.h>#include <io/cam/dec_cam.h>#include <io/cam/uagt.h>#include <sys/conf.h>#include <io/common/devdriver.h>#include <io/cam/pdrv.h>#include <io/common/pt.h>#include <sys/disklabel.h>#include <io/cam/cam_disk.h>#include <io/common/devdriver.h>#include <sys/buf.h>#include <sys/user.h>#include "rf_raid.h"#include "rf_raidframe.h"#include "rf_dag.h"#include "rf_dagflags.h"#include "rf_diskqueue.h"#include "rf_acctrace.h"#include "rf_etimer.h"#include "rf_general.h"#include "rf_debugMem.h"#include "rf_kintf.h"#include "rf_options.h"#if DKUSAGE > 0#include <sys/dkusage.h>#include <io/common/iotypes.h>#include <io/cam/dec_cam.h>#include <io/cam/cam.h>#include <io/cam/pdrv.h>#endif /* DKUSAGE > 0 */#define DEBUGstatic int rf_kdebug_level = 0;#define RFK_BOOT_NONE 0#define RFK_BOOT_GOOD 1#define RFK_BOOT_BAD  2static int rf_kbooted = RFK_BOOT_NONE;extern struct buf *ubc_bufget();#ifdef DEBUG#define db0_printf(a) printf a#define db_printf(a) if (rf_kdebug_level > 0) printf a#define db1_printf(a) if (rf_kdebug_level > 0) printf a#define db2_printf(a) if (rf_kdebug_level > 1) printf a#define db3_printf(a) if (rf_kdebug_level > 2) printf a#define db4_printf(a) if (rf_kdebug_level > 3) printf a#define db5_printf(a) if (rf_kdebug_level > 4) printf a#else /* DEBUG */#define db0_printf(a) printf a#define db1_printf(a) { }#define db2_printf(a) { }#define db3_printf(a) { }#define db4_printf(a) { }#define db5_printf(a) { }#endif /* DEBUG */static RF_Raid_t *raidPtrs[NRAIDFRAME]; /* global raid device descriptors */static int rf_pending_testaccs;RF_DECLARE_STATIC_MUTEX(rf_sparet_wait_mutex)RF_DECLARE_STATIC_MUTEX(rf_async_done_q_mutex)static RF_SparetWait_t *rf_sparet_wait_queue;      /* requests to install a spare table */static RF_SparetWait_t *rf_sparet_resp_queue;      /* responses from installation process */static struct rf_test_acc    *rf_async_done_qh, *rf_async_done_qt;static struct rf_recon_req *recon_queue = NULL;          /* used to communicate reconstruction requests */decl_simple_lock_data(,recon_queue_mutex)#define LOCK_RECON_Q_MUTEX() simple_lock(&recon_queue_mutex)#define UNLOCK_RECON_Q_MUTEX() simple_unlock(&recon_queue_mutex)/* prototypes */static int rf_WrapUpTestAcc(struct rf_test_acc *ta, RF_Raid_t *raidPtr);static struct rf_test_acc *rf_DupTestAccDesc(struct rf_test_acc *ta);static void rf_AsyncTestAccCallbackFunc(struct rf_test_acc *ta);static void KernelWakeupFunc(struct buf  *bp);static void InitBP(struct buf *bp, unsigned rw_flag, dev_t dev,	RF_SectorNum_t startSect, RF_SectorCount_t numSect, caddr_t buf,	void (*cbFunc)(), void *cbArg, int logBytesPerSector,	struct proc *b_proc);#define Dprintf0(s)       if (rf_queueDebug) rf_debug_printf(s,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)#define Dprintf1(s,a)     if (rf_queueDebug) rf_debug_printf(s,a,NULL,NULL,NULL,NULL,NULL,NULL,NULL)#define Dprintf2(s,a,b)   if (rf_queueDebug) rf_debug_printf(s,a,b,NULL,NULL,NULL,NULL,NULL,NULL)#define Dprintf3(s,a,b,c) if (rf_queueDebug) rf_debug_printf(s,a,b,c,NULL,NULL,NULL,NULL,NULL)#define rf_FreeTestAccDesc(x) RF_Free((x),sizeof(struct rf_test_acc))/* this is so that we can compile under 2.0 as well as 3.2 */#ifndef proc_to_task#define proc_to_task(x) ((x)->task)#endif /* !proc_to_task *//********************************************************* * * initialization code called at boot time (startup.c) * ********************************************************/int rf_boot(){  int i, rc;  rc = rf_mutex_init(&rf_sparet_wait_mutex);  if (rc) {    RF_PANIC();  }  rc = rf_mutex_init(&rf_async_done_q_mutex);  if (rc) {    RF_PANIC();  }  rf_sparet_wait_queue = rf_sparet_resp_queue = NULL;  recon_queue = NULL;  rf_async_done_qh = rf_async_done_qt = NULL;  for (i=0; i<NRAIDFRAME; i++)    raidPtrs[i] = NULL;  rc = rf_BootRaidframe();  if (rc == 0)    printf("Kernelized RAIDframe activated\n");  else    rf_kbooted = RFK_BOOT_BAD;  return(rc);}/********************************************************* * * the entries in the block and character device switches * ********************************************************//* * We don't check if raidframe is configured on open, because open is called * for the ioctl which does the configuration. * * A RAID minor number consists of the partition number in the low * six bits, and the array identifier above that. */int rf_open(dev, flag, fmt)  dev_t  dev;  int    flag;  int    fmt;{	unsigned int raidID;	int rc;	if (rf_kbooted == RFK_BOOT_NONE) {		rf_kbooted = RFK_BOOT_GOOD;		rc = rf_boot();		if (rc) {			rf_kbooted = RFK_BOOT_BAD;			return(rc);		}	}	db2_printf(("rf_open(%lx %d %d)\n", (u_long)dev, flag, fmt));	raidID = RF_DEV2RAIDID(dev);	db5_printf(("rf_open: raidID=%d\n", raidID));	if (raidID >= NRAIDFRAME)		return(ENODEV);	db5_printf(("rf_open: raidPtrs[%d]=%lx\n", raidID, raidPtrs[raidID]));	if (!raidPtrs[raidID]) {		RF_Calloc(raidPtrs[raidID], 1, sizeof(RF_Raid_t), (RF_Raid_t *));	}	if (!raidPtrs[raidID])		return(ENOMEM);	db4_printf(("rf_open: raidPtrs[%d]=%lx post-alloc\n", raidID, raidPtrs[raidID]));	return(0);}int rf_close(dev, flag, fmt)  dev_t  dev;  int    flag;  int    fmt;{  unsigned int raidID;  if (rf_kbooted != RFK_BOOT_GOOD) {    return(EINVAL);  }  raidID = RF_DEV2RAIDID(dev);  if (raidID >= NRAIDFRAME)    return(ENODEV);  if (!raidPtrs[raidID])    return(EINVAL);  return(0);}void rf_strategy(bp)  struct buf   *bp;{	unsigned int raidID = RF_DEV2RAIDID(bp->b_dev);	RF_Raid_t *raidPtr;	if (rf_kbooted != RFK_BOOT_GOOD)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -