Browse Source

Plan 9 from Bell Labs 2007-11-13

David du Colombier 16 years ago
parent
commit
5e3eddcbd5
5 changed files with 68 additions and 67 deletions
  1. 2 2
      dist/replica/_plan9.db
  2. 2 2
      dist/replica/plan9.db
  3. 2 0
      dist/replica/plan9.log
  4. 3 3
      sys/man/2/9pfid
  5. 59 60
      sys/src/9/port/devaoe.c

+ 2 - 2
dist/replica/_plan9.db

@@ -7506,7 +7506,7 @@ sys/man/2 - 20000000775 sys sys 1143130045 0
 sys/man/2/0intro - 664 sys sys 1115941566 11660
 sys/man/2/9p - 664 sys sys 1175867369 15852
 sys/man/2/9pcmdbuf - 664 sys sys 1186721809 2162
-sys/man/2/9pfid - 664 sys sys 1106072437 3663
+sys/man/2/9pfid - 664 sys sys 1194905671 3696
 sys/man/2/9pfile - 664 sys sys 1048637158 4408
 sys/man/2/INDEX - 664 sys sys 1183240469 20532
 sys/man/2/INDEX.html - 664 sys sys 1183240476 27618
@@ -8205,7 +8205,7 @@ sys/src/9/port/chan.c - 664 sys sys 1146151714 34773
 sys/src/9/port/cis.c - 664 sys sys 1099761153 9248
 sys/src/9/port/debugalloc.c - 664 sys sys 1014931171 10402
 sys/src/9/port/dev.c - 664 sys sys 1146151714 8177
-sys/src/9/port/devaoe.c - 664 sys sys 1194752565 41987
+sys/src/9/port/devaoe.c - 664 sys sys 1194913595 42084
 sys/src/9/port/devaudio.c - 664 sys sys 1170456648 21199
 sys/src/9/port/devbridge.c - 664 sys sys 1187735844 24076
 sys/src/9/port/devcap.c - 664 sys sys 1178886040 4141

+ 2 - 2
dist/replica/plan9.db

@@ -7506,7 +7506,7 @@ sys/man/2 - 20000000775 sys sys 1143130045 0
 sys/man/2/0intro - 664 sys sys 1115941566 11660
 sys/man/2/9p - 664 sys sys 1175867369 15852
 sys/man/2/9pcmdbuf - 664 sys sys 1186721809 2162
-sys/man/2/9pfid - 664 sys sys 1106072437 3663
+sys/man/2/9pfid - 664 sys sys 1194905671 3696
 sys/man/2/9pfile - 664 sys sys 1048637158 4408
 sys/man/2/INDEX - 664 sys sys 1183240469 20532
 sys/man/2/INDEX.html - 664 sys sys 1183240476 27618
@@ -8205,7 +8205,7 @@ sys/src/9/port/chan.c - 664 sys sys 1146151714 34773
 sys/src/9/port/cis.c - 664 sys sys 1099761153 9248
 sys/src/9/port/debugalloc.c - 664 sys sys 1014931171 10402
 sys/src/9/port/dev.c - 664 sys sys 1146151714 8177
-sys/src/9/port/devaoe.c - 664 sys sys 1194752565 41987
+sys/src/9/port/devaoe.c - 664 sys sys 1194913595 42084
 sys/src/9/port/devaudio.c - 664 sys sys 1170456648 21199
 sys/src/9/port/devbridge.c - 664 sys sys 1187735844 24076
 sys/src/9/port/devcap.c - 664 sys sys 1178886040 4141

+ 2 - 0
dist/replica/plan9.log

@@ -53352,3 +53352,5 @@
 1194753604 1 c sys/src/9/port/sdaoe.c - 664 sys sys 1194752512 9922
 1194796805 0 c sys/src/9/pc/etherigbe.c - 664 sys sys 1194796690 45327
 1194796805 1 c sys/src/boot/pc/etherigbe.c - 664 sys sys 1194796683 41188
+1194906629 0 c sys/man/2/9pfid - 664 sys sys 1194905671 3696
+1194913805 0 c sys/src/9/port/devaoe.c - 664 sys sys 1194913595 42084

+ 3 - 3
sys/man/2/9pfid

