net: Add a helper chan2conv()
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 30 Mar 2016 21:03:47 +0000 (17:03 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 5 Apr 2016 19:42:18 +0000 (15:42 -0400)
Cleans up a few places.  There still are some places that walk the
inscrutable pointer chain from FS to CV, but whatever.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/net/devip.c

index fe99cad..c83e1c5 100644 (file)
@@ -100,6 +100,12 @@ extern char *eve;
 static long ndbwrite(struct Fs *, char *unused_char_p_t, uint32_t, int);
 static void closeconv(struct conv *);
 
+static struct conv *chan2conv(struct chan *chan)
+{
+       /* That's a lot of pointers to get to the conv! */
+       return ipfs[chan->dev]->p[PROTO(chan->qid)]->conv[CONV(chan->qid)];
+}
+
 static inline int founddevdir(struct chan *c, struct qid q, char *n,
                                                          int64_t length, char *user, long perm,
                                                          struct dir *db)
@@ -123,7 +129,7 @@ static int ip3gen(struct chan *c, int i, struct dir *dp)
        struct conv *cv;
        char *p;
 
-       cv = ipfs[c->dev]->p[PROTO(c->qid)]->conv[CONV(c->qid)];
+       cv = chan2conv(c);
        if (cv->owner == NULL)
                kstrdup(&cv->owner, eve);
        mkqid(&q, QID(PROTO(c->qid), CONV(c->qid), i), 0, QTFILE);
@@ -827,14 +833,10 @@ static long ipread(struct chan *ch, void *a, long n, int64_t off)
 static struct block *ipbread(struct chan *ch, long n, uint32_t offset)
 {
        struct conv *c;
-       struct Proto *x;
-       struct Fs *f;
 
        switch (TYPE(ch->qid)) {
                case Qdata:
-                       f = ipfs[ch->dev];
-                       x = f->p[PROTO(ch->qid)];
-                       c = x->conv[CONV(ch->qid)];
+                       c = chan2conv(ch);
                        return qbread(c->rq, n);
                default:
                        return devbread(ch, n, offset);
@@ -1290,15 +1292,11 @@ static long ipwrite(struct chan *ch, void *v, long n, int64_t off)
 static long ipbwrite(struct chan *ch, struct block *bp, uint32_t offset)
 {
        struct conv *c;
-       struct Proto *x;
-       struct Fs *f;
        int n;
 
        switch (TYPE(ch->qid)) {
                case Qdata:
-                       f = ipfs[ch->dev];
-                       x = f->p[PROTO(ch->qid)];
-                       c = x->conv[CONV(ch->qid)];
+                       c = chan2conv(ch);
                        if (bp->next)
                                bp = concatblock(bp);
                        n = BLEN(bp);
@@ -1347,9 +1345,7 @@ static void ip_wake_cb(struct queue *q, void *data, int filter)
 
 int iptapfd(struct chan *chan, struct fd_tap *tap, int cmd)
 {
-       struct conv *conv;
-       struct Proto *x;
-       struct Fs *f;
+       struct conv *conv = chan2conv(chan);
        int ret;
 
        #define DEVIP_LEGAL_DATA_TAPS (FDTAP_FILT_READABLE | FDTAP_FILT_WRITABLE | \
@@ -1357,11 +1353,6 @@ int iptapfd(struct chan *chan, struct fd_tap *tap, int cmd)
                                       FDTAP_FILT_ERROR)
        #define DEVIP_LEGAL_LISTEN_TAPS (FDTAP_FILT_READABLE | FDTAP_FILT_HANGUP)
 
-       /* That's a lot of pointers to get to the conv! */
-       f = ipfs[chan->dev];
-       x = f->p[PROTO(chan->qid)];
-       conv = x->conv[CONV(chan->qid)];
-
        switch (TYPE(chan->qid)) {
                case Qdata:
                        if (tap->filter & ~DEVIP_LEGAL_DATA_TAPS) {