Revision a742994aa2e271eb8cd8e043d276515ec858ed73 authored by Filipe Manana on 13 February 2015, 16:56:14 UTC, committed by Chris Mason on 14 February 2015, 16:22:49 UTC
If we are recording in the tree log that an inode has new names (new hard
links were added), we would drop items, belonging to the inode, that we
shouldn't:

1) When the flag BTRFS_INODE_COPY_EVERYTHING is set in the inode's runtime
   flags, we ended up dropping all the extent and xattr items that were
   previously logged. This was done only in memory, since logging a new
   name doesn't imply syncing the log;

2) When the flag BTRFS_INODE_COPY_EVERYTHING is set in the inode's runtime
   flags, we ended up dropping all the xattr items that were previously
   logged. Like the case before, this was done only in memory because
   logging a new name doesn't imply syncing the log.

This led to some surprises in scenarios such as the following:

1) write some extents to an inode;
2) fsync the inode;
3) truncate the inode or delete/modify some of its xattrs
4) add a new hard link for that inode
5) fsync some other file, to force the log tree to be durably persisted
6) power failure happens

The next time the fs is mounted, the fsync log replay code is executed,
and the resulting file doesn't have the content it had when the last fsync
against it was performed, instead if has a content matching what it had
when the last transaction commit happened.

So change the behaviour such that when a new name is logged, only the inode
item and reference items are processed.

This is easy to reproduce with the test I just made for xfstests, whose
main body is:

  _scratch_mkfs >> $seqres.full 2>&1
  _init_flakey
  _mount_flakey

  # Create our test file with some data.
  $XFS_IO_PROG -f -c "pwrite -S 0xaa -b 8K 0 8K" \
      $SCRATCH_MNT/foo | _filter_xfs_io

  # Make sure the file is durably persisted.
  sync

  # Append some data to our file, to increase its size.
  $XFS_IO_PROG -f -c "pwrite -S 0xcc -b 4K 8K 4K" \
      $SCRATCH_MNT/foo | _filter_xfs_io

  # Fsync the file, so from this point on if a crash/power failure happens, our
  # new data is guaranteed to be there next time the fs is mounted.
  $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo

  # Now shrink our file to 5000 bytes.
  $XFS_IO_PROG -c "truncate 5000" $SCRATCH_MNT/foo

  # Now do an expanding truncate to a size larger than what we had when we last
  # fsync'ed our file. This is just to verify that after power failure and
  # replaying the fsync log, our file matches what it was when we last fsync'ed
  # it - 12Kb size, first 8Kb of data had a value of 0xaa and the last 4Kb of
  # data had a value of 0xcc.
  $XFS_IO_PROG -c "truncate 32K" $SCRATCH_MNT/foo

  # Add one hard link to our file. This made btrfs drop all of our file's
  # metadata from the fsync log, including the metadata relative to the
  # extent we just wrote and fsync'ed. This change was made only to the fsync
  # log in memory, so adding the hard link alone doesn't change the persisted
  # fsync log. This happened because the previous truncates set the runtime
  # flag BTRFS_INODE_NEEDS_FULL_SYNC in the btrfs inode structure.
  ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link

  # Now make sure the in memory fsync log is durably persisted.
  # Creating and fsync'ing another file will do it.
  # After this our persisted fsync log will no longer have metadata for our file
  # foo that points to the extent we wrote and fsync'ed before.
  touch $SCRATCH_MNT/bar
  $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar

  # As expected, before the crash/power failure, we should be able to see a file
  # with a size of 32Kb, with its first 5000 bytes having the value 0xaa and all
  # the remaining bytes with value 0x00.
  echo "File content before:"
  od -t x1 $SCRATCH_MNT/foo

  # Simulate a crash/power loss.
  _load_flakey_table $FLAKEY_DROP_WRITES
  _unmount_flakey

  _load_flakey_table $FLAKEY_ALLOW_WRITES
  _mount_flakey

  # After mounting the fs again, the fsync log was replayed.
  # The expected result is to see a file with a size of 12Kb, with its first 8Kb
  # of data having the value 0xaa and its last 4Kb of data having a value of 0xcc.
  # The btrfs bug used to leave the file as it used te be as of the last
  # transaction commit - that is, with a size of 8Kb with all bytes having a
  # value of 0xaa.
  echo "File content after:"
  od -t x1 $SCRATCH_MNT/foo

