summaryrefslogtreecommitdiffstats
path: root/sys/netsmb/smb_trantcp.c
diff options
context:
space:
mode:
authorbp <bp@FreeBSD.org>2001-12-02 08:47:29 +0000
committerbp <bp@FreeBSD.org>2001-12-02 08:47:29 +0000
commit0b6f0e4522eeceef1d5e5dc2e920666192f7ec2a (patch)
tree4dd79521a04986ca1ef5e89d2110be2df70ef2e7 /sys/netsmb/smb_trantcp.c
parent124068ba6b175b9c0386b32be7f7d51a5d46908a (diff)
downloadFreeBSD-src-0b6f0e4522eeceef1d5e5dc2e920666192f7ec2a.zip
FreeBSD-src-0b6f0e4522eeceef1d5e5dc2e920666192f7ec2a.tar.gz
Pull netsmb requester from the pre-KSE world. This update mostly based
on the patches submitted by Max Khon <fjoe@iclub.nsu.ru>
Diffstat (limited to 'sys/netsmb/smb_trantcp.c')
-rw-r--r--sys/netsmb/smb_trantcp.c105
1 files changed, 59 insertions, 46 deletions
diff --git a/sys/netsmb/smb_trantcp.c b/sys/netsmb/smb_trantcp.c
index 3d6b082..7c4d74b 100644
--- a/sys/netsmb/smb_trantcp.c
+++ b/sys/netsmb/smb_trantcp.c
@@ -70,12 +70,12 @@ SYSCTL_DECL(_net_smb);
SYSCTL_INT(_net_smb, OID_AUTO, tcpsndbuf, CTLFLAG_RW, &smb_tcpsndbuf, 0, "");
SYSCTL_INT(_net_smb, OID_AUTO, tcprcvbuf, CTLFLAG_RW, &smb_tcprcvbuf, 0, "");
-#define nb_sosend(so,m,flags,p) (so)->so_proto->pr_usrreqs->pru_sosend( \
- so, NULL, 0, m, 0, flags, p)
+#define nb_sosend(so,m,flags,td) (so)->so_proto->pr_usrreqs->pru_sosend( \
+ so, NULL, 0, m, 0, flags, td)
static int nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp,
- u_int8_t *rpcodep, struct proc *p);
-static int smb_nbst_disconnect(struct smb_vc *vcp, struct proc *p);
+ u_int8_t *rpcodep, struct thread *td);
+static int smb_nbst_disconnect(struct smb_vc *vcp, struct thread *td);
static int
nb_setsockopt_int(struct socket *so, int level, int name, int val)
@@ -91,16 +91,18 @@ nb_setsockopt_int(struct socket *so, int level, int name, int val)
}
static __inline int
-nb_poll(struct nbpcb *nbp, int events, struct proc *p)
+nb_poll(struct nbpcb *nbp, int events, struct thread *td)
{
return nbp->nbp_tso->so_proto->pr_usrreqs->pru_sopoll(nbp->nbp_tso,
- events, NULL, p);
+ events, NULL, td);
}
static int
-nbssn_rselect(struct nbpcb *nbp, struct timeval *tv, int events, struct proc *p)
+nbssn_rselect(struct nbpcb *nbp, struct timeval *tv, int events,
+ struct thread *td)
{
struct timeval atv, rtv, ttv;
+ struct proc *p;
int timo, error;
if (tv) {
@@ -113,10 +115,13 @@ nbssn_rselect(struct nbpcb *nbp, struct timeval *tv, int events, struct proc *p)
timevaladd(&atv, &rtv);
}
timo = 0;
+ p = td->td_proc;
PROC_LOCK(p);
- p->p_flag |= P_SELECT;
+ mtx_lock_spin(&sched_lock);
+ td->td_flags |= TDF_SELECT;
+ mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
- error = nb_poll(nbp, events, p);
+ error = nb_poll(nbp, events, td);
PROC_LOCK(p);
if (error) {
error = 0;
@@ -131,19 +136,24 @@ nbssn_rselect(struct nbpcb *nbp, struct timeval *tv, int events, struct proc *p)
* the process, test P_SELECT and rescan file descriptors if
* necessary.
*/
- if ((p->p_flag & P_SELECT) == 0) {
- p->p_flag |= P_SELECT;
+ mtx_lock_spin(&sched_lock);
+ if ((td->td_flags & TDF_SELECT) == 0) {
+ td->td_flags |= TDF_SELECT;
+ mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
- error = nb_poll(nbp, events, p);
+ error = nb_poll(nbp, events, td);
PROC_LOCK(p);
- }
+ } else
+ mtx_unlock_spin(&sched_lock);
goto done;
}
ttv = atv;
timevalsub(&ttv, &rtv);
timo = tvtohz(&ttv);
}
- p->p_flag &= ~P_SELECT;
+ mtx_lock_spin(&sched_lock);
+ td->td_flags &= ~TDF_SELECT;
+ mtx_unlock_spin(&sched_lock);
if (timo > 0)
error = cv_timedwait(&selwait, &p->p_mtx, timo);
else {
@@ -152,8 +162,11 @@ nbssn_rselect(struct nbpcb *nbp, struct timeval *tv, int events, struct proc *p)
}
done:
+ mtx_lock_spin(&sched_lock);
+ td->td_flags &= ~TDF_SELECT;
+ mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
- p->p_flag &= ~P_SELECT;
+
done_noproclock:
if (error == ERESTART)
return 0;
@@ -208,12 +221,12 @@ nb_put_name(struct mbchain *mbp, struct sockaddr_nb *snb)
}
static int
-nb_connect_in(struct nbpcb *nbp, struct sockaddr_in *to, struct proc *p)
+nb_connect_in(struct nbpcb *nbp, struct sockaddr_in *to, struct thread *td)
{
struct socket *so;
int error, s;
- error = socreate(AF_INET, &so, SOCK_STREAM, IPPROTO_TCP, p);
+ error = socreate(AF_INET, &so, SOCK_STREAM, IPPROTO_TCP, td);
if (error)
return error;
nbp->nbp_tso = so;
@@ -229,14 +242,14 @@ nb_connect_in(struct nbpcb *nbp, struct sockaddr_in *to, struct proc *p)
nb_setsockopt_int(so, IPPROTO_TCP, TCP_NODELAY, 1);
so->so_rcv.sb_flags &= ~SB_NOINTR;
so->so_snd.sb_flags &= ~SB_NOINTR;
- error = soconnect(so, (struct sockaddr*)to, p);
+ error = soconnect(so, (struct sockaddr*)to, td);
if (error)
goto bad;
s = splnet();
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
tsleep(&so->so_timeo, PSOCK, "nbcon", 2 * hz);
if ((so->so_state & SS_ISCONNECTING) && so->so_error == 0 &&
- (error = nb_intr(nbp, p)) != 0) {
+ (error = nb_intr(nbp, td->td_proc)) != 0) {
so->so_state &= ~SS_ISCONNECTING;
splx(s);
goto bad;
@@ -251,12 +264,12 @@ nb_connect_in(struct nbpcb *nbp, struct sockaddr_in *to, struct proc *p)
splx(s);
return 0;
bad:
- smb_nbst_disconnect(nbp->nbp_vc, p);
+ smb_nbst_disconnect(nbp->nbp_vc, td);
return error;
}
static int
-nbssn_rq_request(struct nbpcb *nbp, struct proc *p)
+nbssn_rq_request(struct nbpcb *nbp, struct thread *td)
{
struct mbchain mb, *mbp = &mb;
struct mdchain md, *mdp = &md;
@@ -274,7 +287,7 @@ nbssn_rq_request(struct nbpcb *nbp, struct proc *p)
nb_put_name(mbp, nbp->nbp_paddr);
nb_put_name(mbp, nbp->nbp_laddr);
nb_sethdr(mbp->mb_top, NB_SSN_REQUEST, mb_fixhdr(mbp) - 4);
- error = nb_sosend(nbp->nbp_tso, mbp->mb_top, 0, p);
+ error = nb_sosend(nbp->nbp_tso, mbp->mb_top, 0, td);
if (!error) {
nbp->nbp_state = NBST_RQSENT;
}
@@ -283,14 +296,14 @@ nbssn_rq_request(struct nbpcb *nbp, struct proc *p)
if (error)
return error;
TIMESPEC_TO_TIMEVAL(&tv, &nbp->nbp_timo);
- error = nbssn_rselect(nbp, &tv, POLLIN, p);
+ error = nbssn_rselect(nbp, &tv, POLLIN, td);
if (error == EWOULDBLOCK) { /* Timeout */
NBDEBUG("initial request timeout\n");
return ETIMEDOUT;
}
if (error) /* restart or interrupt */
return error;
- error = nbssn_recv(nbp, &m0, &rplen, &rpcode, p);
+ error = nbssn_recv(nbp, &m0, &rplen, &rpcode, td);
if (error) {
NBDEBUG("recv() error %d\n", error);
return error;
@@ -319,12 +332,12 @@ nbssn_rq_request(struct nbpcb *nbp, struct proc *p)
md_get_uint16(mdp, &port);
sin.sin_port = port;
nbp->nbp_state = NBST_RETARGET;
- smb_nbst_disconnect(nbp->nbp_vc, p);
- error = nb_connect_in(nbp, &sin, p);
+ smb_nbst_disconnect(nbp->nbp_vc, td);
+ error = nb_connect_in(nbp, &sin, td);
if (!error)
- error = nbssn_rq_request(nbp, p);
+ error = nbssn_rq_request(nbp, td);
if (error) {
- smb_nbst_disconnect(nbp->nbp_vc, p);
+ smb_nbst_disconnect(nbp->nbp_vc, td);
break;
}
} while(0);
@@ -335,7 +348,7 @@ nbssn_rq_request(struct nbpcb *nbp, struct proc *p)
static int
nbssn_recvhdr(struct nbpcb *nbp, int *lenp,
- u_int8_t *rpcodep, int flags, struct proc *p)
+ u_int8_t *rpcodep, int flags, struct thread *td)
{
struct socket *so = nbp->nbp_tso;
struct uio auio;
@@ -351,7 +364,7 @@ nbssn_recvhdr(struct nbpcb *nbp, int *lenp,
auio.uio_rw = UIO_READ;
auio.uio_offset = 0;
auio.uio_resid = sizeof(len);
- auio.uio_procp = p;
+ auio.uio_td = td;
error = so->so_proto->pr_usrreqs->pru_soreceive
(so, (struct sockaddr **)NULL, &auio,
(struct mbuf **)NULL, (struct mbuf **)NULL, &flags);
@@ -374,7 +387,7 @@ nbssn_recvhdr(struct nbpcb *nbp, int *lenp,
static int
nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp,
- u_int8_t *rpcodep, struct proc *p)
+ u_int8_t *rpcodep, struct thread *td)
{
struct socket *so = nbp->nbp_tso;
struct uio auio;
@@ -390,7 +403,7 @@ nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp,
*mpp = NULL;
for(;;) {
m = NULL;
- error = nbssn_recvhdr(nbp, &len, &rpcode, MSG_DONTWAIT, p);
+ error = nbssn_recvhdr(nbp, &len, &rpcode, MSG_DONTWAIT, td);
if (so->so_state &
(SS_ISDISCONNECTING | SS_ISDISCONNECTED | SS_CANTRCVMORE)) {
nbp->nbp_state = NBST_CLOSED;
@@ -405,7 +418,7 @@ nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp,
continue;
bzero(&auio, sizeof(auio));
auio.uio_resid = len;
- auio.uio_procp = p;
+ auio.uio_td = td;
do {
rcvflg = MSG_WAITALL;
error = so->so_proto->pr_usrreqs->pru_soreceive
@@ -445,7 +458,7 @@ nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp,
* SMB transport interface
*/
static int
-smb_nbst_create(struct smb_vc *vcp, struct proc *p)
+smb_nbst_create(struct smb_vc *vcp, struct thread *td)
{
struct nbpcb *nbp;
@@ -461,13 +474,13 @@ smb_nbst_create(struct smb_vc *vcp, struct proc *p)
}
static int
-smb_nbst_done(struct smb_vc *vcp, struct proc *p)
+smb_nbst_done(struct smb_vc *vcp, struct thread *td)
{
struct nbpcb *nbp = vcp->vc_tdata;
if (nbp == NULL)
return ENOTCONN;
- smb_nbst_disconnect(vcp, p);
+ smb_nbst_disconnect(vcp, td);
if (nbp->nbp_laddr)
free(nbp->nbp_laddr, M_SONAME);
if (nbp->nbp_paddr)
@@ -477,7 +490,7 @@ smb_nbst_done(struct smb_vc *vcp, struct proc *p)
}
static int
-smb_nbst_bind(struct smb_vc *vcp, struct sockaddr *sap, struct proc *p)
+smb_nbst_bind(struct smb_vc *vcp, struct sockaddr *sap, struct thread *td)
{
struct nbpcb *nbp = vcp->vc_tdata;
struct sockaddr_nb *snb;
@@ -510,7 +523,7 @@ smb_nbst_bind(struct smb_vc *vcp, struct sockaddr *sap, struct proc *p)
}
static int
-smb_nbst_connect(struct smb_vc *vcp, struct sockaddr *sap, struct proc *p)
+smb_nbst_connect(struct smb_vc *vcp, struct sockaddr *sap, struct thread *td)
{
struct nbpcb *nbp = vcp->vc_tdata;
struct sockaddr_in sin;
@@ -536,7 +549,7 @@ smb_nbst_connect(struct smb_vc *vcp, struct sockaddr *sap, struct proc *p)
nbp->nbp_paddr = snb;
sin = snb->snb_addrin;
getnanotime(&ts1);
- error = nb_connect_in(nbp, &sin, p);
+ error = nb_connect_in(nbp, &sin, td);
if (error)
return error;
getnanotime(&ts2);
@@ -547,14 +560,14 @@ smb_nbst_connect(struct smb_vc *vcp, struct sockaddr *sap, struct proc *p)
timespecadd(&nbp->nbp_timo, &ts2);
timespecadd(&nbp->nbp_timo, &ts2);
timespecadd(&nbp->nbp_timo, &ts2); /* * 4 */
- error = nbssn_rq_request(nbp, p);
+ error = nbssn_rq_request(nbp, td);
if (error)
- smb_nbst_disconnect(vcp, p);
+ smb_nbst_disconnect(vcp, td);
return error;
}
static int
-smb_nbst_disconnect(struct smb_vc *vcp, struct proc *p)
+smb_nbst_disconnect(struct smb_vc *vcp, struct thread *td)
{
struct nbpcb *nbp = vcp->vc_tdata;
struct socket *so;
@@ -574,7 +587,7 @@ smb_nbst_disconnect(struct smb_vc *vcp, struct proc *p)
}
static int
-smb_nbst_send(struct smb_vc *vcp, struct mbuf *m0, struct proc *p)
+smb_nbst_send(struct smb_vc *vcp, struct mbuf *m0, struct thread *td)
{
struct nbpcb *nbp = vcp->vc_tdata;
int error;
@@ -587,7 +600,7 @@ smb_nbst_send(struct smb_vc *vcp, struct mbuf *m0, struct proc *p)
if (m0 == NULL)
return ENOBUFS;
nb_sethdr(m0, NB_SSN_MESSAGE, m_fixhdr(m0) - 4);
- error = nb_sosend(nbp->nbp_tso, m0, 0, p);
+ error = nb_sosend(nbp->nbp_tso, m0, 0, td);
return error;
abort:
if (m0)
@@ -597,14 +610,14 @@ abort:
static int
-smb_nbst_recv(struct smb_vc *vcp, struct mbuf **mpp, struct proc *p)
+smb_nbst_recv(struct smb_vc *vcp, struct mbuf **mpp, struct thread *td)
{
struct nbpcb *nbp = vcp->vc_tdata;
u_int8_t rpcode;
int error, rplen;
nbp->nbp_flags |= NBF_RECVLOCK;
- error = nbssn_recv(nbp, mpp, &rplen, &rpcode, p);
+ error = nbssn_recv(nbp, mpp, &rplen, &rpcode, td);
nbp->nbp_flags &= ~NBF_RECVLOCK;
return error;
}
OpenPOWER on IntegriCloud