git: 9front

Download patch

ref: 662084ed5ad0f815fe4147629102f155c19faae1
parent: c17fa7ea253e18978aaaeb20e13cd379faa50590
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Nov 23 11:05:11 EST 2024

auth/factotum: mount factotum onto /mnt/factotum instead of /mnt by default

Factotum used to mount itself on /mnt and serving the first-level
directory "factotum" itself. This has the undesired consequence
that it has to respond to all walks crossing the /mnt directory.

Instead, we make factotum interpret the previously ignored
mount-spec (aname). If it is "factotum", it serves the
factotum directory as the root, so it can be directly mounted
onto /mnt/factotum. For backwards compatibility, the old
behaviour is preserved.

The namespace file will now always mount factotum onto /mnt/factotum.
In the case of a old factotum, that ignores the mount-spec,
do a bind moving /mnt/factotum/factotum to /mnt/factotum.

--- a/lib/namespace
+++ b/lib/namespace
@@ -12,13 +12,14 @@
 mount -C /srv/boot /root $rootspec
 bind -a $rootdir /
 
-# authentication
-mount -b /srv/factotum /mnt
-
 # mount points
 mount -a /srv/slashn /n
 mount -a /srv/slashmnt /mnt
 mount -a /srv/mntexport /mnt/exportfs
+
+# authentication
+mount /srv/factotum /mnt/factotum factotum
+bind -q /mnt/factotum/factotum /mnt/factotum
 
 # standard bin
 bind /$cputype/bin /bin
--- a/rc/bin/cpurc
+++ b/rc/bin/cpurc
@@ -17,11 +17,9 @@
 mntgen -s slashmnt /mnt && chmod 666 /srv/slashmnt
 mntgen -s mntexport /mnt/exportfs && chmod 666 /srv/mntexport}
 
-# move factotum from /mnt to /mnt/factotum
-mount /srv/factotum /mnt/temp
-unmount /srv/factotum /mnt
-bind /mnt/temp/factotum /mnt/factotum
-unmount /mnt/temp
+# now that /mnt exists, mount factotum
+mount /srv/factotum /mnt/factotum factotum
+bind -q /mnt/factotum/factotum /mnt/factotum
 
 # usb listener
 nusbrc
--- a/rc/bin/termrc
+++ b/rc/bin/termrc
@@ -18,11 +18,9 @@
 mntgen -s slashmnt /mnt && chmod 666 /srv/slashmnt
 mntgen -s mntexport /mnt/exportfs && chmod 666 /srv/mntexport}
 
-# move factotum from /mnt to /mnt/factotum
-mount /srv/factotum /mnt/temp
-unmount /srv/factotum /mnt
-bind /mnt/temp/factotum /mnt/factotum
-unmount /mnt/temp
+# now that /mnt exists, mount factotum
+mount /srv/factotum /mnt/factotum factotum
+bind -q /mnt/factotum/factotum /mnt/factotum
 
 # usb listener
 nusbrc
--- a/sys/man/4/factotum
+++ b/sys/man/4/factotum
@@ -741,3 +741,16 @@
 .B /sys/src/cmd/auth/factotum
 .SH "SEE ALSO"
 .IR authsrv (6)
+.SH "HISTORY"
+Since November 2024,
+.I auth/factotum
+understand the previously ignored
+mount specifier
+.BR factotum ,
+causing it to serve the second-level directory
+as the root of the file-system.
+This allows directly mounting it on
+.BR /mnt/factotum ,
+avoiding the need to respond to walks
+passing over
+.BR /mnt .
--- a/sys/src/cmd/auth/factotum/fs.c
+++ b/sys/src/cmd/auth/factotum/fs.c
@@ -7,7 +7,7 @@
 int		gflag;
 char		*owner;
 int		kflag;
-char		*mtpt = "/mnt";
+char		*mtpt = nil;
 Keyring	*ring;
 char		*service;
 int		sflag;
@@ -153,7 +153,12 @@
 		promptforhostowner();
 	owner = getuser();
 
-	postmountsrv(&fs, service, mtpt, MBEFORE);
+	if(mtpt == nil){
+		mtpt = "/mnt";
+		mount(postsrv(&fs, service), -1, "/mnt/factotum", MREPL, "factotum");
+	} else {
+		mount(postsrv(&fs, service), -1, mtpt, MBEFORE, "");
+	}
 	if(service){
 		nulldir(&d);
 		d.mode = 0666;
@@ -236,7 +241,14 @@
 static void
 fsattach(Req *r)
 {
-	r->fid->qid = mkqid(QTDIR, Qroot);
+	if(strcmp(r->ifcall.aname, "factotum") == 0)
+		r->fid->qid = mkqid(QTDIR, Qfactotum);
+	else if(*r->ifcall.aname == 0)
+		r->fid->qid = mkqid(QTDIR, Qroot);
+	else {
+		respond(r, "unknown mount spec");
+		return;
+	}
 	r->ofcall.qid = r->fid->qid;
 	respond(r, nil);
 }
--