code: mafs

Download patch

ref: 16f09290e03ec4fba68b6587dc01c13299c2a6f6
parent: ec333deceba9dd45dabf4d36138398bdd020f449
author: 9ferno <gophone2015@gmail.com>
date: Thu Nov 17 15:22:27 EST 2022

added notes on shutdown

--- a/9p.c
+++ b/9p.c
@@ -945,8 +945,21 @@
 	1. by unmounting and removing the /srv/mfs_service file (can be rm and unmount too)
 	2. by writing halt to /adm/ctl file. unmount() the file system to keep it clean.
 
-	In the second instance, fsend() is called and it stops the srv() process afterwards.
-	In the first instance, a worker needs to tell the srv() process to shutdown.
+	In the first instance, the srv() process is driving the shutdown. It calls fsend().
+		rm /srv/mfs_service file does not wait for fsend() to finish. Hence, there
+		is no way to ensure that any pending writes have been flushed to the disk.
+		If the system is shutdown or restarted immediately, there is a high possibility
+		that the filesystem will be in an inconsistent state. This is more probable
+		when disk/mafs (asynchronous writes) is used.
+	In the second instance, fsend() is called by the worker process. It does not return
+		until all the pending writes have been flushed to the disk. It also removes the
+		/srv/mfs_service file and also stops the srv() process. Hence, this is the
+		preferred approach to shutting down the file system.
+
+	There is no way to unmount() automatically on shutdown. The mount() and unmount()
+		calls are client driven and it is not the responsibility of the server to find
+		all the clients that mounted it. Just shutdown and let the respective clients
+		deal with their mess.
  */
 void
 shutdown(void)
@@ -1050,7 +1063,7 @@
 		startproc(&buf, i);
 }
 
-/* read the comment above shutdown() to understand how this works */
+/* read the comment above shutdown() to understand */
 void
 fsend(Srv *)
 {
--- a/ctl.c
+++ b/ctl.c
@@ -147,6 +147,7 @@
 }
 
 u32 mpsrvpid = 0;
+/* check the comments above shutdown() to understand */
 void
 ctlwrite(Req *req)
 {
@@ -168,6 +169,10 @@
 				/* /srv/mafs_service file will not exist when mounted with -s */
 				if(mpsrvpid &&
 					snprint(srvfilename, Namelen, "/srv/%s", service) > 5){
+					/*
+						this stuff is only needed when the worker is doing
+						the shutdown()
+					 */
 					n = remove(srvfilename);
 					close(req->srv->infd);
 					close(req->srv->outfd);
--- a/docs/mafs.ms
+++ b/docs/mafs.ms
@@ -1222,8 +1222,24 @@
 .sp
 	echo sync >> /n/mafs_myservice/adm/ctl
 .sp
-Stop M[a]fs. This command does not return until all the writes are written to the disk. So, could take a long time if you have a long writer queue.
 .sp
+.ne 4
+Stop M[a]fs: There are 2 ways to shutdown:
+.br
+.in 3n
+1. Unmount and remove the /srv/mfs_service file (can be rm and unmount too).
+.br
+2. Write halt into the /adm/ctl file. Unmount() the m[a]fs file system to keep it clean.
+.in 0
+.sp
+In the first instance, the srv() process is driving the shutdown. It calls fsend(). rm /srv/mfs_service file does not wait for fsend() to finish. Hence, there is no way to ensure that any pending writes have been flushed to the disk. If the system is shutdown or restarted immediately, there is a high possibility that the filesystem will be in an inconsistent state. This is more probable when disk/mafs (asynchronous writes) is used.
+.sp
+In the second instance, fsend() is called by the worker process. It does not return until all the pending writes have been flushed to the disk. It also removes the /srv/mfs_service file and also stops the srv() process. Hence, this is the preferred approach to shutting down the file system.
+.sp
+There is no way to unmount() automatically on shutdown. The mount() and unmount() calls are client driven and it is not the responsibility of the server to find all the clients that mounted it. Just shutdown and let the respective clients deal with their mess.
+.sp
+The below command does not return until all the writes are written to the disk. So, could take a long time if you have a long writer queue. This is the proper way to shutdown the m[a]fs file system.
+.sp
 	echo halt >> /n/mafs_myservice/adm/ctl
 .sp
 Interpret the contents of a block based on the tag and write out a single formatted block based on the tag
@@ -1467,7 +1483,6 @@
 		192.80 MB/s
 	dd -if /dev/zero -of /n/ramfs/file -count 700 -bs 1m
 
-	mount -c <{disk/mafs -s -r mafs_disk.file <[0=1]} /n/mafs_disk.file
 	disk/mfs -r mfs_ramfs_file /n/ramfs/file
 	mount -c /srv/mfs_ramfs_file /n/mfs_ramfs_file
 	cat /dev/zero | tput -p > /n/mfs_ramfs_file/zeros.file
@@ -1526,6 +1541,21 @@
 		63.81 MB/s
 	echo halt >>/srv/hjfs.cmd
 	unmount /n/ramfs
+.fi
+.sp
+Profiling instructions:
+.nf
+	Set LDFLAGS=-p in the mkfile and install the executables.
+	profilesize=2000000
+	ramfs -m /n/ramfs
+	touch /n/ramfs/file
+	dd -if /dev/zero -of /n/ramfs/file -count 700 -bs 1m
+	mount -c <{disk/mafs -s -r mafs_disk.file /n/ramfs/file <[0=1]} /n/mfs_ramfs_file
+	cat /dev/zero | tput -p > /n/mfs_ramfs_file/zeros.file
+		57.94 MB/s
+		55.27 MB/s
+		46.67 MB/s
+	echo halt >> /n/mfs_ramfs_file/adm/ctl; lc /srv
 .fi
 .sp
 .sp