shithub: neoventi

Download patch

ref: d6ee43fab6d65482800c76267ccd53469a429d7e
parent: 45d94ff4f17612bbe5fd67288fafaeb1e88e7259
author: Noam Preil <noam@pixelhero.dev>
date: Fri Jun 28 15:52:51 EDT 2024

feat: config parsing

--- a/disk.c
+++ b/disk.c
@@ -286,7 +286,7 @@
 void
 initarenas(void)
 {
-	initarenapart("/dev/" MACHINE "/arenas");
+	initarenapart(arenapath);
 }
 
 static void
@@ -391,7 +391,7 @@
 void
 initindex(void)
 {
-	initisectpart("/dev/" MACHINE "/isect");
+	initisectpart(isectpath);
 	parseindex();
 	for(int i = 0; i < index.namap; i += 1){
 		int found = 0;
--- a/mkfile
+++ b/mkfile
@@ -12,7 +12,7 @@
 LDFLAGS=-p
 
 vac:VE:
-	vacfs -h tcp!127.1!14011 vac:4091f8b8aafc7b8a815f38534b70a171e4ae3e44
+	vacfs -h tcp!127.1!14011 vac:3a51e294f70a87dc6c12805d82787e0a8a3e117f
 
 run:VE: $O.neoventi
 	./$O.neoventi & pid=$apid
--- a/neoventi.c
+++ b/neoventi.c
@@ -5,17 +5,96 @@
 #include "neoventi.h"
 
 int mainstacksize = 128*1024;
+char *configpath = "/dev/kaladin/arenas";
 
+char *arenapath;
+char *isectpath;
+char *tcpaddr;
+
 void
 parseargs(int argc, char **argv)
 {
-	if(argc != 1)
-		sysfatal("TODO: arg parsing");
+	ARGBEGIN {
+	case 'c':
+		configpath = ARGF();
+		if(configpath == nil)
+			sysfatal("must specify a config path");
+		break;
+	default:
+		sysfatal("unsupported flag '%c'", ARGC());
+		break;
+	} ARGEND;
 }
 
 static void
+configvalidate(char *buf)
+{
+	if(memcmp(buf, "venti config\n", 13) != 0)
+		sysfatal("invalid config");
+}
+
+static void
+configparse(char *buf)
+{
+	char *lines[16];
+	char *fields[2];
+	int nlines = getfields(buf+13, lines, 16, 0, "\n");
+	for(int i = 0; i < nlines; i += 1){
+		if(strlen(lines[i]) == 0)
+			continue;
+		if(tokenize(lines[i], fields, 2) != 2)
+			sysfatal("invalid config, bad tokenize on line %d", i);
+		if(strcmp(fields[0], "arenas") == 0)
+			arenapath = strdup(fields[1]);
+		else if(strcmp(fields[0], "isect") == 0)
+			isectpath = strdup(fields[1]);
+		else if(strcmp(fields[0], "bcmem") == 0 || strcmp(fields[0], "mem") == 0 || strcmp(fields[0], "icmem") == 0)
+			// ignore cache sizing
+			;
+		else if(strcmp(fields[0], "addr") == 0)
+			tcpaddr = strdup(fields[1]);
+		else if(strcmp(fields[0], "httpaddr") == 0)
+			// no http server, fuck that
+			;
+		else if(strcmp(fields[0], "index") == 0)
+			// apparently no effect????
+			;
+		else
+			fprint(2, "ignoring config directive '%s'\n", fields[0]);
+	}
+}
+
+static void
+loadconfig(void)
+{
+	// Config is either a flat file, or is the last 8K of a 256K block
+	int fd = open(configpath, OREAD);
+	Dir *dir = dirfstat(fd);
+	// NOTE venti technically allows for 8K bytes of config. Fuck that.
+	// 8191 bytes is enough for anybody.
+	char buf[8192];
+	if(fd < 0 || dir == nil)
+		sysfatal("unable to open config '%s'", configpath);
+	print("len: %d\n", dir->length);
+	if(dir->length > 256*1024){
+		// Config partition
+		vlong w = pread(fd, buf, 8192, 248*1024);
+		if(w < 0)
+			sysfatal("unable to read configpart '%s'", configpath);
+		else if(w == 0)
+			sysfatal("configpart empty!");
+	} else if(pread(fd, buf, 8192, 0) <= 0)
+		sysfatal("unable to read config file '%s'", configpath);
+	// Just in case.
+	buf[8191] = 0;
+	configvalidate(buf);
+	configparse(buf);
+}
+
+static void
 init(void)
 {
+	loadconfig();
 	initarenas();
 	initindex();
 	cacheinit();
@@ -34,6 +113,8 @@
 	print("Initializing neoventi build 5... ");
 	init();
 	validate();
-	print("initialized, launching server.\n");
-	serve("tcp!127.1!14011");
+	print("initialized, launching server...");
+	print("overridding tcp address for simultaneous testing! tcp!*!14011...\n");
+	tcpaddr = "tcp!*!14011";
+	serve(tcpaddr);
 }
--- a/neoventi.h
+++ b/neoventi.h
@@ -4,8 +4,6 @@
 #define	U64GET(p)	(((u64int)U32GET(p)<<32)|(u64int)U32GET((p)+4))
 #define	U16PUT(p,v)	(p)[0]=(v)>>8;(p)[1]=(v)
 
-#define MACHINE "kaladin"
-
 enum {
 	VtRerror = 1,
 	VtTping,
@@ -137,4 +135,8 @@
 void initindex(void);
 void cacheinit(void);
 int cachelookup(char **buf, u16int arenaindex, u32int blockindex);
-void cachedone(u16int arenaindex, u16int blockindex);
\ No newline at end of file
+void cachedone(u16int arenaindex, u16int blockindex);
+
+extern char *arenapath;
+extern char *isectpath;
+
--- a/notebook
+++ b/notebook
@@ -1117,4 +1117,41 @@
 
 92.7 1415.727 11089337	read
 
-We're blocked on the client :P Most of the runtime is waiting for vacfs to get back to us :D
\ No newline at end of file
+We're blocked on the client :P Most of the runtime is waiting for vacfs to get back to us :D
+
+What the hell is wrong with the config??
+
+It should be the last Maxconfig bytes of the first PartBlank!
+
+readifile() →  readpart(PartBlank-Maxconfig, Maxconfig) → pread(fd, buf, Maxconfig, PartBlank-Maxconfig)
+dat.h:40: 	PartBlank		= 256*1024,	/* untouched section at beginning of partition */
+	Maxconfig = 8 * 1024,
+
+% venti/conf /dev/jasnah/arenas 
+index main
+arenas /dev/jasnah/arenas
+isect /dev/jasnah/isect
+mem 256m
+bcmem 256m
+icmem 512m
+httpaddr tcp!*!13012
+addr tcp!*!13011
+
+% dd -if /dev/jasnah/arenas -bs 8192 -count 1 -skip 248
+[garbage]
+
+% dd -if /dev/jasnah/arenas -bs 8192 -count 1 -iseek 248
+[garbage]
+
+% dd -if /dev/jasnah/arenas -bs 1 -count 8192 -skip 253952
+[garbage]
+
+I'm preeeetty sure I"m using dd right >_<
+
+Do I have the address wrong??
+
+...oh wait. oops. 248KiB in. not 248*8K in. dummy.
+
+% dd -if /dev/jasnah/arenas -bs 1024 -count 8 -skip 248
+
+that works. lol.
--