lkml.org 
[lkml]   [2001]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: nfs MAP_SHARED corruption fix
Hi Andrea, Trond,

the demo for the NFS SHARED_MAP corruption:

garloff@daubechies:~/C $ uname -sr
Linux 2.4.4
garloff@daubechies:~/C $ ./test_nfs_shared_map ; head -1 ./testfile; sleep 10; head -1 ./testfile
Linux NFS rocks.
Linux NFS sucks.

Sources attached. I still have to test your fix, Trond.

Regards,
--
Kurt Garloff <garloff@suse.de> Eindhoven, NL
GPG key: See mail header, key servers Linux kernel development
SuSE GmbH, Nuernberg, FRG SCSI, Security
/** test_nfs_shared_map.c
*
* Creates a file, expands it by ftruncate, mmaps it, writes
* to the mapped memory, unmaps it and closes the file again.
*
* This triggers a bug in 2.4.4 NFS client code: The file won't
* contain the data written to the mapped memory.
*
* (c) Kurt Garloff <garloff@suse.de>, 2001-05-09, GNU GPL
*/

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>


const char * const bad = "Linux NFS sucks.\n";
const char * const good = "Linux NFS rocks.\n";
const char * const name = "testfile";

#define LEN 4096

int die (const char* const txt)
{
perror (txt);
exit (errno);
}

int main ()
{
char* adr; int err;
int fd = open (name, O_RDWR | O_CREAT | O_TRUNC, 0644);
if (fd <= 0) die ("create testfile");
err = write (fd, bad, strlen (bad));
close (fd);
truncate (name, LEN);
sync ();
fd = open (name, O_RDWR);
if (fd <= 0) die ("open testfile");
adr = (char*) mmap (0, LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (!adr) die ("mmap failed");
strcpy (adr, good);
strcpy (adr+32, good);
#ifdef NEED_MSYNC
msync (adr, LEN, MS_SYNC);
#endif
munmap (adr, LEN);
close (fd);
}
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 12:52    [W:0.035 / U:0.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site