9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] devfs config file loading
@ 2021-03-27 20:36 james palmer
  2021-03-29 13:42 ` cinap_lenrek
  0 siblings, 1 reply; 5+ messages in thread
From: james palmer @ 2021-03-27 20:36 UTC (permalink / raw)
  To: 9front mailing list

hi there,

should the devfs config file be loaded by bootrc instead of the driver?

the current setup (devfs reads the file specified when the kernel starts)
prevents me from loading the fsconfig from a usb disk (i want to use it like a usb keydisk for an encrypted rootfs).

a solution would be to load the fsconfig in bootrc before the rootfs is mounted and
after nusbrc has been run. i plan to patch this myself, but before i do i wanted some
feedback on whether this is a good idea and if there is another way to do what i want.

thanks,
- james

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] devfs config file loading
  2021-03-27 20:36 [9front] devfs config file loading james palmer
@ 2021-03-29 13:42 ` cinap_lenrek
  2021-03-29 16:30   ` james palmer
  0 siblings, 1 reply; 5+ messages in thread
From: cinap_lenrek @ 2021-03-29 13:42 UTC (permalink / raw)
  To: 9front

> should the devfs config file be loaded by bootrc instead of the driver?

yes, that makes sense.

tho that should already be happening?

boorc runs nusbrc first, then runs configlocal(), which calls diskparts,
which after having parsed all partition tables of all the disks (/dev/sd*),
it will execute this line:

	# set up any fs(3) partitions
	if (! test -e /dev/fs/ctl && test -e '#k/fs')
		bind -b '#k' /dev

the fs configuration is read at walk time (rdconf() called from mwalk()) so
the line above should trigger the fs configuration load. at at this time,
all the usb devices (and their partitions) should have been enumerated?

you can try setting the debug variable in devfs.c and add debug print to
diskparts script and see if that is correct. there might be some place
where we accidentally trigger a config load before usb is enumerated?

--
cinap

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] devfs config file loading
  2021-03-29 13:42 ` cinap_lenrek
@ 2021-03-29 16:30   ` james palmer
  2021-03-29 18:10     ` james palmer
  0 siblings, 1 reply; 5+ messages in thread
From: james palmer @ 2021-03-29 16:30 UTC (permalink / raw)
  To: 9front mailing list

Quoth cinap_lenrek@felloff.net:
> the fs configuration is read at walk time (rdconf() called from mwalk()) so
> the line above should trigger the fs configuration load. at at this time,
> all the usb devices (and their partitions) should have been enumerated?
>

ah that will be my mistake.
i added '#k' to the list of binds at the top of bootrc
so the the config load will fail because nusbrc has not been executed.

problem solved thanks :)
- james

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] devfs config file loading
  2021-03-29 16:30   ` james palmer
@ 2021-03-29 18:10     ` james palmer
  2021-03-31 15:57       ` cinap_lenrek
  0 siblings, 1 reply; 5+ messages in thread
From: james palmer @ 2021-03-29 18:10 UTC (permalink / raw)
  To: 9front mailing list

Quoth james@biobuf.link:
> problem solved thanks :)
>

no it's not. (note to self: test things)
seems like /dev/fs/ctl used to print out "fsdev:" as the first line
because rdconf checks for the first line being this before loading the config.

my config was just the plain output of 'disk/cryptsetup -o /dev/sdE1/fs'.
(note that the example in the manpage 'cp /dev/fs/ctl /dev/fd0disk' would also not work for the same reason)

should this check be removed or documented?

- james

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9front] devfs config file loading
  2021-03-29 18:10     ` james palmer
