public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* nfs MAP_SHARED corruption fix
@ 2001-05-08 14:00 Andrea Arcangeli
  2001-05-08 15:21 ` Trond Myklebust
  0 siblings, 1 reply; 15+ messages in thread
From: Andrea Arcangeli @ 2001-05-08 14:00 UTC (permalink / raw)
  To: linux-kernel

This fixes corruption with MAP_SHARED on top of nfs filesystem in 2.4:

--- 2.4.5pre1aa2/fs/nfs/write.c.~1~	Tue May  1 19:35:29 2001
+++ 2.4.5pre1aa2/fs/nfs/write.c	Tue May  8 02:04:15 2001
@@ -1533,6 +1533,7 @@
 	if (!inode && file)
 		inode = file->f_dentry->d_inode;
 
+	filemap_fdatasync(inode->i_mapping);
 	do {
 		error = 0;
 		if (wait)

Andrea

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: nfs MAP_SHARED corruption fix
@ 2001-05-09 10:55 Kurt Garloff
  0 siblings, 0 replies; 15+ messages in thread
From: Kurt Garloff @ 2001-05-09 10:55 UTC (permalink / raw)
  To: Andrea Arcangeli, Trond Myklebust; +Cc: Linux kernel list


[-- Attachment #1.1: Type: text/plain, Size: 544 bytes --]

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

[-- Attachment #1.2: test_nfs_shared_map.c --]
[-- Type: text/plain, Size: 1197 bytes --]

/** 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);
}

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2001-05-10 12:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-08 14:00 nfs MAP_SHARED corruption fix Andrea Arcangeli
2001-05-08 15:21 ` Trond Myklebust
2001-05-08 15:38   ` Kurt Garloff
2001-05-09  7:30     ` Trond Myklebust
2001-05-09 13:25       ` Andrea Arcangeli
2001-05-09 22:02       ` Marcelo Tosatti
2001-05-10  0:08         ` Andrea Arcangeli
2001-05-09 22:38           ` Marcelo Tosatti
2001-05-10  1:16             ` Andrea Arcangeli
2001-05-10  0:00               ` Marcelo Tosatti
2001-05-10 10:11                 ` Trond Myklebust
2001-05-10 10:14                 ` Trond Myklebust
2001-05-09  2:48   ` Andrea Arcangeli
2001-05-09  7:00     ` Trond Myklebust
  -- strict thread matches above, loose matches on Subject: below --
2001-05-09 10:55 Kurt Garloff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox