~kris/9p

9hist

fc3f92f3be911a3c7ddd2dce0c1ceef60e89b079 — David du Colombier 36 years ago f31940b
Plan 9 from Bell Labs 1990-07-25
10 files changed, 156 insertions(+), 50 deletions(-)

M gnot/devdk.c
M gnot/devincon.c
M gnot/devmnt.c
M gnot/errno.h
M gnot/proc.c
M gnot/sturp.c
M port/devbit.c
M port/devmnt.c
M port/devsrv.c
M port/sturp.c
M gnot/devdk.c => gnot/devdk.c +6 -3
@@ 456,6 456,7 @@ dkmuxconfig(Dk *dp, Block *bp)
	 */
	dp->restart = 1;
	n = getfields((char *)bp->rptr, fields, 4, ' ');
	strcpy(dp->name, "dk");
	switch(n){
	case 4:
		strncpy(dp->name, fields[3], sizeof(dp->name));


@@ 494,7 495,7 @@ dkmuxconfig(Dk *dp, Block *bp)
	/*
	 *  start a process to deal with it
	 */
	sprint(buf, "**csckproc%d**", dp->ncsc);
	sprint(buf, "csckproc%d", dp->ncsc);
	kproc(buf, dkcsckproc, dp);
	poperror();



@@ 503,7 504,7 @@ dkmuxconfig(Dk *dp, Block *bp)
	 */
	if(dktimeron == 0){
		dktimeron = 1;
		kproc("**dktimer**", dktimer, 0);
		kproc("dktimer", dktimer, 0);
	}
}



