diff options
author | Miao Xie <miaox@cn.fujitsu.com> | 2012-09-06 04:01:21 -0600 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2012-10-01 15:19:10 -0400 |
commit | b9a8cc5bef963b76c5b6c3016b7e91988a3e758b (patch) | |
tree | ee3d69f930908f0de9e2e90f2bfb450fffeba018 /fs/btrfs/ordered-data.h | |
parent | 361048f586f59d414421c6486dd846063a0cac98 (diff) | |
download | linux-b9a8cc5bef963b76c5b6c3016b7e91988a3e758b.tar.bz2 |
Btrfs: fix file extent discount problem in the, snapshot
If a snapshot is created while we are writing some data into the file,
the i_size of the corresponding file in the snapshot will be wrong, it will
be beyond the end of the last file extent. And btrfsck will report:
root 256 inode 257 errors 100
Steps to reproduce:
# mkfs.btrfs <partition>
# mount <partition> <mnt>
# cd <mnt>
# dd if=/dev/zero of=tmpfile bs=4M count=1024 &
# for ((i=0; i<4; i++))
> do
> btrfs sub snap . $i
> done
This because the algorithm of disk_i_size update is wrong. Though there are
some ordered extents behind the current one which we use to update disk_i_size,
it doesn't mean those extents will be dealt with in the same transaction. So
We shouldn't use the offset of those extents to update disk_i_size. Or we will
get the wrong i_size in the snapshot.
We fix this problem by recording the max real i_size. If we find there is a
ordered extent which is in front of the current one and doesn't complete, we
will record the end of the current one into that ordered extent. Surely, if
the current extent holds the end of other extent(it must be greater than
the current one because it is behind the current one), we will record the
number that the current extent holds. In this way, we can exclude the ordered
extents that may not be dealth with in the same transaction, and be easy to
know the real disk_i_size.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Diffstat (limited to 'fs/btrfs/ordered-data.h')
-rw-r--r-- | fs/btrfs/ordered-data.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index e03c560d2997..c2443a431ca5 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -96,6 +96,13 @@ struct btrfs_ordered_extent { /* number of bytes that still need writing */ u64 bytes_left; + /* + * the end of the ordered extent which is behind it but + * didn't update disk_i_size. Please see the comment of + * btrfs_ordered_update_i_size(); + */ + u64 outstanding_isize; + /* flags (described above) */ unsigned long flags; |