Subject: kern/15061: mouting a fs (on the same disk?) causes EIO for nfs
To: None <gnats-bugs@gnats.netbsd.org>
From: None <lha@stacken.kth.se>
List: netbsd-bugs
Date: 12/27/2001 12:10:21
>Number:         15061
>Category:       kern
>Synopsis:       mouting a fs (on the same disk?) causes EIO for nfs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 27 03:11:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Love
>Release:        NetBSD 1.5ZA
>Organization:
	Stacken Computer Club
>Environment:
System: NetBSD nutcracker.stacken.kth.se 1.5ZA NetBSD 1.5ZA (NUTCRACKER) #45: Mon Dec 24 19:45:09 CET 2001 lha@nutcracker.stacken.kth.se:/usr/src/sys/arch/i386/compile/NUTCRACKER i386
Architecture: i386
Machine: i386
>Description:
	
	I was cross compiling a sparc-snapshot from my NetBSD/i386 at
	the same time I tried to bootstrap AFS on my server at my
	parents house when I found this problem with NFS.

	When I mounted a partition (/vicepa) on the same disk (sd1) as
	my nfs partition /export I got EIO in the build of the sparc
	snapshot, quite irritating.

>How-To-Repeat:

	: lha@nutcracker ; mount | grep 'type nfs'
	daisy:/export on /daisy/export type nfs
	: lha@nutcracker ; ./nfs-wr /daisy/export/scratch/foo

	: root@daisy ; mount /vicepa

	[ still running nfs-wr on nutcracker, then when the mount ]
	[ command on daisy is run ]
	nfs-wr: read: Input/output error
	: lha@nutcracker ; 


cat >> nfs-rw.c <<EOF
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/time.h>

#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define FILENO_STDIN 0

#define BUFSZ	8194

unsigned char buf[BUFSZ], savedbuf[BUFSZ];

int
main(int argc, char **argv)
{

	int fd, done, ret, i;
	struct timeval tv;
	fd_set fds;
	char *fn;

	done = 0;

	if (argc != 2)
		errx(1, "missing argument filename");
	
	fn = argv[1];

	srandom(time(NULL) ^ getpid());

	for (i = 0; i < sizeof(buf); i++)
		buf[i] = random();
	memcpy(savedbuf, buf, sizeof(buf));

	if ((fd = open(fn, O_RDWR|O_CREAT, 0644)) < 0)
		err(1, "open");

	while (!done) {

		FD_ZERO(&fds);
		FD_SET(FILENO_STDIN, &fds);

		tv.tv_sec = tv.tv_usec = 0;

		ret = select(FILENO_STDIN + 1, &fds, NULL, NULL, &tv);
		if (ret > 0) {
			if (!FD_ISSET(FILENO_STDIN, &fds))
				errx(1, "select returned on unknown fd ?");

			if (ioctl (FILENO_STDIN, FIONREAD, &ret) < 0)
				err(1, "ioctl on fd %d", fd);

			break;
		} else if (ret == 0) {
			; /* timeout */
		} else {
			errx(1, "select error");
		}

		if (lseek(fd, 0, SEEK_SET) < 0)
			err(1, "fseek(write)");

		if (write(fd, buf, sizeof(buf)) != sizeof(buf))
			err(1, "write");
		
		if (fsync(fd) < 0)
		    err(1, "fsync");

		if (lseek(fd, 0, SEEK_SET) < 0)
			err(1, "fseek(read)");

		if (read(fd, buf, sizeof(buf)) != sizeof(buf))
			err(1, "read");

		if (memcmp(buf, savedbuf, sizeof(buf)) != 0)
			errx(1, "written buffer is not the save as saved");

#ifdef DEBUG
		printf("."); fflush(stdout);
#endif
	}

	if (close (fd) < 0)
		err(1, "close");

	if (ret > 0) {
		char c;
		while (ret--)
			if (read(FILENO_STDIN, &c, 1) <= 0)
				break;
	}

	return 0;
}
EOF

>Fix:

	No clue, I don't do NFS except for bootstrapping/debugging AFS
>Release-Note:
>Audit-Trail:
>Unformatted: