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.
This commit is contained in:
Ori Bernstein 2022-06-07 22:38:04 +00:00
parent 13065e16b3
commit 4eeefed7b0
7 changed files with 12 additions and 26 deletions

View file

@ -1,7 +1,4 @@
#include "all.h"
#include <fcall.h>
enum { MSIZE = MAXDAT+MAXMSG };
static int
mkmode9p1(ulong mode9p2)
@ -155,10 +152,10 @@ version(Chan* chan, Fcall* f, Fcall* r)
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 @@ serve9p2(Msgbuf* mb)
* 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 @@ serve9p2(Msgbuf* mb)
*/
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);

View file

@ -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

View file

@ -711,9 +711,9 @@ cmd_time(int argc, char *argv[])
{
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 @@ cmd_time(int argc, char *argv[])
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

View file

@ -1,5 +1,4 @@
#include "all.h"
#include <fcall.h>
/* 9p2 */
int version(Chan*, Fcall*, Fcall*);

View file

@ -20,18 +20,10 @@ typedef vlong Devsize; /* in bytes */
#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 @@ enum {
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 @@ enum {
struct Msgbuf
{
ulong magic;
short count;
ulong count;
short flags;
#define LARGE (1<<0)
#define FREE (1<<1)

View file

@ -1,6 +1,5 @@
#include "all.h"
#include "io.h"
#include <fcall.h> /* 9p2000 */
#include <thread.h>
enum {

View file

@ -101,8 +101,6 @@ loop:
unlock(&flock);
}
enum { NOFID = (ulong)~0 };
/*
* returns a locked file structure
*/