@ 2021-03-31 15:57       ` cinap_lenrek
  0 siblings, 0 replies; 5+ messages in thread
From: cinap_lenrek @ 2021-03-31 15:57 UTC (permalink / raw)
  To: 9front

i pushed a fix to devfs, fixing some locking errors and removed
the "devfs:\n" signature check.

changeset:   8386:a62bc34fa4fa
tag:         tip
parent:      8385:1e6f4a46ea24
parent:      8383:75ba75e18763
user:        cinap_lenrek@felloff.net
date:        Wed Mar 31 17:50:25 2021 +0200
summary:     merge

diff -r 1e6f4a46ea24 -r a62bc34fa4fa sys/src/9/port/devfs.c
--- a/sys/src/9/port/devfs.c	Mon Mar 29 09:29:35 2021 -0700
+++ b/sys/src/9/port/devfs.c	Wed Mar 31 17:50:25 2021 +0200
@@ -117,12 +117,10 @@
 static char *disk;		/* default tree name used */
 static char *source;		/* default inner device used */
 static int sectorsz = Sectorsz;	/* default sector size */
-static char confstr[Maxconf];	/* textual configuration */
+static char *confstr;		/* textual configuration */
 
 static int debug;
 
-static char cfgstr[] = "fsdev:\n";
-
 static Qid tqid = {Qtop, 0, QTDIR};
 static Qid cqid = {Qctl, 0, 0};
 
@@ -180,6 +178,36 @@
 	return s;
 }
 
+static char*
+seprintconf(char *s, char *e)
+{
+	int	i, j;
+	Tree	*t;
+
+	*s = 0;
+	for(i = 0; i < ntrees; i++){
+		t = trees[i];
+		if(t != nil)
+			for(j = 0; j < t->nadevs; j++)
+				if(t->devs[j] != nil)
+					s = seprintdev(s, e, t->devs[j]);
+	}
+	return s;
+}
+
+/* called with lck w */
+static void
+setconfstr(void)
+{
+	char *s;
+
+	s = confstr;
+	if(s == nil)
+		s = smalloc(Maxconf);
+	seprintconf(s, s+Maxconf);
+	confstr = s;
+}
+
 static vlong
 mkpath(int tree, int devno)
 {
@@ -405,6 +433,8 @@
 			}
 		}
 	}
+	if(some)
+		setconfstr();
 	wunlock(&lck);
 	if(some == 0 && alltrees == 0)
 		error(Enonexist);
@@ -560,7 +590,11 @@
 	Tree	*t;
 
 	/* ignore comments & empty lines */
-	if (*a == '\0' || *a == '#' || *a == '\n')
+	if (n < 1 || *a == '\0' || *a == '#' || *a == '\n')
+		return;
+
+	/* ignore historical config signature */
+	if (n >= 6 && memcmp(a, "fsdev:", 6) == 0)
 		return;
 
 	dprint("mconfig\n");
@@ -722,8 +756,9 @@
 	}
 	setdsize(mp, ilen);
 
+	setconfstr();
+	wunlock(&lck);
 	poperror();
-	wunlock(&lck);
 	free(idev);
 	free(ilen);
 	free(cb);
@@ -732,21 +767,30 @@
 static void
 rdconf(void)
 {
-	int mustrd;
 	char *c, *e, *p, *s;
 	Chan *cc;
-	static int configed;
+	int mustrd;
 
 	/* only read config file once */
-	if (configed)
+	if (confstr != nil)
 		return;
-	configed = 1;
+
+	wlock(&lck);
+	if (confstr != nil) {
+		wunlock(&lck);
+		return;	/* already done */
+	}
+
+	/* add the std "fs" tree */
+	if(ntrees == 0){
+		fstree.name = "fs";
+		trees[ntrees++] = &fstree;
+	}
+
+	setconfstr();
+	wunlock(&lck);
 
 	dprint("rdconf\n");
-	/* add the std "fs" tree */
-	trees[0] = &fstree;
-	ntrees++;
-	fstree.name = "fs";
 
 	/* identify the config file */
 	s = getconf("fsconfig");
@@ -756,7 +800,9 @@
 	} else
 		mustrd = 1;
 
+	c = smalloc(Maxconf+1);
 	if(waserror()){
+		free(c);
 		if(!mustrd)
 			return;
 		nexterror();
@@ -768,23 +814,12 @@
 		cclose(cc);
 		nexterror();
 	}
-	devtab[cc->type]->read(cc, confstr, sizeof confstr, 0);
+	devtab[cc->type]->read(cc, c, Maxconf, 0);
+	cclose(cc);
 	poperror();
-	cclose(cc);
 
-	/* validate, copy and erase config; mconfig will repopulate confstr */
-	if (strncmp(confstr, cfgstr, sizeof cfgstr - 1) != 0)
-		error("bad #k config, first line must be: 'fsdev:\\n'");
-
-	c = nil;
-	kstrdup(&c, confstr + sizeof cfgstr - 1);
-	if(waserror()){
-		free(c);
-		nexterror();
-	}
-	memset(confstr, 0, sizeof confstr);
 	/* process config copy one line at a time */
-	for (p = c; p != nil && *p != '\0'; p = e){
+	for (p = c; *p != '\0'; p = e){
 		e = strchr(p, '\n');
 		if (e == nil)
 			e = p + strlen(p);
@@ -792,10 +827,9 @@
 			e++;
 		mconfig(p, e - p);
 	}
-	poperror();
+
 	free(c);
-
-	poperror();	/* mustrd */
+	poperror();	/* c */
 }
 
 static int
@@ -1138,23 +1172,6 @@
 	return res;
 }
 
-static char*
-seprintconf(char *s, char *e)
-{
-	int	i, j;
-	Tree	*t;
-
-	*s = 0;
-	for(i = 0; i < ntrees; i++){
-		t = trees[i];
-		if(t != nil)
-			for(j = 0; j < t->nadevs; j++)
-				if(t->devs[j] != nil)
-					s = seprintdev(s, e, t->devs[j]);
-	}
-	return s;
-}
-
 static long
 mread(Chan *c, void *a, long n, vlong off)
 {
@@ -1175,7 +1192,6 @@
 		goto Done;
 	}
 	if(c->qid.path == Qctl){
-		seprintconf(confstr, confstr + sizeof(confstr));
 		res = readstr((long)off, a, n, confstr);
 		goto Done;
 	}

--
cinap

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-31 16:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27 20:36 [9front] devfs config file loading james palmer
2021-03-29 13:42 ` cinap_lenrek
2021-03-29 16:30   ` james palmer
2021-03-29 18:10     ` james palmer
2021-03-31 15:57       ` cinap_lenrek

9front - general discussion about 9front

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/9front

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 9front 9front/ http://inbox.vuxu.org/9front \
		9front@9front.org
	public-inbox-index 9front

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.9front


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git