Deleted Added
full compact
smb_iod.c (82045) smb_iod.c (87192)
1/*
2 * Copyright (c) 2000-2001 Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 2000-2001 Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: head/sys/netsmb/smb_iod.c 82045 2001-08-21 09:10:23Z bp $
32 * $FreeBSD: head/sys/netsmb/smb_iod.c 87192 2001-12-02 08:47:29Z bp $
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/proc.h>
38#include <sys/kernel.h>
39#include <sys/kthread.h>
40#include <sys/malloc.h>

--- 57 unchanged lines hidden (view full) ---

98 }
99 SMB_IOD_RQUNLOCK(iod);
100}
101
102static void
103smb_iod_closetran(struct smbiod *iod)
104{
105 struct smb_vc *vcp = iod->iod_vc;
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/proc.h>
38#include <sys/kernel.h>
39#include <sys/kthread.h>
40#include <sys/malloc.h>

--- 57 unchanged lines hidden (view full) ---

98 }
99 SMB_IOD_RQUNLOCK(iod);
100}
101
102static void
103smb_iod_closetran(struct smbiod *iod)
104{
105 struct smb_vc *vcp = iod->iod_vc;
106 struct proc *p = iod->iod_p;
106 struct thread *td = iod->iod_td;
107
108 if (vcp->vc_tdata == NULL)
109 return;
107
108 if (vcp->vc_tdata == NULL)
109 return;
110 SMB_TRAN_DISCONNECT(vcp, p);
111 SMB_TRAN_DONE(vcp, p);
110 SMB_TRAN_DISCONNECT(vcp, td);
111 SMB_TRAN_DONE(vcp, td);
112 vcp->vc_tdata = NULL;
113}
114
115static void
116smb_iod_dead(struct smbiod *iod)
117{
118 iod->iod_state = SMBIOD_ST_DEAD;
119 smb_iod_closetran(iod);
120 smb_iod_invrq(iod);
121}
122
123static int
124smb_iod_connect(struct smbiod *iod)
125{
126 struct smb_vc *vcp = iod->iod_vc;
112 vcp->vc_tdata = NULL;
113}
114
115static void
116smb_iod_dead(struct smbiod *iod)
117{
118 iod->iod_state = SMBIOD_ST_DEAD;
119 smb_iod_closetran(iod);
120 smb_iod_invrq(iod);
121}
122
123static int
124smb_iod_connect(struct smbiod *iod)
125{
126 struct smb_vc *vcp = iod->iod_vc;
127 struct proc *p = iod->iod_p;
127 struct thread *td = iod->iod_td;
128 int error;
129
130 SMBIODEBUG("%d\n", iod->iod_state);
131 switch(iod->iod_state) {
132 case SMBIOD_ST_VCACTIVE:
133 SMBERROR("called for already opened connection\n");
134 return EISCONN;
135 case SMBIOD_ST_DEAD:
136 return ENOTCONN; /* XXX: last error code ? */
137 default:
138 break;
139 }
140 vcp->vc_genid++;
141 error = 0;
142 itry {
128 int error;
129
130 SMBIODEBUG("%d\n", iod->iod_state);
131 switch(iod->iod_state) {
132 case SMBIOD_ST_VCACTIVE:
133 SMBERROR("called for already opened connection\n");
134 return EISCONN;
135 case SMBIOD_ST_DEAD:
136 return ENOTCONN; /* XXX: last error code ? */
137 default:
138 break;
139 }
140 vcp->vc_genid++;
141 error = 0;
142 itry {
143 ithrow(SMB_TRAN_CREATE(vcp, p));
143 ithrow(SMB_TRAN_CREATE(vcp, td));
144 SMBIODEBUG("tcreate\n");
145 if (vcp->vc_laddr) {
144 SMBIODEBUG("tcreate\n");
145 if (vcp->vc_laddr) {
146 ithrow(SMB_TRAN_BIND(vcp, vcp->vc_laddr, p));
146 ithrow(SMB_TRAN_BIND(vcp, vcp->vc_laddr, td));
147 }
148 SMBIODEBUG("tbind\n");
147 }
148 SMBIODEBUG("tbind\n");
149 ithrow(SMB_TRAN_CONNECT(vcp, vcp->vc_paddr, p));
149 ithrow(SMB_TRAN_CONNECT(vcp, vcp->vc_paddr, td));
150 SMB_TRAN_SETPARAM(vcp, SMBTP_SELECTID, &iod->iod_flags);
151 iod->iod_state = SMBIOD_ST_TRANACTIVE;
152 SMBIODEBUG("tconnect\n");
153/* vcp->vc_mid = 0;*/
154 ithrow(smb_smb_negotiate(vcp, &iod->iod_scred));
155 SMBIODEBUG("snegotiate\n");
156 ithrow(smb_smb_ssnsetup(vcp, &iod->iod_scred));
157 iod->iod_state = SMBIOD_ST_VCACTIVE;

--- 45 unchanged lines hidden (view full) ---

203 SMBS_ST_UNLOCK(ssp);
204 wakeup(&ssp->ss_vcgenid);
205 return error;
206}
207
208static int
209smb_iod_sendrq(struct smbiod *iod, struct smb_rq *rqp)
210{
150 SMB_TRAN_SETPARAM(vcp, SMBTP_SELECTID, &iod->iod_flags);
151 iod->iod_state = SMBIOD_ST_TRANACTIVE;
152 SMBIODEBUG("tconnect\n");
153/* vcp->vc_mid = 0;*/
154 ithrow(smb_smb_negotiate(vcp, &iod->iod_scred));
155 SMBIODEBUG("snegotiate\n");
156 ithrow(smb_smb_ssnsetup(vcp, &iod->iod_scred));
157 iod->iod_state = SMBIOD_ST_VCACTIVE;

--- 45 unchanged lines hidden (view full) ---

203 SMBS_ST_UNLOCK(ssp);
204 wakeup(&ssp->ss_vcgenid);
205 return error;
206}
207
208static int
209smb_iod_sendrq(struct smbiod *iod, struct smb_rq *rqp)
210{
211 struct proc *p = iod->iod_p;
211 struct thread *td = iod->iod_td;
212 struct smb_vc *vcp = iod->iod_vc;
213 struct smb_share *ssp = rqp->sr_share;
214 struct mbuf *m;
215 int error;
216
217 SMBIODEBUG("iod_state = %d\n", iod->iod_state);
218 switch (iod->iod_state) {
219 case SMBIOD_ST_NOTCONN:

--- 23 unchanged lines hidden (view full) ---

243 * If all attempts to send a request failed, then
244 * something is seriously hosed.
245 */
246 return ENOTCONN;
247 }
248 SMBSDEBUG("M:%04x, P:%04x, U:%04x, T:%04x\n", rqp->sr_mid, 0, 0, 0);
249 m_dumpm(rqp->sr_rq.mb_top);
250 m = m_copym(rqp->sr_rq.mb_top, 0, M_COPYALL, M_WAIT);
212 struct smb_vc *vcp = iod->iod_vc;
213 struct smb_share *ssp = rqp->sr_share;
214 struct mbuf *m;
215 int error;
216
217 SMBIODEBUG("iod_state = %d\n", iod->iod_state);
218 switch (iod->iod_state) {
219 case SMBIOD_ST_NOTCONN:

--- 23 unchanged lines hidden (view full) ---

243 * If all attempts to send a request failed, then
244 * something is seriously hosed.
245 */
246 return ENOTCONN;
247 }
248 SMBSDEBUG("M:%04x, P:%04x, U:%04x, T:%04x\n", rqp->sr_mid, 0, 0, 0);
249 m_dumpm(rqp->sr_rq.mb_top);
250 m = m_copym(rqp->sr_rq.mb_top, 0, M_COPYALL, M_WAIT);
251 error = rqp->sr_lerror = m ? SMB_TRAN_SEND(vcp, m, p) : ENOBUFS;
251 error = rqp->sr_lerror = m ? SMB_TRAN_SEND(vcp, m, td) : ENOBUFS;
252 if (error == 0) {
253 getnanotime(&rqp->sr_timesent);
254 iod->iod_lastrqsent = rqp->sr_timesent;
255 rqp->sr_flags |= SMBR_SENT;
256 rqp->sr_state = SMBRQ_SENT;
257 return 0;
258 }
259 /*

--- 12 unchanged lines hidden (view full) ---

272
273/*
274 * Process incoming packets
275 */
276static int
277smb_iod_recvall(struct smbiod *iod)
278{
279 struct smb_vc *vcp = iod->iod_vc;
252 if (error == 0) {
253 getnanotime(&rqp->sr_timesent);
254 iod->iod_lastrqsent = rqp->sr_timesent;
255 rqp->sr_flags |= SMBR_SENT;
256 rqp->sr_state = SMBRQ_SENT;
257 return 0;
258 }
259 /*

--- 12 unchanged lines hidden (view full) ---

272
273/*
274 * Process incoming packets
275 */
276static int
277smb_iod_recvall(struct smbiod *iod)
278{
279 struct smb_vc *vcp = iod->iod_vc;
280 struct proc *p = iod->iod_p;
280 struct thread *td = iod->iod_td;
281 struct smb_rq *rqp;
282 struct mbuf *m;
283 u_char *hp;
284 u_short mid;
285 int error;
286
287 switch (iod->iod_state) {
288 case SMBIOD_ST_NOTCONN:
289 case SMBIOD_ST_DEAD:
290 case SMBIOD_ST_RECONNECT:
291 return 0;
292 default:
293 break;
294 }
295 for (;;) {
296 m = NULL;
281 struct smb_rq *rqp;
282 struct mbuf *m;
283 u_char *hp;
284 u_short mid;
285 int error;
286
287 switch (iod->iod_state) {
288 case SMBIOD_ST_NOTCONN:
289 case SMBIOD_ST_DEAD:
290 case SMBIOD_ST_RECONNECT:
291 return 0;
292 default:
293 break;
294 }
295 for (;;) {
296 m = NULL;
297 error = SMB_TRAN_RECV(vcp, &m, p);
297 error = SMB_TRAN_RECV(vcp, &m, td);
298 if (error == EWOULDBLOCK)
299 break;
300 if (SMB_TRAN_FATAL(vcp, error)) {
301 smb_iod_dead(iod);
302 break;
303 }
304 if (error)
305 break;

--- 44 unchanged lines hidden (view full) ---

350 m_freem(m);
351 }
352 }
353 /*
354 * check for interrupts
355 */
356 SMB_IOD_RQLOCK(iod);
357 TAILQ_FOREACH(rqp, &iod->iod_rqlist, sr_link) {
298 if (error == EWOULDBLOCK)
299 break;
300 if (SMB_TRAN_FATAL(vcp, error)) {
301 smb_iod_dead(iod);
302 break;
303 }
304 if (error)
305 break;

--- 44 unchanged lines hidden (view full) ---

350 m_freem(m);
351 }
352 }
353 /*
354 * check for interrupts
355 */
356 SMB_IOD_RQLOCK(iod);
357 TAILQ_FOREACH(rqp, &iod->iod_rqlist, sr_link) {
358 if (smb_proc_intr(rqp->sr_cred->scr_p)) {
358 if (smb_proc_intr(rqp->sr_cred->scr_td->td_proc)) {
359 smb_iod_rqprocessed(rqp, EINTR);
360 }
361 }
362 SMB_IOD_RQUNLOCK(iod);
363 return 0;
364}
365
366int

--- 27 unchanged lines hidden (view full) ---

394int
395smb_iod_addrq(struct smb_rq *rqp)
396{
397 struct smb_vc *vcp = rqp->sr_vc;
398 struct smbiod *iod = vcp->vc_iod;
399 int error;
400
401 SMBIODEBUG("\n");
359 smb_iod_rqprocessed(rqp, EINTR);
360 }
361 }
362 SMB_IOD_RQUNLOCK(iod);
363 return 0;
364}
365
366int

--- 27 unchanged lines hidden (view full) ---

394int
395smb_iod_addrq(struct smb_rq *rqp)
396{
397 struct smb_vc *vcp = rqp->sr_vc;
398 struct smbiod *iod = vcp->vc_iod;
399 int error;
400
401 SMBIODEBUG("\n");
402 if (rqp->sr_cred->scr_p == iod->iod_p) {
402 if (rqp->sr_cred->scr_td->td_proc == iod->iod_p) {
403 rqp->sr_flags |= SMBR_INTERNAL;
404 SMB_IOD_RQLOCK(iod);
405 TAILQ_INSERT_HEAD(&iod->iod_rqlist, rqp, sr_link);
406 SMB_IOD_RQUNLOCK(iod);
407 for (;;) {
408 if (smb_iod_sendrq(iod, rqp) != 0) {
409 smb_iod_dead(iod);
410 break;

--- 215 unchanged lines hidden (view full) ---

626 }
627 }
628#endif
629 smb_iod_sendall(iod);
630 smb_iod_recvall(iod);
631 return;
632}
633
403 rqp->sr_flags |= SMBR_INTERNAL;
404 SMB_IOD_RQLOCK(iod);
405 TAILQ_INSERT_HEAD(&iod->iod_rqlist, rqp, sr_link);
406 SMB_IOD_RQUNLOCK(iod);
407 for (;;) {
408 if (smb_iod_sendrq(iod, rqp) != 0) {
409 smb_iod_dead(iod);
410 break;

--- 215 unchanged lines hidden (view full) ---

626 }
627 }
628#endif
629 smb_iod_sendall(iod);
630 smb_iod_recvall(iod);
631 return;
632}
633
634#ifndef FB_CURRENT
635#define kthread_create_compat kthread_create2
636#else
637#define kthread_create_compat kthread_create
638#endif
639
640
641void
642smb_iod_thread(void *arg)
643{
644 struct smbiod *iod = arg;
645
646 mtx_lock(&Giant);
634void
635smb_iod_thread(void *arg)
636{
637 struct smbiod *iod = arg;
638
639 mtx_lock(&Giant);
647 smb_makescred(&iod->iod_scred, iod->iod_p, NULL);
640 /*
641 * Here we assume that the thread structure will be the same
642 * for an entire kthread (kproc, to be more precise) life.
643 */
644 iod->iod_td = curthread;
645 smb_makescred(&iod->iod_scred, iod->iod_td, NULL);
648 while ((iod->iod_flags & SMBIOD_SHUTDOWN) == 0) {
649 smb_iod_main(iod);
650 SMBIODEBUG("going to sleep for %d ticks\n", iod->iod_sleeptimo);
651/* mtx_unlock(&Giant, MTX_DEF);*/
652 if (iod->iod_flags & SMBIOD_SHUTDOWN)
653 break;
654 tsleep(&iod->iod_flags, PWAIT, "90idle", iod->iod_sleeptimo);
655 }

--- 14 unchanged lines hidden (view full) ---

670 iod->iod_sleeptimo = hz * SMBIOD_SLEEP_TIMO;
671 iod->iod_pingtimo.tv_sec = SMBIOD_PING_TIMO;
672 getnanotime(&iod->iod_lastrqsent);
673 vcp->vc_iod = iod;
674 smb_sl_init(&iod->iod_rqlock, "90rql");
675 TAILQ_INIT(&iod->iod_rqlist);
676 smb_sl_init(&iod->iod_evlock, "90evl");
677 STAILQ_INIT(&iod->iod_evlist);
646 while ((iod->iod_flags & SMBIOD_SHUTDOWN) == 0) {
647 smb_iod_main(iod);
648 SMBIODEBUG("going to sleep for %d ticks\n", iod->iod_sleeptimo);
649/* mtx_unlock(&Giant, MTX_DEF);*/
650 if (iod->iod_flags & SMBIOD_SHUTDOWN)
651 break;
652 tsleep(&iod->iod_flags, PWAIT, "90idle", iod->iod_sleeptimo);
653 }

--- 14 unchanged lines hidden (view full) ---

668 iod->iod_sleeptimo = hz * SMBIOD_SLEEP_TIMO;
669 iod->iod_pingtimo.tv_sec = SMBIOD_PING_TIMO;
670 getnanotime(&iod->iod_lastrqsent);
671 vcp->vc_iod = iod;
672 smb_sl_init(&iod->iod_rqlock, "90rql");
673 TAILQ_INIT(&iod->iod_rqlist);
674 smb_sl_init(&iod->iod_evlock, "90evl");
675 STAILQ_INIT(&iod->iod_evlist);
678 error = kthread_create_compat(smb_iod_thread, iod, &iod->iod_p,
676 error = kthread_create(smb_iod_thread, iod, &iod->iod_p,
679 RFNOWAIT, "smbiod%d", iod->iod_id);
680 if (error) {
681 SMBERROR("can't start smbiod: %d", error);
682 free(iod, M_SMBIOD);
683 return error;
684 }
685 return 0;
686}

--- 23 unchanged lines hidden ---
677 RFNOWAIT, "smbiod%d", iod->iod_id);
678 if (error) {
679 SMBERROR("can't start smbiod: %d", error);
680 free(iod, M_SMBIOD);
681 return error;
682 }
683 return 0;
684}

--- 23 unchanged lines hidden ---