Chan refcnting uses a helper
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 13 May 2014 23:56:16 +0000 (16:56 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 13 May 2014 23:56:16 +0000 (16:56 -0700)
We needed to backtrace all of our chan increfs to track down a bug.  I have a
feeling we'll need it in the future.

kern/drivers/dev/mnt.c
kern/drivers/dev/srv.c
kern/include/ns.h
kern/src/ns/chan.c
kern/src/ns/pgrp.c
kern/src/ns/sysfile.c

index 55cccec..ac0c426 100644 (file)
@@ -304,7 +304,7 @@ struct chan *mntauth(struct chan *c, char *spec)
 
        c->qid = r->reply.aqid;
        c->mchan = m->c;
-       kref_get(&m->c->ref, 1);
+       chan_incref(m->c);
        c->mqid = c->qid;
        c->mode = ORDWR;
 
@@ -370,7 +370,7 @@ static struct chan *mntattach(char *muxattach)
 
        c->qid = r->reply.qid;
        c->mchan = m->c;
-       kref_get(&m->c->ref, 1);
+       chan_incref(m->c);
        c->mqid = c->qid;
 
        poperror();     /* r */
@@ -465,7 +465,7 @@ static struct walkqid *mntwalk(struct chan *c, struct chan *nc, char **name,
                if (wq->clone != c) {
                        wq->clone->type = c->type;
                        wq->clone->mchan = c->mchan;
-                       kref_get(&c->mchan->ref, 1);
+                       chan_incref(c->mchan);
                }
                if (r->reply.nwqid > 0)
                        wq->clone->qid = r->reply.wqid[r->reply.nwqid - 1];
index 4adec39..79692de 100644 (file)
@@ -217,7 +217,7 @@ static struct chan *srvopen(struct chan *c, int omode)
        /* the magic of srv: open c, get c->srv->chan back */
        cclose(c);
        c = srv->chan;
-       kref_get(&c->ref, 1);
+       chan_incref(c);
        poperror();
        kref_put(&srv->ref);
        return c;
index ca80abe..009919a 100644 (file)
@@ -600,6 +600,7 @@ struct block *bl2mem(uint8_t * unused_uint8_p_t, struct block *, int);
 int blocklen(struct block *);
 char *channame(struct chan *);
 void cclose(struct chan *);
+void chan_incref(struct chan *);
 void chandevinit(void);
 void chandevreset(void);
 void chandevshutdown(void);
index 6060e8e..17ec2d6 100644 (file)
@@ -276,6 +276,13 @@ void cclose(struct chan *c)
        kref_put(&c->ref);
 }
 
+/* convenience wrapper for interposition.  if you do use this, don't forget
+ * about the kref_get_not_zero in plan9setup() */
+void chan_incref(struct chan *c)
+{
+       kref_get(&c->ref, 1);
+}
+
 /*
  * Make sure we have the only copy of c.  (Copy on write.)
  */
@@ -337,7 +344,7 @@ struct mhead *newmhead(struct chan *from)
        mh = kzmalloc(sizeof(struct mhead), 0);
        kref_init(&mh->ref, mh_release, 1);
        mh->from = from;
-       kref_get(&from->ref, 1);
+       chan_incref(from);
 
 /*
        n = from->name->len;
@@ -575,7 +582,7 @@ findmount(struct chan **cp,
                        }
                        if (*cp != NULL)
                                cclose(*cp);
-                       kref_get(&m->mount->to->ref, 1);
+                       chan_incref(m->mount->to);
                        *cp = m->mount->to;
                        runlock(&m->lock);
                        return 1;
@@ -623,7 +630,7 @@ struct chan *undomount(struct chan *c, struct cname *name)
                                        if (strcmp(t->head->from->name->s, name->s) != 0)
                                                continue;
                                        nc = t->head->from;
-                                       kref_get(&nc->ref, 1);
+                                       chan_incref(nc);
                                        cclose(c);
                                        c = nc;
                                        break;
@@ -651,7 +658,7 @@ int walk(struct chan **cp, char **names, int nnames, int nomount, int *nerror)
        struct walkqid *wq;
 
        c = *cp;
-       kref_get(&c->ref, 1);
+       chan_incref(c);
        cname = c->name;
        kref_get(&cname->ref, 1);
        mh = NULL;
@@ -967,7 +974,7 @@ struct chan *namec(char *aname, int amode, int omode, uint32_t perm)
                        c = current->slash;
                        if (!c)
                                panic("no slash!");
-                       kref_get(&c->ref, 1);
+                       chan_incref(c);
                        break;
 
                case '#':
@@ -1012,7 +1019,7 @@ struct chan *namec(char *aname, int amode, int omode, uint32_t perm)
                        c = current->dot;
                        if (!c)
                                panic("no dot!");
-                       kref_get(&c->ref, 1);
+                       chan_incref(c);
                        break;
        }
        prefix = name - aname;
@@ -1238,7 +1245,7 @@ Open:
                                        cnew = createdir(cnew, m);
                                else {
                                        cnew = c;
-                                       kref_get(&cnew->ref, 1);
+                                       chan_incref(cnew);
                                }
 
                                /*
index 7fc8388..59aacfe 100644 (file)
@@ -215,7 +215,7 @@ struct fgrp *dupfgrp(struct proc *new_proc, struct fgrp *f)
        new->minfd = f->minfd;
        for (i = 0; i <= f->maxfd; i++) {
                if ((c = f->fd[i])) {
-                       kref_get(&c->ref, 1);
+                       chan_incref(c);
                        claim_fd(&new_proc->open_files, i);
                        new->fd[i] = c;
                }
@@ -232,7 +232,7 @@ struct mount *newmount(struct mhead *mh, struct chan *to, int flag, char *spec)
        m = kzmalloc(sizeof(struct mount), 0);
        m->to = to;
        m->head = mh;
-       kref_get(&to->ref, 1);
+       chan_incref(to);
        m->mountid = NEXT_ID(mountid);
        m->mflag = flag;
        if (spec != 0)
index db8fe4f..3725e5d 100644 (file)
@@ -95,7 +95,7 @@ struct chan *fdtochan(struct fgrp *f, int fd, int mode, int chkmnt, int iref)
                error(Ebadfd);
        }
        if (iref)
-               kref_get(&c->ref, 1);
+               chan_incref(c);
        spin_unlock(&f->lock);
 
        if (chkmnt && (c->flag & CMSG)) {
@@ -1434,7 +1434,7 @@ int plan9setup(struct proc *new_proc, struct proc *parent)
        new_proc->pgrp = parent->pgrp;
        /* copy semantics on / and . (doesn't make a lot of sense in akaros o/w) */
        /* / should never disappear while we hold a ref to parent */
-       kref_get(&parent->slash->ref, 1);
+       chan_incref(parent->slash);
        new_proc->slash = parent->slash;
        /* dot could change concurrently, and we could fail to gain a ref if whoever
         * decref'd dot triggered the release.  if that did happen, new_proc->dot