FreeBSD/sys/cam/ctl/ctl.c
/*
 * Delete a LUN.
 * Assumptions:
 * - LUN has already been marked invalid and any pending I/O has been taken
 *   care of.
 */
Delete a LUN.
Assumptions:
- LUN has already been marked invalid and any pending I/O has been taken
care of.
Delete a LUN . Assumptions : - LUN has already been marked invalid and any pending I / O has been taken care of .
static int
ctl_free_lun(struct ctl_lun *lun)
{
	struct ctl_softc *softc;
	struct ctl_lun *nlun;
	int i;
	softc = lun->ctl_softc;
	mtx_assert(&softc->ctl_lock, MA_OWNED);
	STAILQ_REMOVE(&softc->lun_list, lun, ctl_lun, links);
	ctl_clear_mask(softc->ctl_lun_mask, lun->lun);
	softc->ctl_luns[lun->lun] = NULL;
	if (!TAILQ_EMPTY(&lun->ooa_queue))
		panic("Freeing a LUN %p with outstanding I/O!!\n", lun);
	softc->num_luns--;
	atomic_subtract_int(&lun->be_lun->be->num_luns, 1);
	lun->be_lun->lun_shutdown(lun->be_lun->be_lun);
	ctl_tpc_lun_shutdown(lun);
	mtx_destroy(&lun->lun_lock);
	free(lun->lun_devid, M_CTL);
	for (i = 0; i < CTL_MAX_PORTS; i++)
		free(lun->pending_ua[i], M_CTL);
	for (i = 0; i < CTL_MAX_PORTS; i++)
		free(lun->pr_keys[i], M_CTL);
	free(lun->write_buffer, M_CTL);
	if (lun->flags & CTL_LUN_MALLOCED)
		free(lun, M_CTL);
	STAILQ_FOREACH(nlun, &softc->lun_list, links) {
		mtx_lock(&nlun->lun_lock);
		ctl_est_ua_all(nlun, -1, CTL_UA_LUN_CHANGE);
		mtx_unlock(&nlun->lun_lock);
	}
	return (0);
}
static int ctl_free_lun ( struct ctl_lun * lun ) { struct ctl_softc * softc ; struct ctl_lun * nlun ; int i ; softc = lun -> ctl_softc ; mtx_assert ( & softc -> ctl_lock , MA_OWNED ) ; STAILQ_REMOVE ( & softc -> lun_list , lun , ctl_lun , links ) ; ctl_clear_mask ( softc -> ctl_lun_mask , lun -> lun ) ; softc -> ctl_luns [ lun -> lun ] = NULL ; if ( ! TAILQ_EMPTY ( & lun -> ooa_queue ) ) panic ( " \n " , lun ) ; softc -> num_luns -- ; atomic_subtract_int ( & lun -> be_lun -> be -> num_luns , 1 ) ; lun -> be_lun -> lun_shutdown ( lun -> be_lun -> be_lun ) ; ctl_tpc_lun_shutdown ( lun ) ; mtx_destroy ( & lun -> lun_lock ) ; free ( lun -> lun_devid , M_CTL ) ; for ( i = 0 ; i < CTL_MAX_PORTS ; i ++ ) free ( lun -> pending_ua [ i ] , M_CTL ) ; for ( i = 0 ; i < CTL_MAX_PORTS ; i ++ ) free ( lun -> pr_keys [ i ] , M_CTL ) ; free ( lun -> write_buffer , M_CTL ) ; if ( lun -> flags & CTL_LUN_MALLOCED ) free ( lun , M_CTL ) ; STAILQ_FOREACH ( nlun , & softc -> lun_list , links ) { mtx_lock ( & nlun -> lun_lock ) ; ctl_est_ua_all ( nlun , -1 , CTL_UA_LUN_CHANGE ) ; mtx_unlock ( & nlun -> lun_lock ) ; } return ( 0 ) ; }
Delete a LUN.
Delete a LUN .
/*
	 * Tell the backend to free resources, if this LUN has a backend.
	 */