git: 9front

Download patch

ref: c5804dadfe84e36cedfc6acee88b81a8b3213ac3
parent: 2beb3a38286006e92748c0159db05b70b7c5bca2
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Aug 9 17:16:10 EDT 2015

kernel: pgrpcpy(), simplify Mount structure

instead of ordering the source mount list, order the new destination
list which has the advantage that we do not need to wlock the source
namespace, so copying can be done in parallel and we do not need the
copy forward pointer in the Mount structure.

the Mhead back pointer in the Mount strcture was unused, removed.

--- a/sys/src/9/port/chan.c
+++ b/sys/src/9/port/chan.c
@@ -704,7 +704,7 @@
 		 *  node to the mount chain.
 		 */
 		if(order != MREPL)
-			m->mount = newmount(m, old, 0, 0);
+			m->mount = newmount(old, 0, nil);
 	}
 	wlock(&m->lock);
 	if(waserror()){
@@ -713,7 +713,7 @@
 	}
 	wunlock(&pg->ns);
 
-	nm = newmount(m, new, flag, spec);
+	nm = newmount(new, flag, spec);
 	if(mh != nil && mh->mount != nil){
 		/*
 		 *  copy a union when binding it onto a directory
@@ -724,7 +724,7 @@
 		h = &nm->next;
 		um = mh->mount;
 		for(um = um->next; um != nil; um = um->next){
-			f = newmount(m, um->to, flg, um->spec);
+			f = newmount(um->to, flg, um->spec);
 			*h = f;
 			h = &f->next;
 		}
--- a/sys/src/9/port/devshr.c
+++ b/sys/src/9/port/devshr.c
@@ -531,7 +531,6 @@
 
 		incref(mpt);
 		mpt->m.mflag = (h->mount == nil) ? MCREATE : 0;
-		mpt->m.head = h;
 		mpt->m.next = h->mount;
 		h->mount = &mpt->m;
 
@@ -602,7 +601,6 @@
 			if(*ml == m){
 				*ml = m->next;
 				m->next = nil;
-				m->head = nil;
 				putmpt(mpt);
 				break;
 			}
--- a/sys/src/9/port/pgrp.c
+++ b/sys/src/9/port/pgrp.c
@@ -115,11 +115,12 @@
 void
 pgrpcpy(Pgrp *to, Pgrp *from)
 {
-	int i;
 	Mount *n, *m, **link, *order;
 	Mhead *f, **tom, **l, *mh;
+	int i;
 
-	wlock(&from->ns);
+	wlock(&to->ns);
+	rlock(&from->ns);
 	order = nil;
 	tom = to->mnthash;
 	for(i = 0; i < MNTHASH; i++) {
@@ -131,9 +132,14 @@
 			l = &mh->hash;
 			link = &mh->mount;
 			for(m = f->mount; m != nil; m = m->next) {
-				n = newmount(mh, m->to, m->mflag, m->spec);
-				m->copy = n;
-				pgrpinsert(&order, m);
+				n = smalloc(sizeof(Mount));
+				n->mountid = m->mountid;
+				n->mflag = m->mflag;
+				n->to = m->to;
+				incref(n->to);
+				if(m->spec != nil)
+					kstrdup(&n->spec, m->spec);
+				pgrpinsert(&order, n);
 				*link = n;
 				link = &n->next;
 			}
@@ -144,8 +150,9 @@
 	 * Allocate mount ids in the same sequence as the parent group
 	 */
 	for(m = order; m != nil; m = m->order)
-		m->copy->mountid = incref(&mountid);
-	wunlock(&from->ns);
+		m->mountid = incref(&mountid);
+	runlock(&from->ns);
+	wunlock(&to->ns);
 }
 
 Fgrp*
@@ -246,12 +253,11 @@
 
 
 Mount*
-newmount(Mhead *mh, Chan *to, int flag, char *spec)
+newmount(Chan *to, int flag, char *spec)
 {
 	Mount *m;
 
 	m = smalloc(sizeof(Mount));
-	m->head = mh;
 	m->to = to;
 	incref(to);
 	m->mountid = incref(&mountid);
--- a/sys/src/9/port/portdat.h
+++ b/sys/src/9/port/portdat.h
@@ -255,8 +255,6 @@
 {
 	ulong	mountid;
 	Mount*	next;
-	Mhead*	head;
-	Mount*	copy;
 	Mount*	order;
 	Chan*	to;			/* channel replacing channel */
 	int	mflag;
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -190,7 +190,7 @@
 Chan*		newchan(void);
 int		newfd(Chan*);
 Mhead*		newmhead(Chan*);
-Mount*		newmount(Mhead*, Chan*, int, char*);
+Mount*		newmount(Chan*, int, char*);
 Page*		newpage(int, Segment **, uintptr);
 Path*		newpath(char*);
 Pgrp*		newpgrp(void);
--