Bug in NFS writes with wsize > 8192.

Juan-Mariano de Goyeneche (jmseyas@dit.upm.es)
Mon, 27 Jul 1998 13:26:44 +0200


Hi all!

There seems to be a problem with NFS, at least in recent 2.0.x kernels,
including 2.0.35.

NFS2 limits the maximum number of bytes of data in a READ or WRITE request to
8192 bytes. (That limit disappears in NFS3, BTW.)

If you specify an wsize greater than 8192, Linux tries to send bigger
chunks of data. The BIG problem is when you write to an NFS mounted
partition: all packets bigger than 8192 are interpreted as bad ones by
the libc at the other end (the svc_getargs() fails).

In the best case, the program will report an I/O error and create the
file with 0 length. In the worse... only the last fragment,
if it is smaller than 8193 bytes, is written to disk.

I think the problem is with a single constant: NFS_MAX_FILE_IO_BUFFER_SIZE.
In nfs_read_super(), the wsize provided is checked against a MAX:
else if (server->wsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
server->wsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
but NFS_MAX_FILE_IO_BUFFER_SIZE is set to 16384, not 8192.

I've written the following patch, which fixes the bug. Hope it is "the right"
(tm) solution. I've tested it for a while.

Regards,

Juan-Mariano.

=============================================================================

--- linux/include/linux/nfs_fs.h.orig Sat Jul 25 11:54:53 1998
+++ linux/include/linux/nfs_fs.h Sat Jul 25 11:55:06 1998
@@ -22,7 +22,15 @@

#define NFS_READDIR_CACHE_SIZE 64

-#define NFS_MAX_FILE_IO_BUFFER_SIZE 16384
+/*
+ * NFS_MAX_FILE_IO_BUFFER_SIZE _must_ be 8192, not 16384.
+ * The maximum number of bytes of data in a READ or WRITE request is fixed in
+ * NFS version 2 (see RFC 1094, Sect. 3.5) and hardwired on the libc to 8192,
+ * regardless the rsize/wsize values. If you increase it, you'll loose your
+ * data when writing chunks grater than 8192 bytes! - In memory of josem, who
+ * lost all his mail due to this bug -- Juan-Mariano de Goyeneche, 25-7-1998.
+ */
+#define NFS_MAX_FILE_IO_BUFFER_SIZE 8192
#define NFS_DEF_FILE_IO_BUFFER_SIZE 1024

/*

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html