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/btrfs_inode.h | |
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/btrfs_inode.h')
-rw-r--r-- | fs/btrfs/btrfs_inode.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 72677ce2b74f..3af4cfb5654c 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -86,12 +86,6 @@ struct btrfs_inode { | |||
86 | */ | 86 | */ |
87 | u64 logged_trans; | 87 | u64 logged_trans; |
88 | 88 | ||
89 | /* | ||
90 | * trans that last made a change that should be fully fsync'd. This | ||
91 | * gets reset to zero each time the inode is logged | ||
92 | */ | ||
93 | u64 log_dirty_trans; | ||
94 | |||
95 | /* total number of bytes pending delalloc, used by stat to calc the | 89 | /* total number of bytes pending delalloc, used by stat to calc the |
96 | * real block usage of the file | 90 | * real block usage of the file |
97 | */ | 91 | */ |
@@ -121,6 +115,13 @@ struct btrfs_inode { | |||
121 | /* the start of block group preferred for allocations. */ | 115 | /* the start of block group preferred for allocations. */ |
122 | u64 block_group; | 116 | u64 block_group; |
123 | 117 | ||
118 | /* the fsync log has some corner cases that mean we have to check | ||
119 | * directories to see if any unlinks have been done before | ||
120 | * the directory was logged. See tree-log.c for all the | ||
121 | * details | ||
122 | */ | ||
123 | u64 last_unlink_trans; | ||
124 | |||
124 | struct inode vfs_inode; | 125 | struct inode vfs_inode; |
125 | }; | 126 | }; |
126 | 127 | ||