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

1991/1011/port/pgrp.c (diff list | history)

1991/0806/sys/src/9/port/pgrp.c:28,331991/1011/sys/src/9/port/pgrp.c:28,34 (short | long | prev | next)
1990/0227    
struct{ 
	Lock; 
	Mount	*free; 
1991/1011    
	Mhead	*mhfree; 
1990/0227    
	ulong	mountid; 
}mountalloc; 
 
1991/0806/sys/src/9/port/pgrp.c:39,531991/1011/sys/src/9/port/pgrp.c:40,54
1991/0705    
	Egrp *e, *ee; 
	Fgrp *f, *fe; 
	Mount *m, *em; 
1991/1011    
	Mhead *hm, *hem; 
1990/0227    
 
1990/1110    
	pgrpalloc.arena = ialloc(conf.npgrp*sizeof(Pgrp), 0); 
	pgrpalloc.free = pgrpalloc.arena; 
1990/0227    
 
	p = pgrpalloc.free; 
1990/0825    
	for(i=0; i<conf.npgrp; i++,p++){ 
1991/1011    
	for(i=0; i<conf.npgrp; i++,p++) { 
1990/1110    
		p->index = i; 
1990/0227    
		p->next = p+1; 
		p->mtab = ialloc(conf.nmtab*sizeof(Mtab), 0); 
	} 
1990/0825    
	p[-1].next = 0; 
1990/0227    
 
1991/0806/sys/src/9/port/pgrp.c:64,751991/1011/sys/src/9/port/pgrp.c:65,70
1991/0705    
	for(f = fgrpalloc.free; f < fe; f++) 
		f->next = f+1; 
	f->next = 0; 
                 
	mountalloc.free = ialloc(conf.nmount*sizeof(Mount), 0); 
	em = &mountalloc.free[conf.nmount-1]; 
	for(m = mountalloc.free; m < em; m++) 
1990/0227    
		m->next = m+1; 
	m->next = 0; 
} 
 
Pgrp* 
1991/0806/sys/src/9/port/pgrp.c:119,1261991/1011/sys/src/9/port/pgrp.c:114,121
1991/0705    
			pgrpalloc.free = p->next; 
			p->ref = 1; 
			p->pgrpid = ++pgrpalloc.pgrpid; 
			p->nmtab = 0; 
1991/0806    
			memset(p->rendhash, 0, sizeof(p->rendhash)); 
1991/1011    
			memset(p->mnthash, 0, sizeof(p->mnthash)); 
1991/0705    
			unlock(&pgrpalloc); 
			return p; 
		} 
