plan 9 kernel history: overview | file list | diff list

1993/1016/port/cache.c (diff list | history)

1993/1015/sys/src/9/port/cache.c:58,641993/1016/sys/src/9/port/cache.c:58,64 (short | long | prev | next)
1993/1014    
	cache.head = xalloc(sizeof(Mntcache)*NFILE); 
	m = cache.head; 
	 
1993/1015    
	for(i = 0; i < NFILE; i++) { 
1993/1016    
	for(i = 0; i < NFILE-1; i++) { 
1993/1014    
		m->next = m+1; 
		m->prev = m-1; 
		m++; 
1993/1015/sys/src/9/port/cache.c:69,1041993/1016/sys/src/9/port/cache.c:69,79
1993/1014    
	cache.head->prev = 0; 
} 
 
1993/1013    
Mntcache* 
clook(Chan *c) 
1993/1011    
{ 
1993/1013    
	int h; 
1993/1014    
	Mntcache *m; 
1993/1011    
                 
1993/1013    
	h = c->qid.path%NHASH; 
                 
	lock(&cache); 
	for(m = cache.hash[h]; m; m = m->hash) { 
1993/1014    
		if(m->path == c->qid.path) { 
1993/1013    
			qlock(m); 
			if(m->path == c->qid.path) 
			if(m->dev  == c->dev) 
			if(m->type == c->type) { 
				unlock(&cache); 
				return m; 
			} 
			qunlock(m); 
		} 
	} 
	unlock(&cache); 
	return 0; 
} 
                 
void 
1993/1015    
cprint(Mntcache *m, char *s) 
1993/1014    
{ 
	Extent *e; 
1993/1015    
return; 
1993/1016    
 
1993/1015    
	print("%s: 0x%lux.0x%lux %d %d\n", 
			s, m->path, m->vers, m->type, m->dev); 
1993/1014    
 
1993/1015/sys/src/9/port/cache.c:134,1441993/1016/sys/src/9/port/cache.c:109,116
1993/1013    
} 
 
void 
1993/1015    
ctail(Mntcache *m, int dolock) 
1993/1016    
ctail(Mntcache *m) 
1993/1013    
{ 
1993/1015    
	if(dolock) 
		lock(&cache); 
1993/1013    
                 
	/* Unlink and send to the tail */ 
	if(m->prev)  
		m->prev->next = m->next; 
1993/1015/sys/src/9/port/cache.c:159,1671993/1016/sys/src/9/port/cache.c:131,136
1993/1013    
		cache.head = cache.tail = m; 
		m->prev = m->next = 0; 
	} 
                 
1993/1015    
	if(dolock) 
		unlock(&cache); 
1993/1013    
} 
 
void 
1993/1015/sys/src/9/port/cache.c:172,2181993/1016/sys/src/9/port/cache.c:141,189
1993/1015    
	if(c->qid.path & CHDIR) 
		return; 
 
1993/1013    
	m = clook(c); 
	if(m != 0) { 
1993/1015    
		c->mcp = m; 
		ctail(m, 1); 
1993/1016    
	lock(&cache); 
	for(m = cache.hash[c->qid.path%NHASH]; m; m = m->hash) { 
		if(m->path == c->qid.path) 
		if(m->dev == c->dev && m->type == c->type) { 
			c->mcp = m; 
			ctail(m); 
			unlock(&cache); 
1993/1015    
 
1993/1013    
		/* File was updated */ 
1993/1015    
		if(m->vers != c->qid.vers) { 
cprint(m, "copen mod"); 
1993/1013    
			cnodata(m); 
1993/1015    
			m->vers = c->qid.vers; 
1993/1016    
			/* File was updated, invalidate cache */ 
			if(m->vers != c->qid.vers) { 
				qlock(m); 
				cnodata(m); 
				m->vers = c->qid.vers; 
				qunlock(m); 
			} 
			return; 
1993/1015    
		} 
1993/1013    
		qunlock(m); 
1993/1015    
cprint(m, "copen lru"); 
1993/1013    
		return; 
	} 
 
	/* LRU the cache headers */ 
	m = cache.head; 
	qlock(m); 
1993/1014    
	lock(&cache); 
	l = &cache.hash[m->path%NHASH]; 
1993/1013    
	for(f = *l; f; f = f->next) { 
1993/1016    
	for(f = *l; f; f = f->hash) { 
1993/1013    
		if(f == m) { 
			*l = f->next; 
1993/1016    
			*l = f->hash; 
1993/1013    
			break; 
		} 
		l = &f->next; 
1993/1016    
		l = &f->hash; 
1993/1013    
	} 
	l = &cache.hash[c->qid.path%NHASH]; 
	m->hash = *l; 
	*l = m; 
1993/1015    
	ctail(m, 0); 
1993/1014    
	unlock(&cache); 
1993/1016    
	ctail(m); 
1993/1015    
 
1993/1014    
	m->Qid = c->qid; 
1993/1013    
	m->dev = c->dev; 
	m->type = c->type; 
	cnodata(m); 
	c->mcp = m; 
1993/1016    
	unlock(&cache); 
 
	qlock(m); 
	cnodata(m); 
1993/1013    
	qunlock(m); 
1993/1015    
cprint(m, "copen new"); 
1993/1013    
} 
 
static int 
1993/1015/sys/src/9/port/cache.c:254,2611993/1016/sys/src/9/port/cache.c:225,236
1993/1013    
	end = offset+len; 
1993/1014    
	t = &m->list; 
	for(e = *t; e; e = e->next) { 
1993/1013    
		if(e->start >= offset && e->start+e->len < end) 
1993/1016    
		if(offset > e->start && offset < e->start+e->len) 
1993/1013    
			break; 
1993/1016    
		if(offset < e->start) { 
			qunlock(m); 
			return 0; 
		}	 
1993/1014    
		t = &e->next; 
1993/1013    
	} 
 
1993/1015/sys/src/9/port/cache.c:288,2931993/1016/sys/src/9/port/cache.c:263,270
1993/1013    
			l = e->len-o; 
 
1993/1014    
		memmove(buf, (uchar*)VA(k) + o, l); 
1993/1016    
 
		poperror(); 
1993/1013    
		kunmap(k); 
		putpage(p); 
 
1993/1015/sys/src/9/port/cache.c:313,3181993/1016/sys/src/9/port/cache.c:290,296
1993/1014    
	Extent *e, *start, **t; 
 
	start = 0; 
1993/1016    
	*tail = 0; 
1993/1014    
	t = &start; 
	while(len) { 
		e = malloc(sizeof(Extent)); 
1993/1015/sys/src/9/port/cache.c:348,3531993/1016/sys/src/9/port/cache.c:326,332
1993/1014    
		*tail = e; 
		t = &e->next; 
	} 
1993/1016    
 
1993/1014    
	return start; 
} 
 
1993/1015/sys/src/9/port/cache.c:370,3761993/1016/sys/src/9/port/cache.c:349,355
1993/1014    
} 
 
