changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: fix keeping track of qids. next is only opening them at Topen and closing at Tclunk. not open at Twalk and never close.

changeset 101: b3487ae9e237
parent 100: a332f10eb972
child 102: 2415b13613b1
author: Mechiel Lukkien <mechiel@ueber.net>
date: Mon, 06 Aug 2007 23:31:26 +0200
files: appl/cmd/vacfs.b
description: fix keeping track of qids. next is only opening them at Topen and closing at Tclunk. not open at Twalk and never close.
     1.1--- a/appl/cmd/vacfs.b	Mon Aug 06 17:56:04 2007 +0200
     1.2+++ b/appl/cmd/vacfs.b	Mon Aug 06 23:31:26 2007 +0200
     1.3@@ -38,6 +38,7 @@
     1.4 	qid:	int;
     1.5 	de: 	ref Direntry;
     1.6 	size:	big;
     1.7+	nused:	int;
     1.8 	pick {
     1.9 	File =>	vf: 	ref Vacfile;
    1.10 	Dir =>	vd:	ref Vacdir;
    1.11@@ -61,7 +62,7 @@
    1.12 qidscores: list of (string, int);
    1.13 
    1.14 
    1.15-childget(qid: int, vqid: big): ref Elem
    1.16+childget(qid: int, vqid: big): int
    1.17 {
    1.18 	for(l := qids[qid % len qids]; l != nil; l = tl l) {
    1.19 		if((hd l).qid != qid)
    1.20@@ -69,10 +70,10 @@
    1.21 		for(m := (hd l).cqids; m != nil; m = tl m) {
    1.22 			(vq, cq) := hd m;
    1.23 			if(vq == vqid)
    1.24-				return get(cq);
    1.25+				return cq;
    1.26 		}
    1.27 	}
    1.28-	return nil;
    1.29+	return -1;
    1.30 }
    1.31 
    1.32 childput(qid: int, vqid: big): int
    1.33@@ -109,7 +110,7 @@
    1.34 
    1.35 Elem.mkdir(qid: int, de: ref Direntry, size: big, vd: ref Vacdir, pqid: int): ref Elem.Dir
    1.36 {
    1.37-	return ref Elem.Dir(qid, de, size, vd, pqid, (-1, nil));
    1.38+	return ref Elem.Dir(qid, de, size, 1, vd, pqid, (-1, nil));
    1.39 }
    1.40 
    1.41 Elem.new(nqid: int, vd: ref Vacdir, de: ref Direntry, pqid: int): ref Elem
    1.42@@ -119,7 +120,7 @@
    1.43 		return nil;
    1.44 	if(de.mode & Vac->Modedir)
    1.45 		return Elem.mkdir(nqid, de, e.size, Vacdir.new(session, e, me), pqid);
    1.46-	return ref Elem.File(nqid, de, e.size, Vacfile.new(session, e));
    1.47+	return ref Elem.File(nqid, de, e.size, 1, Vacfile.new(session, e));
    1.48 }
    1.49 
    1.50 Elem.stat(e: self ref Elem): ref Sys->Dir
    1.51@@ -140,7 +141,7 @@
    1.52 		if(ne == nil) {
    1.53 			(ok, score) := Score.parse(name);
    1.54 			if(ok != 0)
    1.55-				return (nil, "bad score: "+name);
    1.56+				return (nil, "bad score");
    1.57 
    1.58 			(vd, de, err) := vac->vdroot(session, score);
    1.59 			if(err != nil)
    1.60@@ -156,10 +157,12 @@
    1.61 	de := ed.vd.walk(name);
    1.62 	if(de == nil)
    1.63 		return (nil, sprint("%r"));
    1.64-	ne := childget(ed.qid, de.qid);
    1.65+	cqid := childget(ed.qid, de.qid);
    1.66+	if(cqid < 0)
    1.67+		cqid = childput(ed.qid, de.qid);
    1.68+	ne := get(cqid);
    1.69 	if(ne == nil) {
    1.70-		nqid := childput(ed.qid, de.qid);
    1.71-		ne = Elem.new(nqid, ed.vd, de, ed.qid);
    1.72+		ne = Elem.new(cqid, ed.vd, de, ed.qid);
    1.73 		set(ne);
    1.74 	}
    1.75 	return (ne, nil);
    1.76@@ -178,6 +181,22 @@
    1.77 	elems[e.qid % len elems] = e::elems[e.qid % len elems];
    1.78 }
    1.79 
    1.80+remove[T](l: list of T, e: T): list of T
    1.81+{
    1.82+	r: list of T;
    1.83+	for(; l != nil; l = tl l)
    1.84+		if(hd l != e)
    1.85+			r = hd l::r;
    1.86+	return r;
    1.87+}
    1.88+
    1.89+del(e: ref Elem)
    1.90+{
    1.91+	return;
    1.92+	i := e.qid % len elems;
    1.93+	elems[i] = remove(elems[i], e);
    1.94+}
    1.95+
    1.96 getfile(qid: int): ref Elem.File
    1.97 {
    1.98 	pick file := get(qid) {
    1.99@@ -309,8 +328,19 @@
   1.100 				break;
   1.101 			}
   1.102 			c.open(mode, f.qid);
   1.103+			e := get(int c.path);
   1.104+			if(e != nil)
   1.105+				e.nused++;
   1.106 			ss.reply(ref Rmsg.Open(m.tag, f.qid, ss.iounit()));
   1.107 
   1.108+		Clunk =>
   1.109+			f := ss.getfid(m.fid);
   1.110+			if(f != nil) {
   1.111+				e := get(int f.path);
   1.112+				if(e != nil && --e.nused <= 0)
   1.113+					del(e);
   1.114+			}
   1.115+			ss.default(m);
   1.116 
   1.117 		* =>
   1.118 			ss.default(m);
   1.119@@ -348,7 +378,7 @@
   1.120 		say(sprint("have navop, path=%bd", navop.path));
   1.121 		pick n := navop {
   1.122 		Stat =>
   1.123-			say(sprint("have stat"));
   1.124+			say(sprint("have stat path=%bd", n.path));
   1.125 			n.reply <-= (get(int n.path).stat(), nil);
   1.126 
   1.127 		Walk =>
   1.128@@ -382,11 +412,13 @@
   1.129 					continue loop;
   1.130 				}
   1.131 				if(de != nil) {
   1.132-					ne := childget(ed.qid, de.qid);
   1.133-					if(ne == nil) {
   1.134-						nqid := childput(ed.qid, de.qid);
   1.135-						ne = Elem.new(nqid, ed.vd, de, ed.qid);
   1.136-					}
   1.137+					cqid := childget(ed.qid, de.qid);
   1.138+					if(cqid < 0)
   1.139+						cqid = childput(ed.qid, de.qid);
   1.140+					ne := get(cqid);
   1.141+					if(ne == nil)
   1.142+						ne = Elem.new(cqid, ed.vd, de, ed.qid);
   1.143+					say(sprint("readdir, childget(%d, %bd) = %d", ed.qid, de.qid, ne.qid));
   1.144 					ed.prev = (n.offset, ne.stat());
   1.145 				} else {
   1.146 					ed.prev = (n.offset, nil);