Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2006/0211/5

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


Clean up various flush-related code.
 [rsc] --rw-rw-r-- M 771144 rsc sys 33422 Feb 11 09:14 sys/src/cmd/fossil/9fsys.c
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/9fsys.c:464,470 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/9fsys.c:464,471
	  fsysSync(Fsys* fsys, int argc, char* argv[])
	  {
	  	char *usage = "usage: [fsys name] sync";
	- 
	+ 	int n;
	+ 	
	  	ARGBEGIN{
	  	default:
	  		return cliError(usage);
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/9fsys.c:472,478 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/9fsys.c:473,481
	  	if(argc > 0)
	  		return cliError(usage);
	  
	+ 	n = cacheDirty(fsys->fs->cache);
	  	fsSync(fsys->fs);
	+ 	consPrint("\t%s sync: wrote %d blocks\n", fsys->name, n);
	  	return 1;
	  }
	  
 [rsc] --rw-rw-r-- M 771144 rsc sys 43883 Feb 11 09:13 sys/src/cmd/fossil/cache.c
	[diffs elided - too long]
	[diff -c /n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/cache.c /n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/cache.c]
 [rsc] --rw-rw-r-- M 771144 rsc sys 29983 Feb 11 09:14 sys/src/cmd/fossil/file.c
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/file.c:894,900 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/file.c:894,900
	  	f->dir.qidSpace = 1;
	  	f->dir.qidOffset = offset;
	  	f->dir.qidMax = max;
	- 	ret = fileMetaFlush2(f, nil);
	+ 	ret = fileMetaFlush2(f, nil)>=0;
	  	fileMetaUnlock(f);
	  	fileUnlock(f);
	  	return ret;
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/file.c:965,986 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/file.c:965,986
	  	return 1;
	  }
	  
	- void
	+ int
	  fileMetaFlush(File *f, int rec)
	  {
	  	File **kids, *p;
	  	int nkids;
	- 	int i;
	+ 	int i, rv;
	  
	  	fileMetaLock(f);
	- 	fileMetaFlush2(f, nil);
	+ 	rv = fileMetaFlush2(f, nil);
	  	fileMetaUnlock(f);
	  
	  	if(!rec || !fileIsDir(f))
	- 		return;
	+ 		return rv;
	  
	  	if(!fileLock(f))
	- 		return;
	+ 		return rv;
	  	nkids = 0;
	  	for(p=f->down; p; p=p->next)
	  		nkids++;
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/file.c:993,1002 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/file.c:993,1003
	  	fileUnlock(f);
	  
	  	for(i=0; i<nkids; i++){
	- 		fileMetaFlush(kids[i], 1);
	+ 		rv |= fileMetaFlush(kids[i], 1);
	  		fileDecRef(kids[i]);
	  	}
	  	vtMemFree(kids);
	+ 	return rv;
	  }
	  
	  /* assumes metaLock is held */
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/file.c:1011,1017 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/file.c:1012,1018
	  	u32int boff;
	  
	  	if(!f->dirty)
	- 		return 1;
	+ 		return 0;
	  
	  	if(oelem == nil)
	  		oelem = f->dir.elem;
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/file.c:1021,1027 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/file.c:1022,1028
	  	fp = f->up;
	  
	  	if(!sourceLock(fp->msource, -1))
	- 		return 0;
	+ 		return -1;
	  	/* can happen if source is clri'ed out from under us */
	  	if(f->boff == NilBlock)
	  		goto Err1;
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/file.c:1090,1096 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/file.c:1091,1097
	  	blockPut(b);
	  Err1:
	  	sourceUnlock(fp->msource);
	- 	return 0;
	+ 	return -1;
	  }
	  
	  static int
 [rsc] --rw-rw-r-- M 771144 rsc sys 3228 Feb 11 09:14 sys/src/cmd/fossil/fns.h
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fns.h:25,30 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fns.h:25,31
	  Block* cacheAllocBlock(Cache*, int, u32int, u32int, u32int);
	  void cacheFlush(Cache*, int);
	  u32int cacheLocalSize(Cache*, int);
	+ int cacheDirty(Cache*);
	  int readLabel(Cache*, Label*, u32int addr);
	  
	  Block* blockCopy(Block*, u32int, u32int, u32int);
 [rsc] --rw-rw-r-- M 771144 rsc sys 4365 Feb 11 09:14 sys/src/cmd/fossil/fossil-acid
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fossil-acid:66,77 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fossil-acid:66,78
	  
	  // try to say something intelligent about why a process is stuck.
	  _pauses = {
	- 	"open",
	- 	"pread",
	- 	"pwrite",
	- 	"sleep",
	- 	"vtSleep",
	- 	"vtLock",
	+ 	open,
	+ 	pread,
	+ 	pwrite,
	+ 	sleep,
	+ 	vtSleep,
	+ 	vtLock,
	+ 	vtRLock,
	  };
	  
	  defn deadlocklist(l)
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fossil-acid:93,99 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fossil-acid:94,102
	  	stallframe = 0;
	  	stallname = "";
	  	fossilframe = 0;
	+ 	frame = {0};
	  	while stk do {
	+ 		lastframe = frame;
	  		frame = head stk;
	  		name = fmt(frame[0], 'a');
	  		if !stallframe && match(name, _pauses) >= 0 then {
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fossil-acid:106,111 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fossil-acid:109,121
	  			pfl(frame[1]);
	  		}
	  		if !fossilframe && regexp("^/sys/src/cmd/fossil/.*", pcfile(frame[0])) then {
	+ 			if !stallframe then {
	+ 				stallframe = lastframe;
	+ 				stallname = fmt(lastframe[0], 'a');
	+ 				print("\tunexpected stall: ", stallname, "\n");
	+ 				if match(stallname, _pauses) >= 0 then
	+ 					print("\t\t but it matches!\n");
	+ 			}
	  			fossilframe = frame;
	  			print("\t", fmt(frame[0], 'a'), "(");
	  			params(frame[2]);
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fossil-acid:117,123 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fossil-acid:127,133
	  				print("\twaiting to lock block b=(Block)", *cacheLocalLookup:b\X, "\n");
	  			if name == cacheLocal && stallname == vtSleep then
	  				print("\tsleeping on block b=(Block)", *cacheLocal:b\X, "\n");
	- 			if name == blockFlush && stallname == vtSleep then
	+ 			if name == blockWrite && stallname == vtSleep then
	  				print("\tsleeping on block b=(Block)", *blockFlush:b\X, "\n");
	  		}
	  		stk = tail stk;
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fossil-acid:127,134 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fossil-acid:137,148
	  		vtrendez(*vtSleep:q);
	  	if stallname == vtLock then
	  		vtlock(*vtLock:p);
	- 	if !stallframe || !fossilframe then 
	- 		print("\tconfused\n");
	+ 	if !stallframe || !fossilframe then {
	+ 		print("\tconfused:");
	+ 		if !stallframe then print(" stallframe?");
	+ 		if !fossilframe then print(" fossilframe?");
	+ 		print("\n");
	+ 	}
	  	print("\n");
	  }
	  
 [rsc] --rw-rw-r-- M 771144 rsc sys 21572 Feb 11 09:14 sys/src/cmd/fossil/fs.c
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fs.c:782,793 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fs.c:782,795
	  static void
	  fsMetaFlush(void *a)
	  {
	+ 	int rv;
	  	Fs *fs = a;
	  
	  	vtRLock(fs->elk);
	- 	fileMetaFlush(fs->file, 1);
	+ 	rv = fileMetaFlush(fs->file, 1);
	  	vtRUnlock(fs->elk);
	- 	cacheFlush(fs->cache, 0);
	+ 	if(rv > 0)
	+ 		cacheFlush(fs->cache, 0);
	  }
	  
	  static int
 [rsc] --rw-rw-r-- M 771144 rsc sys 1581 Feb 11 09:14 sys/src/cmd/fossil/fs.h
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/fs.h:49,55 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/fs.h:49,55
	  File *fileIncRef(File*);
	  int fileDecRef(File*);
	  int fileIsRoot(File*);
	- void fileMetaFlush(File*, int);
	+ int fileMetaFlush(File*, int);
	  int fileSetQidSpace(File*, u64int, u64int);
	  int fileTruncate(File*, char*);
	  int fileIsRoFs(File*);
 [rsc] --rw-rw-r-- M 771144 rsc sys 2640 Feb 11 09:14 sys/src/cmd/fossil/mkfile
	/n/sourcesdump/2006/0211/plan9/sys/src/cmd/fossil/mkfile:61,80 - 
	/n/sourcesdump/2006/0212/plan9/sys/src/cmd/fossil/mkfile:61,102
	  	slay 8.flfmt | rc
	  	slay 8.fossil | rc
	  	unmount /n/fossil || status=''
	- 	{syscall seek 1 64000000 0; echo} >>/tmp/fossil
	+ 	9fs emelieother
	+ 	bind -c /n/emelieother/rsc/tmp /tmp
	+ 	{syscall seek 1 6400000000 0; echo} >>/tmp/fossil
	  	8.flfmt -y /tmp/fossil
	  	8.conf -w /tmp/fossil flproto
	- 	8.fossil -f /tmp/fossil && mount -c /srv/test.fossil /n/fossil
	+ 	8.fossil -f /tmp/fossil
	+ 	cat /srv/test.fscons &
	+ 	echo fsys main >>/srv/test.fscons
	+ 	mount /srv/test.fossil /n/fossil
	+ 	cd /n/fossil/tmp
	+ 	dd -bs 1048576 -count 256 -if /dev/zero -of a
	+ 	rm a
	+ 	echo sync >>/srv/test.fscons
	+ 	echo sync >>/srv/test.fscons
	+ 	echo sync >>/srv/test.fscons
	+ 	sleep 1
	+ 	echo sync >>/srv/test.fscons
	+ 	sleep 1
	+ 	echo sync >>/srv/test.fscons
	+ 	sleep 1
	+ 	echo sync >>/srv/test.fscons
	+ 	echo check >>/srv/test.fscons
	+ 	echo check >>/srv/test.fscons
	+ 	echo check >>/srv/test.fscons
	+ 	
	+ 
	  #	cp /env/timezone /n/fossil/tmp
	  #	cp /lib/words /n/fossil/tmp
	- 	dircp /sys/src/cmd/aux /n/fossil/tmp
	- 	chmod +t /n/fossil/tmp/lis
	- 	echo SHOULD NOT SEE THIS >>/n/fossil/tmp/lis
	- 	echo snap -a >>/srv/test.fscons
	- 	sleep 2
	- 	mount /srv/test.fossil /n/dump main/archive
	- 	cat /n/dump/*/*/tmp/lis
	- 
	+ #	dircp /n/sources/plan9/sys/src/cmd/aux /n/fossil/tmp
	+ #	>/n/fossil/tmp/lis
	+ #	chmod +t /n/fossil/tmp/lis
	+ #	echo SHOULD NOT SEE THIS >>/n/fossil/tmp/lis
	+ #	echo snap >>/srv/test.fscons
	+ #	sleep 2
	+ #	mount /srv/test.fossil /n/dump main/archive
	+ #	cat /n/dump/*/*/tmp/lis
	  #	@{cd /n/fossil/tmp && time tar xTf /sys/src/cmd/fossil/test.tar}
	  #	unmount /n/fossil
	  #	rm /srv/fossil


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.