@@ 592,8 593,10 @@ dkattach(char *spec)
	Dk *dp;

	/*
	 *  find a multiplexor with the same name
	 *  find a multiplexor with the same name (default dk)
	 */
	if(*spec == 0)
		spec = "dk";
	for(dp = dk; dp < &dk[Ndk]; dp++){
		qlock(dp);
		if(dp->wq && strcmp(spec, dp->name)==0) {

M gnot/devincon.c => gnot/devincon.c +8 -8
@@ 89,7 89,7 @@ Incon incon[Nincon];
enum {
	Selecting,
	Selected,
	Dead,
	Notliving,
};

/*


@@ 177,7 177,7 @@ inconpoll(Incon *ip, int station)
	/*
	 *  get us to a known state
	 */
	ip->state = Dead;
	ip->state = Notliving;
	dev->cmd = INCON_STOP;

	/*


@@ 271,7 271,7 @@ inconreset(void)
/*	inconset(&incon[0], 3, 15); /**/
	for(i=1; i<Nincon; i++){
		incon[i].dev = INCON+i;
		incon[i].state = Dead;
		incon[i].state = Notliving;
		incon[i].dev->cmd = INCON_STOP;
		incon[i].ri = incon[i].wi = 0;
	}


@@ 400,7 400,7 @@ inconstopen(Queue *q, Stream *s)
	char name[32];

	ip = &incon[s->dev];
	sprint(name, "**incon%d**", s->dev);
	sprint(name, "incon%d", s->dev);
	q->ptr = q->other->ptr = ip;
	ip->rq = q;
	kproc(name, inconkproc, ip);


@@ 410,7 410,7 @@ inconstopen(Queue *q, Stream *s)
 *  kill off the kernel process
 */
static int
kDead(void *arg)
kNotliving(void *arg)
{
	Incon *ip;



@@ 427,7 427,7 @@ inconstclose(Queue * q)
	ip->rq = 0;
	qunlock(ip);
	wakeup(&ip->kr);
	sleep(&ip->r, kDead, ip);
	sleep(&ip->r, kNotliving, ip);
}

/*


@@ 500,7 500,7 @@ inconoput(Queue *q, Block *bp)
	/*
	 *  make sure there's an incon out there
	 */
	if(!(dev->status&INCON_ALIVE) || ip->state==Dead){
	if(!(dev->status&INCON_ALIVE) || ip->state==Notliving){
		inconrestart(ip);
		freemsg(q, bp);
		qunlock(&ip->xmit);


@@ 812,7 812,7 @@ inconintr(Ureg *ur)
			ip->dev->cmd = INCON_STOP;
			break;
		}
		ip->state = Dead;
		ip->state = Notliving;
	}
}


M gnot/devmnt.c => gnot/devmnt.c +0 -1
@@ 291,7 291,6 @@ mntattach(char *spec)
	mh = mhalloc();
	if(waserror()){
		mhfree(mh);
		mqfree(q);
		close(c);
		nexterror();
	}

M gnot/errno.h => gnot/errno.h +1 -0
@@ 50,6 50,7 @@ enum{
	Enobitmap,	/* out of bitmap descriptors */
	Enobitstore,	/* out of bitmap storage */
	Ebadbitmap,	/* unallocated bitmap */
	Ebadfont,	/* unallocated font */
	Eshortmsg,	/* short message */
	Ebadmsg,	/* format error or mismatch in message */
	Ebadcnt,	/* read count greater than requested */

M gnot/proc.c => gnot/proc.c +8 -3
@@ 575,6 575,7 @@ kproc(char *name, void (*func)(void *), void *arg)
	int lastvar;	/* used to compute stack address */
	User *up;
	KMap *k;
	static Pgrp *kpgrp;

	/*
	 * Kernel stack


@@ 612,12 613,16 @@ kproc(char *name, void (*func)(void *), void *arg)
		p->mach = m;
		m->proc = p;
		spllo();
		strncpy(p->text, name, sizeof p->text);
		(*func)(arg);
		pexit(0, 1);
	}
	p->pgrp = u->p->pgrp;
	incref(p->pgrp);
	if(kpgrp == 0){
		kpgrp = newpgrp();
		strcpy(kpgrp->user, "bootes");
	}
	p->pgrp = kpgrp;
	incref(kpgrp);
	sprint(p->text, "%s.%.6s", name, u->p->pgrp->user);
	p->nchild = 0;
	p->parent = 0;
	memset(p->time, 0, sizeof(p->time));

M gnot/sturp.c => gnot/sturp.c +78 -30
@@ 11,7 11,7 @@ enum {
	Nmask=		0x7,
};

#define DPRINT if(q->flag&QDEBUG)kprint
#define DPRINT /*if(q->flag&QDEBUG)kprint*/

typedef struct Urp	Urp;



@@ 68,6 68,12 @@ struct Urp {
#define NEXT(x) (((x)+1)&Nmask)

/*
 *  Alarm for urptiming
 */
Alarm	*urptiming;
Lock	urptlock;

/*
 *  Protocol control bytes
 */
#define	SEQ	0010		/* sequence number, ends trailers */


@@ 116,6 122,7 @@ static void	sendrej(Urp*);
static void	initoutput(Urp*, int);
static void	initinput(Urp*, int);
static void	urpkproc(void *arg);
static void	urptimer(Alarm*);
static void	urpvomit(char*, Urp*);

Qinfo urpinfo = { urpciput, urpoput, urpopen, urpclose, "urp" };


@@ 160,10 167,18 @@ urpopen(Queue *q, Stream *s)
	/*
	 *  start the ack/(re)xmit process
	 */
	if(up->kstarted == 0){
		up->kstarted = 1;
		sprint(name, "**urp%d**", up - urp);
		kproc(name, urpkproc, up);
	sprint(name, "urp%d", up - urp);
	kproc(name, urpkproc, up);

	/*
	 *  start the urptimer if it isn't already
	 */
	if(urptiming==0){
		if(canlock(&urptlock)){
			if(urptiming == 0)
				urptiming = alarm(500, urptimer, 0);
			unlock(&urptlock);
		}
	}
}



@@ 171,6 186,14 @@ urpopen(Queue *q, Stream *s)
 *  Shut down the connection and kill off the kernel process
 */
static int
isdead(void *a)
{
	Urp *up;

	up = (Urp *)a;
	return up->kstarted==0;
}
static int
isflushed(void *a)
{
	Urp *up;


@@ 199,7 222,7 @@ urpclose(Queue *q)
	tsleep(&up->r, isflushed, up, 2*60*1000);

	/*
	 *  kill off the kernel process
	 *  tell kernel process to die
	 */
	up->state |= HUNGUP;
	wakeup(&up->rq->r);


@@ 223,10 246,13 @@ urpclose(Queue *q)
		}
	qunlock(&up->xmit);

	if(up->kstarted == 0){
		DPRINT("urpclose %ux\n", up);
		up->state = 0;
	}
	/*
	 *  wait for kernel process to die
	 */
	while(up->kstarted)
		sleep(&up->r, isdead, up);

	up->state = 0;
}

/*


@@ 589,6 615,17 @@ output(Urp *up)
	int n;
	int i;

	/*
	 *  start the urptimer if it isn't already
	 */
	if(urptiming==0){
		if(canlock(&urptlock)){
			if(urptiming == 0)
				urptiming = alarm(500, urptimer, 0);
			unlock(&urptlock);
		}
	}

	if(!canqlock(&up->xmit))
		return;



@@ 607,9 644,7 @@ output(Urp *up)
			sendctl(up, INIT1);
			up->timer = now + MSrexmit;
		}
		qunlock(&up->xmit);
		poperror();
		return;
		goto out;
	}

	/*


@@ 653,9 688,7 @@ output(Urp *up)
		up->timer = NOW + MSrexmit;
		up->state &= ~REJECTING;
		sendctl(up, ENQ);
		qunlock(&up->xmit);
		poperror();
		return;
		goto out;
	}

	/*


@@ 676,6 709,7 @@ output(Urp *up)
		up->next = NEXT(up->next);
		poperror();
	}
out:
	qunlock(&up->xmit);
	poperror();
}


@@ 941,40 975,54 @@ todo(void *arg)
static void
urpkproc(void *arg)
{
	Urp *up; Queue *q;
	Urp *up;

	up = (Urp *)arg;
	q = up->wq;
	up->kstarted = 1;

	if(waserror()){
		print("urpkproc error %ux\n", up);
		up->state = 0;
		up->kstarted = 0;
		wakeup(&up->r);
		return;
	}
	for(;;){
		if(up->state & (HUNGUP|CLOSING)){
			if(isflushed(up))
				wakeup(&up->r);
			if(up->state & HUNGUP)
				break;
		}
		if(up->state == 0){
			DPRINT("urpkproc: %ux->state == 0\n", up);
		if(up->state & HUNGUP)
			break;
		}
		if(!QFULL(up->rq->next))
			sendack(up);
		output(up);
		tsleep(&up->rq->r, todo, up, MSrexmit/2);
		sleep(&up->rq->r, todo, up);
	}
	up->state = 0;
	up->kstarted = 0;
	wakeup(&up->r);
	poperror();
	DPRINT("urpkproc %ux\n", up);
}

/*
 *  timer to wakeup urpkproc's for retransmissions
 */