The test case for xfstests follows soon.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
1 parent 1a4bcf4
History
File Mode Size
bitops
4level-fixup.h -rw-r--r-- 1.0 KB
Kbuild.asm -rw-r--r-- 44 bytes
atomic-long.h -rw-r--r-- 5.1 KB
atomic.h -rw-r--r-- 4.3 KB
atomic64.h -rw-r--r-- 1.9 KB
audit_change_attr.h -rw-r--r-- 445 bytes
audit_dir_write.h -rw-r--r-- 416 bytes
audit_read.h -rw-r--r-- 202 bytes
audit_signal.h -rw-r--r-- 36 bytes
audit_write.h -rw-r--r-- 377 bytes
barrier.h -rw-r--r-- 2.1 KB
bitops.h -rw-r--r-- 1.1 KB
bitsperlong.h -rw-r--r-- 553 bytes
bug.h -rw-r--r-- 5.7 KB
bugs.h -rw-r--r-- 228 bytes
cache.h -rw-r--r-- 345 bytes
cacheflush.h -rw-r--r-- 1.3 KB
checksum.h -rw-r--r-- 2.3 KB
clkdev.h -rw-r--r-- 706 bytes
cmpxchg-local.h -rw-r--r-- 1.4 KB
cmpxchg.h -rw-r--r-- 2.3 KB
cputime.h -rw-r--r-- 293 bytes
cputime_jiffies.h -rw-r--r-- 2.1 KB
cputime_nsecs.h -rw-r--r-- 3.1 KB
current.h -rw-r--r-- 217 bytes
delay.h -rw-r--r-- 1.1 KB
device.h -rw-r--r-- 245 bytes
div64.h -rw-r--r-- 1.3 KB
dma-coherent.h -rw-r--r-- 1.0 KB
dma-contiguous.h -rw-r--r-- 199 bytes
dma-mapping-broken.h -rw-r--r-- 2.8 KB
dma-mapping-common.h -rw-r--r-- 7.4 KB
dma.h -rw-r--r-- 514 bytes
early_ioremap.h -rw-r--r-- 1.3 KB
emergency-restart.h -rw-r--r-- 209 bytes
exec.h -rw-r--r-- 697 bytes
fb.h -rw-r--r-- 232 bytes
fixmap.h -rw-r--r-- 2.7 KB
ftrace.h -rw-r--r-- 460 bytes
futex.h -rw-r--r-- 3.7 KB
getorder.h -rw-r--r-- 1.4 KB
gpio.h -rw-r--r-- 5.7 KB
hardirq.h -rw-r--r-- 493 bytes
hugetlb.h -rw-r--r-- 758 bytes
hw_irq.h -rw-r--r-- 270 bytes
ide_iops.h -rw-r--r-- 752 bytes
int-ll64.h -rw-r--r-- 893 bytes
io-64-nonatomic-hi-lo.h -rw-r--r-- 604 bytes
io-64-nonatomic-lo-hi.h -rw-r--r-- 604 bytes
io.h -rw-r--r-- 17.0 KB
ioctl.h -rw-r--r-- 467 bytes
iomap.h -rw-r--r-- 2.8 KB
irq.h -rw-r--r-- 364 bytes
irq_regs.h -rw-r--r-- 980 bytes
irq_work.h -rw-r--r-- 155 bytes
irqflags.h -rw-r--r-- 1.5 KB
kdebug.h -rw-r--r-- 143 bytes
kmap_types.h -rw-r--r-- 159 bytes
kvm_para.h -rw-r--r-- 441 bytes
libata-portmap.h -rw-r--r-- 153 bytes
linkage.h -rw-r--r-- 225 bytes
local.h -rw-r--r-- 2.2 KB
local64.h -rw-r--r-- 3.8 KB
mcs_spinlock.h -rw-r--r-- 260 bytes
memory_model.h -rw-r--r-- 1.9 KB
mm_hooks.h -rw-r--r-- 668 bytes
mmu.h -rw-r--r-- 410 bytes
mmu_context.h -rw-r--r-- 842 bytes
module.h -rw-r--r-- 1.1 KB
msi.h -rw-r--r-- 799 bytes
mutex-dec.h -rw-r--r-- 2.7 KB
mutex-null.h -rw-r--r-- 648 bytes
mutex-xchg.h -rw-r--r-- 3.7 KB
mutex.h -rw-r--r-- 256 bytes
page.h -rw-r--r-- 2.5 KB
param.h -rw-r--r-- 328 bytes
parport.h -rw-r--r-- 565 bytes
pci-bridge.h -rw-r--r-- 1.7 KB
pci-dma-compat.h -rw-r--r-- 3.7 KB
pci.h -rw-r--r-- 810 bytes
pci_iomap.h -rw-r--r-- 1.2 KB
percpu.h -rw-r--r-- 12.0 KB
pgalloc.h -rw-r--r-- 303 bytes
pgtable-nopmd.h -rw-r--r-- 1.9 KB
pgtable-nopud.h -rw-r--r-- 1.8 KB
pgtable.h -rw-r--r-- 21.9 KB
preempt.h -rw-r--r-- 1.9 KB
ptrace.h -rw-r--r-- 1.6 KB
qrwlock.h -rw-r--r-- 4.4 KB
qrwlock_types.h -rw-r--r-- 421 bytes
resource.h -rw-r--r-- 1.0 KB
rtc.h -rw-r--r-- 5.3 KB
rwsem.h -rw-r--r-- 2.9 KB
scatterlist.h -rw-r--r-- 845 bytes
seccomp.h -rw-r--r-- 938 bytes
sections.h -rw-r--r-- 2.1 KB
segment.h -rw-r--r-- 249 bytes
serial.h -rw-r--r-- 306 bytes
siginfo.h -rw-r--r-- 917 bytes
signal.h -rw-r--r-- 269 bytes
simd.h -rw-r--r-- 397 bytes
sizes.h -rw-r--r-- 78 bytes
spinlock.h -rw-r--r-- 290 bytes
statfs.h -rw-r--r-- 130 bytes
string.h -rw-r--r-- 281 bytes
switch_to.h -rw-r--r-- 992 bytes
syscall.h -rw-r--r-- 6.2 KB
syscalls.h -rw-r--r-- 700 bytes
termios-base.h -rw-r--r-- 2.1 KB
termios.h -rw-r--r-- 2.8 KB
timex.h -rw-r--r-- 469 bytes
tlb.h -rw-r--r-- 6.5 KB
tlbflush.h -rw-r--r-- 446 bytes
topology.h -rw-r--r-- 2.1 KB
trace_clock.h -rw-r--r-- 352 bytes
uaccess-unaligned.h -rw-r--r-- 733 bytes
uaccess.h -rw-r--r-- 7.6 KB
unaligned.h -rw-r--r-- 1.0 KB
unistd.h -rw-r--r-- 279 bytes
user.h -rw-r--r-- 242 bytes
vga.h -rw-r--r-- 548 bytes
vmlinux.lds.h -rw-r--r-- 24.2 KB
vtime.h -rw-r--r-- 52 bytes
word-at-a-time.h -rw-r--r-- 1.2 KB
xor.h -rw-r--r-- 13.6 KB

back to top