Re: [PATCH] Re: ext2fs problem with rename() system call

tytso@mit.edu
Sat, 9 Jan 1999 11:35:39 -0500


Speaking of quick patchlets to ext2, the following patch causes fsync()
to force out the directory information for a file as well as the inode
information. This is necessary since for a freshly created file, when
the application calls fsync(), it expects the file to be there after
fsync() is called, even if the system crashes immediately thereafter.

Without this patch, the inode will be reliably flushed to disk, but
since the directory information won't be, in some cases after a crash
e2fsck might have to link the file to /lost+found. In a number of cases
(such as mail spool files), this might cause data loss, since the
administrator may have a very tough time determing where the file in
/lost+found should be reconnected in the directory tree.

I've tested this, and it works for me against 2.2.0-pre4. Could folks
test and comment on this change?

- Ted

Patch generated: on Sat Jan 9 10:46:14 EST 1999 by tytso@rsts-11.mit.edu
against Linux version 2.2.0

===================================================================
RCS file: fs/ext2/RCS/fsync.c,v
retrieving revision 1.1
diff -u -r1.1 fs/ext2/fsync.c
--- fs/ext2/fsync.c 1999/01/09 15:24:56 1.1
+++ fs/ext2/fsync.c 1999/01/09 15:46:01
@@ -250,24 +250,14 @@
return err;
}

-/*
- * File may be NULL when we are called. Perhaps we shouldn't
- * even pass file to fsync ?
- */
-
-int ext2_sync_file(struct file * file, struct dentry *dentry)
+static int sync_inode(struct inode *inode)
{
int wait, err = 0;
- struct inode *inode = dentry->d_inode;
-
+
if (S_ISLNK(inode->i_mode) && !(inode->i_blocks))
- /*
- * Don't sync fast links!
- */
- goto skip;
+ return 0;

- for (wait=0; wait<=1; wait++)
- {
+ for (wait=0; wait<=1; wait++) {
err |= sync_direct (inode, wait);
err |= sync_indirect (inode,
inode->u.ext2_i.i_data+EXT2_IND_BLOCK,
@@ -279,7 +269,23 @@
inode->u.ext2_i.i_data+EXT2_TIND_BLOCK,
wait);
}
-skip:
err |= ext2_sync_inode (inode);
+ return err;
+}
+
+/*
+ * File may be NULL when we are called by msync on a vma. In the
+ * future, the VFS layer should be changed to not pass the struct file
+ * parameter to the fsync function, since it's not used by any of the
+ * implementations (and the dentry parameter is all that we need).
+ */
+int ext2_sync_file(struct file * file, struct dentry *dentry)
+{
+ int wait, err = 0;
+
+ err = sync_inode(dentry->d_inode);
+ if (dentry->d_parent && dentry->d_parent->d_inode)
+ err |= sync_inode(dentry->d_parent->d_inode);
+
return err ? -EIO : 0;
}

-
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/