FreeBSD/sys/dev/iscsi_initiator/isc_soc.c
/*
 | one per active (connected) session.
 | this thread is responsible for reading
 | in packets from the target.
 */
| one per active (connected) session.
| this thread is responsible for reading
| in packets from the target.
| one per active ( connected ) session . | this thread is responsible for reading | in packets from the target .
static void
isc_in(void *vp)
{
     isc_session_t	*sp = (isc_session_t *)vp;
     struct socket	*so = sp->soc;
     int		error;
     debug_called(8);
     sp->flags |= ISC_CON_RUNNING;
     error = 0;
     while((sp->flags & (ISC_CON_RUN | ISC_LINK_UP)) == (ISC_CON_RUN | ISC_LINK_UP)) {
	  if(sp->soc == NULL || !(so->so_state & SS_ISCONNECTED)) {
	       debug(2, "sp->soc=%p", sp->soc);
	       break;
	  }
	  error = so_input(sp);
	  if(error == 0) {
	       mtx_lock(&sp->io_mtx);
	       if(sp->flags & ISC_OWAITING) {
		    wakeup(&sp->flags);
	       }
	       mtx_unlock(&sp->io_mtx);
	  } else if(error == EPIPE) {
	       break;
	  }
	  else if(error == EAGAIN) {
	       if(so->so_state & SS_ISCONNECTED) 
		    tsleep(sp, PRIBIO, "isc_soc", 2*hz);
	  }
     }
     sdebug(2, "terminated, flags=%x so_count=%d so_state=%x error=%d proc=%p",
	    sp->flags, so->so_count, so->so_state, error, sp->proc);
     if((sp->proc != NULL) && sp->signal) {
	  PROC_LOCK(sp->proc);
	  kern_psignal(sp->proc, sp->signal);
	  PROC_UNLOCK(sp->proc);
	  sp->flags |= ISC_SIGNALED;
	  sdebug(2, "pid=%d signaled(%d)", sp->proc->p_pid, sp->signal);
     }
     else {
     }
     mtx_lock(&sp->io_mtx);
     sp->flags &= ~(ISC_CON_RUNNING | ISC_LINK_UP);
     wakeup(&sp->soc);
     mtx_unlock(&sp->io_mtx);
     sdebug(2, "dropped ISC_CON_RUNNING");
#if __FreeBSD_version >= 800000
     kproc_exit(0);
#else
     kthread_exit(0);
#endif
}
static void isc_in ( void * vp ) { isc_session_t * sp = ( isc_session_t * ) vp ; struct socket * so = sp -> soc ; int error ; debug_called ( 8 ) ; sp -> flags |= ISC_CON_RUNNING ; error = 0 ; while ( ( sp -> flags & ( ISC_CON_RUN | ISC_LINK_UP ) ) == ( ISC_CON_RUN | ISC_LINK_UP ) ) { if ( sp -> soc == NULL || ! ( so -> so_state & SS_ISCONNECTED ) ) { debug ( 2 , " " , sp -> soc ) ; break ; } error = so_input ( sp ) ; if ( error == 0 ) { mtx_lock ( & sp -> io_mtx ) ; if ( sp -> flags & ISC_OWAITING ) { wakeup ( & sp -> flags ) ; } mtx_unlock ( & sp -> io_mtx ) ; } else if ( error == EPIPE ) { break ; } else if ( error == EAGAIN ) { if ( so -> so_state & SS_ISCONNECTED ) tsleep ( sp , PRIBIO , " " , 2 * hz ) ; } } sdebug ( 2 , " " , sp -> flags , so -> so_count , so -> so_state , error , sp -> proc ) ; if ( ( sp -> proc != NULL ) && sp -> signal ) { PROC_LOCK ( sp -> proc ) ; kern_psignal ( sp -> proc , sp -> signal ) ; PROC_UNLOCK ( sp -> proc ) ; sp -> flags |= ISC_SIGNALED ; sdebug ( 2 , " " , sp -> proc -> p_pid , sp -> signal ) ; } else { } mtx_lock ( & sp -> io_mtx ) ; sp -> flags &= ~ ( ISC_CON_RUNNING | ISC_LINK_UP ) ; wakeup ( & sp -> soc ) ; mtx_unlock ( & sp -> io_mtx ) ; sdebug ( 2 , " " ) ; #if __FreeBSD_version >= 800000 kproc_exit ( 0 ) ; #else kthread_exit ( 0 ) ; #endif }
| one per active (connected) session.
| one per active ( connected ) session .
// XXX: hunting ... // there seems to be a problem in 6.0 ... // we have to do something ourselves // like closing this session ... /*
      | we've been terminated
      */ // do we need this mutex ...?