static void
urptimer(Alarm *a)
{
	Urp *up;
	Urp *last;
	Queue *q;

	urptiming = 0;
	for(up = urp, last = &urp[conf.nurp]; up < last; up++){
		if(up->state==0)
			continue;
		if(up->unacked!=up->next && NOW>up->timer){
			q = up->rq;
			if(q)
				wakeup(&q->r);
		}
	}
}

/*
 *  urp got very confused, complain
 */
static void

M port/devbit.c => port/devbit.c +2 -2
@@ 61,7 61,7 @@ struct{

Cursor	arrow =
{
	{0, 0},
	{1, 1},
	{0xFF, 0xE0, 0xFF, 0xE0, 0xFF, 0xC0, 0xFF, 0x00,
	 0xFF, 0x00, 0xFF, 0x80, 0xFF, 0xC0, 0xFF, 0xE0,
	 0xE7, 0xF0, 0xE3, 0xF8, 0xC1, 0xFC, 0x00, 0xFE,


@@ 657,7 657,7 @@ bitwrite(Chan *c, void *va, long n)
			v = GSHORT(p+1);
			f = &bit.font[v];
			if(v<0 || v>=conf.nfont || f->bits==0)
				error(0, Ebadbitmap);
				error(0, Ebadfont);
			f->bits = 0;
			m -= 3;
			p += 3;

M port/devmnt.c => port/devmnt.c +0 -1
@@ 291,7 291,6 @@ mntattach(char *spec)
	mh = mhalloc();
	if(waserror()){
		mhfree(mh);
		mqfree(q);
		close(c);
		nexterror();
	}

M port/devsrv.c => port/devsrv.c +1 -1
@@ 83,7 83,7 @@ srvopen(Chan *c, int omode)
	f = srv.chan[c->qid];
	if(f == 0)
		error(0, Eshutdown);
	if(omode&OTRUNC)
	if(omode & OTRUNC)
		error(0, Eperm);
	if(omode!=f->mode && f->mode!=ORDWR)
		error(0, Eperm);

M port/sturp.c => port/sturp.c +52 -1
@@ 68,6 68,12 @@ struct Urp {
#define NEXT(x) (((x)+1)&Nmask)

/*
 *  Alarm for urptiming
 */
Alarm	*urptiming;
Lock	urptlock;

/*
 *  Protocol control bytes
 */
#define	SEQ	0010		/* sequence number, ends trailers */


@@ 116,6 122,7 @@ static void	sendrej(Urp*);
static void	initoutput(Urp*, int);
static void	initinput(Urp*, int);
static void	urpkproc(void *arg);
static void	urptimer(Alarm*);
static void	urpvomit(char*, Urp*);

Qinfo urpinfo = { urpciput, urpoput, urpopen, urpclose, "urp" };


@@ 165,6 172,17 @@ urpopen(Queue *q, Stream *s)
		sprint(name, "urp%d", up - urp);
		kproc(name, urpkproc, up);
	}

	/*
	 *  start the urptimer if it isn't already
	 */
	if(urptiming==0){
		if(canlock(&urptlock)){
			if(urptiming == 0)
				urptiming = alarm(500, urptimer, 0);
			unlock(&urptlock);
		}
	}
}

/*


@@ 589,6 607,17 @@ output(Urp *up)
	int n;
	int i;

	/*
	 *  start the urptimer if it isn't already
	 */
	if(urptiming==0){
		if(canlock(&urptlock)){
			if(urptiming == 0)
				urptiming = alarm(500, urptimer, 0);
			unlock(&urptlock);
		}
	}

	if(!canqlock(&up->xmit))
		return;



@@ 967,7 996,7 @@ urpkproc(void *arg)
		if(!QFULL(up->rq->next))
			sendack(up);
		output(up);
		tsleep(&up->rq->r, todo, up, MSrexmit/2);
		sleep(&up->rq->r, todo, up);
	}
	up->state = 0;
	up->kstarted = 0;


@@ 975,6 1004,28 @@ urpkproc(void *arg)
}

/*
 *  timer to wakeup urpkproc's for retransmissions
 */
static void
urptimer(Alarm *a)
{
	Urp *up;
	Urp *last;
	Queue *q;

	urptiming = 0;
	for(up = urp, last = &urp[conf.nurp]; up < last; up++){
		if(up->state==0)
			continue;
		if(up->unacked!=up->next && NOW>up->timer){
			q = up->rq;
			if(q)
				wakeup(&q->r);
		}
	}
}

/*
 *  urp got very confused, complain
 */
static void