/*static char *SCCSID = "@(#)reqdone.c	6.1 90/11/18";*/
/*static char *SCCSID = "@(#)ReqDone.c      13.5 90/02/06";*/

#include "os2def.h"			/* Needed by all. */
#include "const.h"			/* SPB, SECSIZE, needed by all. */
#include "misc.h"			/* Needed by "dir.h". */
#include "buf.h"			/* Needed by "dir.h", "fsdata.h". */
#include "chain.h"			/* Needed by "dir.h". */
#include "dir.h"			/* Needed by "fsdata.h". */
#include "lw.h"				/* Needed by "fsdata.h". */
#include "volume.h"			/* Needed by "frame.h", "fsdata.h". */
#include "frame.h"			/* Needed by "fsdata.h". */
#include "fsdata.h"			/* Needed by "asyncio.h". */
#include "pbmacros.h"			/* DECR_HOLDS. */
#include "strat2.h"			/* Needed by "asyncio.h". */
#include "asyncio.h"			/* BEGIN_NOTIFY, PIOH, PLISTENT, etc. */
#include "lprintf.h"
#include "storage.h"			/* Needed by "assert.h", "tables.h". */
#include "tables.h"			/* Needed by "assert.h", "pr_debug.h".*/
#include "assert.h"			/* ASSERT_IOH(). */
#include "pr_lazy.h"			/* RequestDone(). */
#ifdef DEBUG_LW
    #include "pr_debug.h"		/* dprintf(). */
#endif

/** RequestDone is the interrupt handler for each LW async I/O operation.
 *
 *	RequestDone is the interrupt handler which handles each request when it
 *	has been performed.  This routine is called with a pointer to the
 *	request.  The device driver has already set the error and/or status
 *	flags in the request.  If the I/O went OK, then RequestDone can unhold
 *	each buffer for that request, and wakeup anybody waiting for it.  If
 *	an error occurred, then somebody must hotfix the appropriate sectors.
 *	However, RequestDone cannot do this, because it would cause the
 *	interrupt routine to block.  So, RequestDone does nothing in this case.
 *	(See HandleLWErrors, which actually handles the errors.)
 *
 *	ENTRY	preq	pointer to the request that finished
 *
 *	EXIT	none
 *
 *	HISTORY
 *	    02-Feb-90 by JR (John Rogers, JohnRo@Microsoft)
 *		- Added debug message on error.  Also added assertion checking.
 *	    15-Nov-89 by JR (John Rogers, JohnRo@Microsoft)
 *		- Added prologue, as part of rework from code review.
 *	    08-Nov-89 by JR (John Rogers, JohnRo@Microsoft)
 *		- Initial PIC version of scatter/gather support.
 */

BEGIN_NOTIFY( RequestDone, parm, uError)		/* Must not block. */
    PLISTENT preq = (PLISTENT) parm;

#ifdef DEBUG
    PIOH pioh = IOHFromListHead (HeadFromIOReq( preq ));
#endif

#ifdef ASSERT_IOH
    ASSERT_IOH(pioh);
#endif

    /* Was there an error in this request? */
    if (uError) {

#ifdef DEBUG_LW
	dprintf(__FILE__": processing error, preq=%p\n", preq);
#endif

	/*
	 * Do nothing for now.  LWAsync will call HandleLWErrors when 
	 * the entire execution list has completed.  HandleLWErrors will then
	 * call RequestCleanup.
	 */
	;

    } else { /* no error */

	/* Unhold the buffers for this request. */
	/* wakeup anybody waiting on this buffer */
	RequestCleanup( preq );				/* Must not block. */

    } /* no error */

END_NOTIFY
