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.
This commit is contained in:
cinap_lenrek 2015-08-09 21:16:10 +02:00
parent 3af236b5e3
commit 9f4eac5292
5 changed files with 19 additions and 17 deletions

View file

@ -704,7 +704,7 @@ cmount(Chan **newp, Chan *old, int flag, char *spec)
* 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 @@ cmount(Chan **newp, Chan *old, int flag, char *spec)
}
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 @@ cmount(Chan **newp, Chan *old, int flag, char *spec)
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;
}

View file

@ -531,7 +531,6 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
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 @@ shrremove(Chan *c)
if(*ml == m){
*ml = m->next;
m->next = nil;
m->head = nil;
putmpt(mpt);
break;
}

View file

@ -115,11 +115,12 @@ pgrpinsert(Mount **order, Mount *m)
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 @@ pgrpcpy(Pgrp *to, Pgrp *from)
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 @@ pgrpcpy(Pgrp *to, Pgrp *from)
* 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 @@ forceclosefgrp(void)
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);

View file

@ -255,8 +255,6 @@ struct Mount
{
ulong mountid;
Mount* next;
Mhead* head;
Mount* copy;
Mount* order;
Chan* to; /* channel replacing channel */
int mflag;

View file

@ -190,7 +190,7 @@ int needpages(void*);
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);