@@ -51,8 +51,8 @@ Fidpool*	allocfidpool(void (*destroy)(Fid*))
 void	freefidpool(Fidpool *p)
 Fid*	allocfid(Fidpool *p, ulong fid)
 Fid*	lookupfid(Fidpool *p, ulong fid)
+Fid*	removefid(Fidpool *p, ulong fid);
 void	closefid(Fid *f)
-void	removefid(Fid *f)
 .fi
 .PP
 .ft L
@@ -62,8 +62,8 @@ Reqpool*	allocreqpool(void (*destroy)(Req*))
 void	freereqpool(Reqpool *p)
 Req*	allocreq(Reqpool *p, ulong tag)
 Req*	lookupreq(Reqpool *p, ulong tag)
+Req*	removereq(Reqpool *p, ulong tag);
 void	closereq(Req *f)
-void	removereq(Req *r)
 .fi
 .SH DESCRIPTION
 These routines provide management of 
@@ -176,7 +176,7 @@ regarding the
 element.
 .I Removefid
 is equivalent to
-.I closefid
+.I lookupfid
 but also removes the
 .B Fid
 from the pool.

+ 59 - 60
sys/src/9/port/devaoe.c

@@ -36,7 +36,6 @@ enum {
 #define Q3(l, u, t)	((l)<<8 | QID(u, t))
 #define UP(d)		((d)->flag & Dup)
 
-#define	Ticks		MACHP(0)->ticks
 #define	Ms2tk(t)	(((t)*HZ)/1000)
 #define	Tk2ms(t)	(((t)*1000)/HZ)
 
@@ -85,6 +84,11 @@ enum {
 	Cid		= 0xec,
 };
 
+enum {
+	Read,
+	Write,
+};
+
 /*
  * unified set of flags
  * a Netlink + Aoedev most both be jumbo capable
@@ -253,7 +257,7 @@ srballoc(ulong sz)
 
 	srb = malloc(sizeof *srb+sz);
 	srb->dp = srb->data = srb+1;
-	srb->ticksent = Ticks;
+	srb->ticksent = MACHP(0)->ticks;
 	return srb;
 }
 
@@ -264,7 +268,7 @@ srbkalloc(void *db, ulong)
 
 	srb = malloc(sizeof *srb);
 	srb->dp = srb->data = db;
-	srb->ticksent = Ticks;
+	srb->ticksent = MACHP(0)->ticks;
 	return srb;
 }
 
@@ -378,7 +382,7 @@ eventcount(void)
 	else if(events.wp < events.rp)
 		n = Nevents - (events.rp - events.wp);
 	else
-		n = events.wp-events.rp;
+		n = events.wp - events.rp;
 	unlock(&events);
 	return n/Eventlen;
 }
@@ -388,7 +392,7 @@ tsince(int tag)
 {
 	int n;
 
-	n = Ticks & 0xffff;
+	n = MACHP(0)->ticks & 0xffff;
 	n -= tag & 0xffff;
 	if(n < 0)
 		n += 1<<16;
@@ -402,7 +406,7 @@ newtag(Aoedev *d)
 
 	do {
 		t = ++d->lasttag << 16;
-		t |= Ticks & 0xffff;
+		t |= MACHP(0)->ticks & 0xffff;
 	} while (t == Tfree || t == Tmgmt);
 	return t;
 }
@@ -489,7 +493,7 @@ hset(Aoedev *d, Frame *f, Aoehdr *h, int cmd)
 		downdev(d, "resend fails; no netlink/ea");
 		return -1;
 	}
-	if(f->srb && Ticks-f->srb->ticksent > Srbtimeout){
+	if(f->srb && MACHP(0)->ticks - f->srb->ticksent > Srbtimeout){
 		eventlog("%æ: srb timeout\n", d);
 		frameerror(d, f, Etimedout);
 		return -1;
@@ -507,7 +511,7 @@ hset(Aoedev *d, Frame *f, Aoehdr *h, int cmd)
 	f->dl = l;
 	f->nl = l->nl;
 	f->eaidx = i;
-	f->ticksent = Ticks;
+	f->ticksent = MACHP(0)->ticks;
 
 	return f->tag;
 }
@@ -565,6 +569,7 @@ discover(int major, int minor)
 		h->minor = minor;
 		h->cmd = ACconfig;
 		poperror();
+		/* send b down the queue */
 		devtab[nl->dc->type]->bwrite(nl->dc, b, 0);
 	}
 }
