summaryrefslogtreecommitdiff
path: root/sys/dev/raidframe/rf_engine.c
diff options
context:
space:
mode:
authorThierry Deval <tdeval@cvs.openbsd.org>2002-12-16 07:01:06 +0000
committerThierry Deval <tdeval@cvs.openbsd.org>2002-12-16 07:01:06 +0000
commit9f4f754a2c89fa0aae2495b9897832c871e55410 (patch)
tree990a42520130e4092662926e20b65536fa947a43 /sys/dev/raidframe/rf_engine.c
parentd18f950d8b18360863af577de1796c0079f4bc20 (diff)
Major KNF. Incentive from Tedu
Diffstat (limited to 'sys/dev/raidframe/rf_engine.c')
-rw-r--r--sys/dev/raidframe/rf_engine.c670
1 files changed, 382 insertions, 288 deletions
diff --git a/sys/dev/raidframe/rf_engine.c b/sys/dev/raidframe/rf_engine.c
index f988f0de05a..458ab8c00b3 100644
--- a/sys/dev/raidframe/rf_engine.c
+++ b/sys/dev/raidframe/rf_engine.c
@@ -1,5 +1,6 @@
-/* $OpenBSD: rf_engine.c,v 1.12 2002/07/15 18:42:06 art Exp $ */
+/* $OpenBSD: rf_engine.c,v 1.13 2002/12/16 07:01:03 tdeval Exp $ */
/* $NetBSD: rf_engine.c,v 1.10 2000/08/20 16:51:03 thorpej Exp $ */
+
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@@ -29,16 +30,16 @@
/****************************************************************************
* *
- * engine.c -- code for DAG execution engine *
+ * engine.c -- Code for DAG execution engine. *
* *
* Modified to work as follows (holland): *
* A user-thread calls into DispatchDAG, which fires off the nodes that *
- * are direct successors to the header node. DispatchDAG then returns, *
- * and the rest of the I/O continues asynchronously. As each node *
- * completes, the node execution function calls FinishNode(). FinishNode *
+ * are direct successors to the header node. DispatchDAG then returns, *
+ * and the rest of the I/O continues asynchronously. As each node *
+ * completes, the node execution function calls FinishNode(). FinishNode *
* scans the list of successors to the node and increments the antecedent *
- * counts. Each node that becomes enabled is placed on a central node *
- * queue. A dedicated dag-execution thread grabs nodes off of this *
+ * counts. Each node that becomes enabled is placed on a central node *
+ * queue. A dedicated dag-execution thread grabs nodes off of this *
* queue and fires them. *
* *
* NULL nodes are never fired. *
@@ -49,8 +50,8 @@
* If a node fails, the dag either rolls forward to the completion or *
* rolls back, undoing previously-completed nodes and fails atomically. *
* The direction of recovery is determined by the location of the failed *
- * node in the graph. If the failure occurred before the commit node in *
- * the graph, backward recovery is used. Otherwise, forward recovery is *
+ * node in the graph. If the failure occurred before the commit node in *
+ * the graph, backward recovery is used. Otherwise, forward recovery is *
* used. *
* *
****************************************************************************/
@@ -67,56 +68,67 @@
#include "rf_shutdown.h"
#include "rf_raid.h"
-void DAGExecutionThread(RF_ThreadArg_t arg);
-#ifdef RAID_AUTOCONFIG
-void DAGExecutionThread_pre(RF_ThreadArg_t arg);
+int rf_BranchDone(RF_DagNode_t *);
+int rf_NodeReady(RF_DagNode_t *);
+void rf_FireNode(RF_DagNode_t *);
+void rf_FireNodeArray(int, RF_DagNode_t **);
+void rf_FireNodeList(RF_DagNode_t *);
+void rf_PropagateResults(RF_DagNode_t *, int);
+void rf_ProcessNode(RF_DagNode_t *, int);
+
+void rf_DAGExecutionThread(RF_ThreadArg_t);
+#ifdef RAID_AUTOCONFIG
#define RF_ENGINE_PID 10
+void rf_DAGExecutionThread_pre(RF_ThreadArg_t);
extern pid_t lastpid;
#endif /* RAID_AUTOCONFIG */
void **rf_hook_cookies;
extern int numraid;
-#define DO_INIT(_l_,_r_) { \
- int _rc; \
- _rc = rf_create_managed_mutex(_l_,&(_r_)->node_queue_mutex); \
- if (_rc) { \
- return(_rc); \
- } \
- _rc = rf_create_managed_cond(_l_,&(_r_)->node_queue_cond); \
- if (_rc) { \
- return(_rc); \
- } \
-}
+#define DO_INIT(_l_,_r_) \
+do { \
+ int _rc; \
+ _rc = rf_create_managed_mutex(_l_, &(_r_)->node_queue_mutex); \
+ if (_rc) { \
+ return(_rc); \
+ } \
+ _rc = rf_create_managed_cond(_l_, &(_r_)->node_queue_cond); \
+ if (_rc) { \
+ return(_rc); \
+ } \
+} while (0)
-/* synchronization primitives for this file. DO_WAIT should be enclosed in a while loop. */
+/*
+ * Synchronization primitives for this file. DO_WAIT should be enclosed
+ * in a while loop.
+ */
/*
- * XXX Is this spl-ing really necessary?
+ * XXX Is this spl-ing really necessary ?
*/
-#define DO_LOCK(_r_) \
-do { \
- ks = splbio(); \
- RF_LOCK_MUTEX((_r_)->node_queue_mutex); \
+#define DO_LOCK(_r_) \
+do { \
+ ks = splbio(); \
+ RF_LOCK_MUTEX((_r_)->node_queue_mutex); \
} while (0)
-#define DO_UNLOCK(_r_) \
-do { \
- RF_UNLOCK_MUTEX((_r_)->node_queue_mutex); \
- splx(ks); \
+#define DO_UNLOCK(_r_) \
+do { \
+ RF_UNLOCK_MUTEX((_r_)->node_queue_mutex); \
+ splx(ks); \
} while (0)
-#define DO_WAIT(_r_) \
+#define DO_WAIT(_r_) \
RF_WAIT_COND((_r_)->node_queue, (_r_)->node_queue_mutex)
/* XXX RF_SIGNAL_COND? */
-#define DO_SIGNAL(_r_) \
+#define DO_SIGNAL(_r_) \
RF_BROADCAST_COND((_r_)->node_queue)
void rf_ShutdownEngine(void *);
-void
-rf_ShutdownEngine(arg)
- void *arg;
+void
+rf_ShutdownEngine(void *arg)
{
RF_Raid_t *raidPtr;
@@ -125,14 +137,12 @@ rf_ShutdownEngine(arg)
DO_SIGNAL(raidPtr);
}
-int
-rf_ConfigureEngine(
- RF_ShutdownList_t ** listp,
- RF_Raid_t * raidPtr,
- RF_Config_t * cfgPtr)
+int
+rf_ConfigureEngine(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
+ RF_Config_t *cfgPtr)
{
- int rc;
- char raidname[16];
+ int rc;
+ char raidname[16];
DO_INIT(listp, raidPtr);
@@ -143,9 +153,11 @@ rf_ConfigureEngine(
if (rc)
return (rc);
- /* we create the execution thread only once per system boot. no need
+ /*
+ * We create the execution thread only once per system boot. No need
* to check return code b/c the kernel panics if it can't create the
- * thread. */
+ * thread.
+ */
if (rf_engineDebug) {
printf("raid%d: Creating engine thread\n", raidPtr->raidid);
}
@@ -157,94 +169,105 @@ rf_ConfigureEngine(
return (ENOMEM);
bzero(rf_hook_cookies, numraid * sizeof(void *));
}
-#ifdef RAID_AUTOCONFIG
+#ifdef RAID_AUTOCONFIG
if (initproc == NULL) {
rf_hook_cookies[raidPtr->raidid] =
- startuphook_establish(DAGExecutionThread_pre, raidPtr);
+ startuphook_establish(rf_DAGExecutionThread_pre,
+ raidPtr);
} else {
#endif /* RAID_AUTOCONFIG */
snprintf(&raidname[0], 16, "raid%d", raidPtr->raidid);
if (RF_CREATE_THREAD(raidPtr->engine_thread,
- DAGExecutionThread, raidPtr, &raidname[0])) {
- RF_ERRORMSG("RAIDFRAME: Unable to create engine thread\n");
+ rf_DAGExecutionThread, raidPtr, &raidname[0])) {
+ RF_ERRORMSG("RAIDFRAME: Unable to create engine"
+ " thread\n");
return (ENOMEM);
}
if (rf_engineDebug) {
- printf("raid%d: Created engine thread\n", raidPtr->raidid);
+ printf("raid%d: Created engine thread\n",
+ raidPtr->raidid);
}
RF_THREADGROUP_STARTED(&raidPtr->engine_tg);
-#ifdef RAID_AUTOCONFIG
+#ifdef RAID_AUTOCONFIG
}
#endif
- /* XXX something is missing here... */
-#ifdef debug
- printf("Skipping the WAIT_START!!\n");
+ /* XXX Something is missing here... */
+#ifdef debug
+ printf("Skipping the WAIT_START !!!\n");
#endif
- /* engine thread is now running and waiting for work */
+ /* Engine thread is now running and waiting for work. */
if (rf_engineDebug) {
- printf("raid%d: Engine thread running and waiting for events\n", raidPtr->raidid);
+ printf("raid%d: Engine thread running and waiting for events\n",
+ raidPtr->raidid);
}
rc = rf_ShutdownCreate(listp, rf_ShutdownEngine, raidPtr);
if (rc) {
- RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__,
- __LINE__, rc);
+ RF_ERRORMSG3("Unable to add to shutdown list file %s line %d"
+ " rc=%d\n", __FILE__, __LINE__, rc);
rf_ShutdownEngine(NULL);
}
return (rc);
}
-static int
-BranchDone(RF_DagNode_t * node)
+int
+rf_BranchDone(RF_DagNode_t *node)
{
- int i;
+ int i;
- /* return true if forward execution is completed for a node and it's
- * succedents */
+ /*
+ * Return true if forward execution is completed for a node and it's
+ * succedents.
+ */
switch (node->status) {
case rf_wait:
- /* should never be called in this state */
+ /* Should never be called in this state. */
RF_PANIC();
break;
case rf_fired:
- /* node is currently executing, so we're not done */
+ /* Node is currently executing, so we're not done. */
return (RF_FALSE);
case rf_good:
- for (i = 0; i < node->numSuccedents; i++) /* for each succedent */
- if (!BranchDone(node->succedents[i])) /* recursively check
- * branch */
+ /* For each succedent. */
+ for (i = 0; i < node->numSuccedents; i++)
+ /* Recursively check branch. */
+ if (!rf_BranchDone(node->succedents[i]))
return RF_FALSE;
- return RF_TRUE; /* node and all succedent branches aren't in
- * fired state */
+
+ return RF_TRUE; /*
+ * Node and all succedent branches aren't in
+ * fired state.
+ */
break;
case rf_bad:
- /* succedents can't fire */
+ /* Succedents can't fire. */
return (RF_TRUE);
case rf_recover:
- /* should never be called in this state */
+ /* Should never be called in this state. */
RF_PANIC();
break;
case rf_undone:
case rf_panic:
- /* XXX need to fix this case */
- /* for now, assume that we're done */
+ /* XXX Need to fix this case. */
+ /* For now, assume that we're done. */
return (RF_TRUE);
break;
default:
- /* illegal node status */
+ /* Illegal node status. */
RF_PANIC();
break;
}
}
-static int
-NodeReady(RF_DagNode_t * node)
+int
+rf_NodeReady(RF_DagNode_t *node)
{
- int ready;
+ int ready;
switch (node->dagHdr->status) {
case rf_enable:
case rf_rollForward:
- if ((node->status == rf_wait) && (node->numAntecedents == node->numAntDone))
+ if ((node->status == rf_wait) &&
+ (node->numAntecedents == node->numAntDone))
ready = RF_TRUE;
else
ready = RF_FALSE;
@@ -253,13 +276,15 @@ NodeReady(RF_DagNode_t * node)
RF_ASSERT(node->numSuccDone <= node->numSuccedents);
RF_ASSERT(node->numSuccFired <= node->numSuccedents);
RF_ASSERT(node->numSuccFired <= node->numSuccDone);
- if ((node->status == rf_good) && (node->numSuccDone == node->numSuccedents))
+ if ((node->status == rf_good) &&
+ (node->numSuccDone == node->numSuccedents))
ready = RF_TRUE;
else
ready = RF_FALSE;
break;
default:
- printf("Execution engine found illegal DAG status in NodeReady\n");
+ printf("Execution engine found illegal DAG status"
+ " in rf_NodeReady\n");
RF_PANIC();
break;
}
@@ -268,30 +293,32 @@ NodeReady(RF_DagNode_t * node)
}
-
-/* user context and dag-exec-thread context:
- * Fire a node. The node's status field determines which function, do or undo,
+/*
+ * User context and dag-exec-thread context:
+ * Fire a node. The node's status field determines which function, do or undo,
* to be fired.
* This routine assumes that the node's status field has alread been set to
* "fired" or "recover" to indicate the direction of execution.
*/
-static void
-FireNode(RF_DagNode_t * node)
+void
+rf_FireNode(RF_DagNode_t *node)
{
switch (node->status) {
case rf_fired:
- /* fire the do function of a node */
+ /* Fire the do function of a node. */
if (rf_engineDebug) {
- printf("raid%d: Firing node 0x%lx (%s)\n",
- node->dagHdr->raidPtr->raidid,
- (unsigned long) node, node->name);
+ printf("raid%d: Firing node 0x%lx (%s)\n",
+ node->dagHdr->raidPtr->raidid,
+ (unsigned long) node, node->name);
}
if (node->flags & RF_DAGNODE_FLAG_YIELD) {
#if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(_KERNEL)
/* thread_block(); */
/* printf("Need to block the thread here...\n"); */
- /* XXX thread_block is actually mentioned in
- * /usr/include/vm/vm_extern.h */
+ /*
+ * XXX thread_block is actually mentioned in
+ * /usr/include/vm/vm_extern.h
+ */
#else
thread_block();
#endif
@@ -299,22 +326,24 @@ FireNode(RF_DagNode_t * node)
(*(node->doFunc)) (node);
break;
case rf_recover:
- /* fire the undo function of a node */
+ /* Fire the undo function of a node. */
if (rf_engineDebug) {
- printf("raid%d: Firing (undo) node 0x%lx (%s)\n",
- node->dagHdr->raidPtr->raidid,
- (unsigned long) node, node->name);
+ printf("raid%d: Firing (undo) node 0x%lx (%s)\n",
+ node->dagHdr->raidPtr->raidid,
+ (unsigned long) node, node->name);
}
if (node->flags & RF_DAGNODE_FLAG_YIELD) {
#if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(_KERNEL)
/* thread_block(); */
/* printf("Need to block the thread here...\n"); */
- /* XXX thread_block is actually mentioned in
- * /usr/include/vm/vm_extern.h */
+ /*
+ * XXX thread_block is actually mentioned in
+ * /usr/include/vm/vm_extern.h
+ */
#else
thread_block();
#endif
- }
+ }
(*(node->undoFunc)) (node);
break;
default:
@@ -324,26 +353,25 @@ FireNode(RF_DagNode_t * node)
}
-
-/* user context:
+/*
+ * User context:
* Attempt to fire each node in a linear array.
* The entire list is fired atomically.
*/
-static void
-FireNodeArray(
- int numNodes,
- RF_DagNode_t ** nodeList)
+void
+rf_FireNodeArray(int numNodes, RF_DagNode_t **nodeList)
{
RF_DagStatus_t dstat;
RF_DagNode_t *node;
- int i, j;
+ int i, j;
- /* first, mark all nodes which are ready to be fired */
+ /* First, mark all nodes which are ready to be fired. */
for (i = 0; i < numNodes; i++) {
node = nodeList[i];
dstat = node->dagHdr->status;
- RF_ASSERT((node->status == rf_wait) || (node->status == rf_good));
- if (NodeReady(node)) {
+ RF_ASSERT((node->status == rf_wait) ||
+ (node->status == rf_good));
+ if (rf_NodeReady(node)) {
if ((dstat == rf_enable) || (dstat == rf_rollForward)) {
RF_ASSERT(node->status == rf_wait);
if (node->commitNode)
@@ -354,99 +382,107 @@ FireNodeArray(
} else {
RF_ASSERT(dstat == rf_rollBackward);
RF_ASSERT(node->status == rf_good);
- RF_ASSERT(node->commitNode == RF_FALSE); /* only one commit node
- * per graph */
+ /* Only one commit node per graph. */
+ RF_ASSERT(node->commitNode == RF_FALSE);
node->status = rf_recover;
}
}
}
- /* now, fire the nodes */
+ /* Now, fire the nodes. */
for (i = 0; i < numNodes; i++) {
- if ((nodeList[i]->status == rf_fired) || (nodeList[i]->status == rf_recover))
- FireNode(nodeList[i]);
+ if ((nodeList[i]->status == rf_fired) ||
+ (nodeList[i]->status == rf_recover))
+ rf_FireNode(nodeList[i]);
}
}
-/* user context:
+/*
+ * User context:
* Attempt to fire each node in a linked list.
* The entire list is fired atomically.
*/
-static void
-FireNodeList(RF_DagNode_t * nodeList)
+void
+rf_FireNodeList(RF_DagNode_t *nodeList)
{
RF_DagNode_t *node, *next;
RF_DagStatus_t dstat;
- int j;
+ int j;
if (nodeList) {
- /* first, mark all nodes which are ready to be fired */
+ /* First, mark all nodes which are ready to be fired. */
for (node = nodeList; node; node = next) {
next = node->next;
dstat = node->dagHdr->status;
- RF_ASSERT((node->status == rf_wait) || (node->status == rf_good));
- if (NodeReady(node)) {
- if ((dstat == rf_enable) || (dstat == rf_rollForward)) {
+ RF_ASSERT((node->status == rf_wait) ||
+ (node->status == rf_good));
+ if (rf_NodeReady(node)) {
+ if ((dstat == rf_enable) ||
+ (dstat == rf_rollForward)) {
RF_ASSERT(node->status == rf_wait);
if (node->commitNode)
node->dagHdr->numCommits++;
node->status = rf_fired;
- for (j = 0; j < node->numAntecedents; j++)
- node->antecedents[j]->numSuccFired++;
+ for (j = 0; j < node->numAntecedents;
+ j++)
+ node->antecedents[j]
+ ->numSuccFired++;
} else {
RF_ASSERT(dstat == rf_rollBackward);
RF_ASSERT(node->status == rf_good);
- RF_ASSERT(node->commitNode == RF_FALSE); /* only one commit node
- * per graph */
+ /* Only one commit node per graph. */
+ RF_ASSERT(node->commitNode == RF_FALSE);
node->status = rf_recover;
}
}
}
- /* now, fire the nodes */
+ /* Now, fire the nodes. */
for (node = nodeList; node; node = next) {
next = node->next;
- if ((node->status == rf_fired) || (node->status == rf_recover))
- FireNode(node);
+ if ((node->status == rf_fired) ||
+ (node->status == rf_recover))
+ rf_FireNode(node);
}
}
}
-/* interrupt context:
- * for each succedent
- * propagate required results from node to succedent
- * increment succedent's numAntDone
- * place newly-enable nodes on node queue for firing
+
+
+/*
+ * Interrupt context:
+ * For each succedent,
+ * propagate required results from node to succedent.
+ * increment succedent's numAntDone.
+ * place newly-enable nodes on node queue for firing.
*
* To save context switches, we don't place NIL nodes on the node queue,
- * but rather just process them as if they had fired. Note that NIL nodes
+ * but rather just process them as if they had fired. Note that NIL nodes
* that are the direct successors of the header will actually get fired by
* DispatchDAG, which is fine because no context switches are involved.
*
* Important: when running at user level, this can be called by any
* disk thread, and so the increment and check of the antecedent count
- * must be locked. I used the node queue mutex and locked down the
+ * must be locked. I used the node queue mutex and locked down the
* entire function, but this is certainly overkill.
*/
-static void
-PropagateResults(
- RF_DagNode_t * node,
- int context)
+void
+rf_PropagateResults(RF_DagNode_t *node, int context)
{
RF_DagNode_t *s, *a;
RF_Raid_t *raidPtr;
- int i, ks;
- RF_DagNode_t *finishlist = NULL; /* a list of NIL nodes to be
- * finished */
- RF_DagNode_t *skiplist = NULL; /* list of nodes with failed truedata
- * antecedents */
- RF_DagNode_t *firelist = NULL; /* a list of nodes to be fired */
+ int i, ks;
+ /* A list of NIL nodes to be finished. */
+ RF_DagNode_t *finishlist = NULL;
+ /* List of nodes with failed truedata antecedents. */
+ RF_DagNode_t *skiplist = NULL;
+ RF_DagNode_t *firelist = NULL; /* A list of nodes to be fired. */
RF_DagNode_t *q = NULL, *qh = NULL, *next;
- int j, skipNode;
+ int j, skipNode;
raidPtr = node->dagHdr->raidPtr;
DO_LOCK(raidPtr);
- /* debug - validate fire counts */
+ /* Debug - validate fire counts. */
for (i = 0; i < node->numAntecedents; i++) {
a = *(node->antecedents + i);
RF_ASSERT(a->numSuccFired >= a->numSuccDone);
@@ -462,40 +498,60 @@ PropagateResults(
RF_ASSERT(s->status == rf_wait);
(s->numAntDone)++;
if (s->numAntDone == s->numAntecedents) {
- /* look for NIL nodes */
+ /* Look for NIL nodes. */
if (s->doFunc == rf_NullNodeFunc) {
- /* don't fire NIL nodes, just process
- * them */
+ /*
+ * Don't fire NIL nodes, just process
+ * them.
+ */
s->next = finishlist;
finishlist = s;
} else {
- /* look to see if the node is to be
- * skipped */
+ /*
+ * Look to see if the node is to be
+ * skipped.
+ */
skipNode = RF_FALSE;
for (j = 0; j < s->numAntecedents; j++)
- if ((s->antType[j] == rf_trueData) && (s->antecedents[j]->status == rf_bad))
+ if ((s->antType[j] ==
+ rf_trueData) &&
+ (s->antecedents[j]->status
+ == rf_bad))
skipNode = RF_TRUE;
if (skipNode) {
- /* this node has one or more
+ /*
+ * This node has one or more
* failed true data
- * dependencies, so skip it */
+ * dependencies, so skip it.
+ */
s->next = skiplist;
skiplist = s;
- } else
- /* add s to list of nodes (q)
- * to execute */
- if (context != RF_INTR_CONTEXT) {
- /* we only have to
+ } else {
+ /*
+ * Add s to list of nodes (q)
+ * to execute.
+ */
+ if (context != RF_INTR_CONTEXT)
+ {
+ /*
+ * We only have to
* enqueue if we're at
- * intr context */
- s->next = firelist; /* put node on a list to
- * be fired after we
- * unlock */
+ * intr context.
+ */
+ /*
+ * Put node on a list to
+ * be fired after we
+ * unlock.
+ */
+ s->next = firelist;
firelist = s;
- } else { /* enqueue the node for
- * the dag exec thread
- * to fire */
- RF_ASSERT(NodeReady(s));
+ } else {
+ /*
+ * Enqueue the node for
+ * the dag exec thread
+ * to fire.
+ */
+ RF_ASSERT(rf_NodeReady(s));
if (q) {
q->next = s;
q = s;
@@ -504,12 +560,16 @@ PropagateResults(
qh->next = NULL;
}
}
+ }
}
}
}
if (q) {
- /* xfer our local list of nodes to the node queue */
+ /*
+ * Transfer our local list of nodes to the node
+ * queue.
+ */
q->next = raidPtr->node_queue;
raidPtr->node_queue = qh;
DO_SIGNAL(raidPtr);
@@ -528,7 +588,7 @@ PropagateResults(
rf_FinishNode(skiplist, context);
}
for (; finishlist; finishlist = next) {
- /* NIL nodes: no need to fire them */
+ /* NIL nodes: no need to fire them. */
next = finishlist->next;
finishlist->status = rf_good;
for (i = 0; i < finishlist->numAntecedents; i++) {
@@ -537,18 +597,20 @@ PropagateResults(
if (finishlist->commitNode)
finishlist->dagHdr->numCommits++;
/*
- * Okay, here we're calling rf_FinishNode() on nodes that
- * have the null function as their work proc. Such a node
- * could be the terminal node in a DAG. If so, it will
- * cause the DAG to complete, which will in turn free
- * memory used by the DAG, which includes the node in
- * question. Thus, we must avoid referencing the node
- * at all after calling rf_FinishNode() on it.
- */
- rf_FinishNode(finishlist, context); /* recursive call */
+ * Okay, here we're calling rf_FinishNode() on nodes
+ * that have the null function as their work proc.
+ * Such a node could be the terminal node in a DAG.
+ * If so, it will cause the DAG to complete, which will
+ * in turn free memory used by the DAG, which includes
+ * the node in question.
+ * Thus, we must avoid referencing the node at all
+ * after calling rf_FinishNode() on it.
+ */
+ /* Recursive call. */
+ rf_FinishNode(finishlist, context);
}
- /* fire all nodes in firelist */
- FireNodeList(firelist);
+ /* Fire all nodes in firelist. */
+ rf_FireNodeList(firelist);
break;
case rf_rollBackward:
@@ -560,22 +622,32 @@ PropagateResults(
if (a->numSuccDone == a->numSuccFired) {
if (a->undoFunc == rf_NullNodeFunc) {
- /* don't fire NIL nodes, just process
- * them */
+ /*
+ * Don't fire NIL nodes, just process
+ * them.
+ */
a->next = finishlist;
finishlist = a;
} else {
if (context != RF_INTR_CONTEXT) {
- /* we only have to enqueue if
- * we're at intr context */
- a->next = firelist; /* put node on a list to
- * be fired after we
- * unlock */
+ /*
+ * We only have to enqueue if
+ * we're at intr context.
+ */
+ /*
+ * Put node on a list to
+ * be fired after we
+ * unlock.
+ */
+ a->next = firelist;
firelist = a;
- } else { /* enqueue the node for
- * the dag exec thread
- * to fire */
- RF_ASSERT(NodeReady(a));
+ } else {
+ /*
+ * Enqueue the node for
+ * the dag exec thread
+ * to fire.
+ */
+ RF_ASSERT(rf_NodeReady(a));
if (q) {
q->next = a;
q = a;
@@ -588,47 +660,50 @@ PropagateResults(
}
}
if (q) {
- /* xfer our local list of nodes to the node queue */
+ /*
+ * Transfer our local list of nodes to the node
+ * queue.
+ */
q->next = raidPtr->node_queue;
raidPtr->node_queue = qh;
DO_SIGNAL(raidPtr);
}
DO_UNLOCK(raidPtr);
- for (; finishlist; finishlist = next) { /* NIL nodes: no need to
- * fire them */
+ for (; finishlist; finishlist = next) {
+ /* NIL nodes: no need to fire them. */
next = finishlist->next;
finishlist->status = rf_good;
/*
- * Okay, here we're calling rf_FinishNode() on nodes that
- * have the null function as their work proc. Such a node
- * could be the first node in a DAG. If so, it will
- * cause the DAG to complete, which will in turn free
- * memory used by the DAG, which includes the node in
- * question. Thus, we must avoid referencing the node
- * at all after calling rf_FinishNode() on it.
- */
- rf_FinishNode(finishlist, context); /* recursive call */
+ * Okay, here we're calling rf_FinishNode() on nodes
+ * that have the null function as their work proc.
+ * Such a node could be the first node in a DAG.
+ * If so, it will cause the DAG to complete, which will
+ * in turn free memory used by the DAG, which includes
+ * the node in question.
+ * Thus, we must avoid referencing the node at all
+ * after calling rf_FinishNode() on it.
+ */
+ rf_FinishNode(finishlist, context);
+ /* Recursive call. */
}
- /* fire all nodes in firelist */
- FireNodeList(firelist);
+ /* Fire all nodes in firelist. */
+ rf_FireNodeList(firelist);
break;
default:
- printf("Engine found illegal DAG status in PropagateResults()\n");
+ printf("Engine found illegal DAG status in"
+ " rf_PropagateResults()\n");
RF_PANIC();
break;
}
}
-
/*
- * Process a fired node which has completed
+ * Process a fired node which has completed.
*/
-static void
-ProcessNode(
- RF_DagNode_t * node,
- int context)
+void
+rf_ProcessNode(RF_DagNode_t *node, int context)
{
RF_Raid_t *raidPtr;
@@ -636,79 +711,82 @@ ProcessNode(
switch (node->status) {
case rf_good:
- /* normal case, don't need to do anything */
+ /* Normal case, don't need to do anything. */
break;
case rf_bad:
- if ((node->dagHdr->numCommits > 0) || (node->dagHdr->numCommitNodes == 0)) {
- node->dagHdr->status = rf_rollForward; /* crossed commit
- * barrier */
+ if ((node->dagHdr->numCommits > 0) ||
+ (node->dagHdr->numCommitNodes == 0)) {
+ /* Crossed commit barrier. */
+ node->dagHdr->status = rf_rollForward;
if (rf_engineDebug || 1) {
- printf("raid%d: node (%s) returned fail, rolling forward\n", raidPtr->raidid, node->name);
+ printf("raid%d: node (%s) returned fail,"
+ " rolling forward\n", raidPtr->raidid,
+ node->name);
}
} else {
- node->dagHdr->status = rf_rollBackward; /* never reached commit
- * barrier */
+ /* Never reached commit barrier. */
+ node->dagHdr->status = rf_rollBackward;
if (rf_engineDebug || 1) {
- printf("raid%d: node (%s) returned fail, rolling backward\n", raidPtr->raidid, node->name);
+ printf("raid%d: node (%s) returned fail,"
+ " rolling backward\n", raidPtr->raidid,
+ node->name);
}
}
break;
case rf_undone:
- /* normal rollBackward case, don't need to do anything */
+ /* Normal rollBackward case, don't need to do anything. */
break;
case rf_panic:
- /* an undo node failed!!! */
- printf("UNDO of a node failed!!!/n");
+ /* An undo node failed !!! */
+ printf("UNDO of a node failed !!!/n");
break;
default:
- printf("node finished execution with an illegal status!!!\n");
+ printf("node finished execution with an illegal status !!!\n");
RF_PANIC();
break;
}
- /* enqueue node's succedents (antecedents if rollBackward) for
- * execution */
- PropagateResults(node, context);
+ /*
+ * Enqueue node's succedents (antecedents if rollBackward) for
+ * execution.
+ */
+ rf_PropagateResults(node, context);
}
-
-/* user context or dag-exec-thread context:
+/*
+ * User context or dag-exec-thread context:
* This is the first step in post-processing a newly-completed node.
* This routine is called by each node execution function to mark the node
* as complete and fire off any successors that have been enabled.
*/
-int
-rf_FinishNode(
- RF_DagNode_t * node,
- int context)
+int
+rf_FinishNode(RF_DagNode_t *node, int context)
{
- /* as far as I can tell, retcode is not used -wvcii */
- int retcode = RF_FALSE;
+ /* As far as I can tell, retcode is not used -wvcii. */
+ int retcode = RF_FALSE;
node->dagHdr->numNodesCompleted++;
- ProcessNode(node, context);
+ rf_ProcessNode(node, context);
return (retcode);
}
-/* user context:
- * submit dag for execution, return non-zero if we have to wait for completion.
- * if and only if we return non-zero, we'll cause cbFunc to get invoked with
+/*
+ * User context:
+ * Submit dag for execution, return non-zero if we have to wait for completion.
+ * If and only if we return non-zero, we'll cause cbFunc to get invoked with
* cbArg when the DAG has completed.
*
- * for now we always return 1. If the DAG does not cause any I/O, then the callback
- * may get invoked before DispatchDAG returns. There's code in state 5 of ContinueRaidAccess
- * to handle this.
+ * For now we always return 1. If the DAG does not cause any I/O, then the
+ * callback may get invoked before DispatchDAG returns. There's code in state
+ * 5 of ContinueRaidAccess to handle this.
*
- * All we do here is fire the direct successors of the header node. The
- * DAG execution thread does the rest of the dag processing.
+ * All we do here is fire the direct successors of the header node. The DAG
+ * execution thread does the rest of the dag processing.
*/
-int
-rf_DispatchDAG(
- RF_DagHeader_t * dag,
- void (*cbFunc) (void *),
- void *cbArg)
+int
+rf_DispatchDAG(RF_DagHeader_t *dag, void (*cbFunc) (void *), void *cbArg)
{
RF_Raid_t *raidPtr;
@@ -723,29 +801,35 @@ rf_DispatchDAG(
if (rf_engineDebug) {
printf("raid%d: Entering DispatchDAG\n", raidPtr->raidid);
}
- raidPtr->dags_in_flight++; /* debug only: blow off proper
- * locking */
+ raidPtr->dags_in_flight++; /*
+ * Debug only: blow off proper
+ * locking.
+ */
dag->cbFunc = cbFunc;
dag->cbArg = cbArg;
dag->numNodesCompleted = 0;
dag->status = rf_enable;
- FireNodeArray(dag->numSuccedents, dag->succedents);
+ rf_FireNodeArray(dag->numSuccedents, dag->succedents);
return (1);
}
-/* dedicated kernel thread:
- * the thread that handles all DAG node firing.
- * To minimize locking and unlocking, we grab a copy of the entire node queue and then set the
- * node queue to NULL before doing any firing of nodes. This way we only have to release the
- * lock once. Of course, it's probably rare that there's more than one node in the queue at
- * any one time, but it sometimes happens.
+
+
+/*
+ * Dedicated kernel thread:
+ * The thread that handles all DAG node firing.
+ * To minimize locking and unlocking, we grab a copy of the entire node queue
+ * and then set the node queue to NULL before doing any firing of nodes.
+ * This way we only have to release the lock once. Of course, it's probably
+ * rare that there's more than one node in the queue at any one time, but it
+ * sometimes happens.
*
- * In the kernel, this thread runs at spl0 and is not swappable. I copied these
+ * In the kernel, this thread runs at spl0 and is not swappable. I copied these
* characteristics from the aio_completion_thread.
*/
-#ifdef RAID_AUTOCONFIG
-void
-DAGExecutionThread_pre(RF_ThreadArg_t arg)
+#ifdef RAID_AUTOCONFIG
+void
+rf_DAGExecutionThread_pre(RF_ThreadArg_t arg)
{
RF_Raid_t *raidPtr;
char raidname[16];
@@ -760,12 +844,12 @@ DAGExecutionThread_pre(RF_ThreadArg_t arg)
lastpid = RF_ENGINE_PID + raidPtr->raidid - 1;
len = sprintf(&raidname[0], "raid%d", raidPtr->raidid);
-#ifdef DIAGNOSTIC
+#ifdef DIAGNOSTIC
if (len >= sizeof(raidname))
panic("raidname expansion too long.");
-#endif /* DIAGNOSTIC */
+#endif /* DIAGNOSTIC */
- if (RF_CREATE_THREAD(raidPtr->engine_thread, DAGExecutionThread,
+ if (RF_CREATE_THREAD(raidPtr->engine_thread, rf_DAGExecutionThread,
raidPtr, &raidname[0])) {
RF_ERRORMSG("RAIDFRAME: Unable to create engine thread\n");
return;
@@ -779,13 +863,13 @@ DAGExecutionThread_pre(RF_ThreadArg_t arg)
}
#endif /* RAID_AUTOCONFIG */
-void
-DAGExecutionThread(RF_ThreadArg_t arg)
+void
+rf_DAGExecutionThread(RF_ThreadArg_t arg)
{
RF_DagNode_t *nd, *local_nq, *term_nq, *fire_nq;
RF_Raid_t *raidPtr;
- int ks;
- int s;
+ int ks;
+ int s;
raidPtr = (RF_Raid_t *) arg;
@@ -796,7 +880,7 @@ DAGExecutionThread(RF_ThreadArg_t arg)
if (rf_engineDebug) {
printf("raid%d: Engine thread is running\n", raidPtr->raidid);
}
- /* XXX what to put here XXX */
+ /* XXX What to put here ? XXX */
s = splbio();
@@ -815,7 +899,7 @@ DAGExecutionThread(RF_ThreadArg_t arg)
raidPtr->node_queue = NULL;
DO_UNLOCK(raidPtr);
- /* first, strip out the terminal nodes */
+ /* First, strip out the terminal nodes. */
while (local_nq) {
nd = local_nq;
local_nq = local_nq->next;
@@ -823,26 +907,34 @@ DAGExecutionThread(RF_ThreadArg_t arg)
case rf_enable:
case rf_rollForward:
if (nd->numSuccedents == 0) {
- /* end of the dag, add to
- * callback list */
+ /*
+ * End of the dag, add to
+ * callback list.
+ */
nd->next = term_nq;
term_nq = nd;
} else {
- /* not the end, add to the
- * fire queue */
+ /*
+ * Not the end, add to the
+ * fire queue.
+ */
nd->next = fire_nq;
fire_nq = nd;
}
break;
case rf_rollBackward:
if (nd->numAntecedents == 0) {
- /* end of the dag, add to the
- * callback list */
+ /*
+ * End of the dag, add to the
+ * callback list.
+ */
nd->next = term_nq;
term_nq = nd;
} else {
- /* not the end, add to the
- * fire queue */
+ /*
+ * Not the end, add to the
+ * fire queue.
+ */
nd->next = fire_nq;
fire_nq = nd;
}
@@ -853,18 +945,20 @@ DAGExecutionThread(RF_ThreadArg_t arg)
}
}
- /* execute callback of dags which have reached the
- * terminal node */
+ /*
+ * Execute callback of dags which have reached the
+ * terminal node.
+ */
while (term_nq) {
nd = term_nq;
term_nq = term_nq->next;
nd->next = NULL;
(nd->dagHdr->cbFunc) (nd->dagHdr->cbArg);
- raidPtr->dags_in_flight--; /* debug only */
+ raidPtr->dags_in_flight--; /* Debug only. */
}
- /* fire remaining nodes */
- FireNodeList(fire_nq);
+ /* Fire remaining nodes. */
+ rf_FireNodeList(fire_nq);
DO_LOCK(raidPtr);
}