code: mafs

Download patch

ref: 9807465425b73988f6c9933a74e0518aa1296d86
parent: 0e95da7146265fe0f54745c89f93d7685a68e1bd
author: 9ferno <gophone2015@gmail.com>
date: Thu Oct 20 00:49:14 EDT 2022

cleaned up the shutdown() procedure

--- a/9p.c
+++ b/9p.c
@@ -128,7 +128,6 @@
 
 	if(shuttingdown){
 		respond(req, errstring[Eshutdown]);
-		shutdown();
 		return;
 	}
 	if(readonly){
@@ -219,7 +218,6 @@
 
 	if(shuttingdown){
 		respond(req, errstring[Eshutdown]);
-		shutdown();
 		return;
 	}
 	if(req->fid->qid.type == QTAUTH){
@@ -747,12 +745,6 @@
 	return;
 }
 
-void
-fshalt(Srv *)
-{
-	shutdown();
-}
-
 /* below is from nemo's Pg 252 */
 typedef	struct	Buffer	Buffer;
 typedef	struct	Work	Work;
@@ -785,7 +777,6 @@
 		rsleep(&b->isempty);
 		if(shuttingdown){
 			qunlock(&b->lck);
-			dprint("shuttingdown\n");
 			return (Work){nil,nil};
 		}
 	}
@@ -886,17 +877,20 @@
 void
 shutdown(void)
 {
-	int i, a;
 	u64 n;
 /*	User *u, *v; */
-	char srvfilename[Namelen];
 
 	if(chatty9p > 1)
-	dprint("shutdown\n");
-	a = 0;
+		dprint("shutdown\n");
+	shuttingdown = 1;
 	fsok(1);
 //	showextents(&frees);
-	shuttingdown = 1;
+//	dprint("&buf.isempty %#p\n", &buf.isempty);
+	if(mpstarted){
+		qlock(&buf.lck);
+		rwakeupall(&buf.isempty);
+		qunlock(&buf.lck);
+	}
 	while((n=pendingwrites())>0){
 		if(chatty9p > 1)
 		dprint("shutdown: pendingwrites %llud of write queue\n", n);
@@ -903,12 +897,6 @@
 		sleep(1000);
 	}
 	savefrees(Bdfrees);
-//	dprint("&buf.isempty %#p\n", &buf.isempty);
-//	rwakeupall(&buf.isempty);
-	for(i = 0; i< 10; i++){
-		a = stopworkers();
-		sleep(a*1000);
-	}
 	while((n=pendingwrites())>0){
 		if(chatty9p > 1)
 		dprint("shutdown: pendingwrites %llud of frees\n", n);
@@ -915,15 +903,6 @@
 		sleep(1000);
 	}
 	stopwriter();
-	if(a > 1){ /* 1 for this running process */
-		dprint("%d processes still running\n", a);
-		for(i = 0; i<Nprocs; i++){
-			if(worker[i].pid > 0)
-				dprint("running %#p\n", worker[i].w.f);
-		}
-		sleep(1000);
-		postnote(PNGROUP, getpid(), "interrupt");
-	}
 
 	/* free users, why bother? leave it alone */
 /*	u = t->users;
@@ -934,14 +913,8 @@
 	}
 	t->users = nil;*/
 
-	/* /srv/mafs_service file will not exist when mounted with -s */
-	if(mpstarted &&
-		sprint(srvfilename, "/srv/%s", service) > 5)
-			remove(srvfilename);
-
 	if(chatty9p > 1)
 		dprint("shutdown: exiting\n");
-	exits(nil);
 	/* chkqunlock(&superlock); exit while holding the lock */
 }
 
@@ -959,9 +932,6 @@
 		w = get(b);
 	}
 	worker[id].pid = 0;
-	if(chatty9p > 1)
-	dprint("worker %d exiting\n", id);
-	exits(nil);
 }
 
 void
@@ -983,8 +953,9 @@
 	snprint(name, 16, "mafs worker %d", id);
 	procsetname(name);
 	work(b, id);
-	dprint("%s process exited\n", name);
-	_exits(nil);
+	if(chatty9p)
+		dprint("%s process exited\n", name);
+	exits(nil);
 }
 
 void
@@ -999,6 +970,16 @@
 	for(i = 0; i < Nprocs; i++){
 		startproc(&buf, i);
 	}
+}
+
+void
+fshalt(Srv *)
+{
+	if(shuttingdown == 0)
+		shutdown();
+	/* no need to bother removing /srv/service
+		as we do for cmdhalt in ctlwrite() of ctl.c
+		as the srv() takes care of that cleanup */
 }
 
 void
--- a/block.c
+++ b/block.c
@@ -47,6 +47,6 @@
 	}
 
 	devread(blkno, buf, 1);
-	showblock(2, buf);
+	showblock(1, buf);
 	exits(0);
 }
--- a/ctl.c
+++ b/ctl.c
@@ -159,7 +159,7 @@
 	int n;
 	char srvfilename[Namelen];
 
-	/*if(chatty9p)*/
+	if(chatty9p)
 		dprint("consproc: >%s\n", req->ifcall.data);
 	while((cb = parsecmd(req->ifcall.data, req->ifcall.count)) != nil){
 		ct = lookupcmd(cb, cmds, nelem(cmds));
@@ -167,16 +167,16 @@
 			req->ofcall.count = req->ifcall.count;
 			req->ofcall.offset = req->ifcall.offset+req->ifcall.count;
 			n = runcmd(ct->index, cb);
-			dprint("before respond\n");
 			respond(req, nil);
-			dprint("after respond\n");
 			if(ct->index == Chalt || n == Chalt){
 				/* /srv/mafs_service file will not exist when mounted with -s */
 				if(mpstarted &&
 					sprint(srvfilename, "/srv/%s", service) > 5)
 					remove(srvfilename);
-				else
+				else{
 					close(1);
+					close(0);
+				}
 				exits(nil);
 			}
 		}else{
--- a/tests/regress.rc
+++ b/tests/regress.rc
@@ -25,7 +25,7 @@
 	# start service
 	if(~ $"debug '')
 		mount -c <{disk/mafs -s -r mafs_^$service -h 10 $disk <[0=1]} /n/mafs_^$service
-	if not # TODO below broke, have no idea why. Needs fixing
+	if not # TODO below breaks auth negotiation. Something is writing to fd 1.
 		mount -c <{disk/mafs $"debug -s -r mafs_^$service -h 10 $disk <[0=1]} /n/mafs_^$service
 	echo service status: $status
 
--- a/writer.c
+++ b/writer.c
@@ -210,7 +210,7 @@
 	}
 	if(chatty9p > 4)
 	dprint("%s process exited\n", name);
-	_exits(nil);
+	exits(nil);
 }
 
 void
@@ -250,6 +250,8 @@
 
 	qlock(&drts.lck);
 	n = drts.n;
+	if(chatty9p>4)
+		stats();
 	qunlock(&drts.lck);
 	return n;
 }
\ No newline at end of file