@@ -574,7 +579,7 @@ discover(int major, int minor)
  * outstanding for 200% of the device round trip time average.
  */
 static void
-aoesweep(void*)
+aoesweepproc(void*)
 {
 	ulong i, tx, timeout, nbc;
 	vlong starttick;
@@ -594,7 +599,7 @@ loop:
 		}
 		nbc = Nbcms/Nms;
 	}
-	starttick = Ticks;
+	starttick = MACHP(0)->ticks;
 	rlock(&devs);
 	for(d = devs.d; d; d = d->next){
 		if(!canqlock(d))
@@ -617,7 +622,7 @@ loop:
 			if(d->nout == d->maxout){
 				if(d->maxout > 1)
 					d->maxout--;
-				d->lastwadj = Ticks;
+				d->lastwadj = MACHP(0)->ticks;
 			}
 			a = (Aoeata*)f->hdr;
 			if(a->scnt > Dbcnt / Aoesectsz &&
@@ -636,14 +641,14 @@ loop:
 			}
 		}
 		if(d->nout == d->maxout && d->maxout < d->nframes &&
-		   TK2MS(Ticks-d->lastwadj) > 10*1000){
+		   TK2MS(MACHP(0)->ticks - d->lastwadj) > 10*1000){
 			d->maxout++;
-			d->lastwadj = Ticks;
+			d->lastwadj = MACHP(0)->ticks;
 		}
 		qunlock(d);
 	}
 	runlock(&devs);
-	i = Nms - TK2MS(Ticks - starttick);
+	i = Nms - TK2MS(MACHP(0)->ticks - starttick);
 	if(i > 0)
 		tsleep(&up->sleep, return0, 0, i);
 	goto loop;
@@ -694,16 +699,13 @@ aoeinit(void)
 
 	if(!canqlock(&l))
 		return;
-	if(init++ > 0){
-		qunlock(&l);
-		return;
+	if(init == 0){
+		fmtinstall(L'æ', fmtæ);
+		events.rp = events.wp = events.buf;
+		kproc("aoesweep", aoesweepproc, nil);
+		aoecfg();
+		init = 1;
 	}
-
-	fmtinstall(L'æ', fmtæ);
-	events.rp = events.wp = events.buf;
-	kproc("aoesweep", aoesweep, nil);
-	aoecfg();
-
 	qunlock(&l);
 }
 
@@ -714,11 +716,9 @@ aoeattach(char *spec)
 
 	if(*spec)
 		error(Enonexist);
-
 	aoeinit();
 	c = devattach(L'æ', spec);
 	mkqid(&c->qid, Qzero, 0, QTDIR);
-
 	return c;
 }
 
@@ -738,7 +738,6 @@ unit2dev(ulong unit)
 	runlock(&devs);
 	uprint("unit lookup failure: %lux pc %p", unit, getcallerpc(&unit));
 	error(up->genbuf);
-//	error("unit lookup failure");
 	return nil;
 }
 
@@ -1157,7 +1156,7 @@ rw(Aoedev *d, int write, uchar *db, long len, uvlong off)
 	}
 	nlen = len;
 	srb->write = write;
-	for (;;) {
+	do {
 		if(!UP(d))
 			error(Eio);
 		srb->sector = off / Aoesectsz;
@@ -1166,19 +1165,17 @@ rw(Aoedev *d, int write, uchar *db, long len, uvlong off)
 		if(n > Srbsz)
 			n = Srbsz;
 		srb->len = n;
-		if(write == 1 && copy == 0)
+		if(write && !copy)
 			memmove(srb->data, db, n);
 		strategy(d, srb);
 		if(srb->error)
 			error(srb->error);
-		if(write == 0 && copy == 0)
+		if(!write && !copy)
 			memmove(db, srb->data, n);
 		nlen -= n;
-		if(nlen == 0)
-			break;
 		db += n;
 		off += n;
-	}
+	} while (nlen > 0);
 	poperror();
 	srbfree(srb);
 	return len;
@@ -1254,7 +1251,7 @@ unitread(Chan *c, void *db, long len, vlong off)
 	case Qctl:
 		return pstat(d, db, len, off);
 	case Qdata:
-		return rw(d, 0, db, len, off);
+		return rw(d, Read, db, len, off);
 	case Qconfig:
 		if (!UP(d))
 			error(Enotup);
