• Miao Xie's avatar
    Btrfs: fix file extent discount problem in the, snapshot · b9a8cc5b
    Miao Xie authored
    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: default avatarMiao Xie <miaox@cn.fujitsu.com>
    b9a8cc5b
ordered-data.h 6.05 KB