home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.aix:11520 comp.unix.questions:13278 comp.unix.wizards:4626 comp.unix.programmer:5263
- Newsgroups: comp.unix.aix,comp.unix.questions,comp.unix.wizards,comp.unix.programmer
- Path: sparky!uunet!walter!porthos!pyuxd!esg
- From: esg@pyuxd.uucp (25235-gokhman)
- Subject: mmap() with shared access fails over NFS using AIX 3.2 on RS 6000
- Organization: Bellcore, Livingston, NJ
- Date: Thu, 12 Nov 92 15:27:10 GMT
- Message-ID: <1992Nov12.152710.26146@porthos.cc.bellcore.com>
- Keywords: memory mapped files over NFS - is there a problem for write ?
- Sender: netnews@porthos.cc.bellcore.com (USENET System Software)
- Lines: 108
-
- Hello netters,
-
- I am trying to do mmap-ing to a file accross NFS using the following
- arguments:
-
- caddr_t pointer = mmap(0, file_length, PROT_READ | PROT_WRITE,
- MAP_FILE | MAP_VARIABLE | MAP_SHARED, fd, 0);
-
- It appears to be successful. However, when I am trying to write
- to the pointed region I get segmentation faults. Segmentation faults
- do not necessarily occur right at the start of the region but also
- in the middle and almost at the end at what seems to be page breaks,
- e.g. location 4096 with 0-4095 bytes written successfully. The problem
- does not occur when files are not NFS mounted. I am aware of the fact
- that the earlier versions of mmap() under AIX 3.1.X were not allowing
- writes over NFS, but my understanding is that AIX 3.2 and up do not
- have this limitations - manuals at least do not mention it. Could it
- be a router-related problem ? Help !!!
-
- Following is the program that I use to examine this situation. Again,
- it always failed over NFS and always worked locally on the same set
- of files:
-
- =========================== CUT HERE ==============================
-
- Thanx in advance,
- Ed Gokhman
-
- # include <stdio.h>
- # include <stdlib.h>
-
- # include <sys/stat.h>
- # include <sys/signal.h>
- # include <fcntl.h>
- # include <unistd.h>
-
- # include <errno.h>
-
- # include <sys/mman.h>
- # include <sys/stat.h>
- # include <sys/mode.h>
- # include <sys/file.h>
- # include <unistd.h>
-
- char *ptr;
-
- caddr_t pointer;
-
- void bus_err_or_segment (int sig)
- {
- fprintf (stderr, "Can not finish this test at byte=%ld", ptr - (char *)pointer);
- }
-
- main (int argc, char **argv)
- {
- size_t file_length;
- struct stat statbuf;
- int fd;
-
- if (argc < 2) {
- fprintf (stderr, "Usage: check <filename>\n");
- exit (1);
- }
- (void) signal ((int) SIGBUS, (void (*)(int)) bus_err_or_segment);
- (void) signal ((int) SIGSEGV, (void (*)(int)) bus_err_or_segment);
-
- if (!stat(argv[1], &statbuf))
- {
- if (!(file_length = statbuf . st_size))
- {
- fprintf (stderr, "%s - empty file\n", argv[1]);
- return;
- }
- }
- else
- {
- fprintf (stderr, "%s - does not exists\n", argv[1]);
- return;
- }
-
- fprintf (stderr, "Mapping %ld bytes in %s\n", file_length, argv[1]);
-
- if ((fd = open ( argv[1], O_RDWR, 0660 )) == -1)
- {
- fprintf(stderr, "Can not open %s with O_RDWR - %s\n", argv[1], strerror(errno));
- exit (1);
- }
-
- errno = 0;
-
- pointer = mmap(0, file_length, PROT_READ | PROT_WRITE,
- MAP_FILE | MAP_VARIABLE | MAP_SHARED, fd, 0);
-
- if (pointer == (caddr_t) -1 || errno)
- {
- fprintf(stderr, "Can not map %s - %s\n", argv[1], strerror(errno));
- return;
- }
-
- for (ptr = (char *)pointer; ptr < (char *)pointer + (int) file_length; ptr++) {
- char a = *ptr;
- *ptr = a;
- }
- munmap (pointer, file_length);
- fprintf(stderr, "Success for %s\n", argv[1]);
- }
-
-
-