@@ -1491,7 +1488,8 @@ unitctlwrite(Aoedev *d, void *db, long n)
 		Setsize,
 	};
 	Cmdbuf *cb;
-	Cmdtab *ct, cmds[] = {
+	Cmdtab *ct;
+	static Cmdtab cmds[] = {
 		{Failio, 	"failio", 	1 },
 		{Ident, 	"identify", 	1 },
 		{Jumbo, 	"jumbo", 	0 },
@@ -1580,7 +1578,7 @@ unitwrite(Chan *c, void *db, long n, vlong off)
 	case Qident:
 		error(Eperm);
 	case Qdata:
-		return rw(d, 1, db, n, off);
+		return rw(d, Write, db, n, off);
 	case Qconfig:
 		if(off + n > sizeof d->config)
 			error(Etoobig);
@@ -1605,21 +1603,19 @@ addnet(char *path, Chan *cc, Chan *dc, Chan *mtu, uchar *ea)
 	}
 	nl = netlinks.nl;
 	e = nl + nelem(netlinks.nl);
-	for(; nl < e; nl++){
-		if(nl->cc)
-			continue;
-		nl->cc = cc;
-		nl->dc = dc;
-		nl->mtu = mtu;
-		strncpy(nl->path, path, sizeof nl->path);
-		memmove(nl->ea, ea, sizeof nl->ea);
-		poperror();
-		nl->flag |= Dup;
-		unlock(&netlinks);
-		return nl;
-	}
-	error("out of netlink structures");
-	return nil;
+	for(; nl < e && nl->cc; nl++)
+		continue;
+	if (nl >= e)
+		error("out of netlink structures");
+	nl->cc = cc;
+	nl->dc = dc;
+	nl->mtu = mtu;
+	strncpy(nl->path, path, sizeof nl->path);
+	memmove(nl->ea, ea, sizeof nl->ea);
+	poperror();
+	nl->flag |= Dup;
+	unlock(&netlinks);
+	return nl;
 }
 
 static int
@@ -2119,10 +2115,8 @@ bail:
 	qunlock(d);
 }
 
-#define ERROR(x) do{ uprint("%s: %s", name, x); error(up->genbuf); }while(0)
-
 static void
-netrdaoe(void *v)
+netrdaoeproc(void *v)
 {
 	int idx;
 	char name[Maxpath+1], *s;
@@ -2144,13 +2138,17 @@ netrdaoe(void *v)
 	if(autodiscover)
 		discover(0xffff, 0xff);
 	for (;;) {
-		if((nl->flag & Dup) == 0)
-			ERROR("netlink is down");
+		if(!(nl->flag & Dup)) {
+			uprint("%s: netlink is down", name);
+			error(up->genbuf);
+		}
 		if (nl->dc == nil)
 			panic("netrdaoe: nl->dc == nil");
 		b = devtab[nl->dc->type]->bread(nl->dc, 1<<16, 0);
-		if(b == nil)
-			ERROR("nil read from network");
+		if(b == nil) {
+			uprint("%s: nil read from network", name);
+			error(up->genbuf);
+		}
 		h = (Aoehdr*)b->rp;
 		if(h->verflag & AFrsp)
 			if(s = aoeerror(h)){
@@ -2226,7 +2224,7 @@ netbind(char *path)
 	getaddr(path, ea);
 	nl = addnet(path, cc, dc, mtu, ea);
 	snprint(addr, sizeof addr, "netrdaoe@%s", path);
-	kproc(addr, netrdaoe, nl);
+	kproc(addr, netrdaoeproc, nl);
 	poperror();
 }
 
@@ -2395,7 +2393,6 @@ discoverstr(char *f)
 static long
 topctlwrite(void *db, long n)
 {
-	char *f;
 	enum {
 		Autodiscover,
 		Bind,
@@ -2406,8 +2403,10 @@ topctlwrite(void *db, long n)
 		Remove,
 		Unbind,
 	};
+	char *f;
 	Cmdbuf *cb;
-	Cmdtab *ct, cmds[] = {
+	Cmdtab *ct;
+	static Cmdtab cmds[] = {
 		{ Autodiscover,	"autodiscover",	0	},
 		{ Bind, 	"bind", 	2	},
 		{ Debug, 	"debug", 	0	},