FreeBSD/sys/cam/scsi/scsi_target.c
/* Enable/disable LUNs, set debugging level */
Enable/disable LUNs, set debugging level
Enable / disable LUNs set debugging level
static int
targioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
{
	struct targ_softc *softc;
	cam_status	   status;
	devfs_get_cdevpriv((void **)&softc);
	switch (cmd) {
	case TARGIOCENABLE:
	{
		struct ioc_enable_lun	*new_lun;
		struct cam_path		*path;
		new_lun = (struct ioc_enable_lun *)addr;
		status = xpt_create_path(&path, NULL,
					  new_lun->path_id,
					  new_lun->target_id,
					  new_lun->lun_id);
		if (status != CAM_REQ_CMP) {
			printf("Couldn't create path, status %#x\n", status);
			break;
		}
		xpt_path_lock(path);
		status = targenable(softc, path, new_lun->grp6_len,
				    new_lun->grp7_len);
		xpt_path_unlock(path);
		xpt_free_path(path);
		break;
	}
	case TARGIOCDISABLE:
		if (softc->periph == NULL) {
			status = CAM_DEV_NOT_THERE;
			break;
		}
		cam_periph_lock(softc->periph);
		status = targdisable(softc);
		cam_periph_unlock(softc->periph);
		break;
	case TARGIOCDEBUG:
	{
		struct ccb_debug cdbg;
		if ((softc->state & TARG_STATE_LUN_ENABLED) == 0) {
			status = CAM_DEV_NOT_THERE;
			break;
		}
		bzero(&cdbg, sizeof cdbg);
		if (*((int *)addr) != 0)
			cdbg.flags = CAM_DEBUG_PERIPH;
		else
			cdbg.flags = CAM_DEBUG_NONE;
		xpt_setup_ccb(&cdbg.ccb_h, softc->path, CAM_PRIORITY_NORMAL);
		cdbg.ccb_h.func_code = XPT_DEBUG;
		cdbg.ccb_h.cbfcnp = targdone;
		xpt_action((union ccb *)&cdbg);
		status = cdbg.ccb_h.status & CAM_STATUS_MASK;
		break;
	}
	default:
		status = CAM_PROVIDE_FAIL;
		break;
	}
	return (targcamstatus(status));
}
static int targioctl ( struct cdev * dev , u_long cmd , caddr_t addr , int flag , struct thread * td ) { struct targ_softc * softc ; cam_status status ; devfs_get_cdevpriv ( ( void * * ) & softc ) ; switch ( cmd ) { case TARGIOCENABLE : { struct ioc_enable_lun * new_lun ; struct cam_path * path ; new_lun = ( struct ioc_enable_lun * ) addr ; status = xpt_create_path ( & path , NULL , new_lun -> path_id , new_lun -> target_id , new_lun -> lun_id ) ; if ( status != CAM_REQ_CMP ) { printf ( " \n " , status ) ; break ; } xpt_path_lock ( path ) ; status = targenable ( softc , path , new_lun -> grp6_len , new_lun -> grp7_len ) ; xpt_path_unlock ( path ) ; xpt_free_path ( path ) ; break ; } case TARGIOCDISABLE : if ( softc -> periph == NULL ) { status = CAM_DEV_NOT_THERE ; break ; } cam_periph_lock ( softc -> periph ) ; status = targdisable ( softc ) ; cam_periph_unlock ( softc -> periph ) ; break ; case TARGIOCDEBUG : { struct ccb_debug cdbg ; if ( ( softc -> state & TARG_STATE_LUN_ENABLED ) == 0 ) { status = CAM_DEV_NOT_THERE ; break ; } bzero ( & cdbg , sizeof cdbg ) ; if ( * ( ( int * ) addr ) != 0 ) cdbg . flags = CAM_DEBUG_PERIPH ; else cdbg . flags = CAM_DEBUG_NONE ; xpt_setup_ccb ( & cdbg . ccb_h , softc -> path , CAM_PRIORITY_NORMAL ) ; cdbg . ccb_h . func_code = XPT_DEBUG ; cdbg . ccb_h . cbfcnp = targdone ; xpt_action ( ( union ccb * ) & cdbg ) ; status = cdbg . ccb_h . status & CAM_STATUS_MASK ; break ; } default : status = CAM_PROVIDE_FAIL ; break ; } return ( targcamstatus ( status ) ) ; }
Enable/disable LUNs, set debugging level
Enable / disable LUNs set debugging level
/*periph*/ /* If no periph available, disallow debugging changes */