On Mon, 25 Aug 2003 11:27:31 +0300
Gavrie Philipson <[EMAIL PROTECTED]> wrote:

> I'll be able to do that tomorrow, hopefully. I'll also do some more
> tests with another NFS server.

Can you please try running the attached test case?  It contains an
extract of the relevant code in standalone form.  Just run with 

  ./mmaptest /disksites/scratchfile

Thanks,
-- 
Martin 
/*
 * Copyright abandoned 2003 by Martin Pool.  Share and enjoy.
 *
 * Test case for mmap failures on NFS, reported to be causing problems
 * in distcc and ccache in August 2003.
 *
 * This is an extracted form of the code in dcc_r_bulk_plain() in
 * distcc 2.10.1.
 *
 * It ought to be valid to just mmap(), truncate, write some data in
 * and then munmap().  This seems correct according to the manuals and
 * the source of other programs, such as tdb.
 *
 * However, on NFS in Red Hat 9, this seems to give a file full of
 * NULLs.  Perhaps the buffer is discarded by the kernel before it
 * gets sent to the NFS server.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/mman.h>


int main(int argc, char *argv[])
{
	int fd, check_fd;
	unsigned char *map_buf, *check_buf;
	const size_t data_len = 100<<10;
	int i;
	unsigned char fill_val = 'a';

	if (argc != 2) {
		fprintf(stderr, "usage: mmaptest FILE\n"
			"FILE is replaced with scratch data!\n"
			"Try a file on NFS to check for bugs.\n");
		return 1;
	}

	if ((fd = open(argv[1], O_CREAT|O_EXCL|O_RDWR, 0600)) == -1) {
		perror("open");
		return 1;
	}

	map_buf = mmap(NULL,	/* anywhere */
		       data_len,
		       PROT_READ|PROT_WRITE,
		       MAP_SHARED,
		       fd,
		       0);	/* offset */

	if (map_buf == MAP_FAILED) {
		perror("mmap");
		return 1;
	}

	if (ftruncate(fd, data_len) == -1) {
		perror("ftruncate");
		return 1;
	}

	memset(map_buf, fill_val, data_len);

	if (munmap(map_buf, data_len) == -1) {
		perror("munmap");
		return 1;
	}

	if (close(fd) == -1) {
		perror("close");
		return 1;
	}

	/* now open the file, re-read and check it */
	if ((check_fd = open(argv[1], O_RDONLY, 0)) == -1) {
		perror("open");
		return 1;
	}

	if (!(check_buf = malloc(data_len))) {
		perror("malloc");
		return 1;
	}

	if (read(check_fd, check_buf, data_len) != data_len) {
		perror("read");
		return 1;
	}

	for (i = 0; i < data_len; i++) {
		if (check_buf[i] != fill_val) {
			fprintf(stderr,
				"mismatch at %d! %#x != %#x\n",
				i, (int) check_buf[i], (int) fill_val);
			return 1;
		}
	}

	if (close(check_fd) == -1) {
		perror("close");
		return 1;
	}

	return 0;
}


/*
 * Local variables:
 * c-file-style: "linux"
 * compile-command: "gcc -Wall -static -o mmaptest mmaptest.c"
 * End:
 */

__ 
distcc mailing list            http://distcc.samba.org/
To unsubscribe or change options: 
http://lists.samba.org/cgi-bin/mailman/listinfo/distcc

Reply via email to