code: mafs

Download patch

ref: abe048fea88c88c401d24783731d62fc5a193565
parent: f37c3c60d0eff2125db1beb476ced0fd0b6b1592
author: 9ferno <gophone2015@gmail.com>
date: Fri Oct 14 11:01:17 EDT 2022

streamlined chatty9p usage

--- a/9p.c
+++ b/9p.c
@@ -354,7 +354,7 @@
 		case Qproot:
 			return nil;
 		default:
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("fswalk1 .. fid->qid.path %llud aux->dblkno %llud\n",
 						fid->qid.path, aux->dblkno);
 			dbuf = getbufchk(aux->dblkno, 1, Breadonly, Tdentry, fid->qid.path);
@@ -361,7 +361,7 @@
 			if(dbuf == nil)
 				return errstring[Ephase];
 			d = &dbuf->io->d;
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("fswalk1 .. d->name %s d->qid.path %llud d->pdblkno %llud\n",
 						d->name, d->qid.path, d->pdblkno);
 			pbuf = getbufchk(d->pdblkno, 1, Breadonly, Tdentry, d->pqpath);
@@ -449,7 +449,7 @@
 	Fid *fid;
 	Spanid s;
 
-/*	if(chatty9p)
+/*	if(chatty9p > 1)
 		dprint("< %ld mafscreate c->path %s req->ifcall.name %s\n"
 				"	c->mode 0x%ux mode 0x%ux perm 0x%lux\n"
 				"	c->qid.path 0x%zux c->qid.vers %lud c->qid.type %ud 0x%ux\n"
@@ -468,7 +468,7 @@
 	}
 	fid = req->fid;
 	aux = fid->aux;
-	if(chatty9p>2)
+	if(chatty9p >2)
 		dprint("fscreate aux 0x%p aux->uid %d fid->qid.path %d aux->dblkno %llud\n",
 				aux, aux->uid, fid->qid.path, aux->dblkno);
 	if(aux == nil ||
@@ -697,7 +697,7 @@
 	fid = req->fid;
 	aux = req->fid->aux;
 	omode = 0;
-	if(chatty9p>2)
+	if(chatty9p > 1)
 		dprint("fsopen fid->qid.path %d mode %d readonly %d\n",
 				 fid->qid.path, mode, readonly);
 	if(readonly && (mode & (ORCLOSE | OTRUNC | OWRITE | ORDWR)) != 0)
@@ -826,7 +826,7 @@
 	if(b->nworks == 1)
 		rwakeup(&b->isempty);
 	qunlock(&b->lck);
-	if(chatty9p)
+	if(chatty9p > 1)
 		stats();
 }
 
@@ -891,7 +891,7 @@
 /*	User *u, *v; */
 	char srvfilename[Namelen];
 
-	if(chatty9p)
+	if(chatty9p > 1)
 	dprint("shutdown\n");
 	a = 0;
 	fsok(1);
@@ -928,7 +928,7 @@
 		sprint(srvfilename, "/srv/%s", service) > 5)
 			remove(srvfilename);
 
-	if(chatty9p)
+	if(chatty9p > 1)
 		dprint("shutdown: exiting\n");
 	exits(nil);
 	/* chkqunlock(&superlock); exit while holding the lock */
@@ -961,7 +961,7 @@
 	case -1:
 		panic("can't fork");
 	case 0:
-		if(chatty9p)
+		if(chatty9p > 1)
 		dprint("child %d pid: %d\n", id, getpid());
 		break;
 	default:
@@ -982,7 +982,7 @@
 
 	mpstarted=1;
 	initworks(&buf);
-	if(chatty9p)
+	if(chatty9p > 1)
 	dprint("parent pid: %d\n", getpid());
 	for(i = 0; i < Nprocs; i++){
 		startproc(&buf, i);
@@ -1233,7 +1233,7 @@
 	 */
 
 	rel2abs(d, offset/Maxspansize, &s);
-	if(chatty9p)
+	if(chatty9p > 1)
 	dprint("update rel2abs d->name %s d->size %llud reli offset %llud\n"
 				"	offset/Maxspansize %llud s.blkno %llud s.len %d\n",
 				d->name, d->size, offset, offset/Maxspansize, s.blkno, s.len);
@@ -1261,12 +1261,12 @@
 
 	if(d == nil || wbuf == nil || wbufsize == 0)
 		return 0;
-	if(chatty9p)
+	if(chatty9p > 1)
 		dprint("append wbufsize %d\n", wbufsize);
 
 	if((lastspansize=d->size%Maxspansize) == 0){
 		/* last extent is full, use a new extent */
-		if(chatty9p)
+		if(chatty9p > 1)
 		dprint("append new extent rel2abs d->name %s reli d->size %llud"
 				" d->size/Maxspansize %llud\n",
 				d->name, d->size, d->size/Maxspansize);
@@ -1303,7 +1303,7 @@
 					" d->name %s reli d->size %llud"
 					" d->size/Maxspansize %llud s.blkno %llud s.len %d\n",
 					d->name, d->size, d->size/Maxspansize, s.blkno, s.len);
-		if(chatty9p)
+		if(chatty9p > 1)
 		dprint("append update rel2abs d->name %s reli d->size %llud"
 				" d->size/Maxspansize %llud s.blkno %llud s.len %d\n",
 				d->name, d->size, d->size/Maxspansize, s.blkno, s.len);
@@ -1326,12 +1326,13 @@
 		nblkno = nbuf->blkno;
 		memcpy(nbuf->io->buf, buf->io->buf, lastspansize);
 		howmuch = min(Maxspansize-lastspansize, wbufsize);
-		if(chatty9p)
+		if(chatty9p > 1)
 		dprint("update lastspansize %llud newnblocks %llud"
 				" nblkno %llud howmuch %llud\n",
 				lastspansize, newnblocks, nblkno, howmuch);
 		memcpy(nbuf->io->buf+lastspansize, wbuf, howmuch);
-		// if(chatty9p)dprint("append contents: %s\n", nbuf->io->buf);
+		// if(chatty9p > 1)
+		//	dprint("append contents: %s\n", nbuf->io->buf);
 		putbuf(nbuf);
 		putbuf(buf);
 
@@ -1389,7 +1390,7 @@
 
 	for(written = 0; written < wbufsize; ){
 
-		if(chatty9p)
+		if(chatty9p > 1)
 			dprint("writefile(): d->name %s d->size %llud offset %llud\n"
 				"	written %d offset+written %llud wbufsize %llud\n",
 				d->name, d->size, offset, written, offset+written, wbufsize);
@@ -1400,11 +1401,11 @@
 			/* new blank blocks until offset
 				fill blank data upto offset */
 
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("writefile(): blank blocks until offset\n");
 
 			n = padblanks(d, dblkno, offset+wbufsize-d->size);
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("writefile(): padblanks returned %d\n", n);
 			if(n<0){
 				dprint("padblanks has an issue %d\n", n);
@@ -1416,7 +1417,7 @@
 			/* replacing existing data
 				no change to file size */
 
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("writefile(): replace existing data\n");
 
 			n = update(d, dblkno,
@@ -1424,7 +1425,7 @@
 							/* how much */
 							min(wbufsize-written, d->size-(offset+written)),
 							offset+written);	/* to where */
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("writefile(): update returned %d\n", n);
 			if(n<0){
 				dprint("update has an issue %d\n", n);
@@ -1435,11 +1436,11 @@
 		}else if(offset+written >= d->size){
 			/* append data, changes file size
 				data blocks from offset until offset+wbufsize */
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("writefile(): append\n");
 			n = append(d, dblkno, wbuf+written, /* from where */
 							wbufsize-written		/* how much */);
-			if(chatty9p)
+			if(chatty9p > 1)
 				dprint("writefile(): append returned %d\n", n);
 			if(n<0){
 				dprint("append has an issue %d\n", n);
--- a/config.c
+++ b/config.c
@@ -61,7 +61,7 @@
 			strncpy(config.service, tokens[++i], Namelen);
 		}
 	}
-	if(chatty9p)
+	if(chatty9p > 1)
 	dprint("config:\n"
 			"size %llud\n"
 			"nblocks %llud\n"
@@ -113,7 +113,7 @@
 			config.service);
 	if(n == Blocksize)
 		panic("config needs more blocks");
-	if(chatty9p)
+	if(chatty9p > 1)
 		dprint("config:\n%s", buf->io->buf);
 	putbuf(buf);
 }
--- a/dentry.c
+++ b/dentry.c
@@ -6,7 +6,7 @@
 	Iobuf *buf;
 	u64 n;
 
-	if(chatty9p > 4)
+	if(chatty9p > 2)
 	dprint("getindspan blkno %llud reli %llud tag %d path %llud\n",
 			blkno, reli, tag, path);
 	if(tag > Tmaxind || reli > nperindunit(tag+1)){
@@ -567,7 +567,7 @@
 	if(readfile(dblkno, Qpfrees, buf, size, 0) != size)
 		panic("loadfrees: could not load frees");
 	n = loadextents(&frees, buf, size);
-	if(chatty9p > 4)
+	if(chatty9p > 2)
 	dprint("loadfrees: loaded free extents %llud\n", n);
 	free(buf);
 
--- a/docs/mafs.ms
+++ b/docs/mafs.ms
@@ -1015,24 +1015,22 @@
 .sp
 .TS
 allbox;
-c l
-l a .
-File	Description
+c l r
+l a r .
+File	Description	chatty9p
 _
-9p.c	9p transactions
-blk.c	routines to show blocks.
+9p.c	9p transactions	2
+sub.c	initialization and super block related routines.	2
+dentry.c	encode/decode the file system abstraction into block operations.	3
+iobuf.c	routines on Iobuf's. The bkp() routines operate on Iobuf's.	5
+extents.[ch]	routines to manage the free blocks.	6
 ctl.c	/adm/ctl operations.
-dentry.c	encode/decode the file system abstraction into block operations.
-extents.[ch]	routines to manage the free blocks.
-iobuf.c	routines on Iobuf's. The bkp() routines operate on Iobuf's.
-sub.c	initialization and super block related routines.
 tag.c	routines to convert from a relative index in a directory entry to a tag.
+blk.c	routines to show blocks.
 console.c	obsolete. /adm/ctl is the console.
 .TE
 .ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n 65n 70n 75n 80n
 .in 0
-.sp
-chatty9p log levels for 9p.c, dentry.c, sub.c and iobuf.c are 1, 2, 3 and 4 respectively.
 .sp
 A Chan's state could get out of sync with the contents if another process changes the on-disk state. Ephase error occurs when that happens.
 .sp
--- a/extents.c
+++ b/extents.c
@@ -21,18 +21,10 @@
  * possible.
  */
 /*
- * Debugging - TODO
- *
  * Verbosity induces the dumping of the pool via p->print at each lock operation.
  * By default, only one line is logged for each alloc, free, and realloc.
  */
 
-/* TODO
-	using this flag to avoid chatty9p from filling up stdout with messages
-	there must be a better way of doing this. Need to figure that out.
- */
-int debug = 0;
-
 Extent *sortbysize(Extents *es, Extent *e);
 void	showextent(char *pre, Extent *e);
 
@@ -89,7 +81,7 @@
 {
 	Extent *dsmall, *fbig, *f, *d;
 
-	if(chatty9p && debug)
+	if(chatty9p > 5)
 		print("	+size %llud .. %llud\n", e->blkno, e->blkno+e->len-1);
 
 	for(f = d = smallest(es);
@@ -130,7 +122,7 @@
 	c->blkno = blkno;
 	c->len = len;
 	es->n++;
-	if(chatty9p && debug)
+	if(chatty9p > 5)
 		print("	+%llud .. %llud\n", blkno, blkno+len-1);
 
 	if(blkno < e->blkno){
@@ -312,7 +304,7 @@
 	/* using the previously used extent */
 	e = es->lru;
 	dir = belongs(es->lru, blkno, len);
-	if(chatty9p && debug){
+	if(chatty9p > 5){
 		print(" 	belongs(e %llud %llud blkno %llud .. %llud) %d\n",
 			 e->blkno, e->blkno+e->len-1, blkno, blkno+len-1, dir);
 	}
@@ -361,13 +353,13 @@
 {
 	Extent *e;
 
-	if(chatty9p && debug){
+	if(chatty9p > 5){
 		showextents("		before\n", es);
 		print(" +%llud %llud\n", blkno, len);
 	}
 	e = doadd(es, blkno, len);
 	es->lru = e;
-	if(chatty9p && debug)
+	if(chatty9p > 5)
 		showextents("		after\n", es);
 	return e;
 }
@@ -452,7 +444,7 @@
 		panic("balloc: es == nil");
 	blkno = 0;
 	qlock(&es->el);
-	if(chatty9p && debug){
+	if(chatty9p > 5){
 		snprint(msg, 64, "balloc() %llud blocks:\n", n);
 		showextents(msg, es);
 	}
--- a/iobuf.c
+++ b/iobuf.c
@@ -400,7 +400,7 @@
 	hiob = amalloc(nbuckets*sizeof(Hiob));
 
 	hp = hiob;
-	if(chatty9p > 5)
+	if(chatty9p > 4)
 		dprint("iobufinit: hiob 0x%p\n", hiob);
 	for(i=0; i<nbuckets; i++){
 		qlock(hp);
--- a/sub.c
+++ b/sub.c
@@ -103,7 +103,7 @@
 	if(blkno == 0)
 		return nil;	/* the caller should trigger an Efull message */
 
-	if(chatty9p > 3)
+	if(chatty9p > 1)
 		dprint("alloc %d at %llud\n", len, blkno);
 	/* cannot do getbufchk() unless we ream the whole disk at start */
 	buf = getbuf(blkno, len, flags|Bmod);
@@ -174,7 +174,7 @@
 	}
 	s = (Superb*)sb->io->buf;
 	s->fsok = ok;
-	if(chatty9p){
+	if(chatty9p > 1){
 		dprint("fsok ok %d\n", ok);
 		showsuper((u8*)s);
 	}
@@ -398,7 +398,7 @@
 	}
 	putbuf(sbuf);
 
-	if(chatty9p)
+	if(chatty9p > 1)
 	dprint("backup config %llud %llud"
 		   " super %llud %llud"
 		   " root %llud %llud\n",
@@ -412,9 +412,9 @@
 
 	bfree(&frees, config.config.dest[1]+1, config.root.dest[0]-config.config.dest[1]-1);
 	bfree(&frees, nbused, config.root.dest[1]-nbused);
-	if(chatty9p)
+	if(chatty9p > 1)
 		showextents("free extents: ", &frees);
-	if(chatty9p > 3)
+	if(chatty9p > 1)
 		dprint("done\n");
 
 	/* this will enable backups */
@@ -440,7 +440,7 @@
 	if(nblocks <= Nminblocks)
 		panic("not enough space");
 
-	if(chatty9p){
+	if(chatty9p > 1){
 		dprint("%s %s ream %llud bytes into %llud blocks\n",
 				service, devfile, size, nblocks);
 		dprint("	(block size: raw %d bytes, usable %d bytes)\n",
--- a/tests/testextents.c
+++ b/tests/testextents.c
@@ -28,7 +28,7 @@
 
 	ARGBEGIN{
 	default:	usage();
-	case 'D':	chatty9p++;					break;
+	case 'D':	chatty9p=6; break;
 	}ARGEND
 
 	if(argc != 0)
--- a/user.c
+++ b/user.c
@@ -268,7 +268,7 @@
 		p = ep+1;
 	}
 
-	if(chatty9p)
+	if(chatty9p > 2)
 	for(u = users; u != nil; u = u->next){
 		dprint("%d:%s:%d(%s):", u->id, u->name, u->lid, username(u->lid, 1, name));
 		for(i = 0; i<u->nmembers; i++)