code: plan9front

Download patch

ref: 4eeefed7b0c1c47329213f1da719820ebbbebf18
parent: 13065e16b3c4fba4d9200ed7fec89ee49338f12a
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jun 7 18:38:04 EDT 2022

cwfs: fix iounit negotiation

cwfs had an issue with iounit negotiation as a result
of the conversion to 9p2000 -- with the move to variable
size messages, the fixed message overhead decreased, but
the advertised message size was still adding the old
fixed overhead.

This meant that if the kernel negotiated the maximum io
size, cwfs would negotiate something larger than it
supported, and would hang up when an io of that size
was made.

In addition, the size of messages was stored in a short,
which means that negotiating an iounit larger than 16384
bytes would overflow the message count, and cause things
to fall over.

Finally, whle we're here, we clean up some duplicated
and unused constants.

--- a/sys/src/cmd/cwfs/9p2.c
+++ b/sys/src/cmd/cwfs/9p2.c
@@ -1,8 +1,5 @@
 #include "all.h"
-#include <fcall.h>
 
-enum { MSIZE = MAXDAT+MAXMSG };
-
 static int
 mkmode9p1(ulong mode9p2)
 {
@@ -155,10 +152,10 @@
 	if(chan->protocol != nil || f->msize < 256)
 		return Eversion;
 
-	if(f->msize < MSIZE)
+	if(f->msize < MAXDAT+IOHDRSZ)
 		r->msize = f->msize;
 	else
-		r->msize = MSIZE;
+		r->msize = MAXDAT+IOHDRSZ;
 
 	/*
 	 * Should check the '.' stuff here.
@@ -1825,7 +1822,7 @@
 	 * replies.
 	 */
 	if(convM2S(mb->data, mb->count, &f) != mb->count){
-		fprint(2, "didn't like %d byte message\n", mb->count);
+		fprint(2, "didn't like %ld byte message\n", mb->count);
 		return 0;
 	}
 	type = f.type;
@@ -1921,7 +1918,7 @@
 		 */
 		if(chan->msize == 0){
 			r.ename = "Tversion not seen";
-			n = convS2M(&r, rmb->data, MAXMSG);
+			n = convS2M(&r, rmb->data, SMALLBUF);
 		} else {
 			snprint(ename, sizeof(ename), "9p2: convS2M: type %d",
 				type);
--- a/sys/src/cmd/cwfs/all.h
+++ b/sys/src/cmd/cwfs/all.h
@@ -1,6 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <ctype.h>
+#include <fcall.h>
 #define Tfile Tfilescsi		/* avoid name conflict */
 #include <disk.h>
 #undef	Tfile
--- a/sys/src/cmd/cwfs/con.c
+++ b/sys/src/cmd/cwfs/con.c
@@ -711,9 +711,9 @@
 {
 	int i, len;
 	char *cmd;
-	Timet t1, t2;
+	vlong t1, t2;
 
-	t1 = time(nil);
+	t1 = nsec();
 	len = 0;
 	for(i=1; i<argc; i++)
 		len += 1 + strlen(argv[i]);
@@ -724,9 +724,9 @@
 		strcat(cmd, argv[i]);
 	}
 	cmd_exec(cmd);
-	t2 = time(nil);
+	t2 = nsec();
 	free(cmd);
-	print("time = %ld ms\n", TK2MS(t2-t1));
+	print("time = %lld ns\n", t2-t1);
 }
 
 void
--- a/sys/src/cmd/cwfs/console.c
+++ b/sys/src/cmd/cwfs/console.c
@@ -1,5 +1,4 @@
 #include	"all.h"
-#include	<fcall.h>
 
 /* 9p2 */
 int	version(Chan*, Fcall*, Fcall*);
--- a/sys/src/cmd/cwfs/portdat.h
+++ b/sys/src/cmd/cwfs/portdat.h
@@ -20,18 +20,10 @@
 #define	HOWMANY(x, y)	(((x)+((y)-1)) / (y))
 #define ROUNDUP(x, y)	(HOWMANY((x), (y)) * (y))
 
-#define	TK2MS(t) (((ulong)(t)*1000)/HZ)	/* ticks to ms - beware rounding */
-#define	MS2TK(t) (((ulong)(t)*HZ)/1000)	/* ms to ticks - beware rounding */
-#define	TK2SEC(t) ((t)/HZ)		/* ticks to seconds */
-
 /* constants that don't affect disk layout */
 enum {
 	MAXDAT		= 8192,		/* max allowable data message */
-	MAXMSG		= 128,		/* max protocol message sans data */
-
 	MB		= 1024*1024,
-
-	HZ		= 1,		/* clock frequency */
 };
 
 /*
@@ -152,8 +144,8 @@
 	DIRPERBUF	= BUFSIZE / sizeof(Dentry),
 	INDPERBUF	= BUFSIZE / sizeof(Off),
 	FEPERBUF	= (BUFSIZE-sizeof(Super1)-sizeof(Off)) / sizeof(Off),
-	SMALLBUF	= MAXMSG,
-	LARGEBUF	= MAXMSG+MAXDAT+256,
+	SMALLBUF	= 128,
+	LARGEBUF	= IOHDRSZ+MAXDAT+256,
 	RAGAP		= (300*1024)/BUFSIZE,	/* readahead parameter */
 	BKPERBLK	= 10,
 	CEPERBK		= (BUFSIZE - BKPERBLK*sizeof(Off)) /
@@ -459,7 +451,7 @@
 struct	Msgbuf
 {
 	ulong	magic;
-	short	count;
+	ulong	count;
 	short	flags;
 		#define	LARGE	(1<<0)
 		#define	FREE	(1<<1)
--- a/sys/src/cmd/cwfs/srv.c
+++ b/sys/src/cmd/cwfs/srv.c
@@ -1,6 +1,5 @@
 #include "all.h"
 #include "io.h"
-#include <fcall.h>		/* 9p2000 */
 #include <thread.h>
 
 enum {
--- a/sys/src/cmd/cwfs/sub.c
+++ b/sys/src/cmd/cwfs/sub.c
@@ -101,8 +101,6 @@
 	unlock(&flock);
 }
 
-enum { NOFID = (ulong)~0 };
-
 /*
  * returns a locked file structure
  */