Re: NFS client write out corrupted file?

Trond Myklebust (trond.myklebust@fys.uio.no)
Fri, 18 Dec 1998 00:24:17 +0100 (CET)


>>>>> " " == Linus Torvalds <torvalds@transmeta.com> writes:

> If you look closely, I essentially got rid of all write
> canceling. It's basically never the right thing to do. It's
> still done if
....
> "Stale file handle" error instead)

You forget that it is also still done in the code for
nfs_truncate_dirty_pages() which again is called by
nfs_notify_change(). It's true though that with proper synchronization
in nfs_notify_change(), that call should be redundant.

>> - If you run 'setattr' on a file in order to truncate it, there
>> is no
>> synchronization to ensure that async writes which would be
>> cancelled are committed before the call to setattr.

> Good point. Feel free to send me patches, hint, hint.

See the appended patch. I haven't removed the call to
nfs_truncate_dirty_pages, but that should probably be done (and the
routine deleted) since it is broken.

Cheers,
Trond

--- linux/fs/nfs/inode.c-2.1.132-0.1 Fri Nov 13 23:48:32 1998
+++ linux/fs/nfs/inode.c Thu Dec 17 23:04:55 1998
@@ -597,8 +597,10 @@
sattr.gid = attr->ia_gid;

sattr.size = (u32) -1;
- if ((attr->ia_valid & ATTR_SIZE) && S_ISREG(inode->i_mode))
+ if ((attr->ia_valid & ATTR_SIZE) && S_ISREG(inode->i_mode)) {
sattr.size = attr->ia_size;
+ nfs_flush_trunc(inode, sattr.size);
+ }

sattr.mtime.seconds = sattr.mtime.useconds = (u32) -1;
if (attr->ia_valid & ATTR_MTIME) {
--- linux/fs/nfs/write.c-2.1.132-0.1 Wed Dec 2 18:45:25 1998
+++ linux/fs/nfs/write.c Thu Dec 17 23:36:34 1998
@@ -583,6 +583,18 @@
NFS_WB(inode, req->wb_pid == pid);
}

+/*
+ * Flush all write requests for truncation:
+ * Simplification of the comparison has the side-effect of
+ * causing all writes in an infested page to be waited upon.
+ */
+int
+nfs_flush_trunc(struct inode *inode, unsigned long from)
+{
+ from &= PAGE_MASK;
+ NFS_WB(inode, req->wb_page->offset >= from);
+}
+
void
nfs_inval(struct inode *inode)
{
--- linux/include/linux/nfs_fs.h-2.1.132-0.1 Wed Dec 2 18:45:42 1998
+++ linux/include/linux/nfs_fs.h Thu Dec 17 23:03:17 1998
@@ -222,6 +222,7 @@
extern int nfs_wb_all(struct inode *);
extern int nfs_wb_page(struct inode *, struct page *);
extern int nfs_wb_pid(struct inode *, pid_t);
+extern int nfs_flush_trunc(struct inode *, unsigned long);

/*
* Invalidate write-backs, possibly trying to write them

-
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.tux.org/lkml/