1993/1013    
void 
1993/1014    
cupdate(Chan *c, uchar *buf, int len, ulong offset) 
1993/1016    
cxupdate(Chan *c, uchar *buf, int len, ulong offset) 
1993/1013    
{ 
	Mntcache *m; 
1993/1014    
	Extent *tail; 
1993/1015/sys/src/9/port/cache.c:377,3851993/1016/sys/src/9/port/cache.c:356,361
1993/1014    
	Extent *e, *f, *p; 
1993/1015    
	int o, ee, eblock; 
1993/1013    
 
1993/1015    
	if(c->qid.path & CHDIR) 
1993/1013    
		return; 
                 
1993/1015    
	if(offset > MAXCACHE || len == 0) 
		return; 
 
1993/1015/sys/src/9/port/cache.c:413,4211993/1016/sys/src/9/port/cache.c:389,399
1993/1014    
			} 
		} 
		e = cchain(buf, offset, len, &tail); 
		m->list = e; 
		if(tail != 0) 
			tail->next = f; 
1993/1016    
		if(e != 0) { 
			m->list = e; 
			if(tail != 0) 
				tail->next = f; 
		} 
1993/1014    
		qunlock(m); 
		return; 
	} 
1993/1015/sys/src/9/port/cache.c:438,4471993/1016/sys/src/9/port/cache.c:416,421
1993/1014    
		o = len; 
		if(o > BY2PG - p->len) 
			o = BY2PG - p->len; 
		if(len <= 0) { 
			qunlock(m); 
1993/1013    
			return; 
1993/1014    
		} 
1993/1015    
		if(cpgmove(p, buf, p->len, o)) { 
			p->len += o; 
1993/1014    
			buf += o; 
1993/1015/sys/src/9/port/cache.c:465,4751993/1016/sys/src/9/port/cache.c:439,449
1993/1014    
	eblock = offset+len; 
	if(eblock > f->start) { 
		o = eblock - f->start; 
		if(o < 0) { 
1993/1016    
		len -= o; 
		if(len <= 0) { 
1993/1014    
			qunlock(m); 
			return; 
		} 
		len -= o; 
	} 
 
1993/1015    
	/* insert a middle block */ 
1993/1015/sys/src/9/port/cache.c:483,4881993/1016/sys/src/9/port/cache.c:457,469
1993/1015    
} 
 
void 
1993/1016    
cupdate(Chan *c, uchar *buf, int len, ulong offset) 
{ 
	cxupdate(c, buf, len, offset); 
	cprint(c->mcp, "cupdate"); 
} 
 
void 
1993/1015    
cwrite(Chan* c, uchar *buf, int len, ulong offset) 
{ 
	int o; 
1993/1015/sys/src/9/port/cache.c:517,5231993/1016/sys/src/9/port/cache.c:498,504
1993/1015    
		if(ee > offset) { 
			o = ee - offset; 
			p->len -= o; 
			if(p->len) 
1993/1016    
			if(p->len == 0) 
1993/1015    
				panic("del empty extent"); 
		} 
	} 
1993/1015/sys/src/9/port/cache.c:531,5421993/1016/sys/src/9/port/cache.c:512,525
1993/1015    
	} 
 
	e = cchain(buf, offset, len, &tail); 
	if(p == 0) 
		m->list = e; 
	else 
		p->next = e; 
	if(tail != 0) 
		tail->next = f; 
1993/1016    
	if(e != 0) { 
		if(p == 0) 
			m->list = e; 
		else 
			p->next = e; 
		if(tail != 0) 
			tail->next = f; 
	} 
1993/1015    
	qunlock(m); 
cprint(m, "cwrite"); 
1993/1011    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)