ref: eddf77b8f9b80a602c636346c3a53ef59e3845ab
parent: dd82b07a863d8ace74ae63a98513db69b24b0019
author: Ori Bernstein <ori@eigenstate.org>
date: Wed May 29 19:53:41 EDT 2024
gefs: revert the last commit; we added a deadlock
--- a/sys/src/cmd/gefs/blk.c
+++ b/sys/src/cmd/gefs/blk.c
@@ -928,6 +928,9 @@
case DFtree:
free(p->t);
break;
+ case DFmnt:
+ free(p->m);
+ break;
case DFblk:
a = getarena(p->bp.addr);
qe.op = Qfree;
--- a/sys/src/cmd/gefs/dat.h
+++ b/sys/src/cmd/gefs/dat.h
@@ -433,6 +433,7 @@
enum {
DFblk,
+ DFmnt,
DFtree,
};
@@ -516,7 +517,6 @@
QLock synclk;
Rendez syncrz;
- RWLock mountlk;
Mount *mounts;
Mount *snapmnt;
Lock connlk;
--- a/sys/src/cmd/gefs/fs.c
+++ b/sys/src/cmd/gefs/fs.c
@@ -96,10 +96,8 @@
*/
qlock(&fs->mutlk);
tracem("packb");
- rlock(&fs->mountlk);
- for(mnt = fs->mounts; mnt != nil; mnt = mnt->next)
+ for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next)
updatesnap(&mnt->root, mnt->root, mnt->name, mnt->flag);
- runlock(&fs->mountlk);
/*
* Now that we've updated the snaps, we can sync the
* dlist; the snap tree will not change from here.
@@ -201,8 +199,7 @@
}
t = nil;
*tp = nil;
- rlock(&fs->mountlk);
- for(mnt = fs->mounts; mnt != nil; mnt = mnt->next){
+ for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next){
if(strcmp(a->old, mnt->name) == 0){
updatesnap(&mnt->root, mnt->root, mnt->name, mnt->flag);
t = agetp(&mnt->root);
@@ -210,7 +207,6 @@
break;
}
}
- runlock(&fs->mountlk);
if(t == nil && (t = opensnap(a->old, nil)) == nil){
if(a->fd != -1)
fprint(a->fd, "snap: open '%s': does not exist\n", a->old);
@@ -627,13 +623,13 @@
return fs->snapmnt;
}
- wlock(&fs->mountlk);
- for(mnt = fs->mounts; mnt != nil; mnt = mnt->next){
+ for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next){
if(strcmp(name, mnt->name) == 0){
ainc(&mnt->ref);
goto Out;
}
}
+
if((mnt = mallocz(sizeof(*mnt), 1)) == nil)
error(Enomem);
if(waserror()){
@@ -648,11 +644,10 @@
mnt->flag = flg;
mnt->root = t;
mnt->next = fs->mounts;
- fs->mounts = mnt;
+ asetp(&fs->mounts, mnt);
poperror();
Out:
- wunlock(&fs->mountlk);
return mnt;
}
@@ -659,22 +654,22 @@
void
clunkmount(Mount *mnt)
{
- Mount *e, **p;
+ Mount *me, **p;
+ Bfree *f;
if(mnt == nil)
return;
if(adec(&mnt->ref) == 0){
- wlock(&fs->mountlk);
- p = &fs->mounts;
- for(e = fs->mounts; e != nil; e = e->next){
- if(e == mnt)
+ for(p = &fs->mounts; (me = *p) != nil; p = &me->next){
+ if(me == mnt)
break;
- p = &e->next;
}
- assert(e != nil);
- *p = e->next;
- free(mnt);
- wunlock(&fs->mountlk);
+ assert(me != nil);
+ f = emalloc(sizeof(Bfree), 0);
+ f->op = DFmnt;
+ f->m = mnt;
+ *p = me->next;
+ limbo(f);
}
}
@@ -2678,8 +2673,7 @@
chsend(fs->admchan, a);
tmnow(&now, nil);
- rlock(&fs->mountlk);
- for(mnt = fs->mounts; mnt != nil; mnt = mnt->next){
+ for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next){
if(!(mnt->flag & Ltsnap))
continue;
if(now.yday != then.yday){
@@ -2702,7 +2696,6 @@
snapmsg("main", mnt->minutely[m], Lauto);
}
}
- runlock(&fs->mountlk);
if(now.hour != then.hour)
h = (h+1)%24;
if(now.min != then.min)
--- a/sys/src/cmd/gefs/snap.c
+++ b/sys/src/cmd/gefs/snap.c
@@ -348,14 +348,12 @@
btupsert(&fs->snap, m, nm);
if(deltree){
reclaimblocks(t->gen, succ, t->pred);
- rlock(&fs->mountlk);
- for(mnt = fs->mounts; mnt != nil; mnt = mnt->next){
+ for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next){
if(mnt->root->gen == t->succ)
mnt->root->pred = t->pred;
if(mnt->root->gen == t->pred)
mnt->root->succ = t->succ;
}
- runlock(&fs->mountlk);
}
}
--
⑨