1991/0806/sys/src/9/port/pgrp.c:202,2191991/1011/sys/src/9/port/pgrp.c:197,218
1990/0227    
void 
closepgrp(Pgrp *p) 
{ 
	int i; 
	Mtab *m; 
                 
1991/1011    
	Mhead **h, **e, *f, *next; 
	 
1990/0227    
	if(decref(p) == 0){ 
1991/0212    
		qlock(&p->debug); 
1990/1110    
		p->pgrpid = -1; 
1990/0227    
		m = p->mtab; 
		for(i=0; i<p->nmtab; i++,m++) 
			if(m->c){ 
				close(m->c); 
				closemount(m->mnt); 
1991/1011    
 
		e = &p->mnthash[MNTHASH]; 
		for(h = p->mnthash; h < e; h++) { 
			for(f = *h; f; f = next) { 
				close(f->from); 
				mountfree(f->mount); 
				next = f->hash; 
				mntheadfree(f); 
1990/0227    
			} 
1991/1011    
		} 
 
1990/0227    
		lock(&pgrpalloc); 
		p->next = pgrpalloc.free; 
		pgrpalloc.free = p; 
1991/0806/sys/src/9/port/pgrp.c:260,3081991/1011/sys/src/9/port/pgrp.c:259,292
1991/0705    
 
 
1990/0227    
Mount* 
newmount(void) 
1991/1011    
newmount(Mhead *mh, Chan *to) 
1990/0227    
{ 
	Mount *m; 
1991/1011    
	Mount *m, *f, *e; 
1990/0227    
 
loop: 
	lock(&mountalloc); 
	if(m = mountalloc.free){		/* assign = */ 
		mountalloc.free = m->next; 
		m->ref = 1; 
1990/0928    
		m->next = 0; 
1990/0227    
		m->mountid = ++mountalloc.mountid; 
1991/1011    
	for(;;) { 
		lock(&mountalloc); 
		if(m = mountalloc.free){		/* assign = */ 
			mountalloc.free = m->next; 
			m->mountid = ++mountalloc.mountid; 
			unlock(&mountalloc); 
			m->next = 0; 
			m->head = mh; 
			m->to = to; 
			incref(to); 
			return m; 
		} 
1990/0227    
		unlock(&mountalloc); 
		return m; 
	} 
	unlock(&mountalloc); 
	print("no mounts\n"); 
	if(u == 0) 
		panic("newmount"); 
	u->p->state = Wakeme; 
	alarm(1000, wakeme, u->p); 
	sched(); 
	goto loop; 
} 
 
void 
closemount(Mount *m) 
{ 
	lock(m); 
	if(m->ref == 1){ 
1990/0321    
		if(m->c) 
			close(m->c); 
1990/0227    
		if(m->next) 
			closemount(m->next); 
		unlock(m); 
1991/1011    
		m = (Mount*)VA(kmap(newpage(0, 0, 0))); 
		e = &m[(BY2PG/sizeof(Mount))-1]; 
		for(f = m; f < e; f++) 
			f->next = f+1; 
 
1990/0227    
		lock(&mountalloc); 
		m->mountid = 0; 
		m->next = mountalloc.free; 
1991/1011    
		e->next = mountalloc.free; 
1990/0227    
		mountalloc.free = m; 
		unlock(&mountalloc); 
		return; 
	} 
	m->ref--; 
	unlock(m); 
} 
 
void 
1991/0806/sys/src/9/port/pgrp.c:348,3681991/1011/sys/src/9/port/pgrp.c:332,411
1991/0514    
void 
pgrpcpy(Pgrp *to, Pgrp *from) 
{ 
	int i; 
	Mtab *m; 
1991/1011    
	Mhead **h, **e, *f, **l, *mh; 
	Mount *n, *m, **link; 
1991/0514    
 
	lock(from); 
	memmove(to->user, from->user, NAMELEN); 
	memmove(to->mtab, from->mtab, from->nmtab*sizeof(Mtab)); 
	to->nmtab = from->nmtab; 
	m = to->mtab; 
	for(i=0; i<from->nmtab; i++,m++) 
		if(m->c){ 
			incref(m->c); 
			lock(m->mnt); 
			m->mnt->ref++; 
			unlock(m->mnt); 
1991/1011    
 
	rlock(&from->ns); 
 
	e = &from->mnthash[MNTHASH]; 
	for(h = from->mnthash; h < e; h++) { 
		for(f = *h; f; f = f->hash) { 
			mh = newmnthead(); 
			mh->from = f->from; 
			incref(mh->from); 
			l = &MOUNTH(to, mh->from); 
			mh->hash = *l; 
			*l = mh; 
			link = &mh->mount; 
			for(m = f->mount; m; m = m->next) { 
				n = newmount(mh, m->to); 
				*link = n; 
				link = &n->next;	 
			} 
1991/0514    
		} 
1991/1011    
	} 
	runlock(&from->ns); 
} 
1991/0514    
 
1990/0227    
	unlock(from); 
1991/1011    
Mhead * 
newmnthead(void) 
{ 
	Mhead *mh, *f, *e; 
 
	for(;;) { 
		lock(&mountalloc); 
		if(mh = mountalloc.mhfree) {		/* Assign '=' */ 
			mountalloc.mhfree = mh->hash; 
			unlock(&mountalloc); 
			mh->hash = 0; 
			mh->mount = 0; 
			return mh; 
		} 
		unlock(&mountalloc); 
 
		mh = (Mhead*)VA(kmap(newpage(0, 0, 0))); 
		e = &mh[(BY2PG/sizeof(Mhead))-1]; 
		for(f = mh; f < e; f++) 
			f->hash = f+1; 
 
		lock(&mountalloc); 
		e->hash = mountalloc.mhfree; 
		mountalloc.mhfree = mh; 
		unlock(&mountalloc); 
	} 
} 
 
void 
mntheadfree(Mhead *mh) 
{ 
	lock(&mountalloc); 
	mh->hash = mountalloc.mhfree; 
	mountalloc.mhfree = mh; 
	unlock(&mountalloc); 
} 
 
void 
mountfree(Mount *m) 
{ 
	Mount *f; 
 
	for(f = m; f->next; f = f->next) 
		close(f->to); 
	close(f->to); 
	lock(&mountalloc); 
	f->next = mountalloc.free; 
	mountalloc.free = m; 
	unlock(&mountalloc); 
1990/0227    
} 


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