diff options
author | Chris Mason <chris.mason@oracle.com> | 2009-03-24 10:24:20 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2009-03-24 16:14:52 -0400 |
commit | 12fcfd22fe5bf4fe74710232098bc101af497995 (patch) | |
tree | b01ba82147ea76c89149e54d475ed97121387261 /fs/btrfs/file.c | |
parent | a74ac3220774d33db967088906dc3351829e2d3a (diff) |
Btrfs: tree logging unlink/rename fixes
The tree logging code allows individual files or directories to be logged
without including operations on other files and directories in the FS.
It tries to commit the minimal set of changes to disk in order to
fsync the single file or directory that was sent to fsync or O_SYNC.
The tree logging code was allowing files and directories to be unlinked
if they were part of a rename operation where only one directory
in the rename was in the fsync log. This patch adds a few new rules
to the tree logging.
1) on rename or unlink, if the inode being unlinked isn't in the fsync
log, we must force a full commit before doing an fsync of the directory
where the unlink was done. The commit isn't done during the unlink,
but it is forced the next time we try to log the parent directory.
Solution: record transid of last unlink/rename per directory when the
directory wasn't already logged. For renames this is only done when
renaming to a different directory.
mkdir foo/some_dir
normal commit
rename foo/some_dir foo2/some_dir
mkdir foo/some_dir
fsync foo/some_dir/some_file
The fsync above will unlink the original some_dir without recording
it in its new location (foo2). After a crash, some_dir will be gone
unless the fsync of some_file forces a full commit
2) we must log any new names for any file or dir that is in the fsync
log. This way we make sure not to lose files that are unlinked during
the same transaction.
2a) we must log any new names for any file or dir during rename
when the directory they are being removed from was logged.
2a is actually the more important variant. Without the extra logging
a crash might unlink the old name without recreating the new one
3) after a crash, we must go through any directories with a link count
of zero and redo the rm -rf
mkdir f1/foo
normal commit
rm -rf f1/foo
fsync(f1)
The directory f1 was fully removed from the FS, but fsync was never
called on f1, only its parent dir. After a crash the rm -rf must
be replayed. This must be able to recurse down the entire
directory tree. The inode link count fixup code takes care of the
ugly details.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index f06c275644b7..32d10a617613 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -1173,8 +1173,11 @@ out_nolock: | |||
1173 | ret = btrfs_log_dentry_safe(trans, root, | 1173 | ret = btrfs_log_dentry_safe(trans, root, |
1174 | file->f_dentry); | 1174 | file->f_dentry); |
1175 | if (ret == 0) { | 1175 | if (ret == 0) { |
1176 | btrfs_sync_log(trans, root); | 1176 | ret = btrfs_sync_log(trans, root); |
1177 | btrfs_end_transaction(trans, root); | 1177 | if (ret == 0) |
1178 | btrfs_end_transaction(trans, root); | ||
1179 | else | ||
1180 | btrfs_commit_transaction(trans, root); | ||
1178 | } else { | 1181 | } else { |
1179 | btrfs_commit_transaction(trans, root); | 1182 | btrfs_commit_transaction(trans, root); |
1180 | } | 1183 | } |
@@ -1266,8 +1269,11 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
1266 | if (ret > 0) { | 1269 | if (ret > 0) { |
1267 | ret = btrfs_commit_transaction(trans, root); | 1270 | ret = btrfs_commit_transaction(trans, root); |
1268 | } else { | 1271 | } else { |
1269 | btrfs_sync_log(trans, root); | 1272 | ret = btrfs_sync_log(trans, root); |
1270 | ret = btrfs_end_transaction(trans, root); | 1273 | if (ret == 0) |
1274 | ret = btrfs_end_transaction(trans, root); | ||
1275 | else | ||
1276 | ret = btrfs_commit_transaction(trans, root); | ||
1271 | } | 1277 | } |
1272 | mutex_lock(&dentry->d_inode->i_mutex); | 1278 | mutex_lock(&dentry->d_inode->i_mutex); |
1273 | out: | 1279 | out: |