[comp.unix.ultrix] suspicious behavior of lseek

emv@ox.com (Ed Vielmetti) (02/21/91)

There's a way to determinine the current position and size of a
file that goes like this:

	curpos = lseek(fd, 0, SEEK_CUR);
	filesize = lseek(fd, 0, SEEK_END);
	if (lseek(fd,curpos,SEEK_SET) != 0) {
	    /* complain bitterly about this and all errors */
	} ;

and you're back to where you came from.  This shouldn't have any side
effects, or should it?

What I'm seeing (Ultrix 4.1, Dec 3100) is that NFS mounted files
sometimes read back nulls at the end of a growing file when the size
is determined this way.  Almost as the the lseek(fd,0,SEEK_END) was
zero-filling some cache somewhere with the wrong thing.  Note that on
"real" unix filesystems this works just fine (45 mb/day read this way).

A possible solution is to run it something like this (not tested)
	
	curpos = lseek(fd, 0, SEEK_CUR);
	if (fstat(fd, stbuf) == 0) {
	    filesize = stbuf.st_size;
	} else {
	    /* complain bitterly about this and all errors */
	} ;

I'd be interested in knowing what exactly goes over the wire for an
NFS fstat() call as opposed to the lseek() call; questions of
efficiency show up since this is going to be happening quite a few
times a minute.

--Ed

Edward Vielmetti
emv@ox.com

(this has been called into Ultrix support, #A 910 220-2454)

davecb@yunexus.YorkU.CA (David Collier-Brown) (02/21/91)

emv@ox.com (Ed Vielmetti) writes:
| What I'm seeing (Ultrix 4.1, Dec 3100) is that NFS mounted files
| sometimes read back nulls at the end of a growing file when the size
| is determined this way.  Almost as the the lseek(fd,0,SEEK_END) was
| zero-filling some cache somewhere with the wrong thing.  Note that on
| "real" unix filesystems this works just fine (45 mb/day read this way).

  This sounds a lot like a recurring Sun NFS problem: under unspecified
high-load conditions and large copies, blocks of files get randomly
filled with NULLs.
  Sun has said ``fixed in 3.2'' ... ``fixed in 4.1.1'' ad nauseam, but
the only reliable advice seems to be ``buy a faster machine''.  Someone
may be able to find more info in the sun-spots archives.

--dave
-- 
David Collier-Brown,  | davecb@Nexus.YorkU.CA | lethe!dave
72 Abitibi Ave.,      | 
Willowdale, Ontario,  | Even cannibals don't usually eat their
CANADA. 416-223-8968  | friends.