|
@@ -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 },
|