⬢ DragonFlyBSD Kernel Audit
DF-2265 / df_pre.c
← back to finding ↓ download raw
/*
 * DF-2263 / DF-2264 / DF-2265 verification harness -- PREAMBLE.
 *
 * This file is concatenated (gen.sh) BEFORE a verbatim copy of
 * sys/bus/cam/scsi/scsi_sa.c and AFTER it df_post.c is appended, and
 * the result is compiled into the kernel (kern/df226x_harness.c,
 * conf/files entry "standard").
 *
 * The ONLY thing this preamble does is interpose, via the C
 * preprocessor, the EXTERNAL (non-static) functions that the real
 * scsi_sa.c code calls on the paths under test, so the harness can
 * fabricate CAM/tape state without any SCSI hardware:
 *
 *	xpt_release_ccb	called by sastart/sagetparams/sasetparams exits
 *	cam_periph_getccbccb allocation in sagetparams/sasetparams
 *	cam_periph_runccb	the CCB "transport" (fake drive responses)
 *	xpt_print	message printing
 *	biodone		counting/observation wrapper (calls the real one)
 *
 * Everything else that executes is the REAL kernel code: sastart,
 * saioctl, sasetparams, sagetparams, cam_periph_lock/unlock/hold,
 * cam_sim_lock, cam_extend_get/set, bioq_*, biodone_sync, bpdone,
 * brelse, lockmgr/lksleep, kmalloc/kfree (M_SCSISA), minor().
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/malloc.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/mtio.h>
#include <sys/buf.h>
#include <sys/buf2.h>
#include <sys/lock.h>
#include <sys/proc.h>
#include <sys/kthread.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <machine/limits.h>

#include <bus/cam/cam.h>
#include <bus/cam/cam_ccb.h>
#include <bus/cam/cam_sim.h>
#include <bus/cam/cam_periph.h>
#include <bus/cam/cam_queue.h>
#include <bus/cam/cam_xpt_sim.h>
#include <bus/cam/cam_xpt_periph.h>
#include <bus/cam/scsi/scsi_all.h>
#include <bus/cam/scsi/scsi_message.h>
#include <bus/cam/scsi/scsi_sa.h>

#include <sys/devicestat.h>

/* ---- interposition of external symbols (see header comment) ---- */
#define xpt_release_ccb		dfh_xpt_release_ccb
#define xpt_schedule		dfh_xpt_schedule
#define cam_periph_getccb	dfh_cam_periph_getccb
#define cam_periph_runccb	dfh_cam_periph_runccb
#define xpt_print		dfh_xpt_print
#define biodone			dfh_biodone

/* shim prototypes (implemented in df_post.c; every call site inside
 * the verbatim scsi_sa.c that follows resolves to these) */
static void	dfh_xpt_release_ccb (union ccb *);
static void	dfh_xpt_schedule (struct cam_periph *, u_int32_t);
static union ccb *dfh_cam_periph_getccb (struct cam_periph *,
					  u_int32_t);
static int	dfh_cam_periph_runccb (union ccb *,
				   int (*)(union ccb *, cam_flags,
				       u_int32_t),
				   cam_flags, u_int32_t, struct devstat *);
static void	dfh_xpt_print (struct cam_path *, const char *, ...);
static void	dfh_biodone (struct bio *);

/*
 * NOTE: gen.sh comments out "device sa" in the guest's kernel config so
 * the kernel no longer compiles scsi_sa.c separately (scsi_sa.o); the
 * verbatim copy inside this TU is then the only one.  Nothing is
 * renamed; all driver code below is byte-for-byte the source file.
 */

/*
 * ==================== VERBATIM scsi_sa.c FOLLOWS ====================
 */