btrfs bug: SysRq-S SysRq-U don't sync btrfs
"Press SysRq-S, wait 5 seconds, press SysRq-U, wait 5 seconds, press SysRq-O" doesn't sync btrfs.
Here is script to reproduce this in Qemu:
https://zerobin.net/?677f7ff6c348d96f#Ka5RFMytXRmyvrwPVp1wuMAgWzaunkJ1+A+/5ahVn2A=
- The bug is reproducible on current master (e53642b87a4f)
- The bug is reproducible with btrfs, but is not reproducible with ext4
- The bug is reproducible both in Qemu and on real hardware
- If I replace SysRq with "sync" or "mount -o remount,ro /disk" command, the bug disappeares
Signature · 1 line
Askar Safin
Quoted 5 lines · Askar Safin
"Press SysRq-S, wait 5 seconds, press SysRq-U, wait 5 seconds, press SysRq-O" doesn't sync btrfs.
Here is script to reproduce this in Qemu:
https://zerobin.net/?677f7ff6c348d96f#Ka5RFMytXRmyvrwPVp1wuMAgWzaunkJ1+A+/5ahVn2A=
Confirmed the sync_fs() callback of btrfs is not executed for the global sync.
Will take a look at it.
Thanks,
Qu
Quoted 7 lines
- The bug is reproducible on current master (
e53642b87a4f)
- The bug is reproducible with btrfs, but is not reproducible with ext4
- The bug is reproducible both in Qemu and on real hardware
- If I replace SysRq with "sync" or "mount -o remount,ro /disk" command, the bug disappeares
Quoted 6 lines · Qu Wenruo
Quoted 3 lines · Askar Safin
"Press SysRq-S, wait 5 seconds, press SysRq-U, wait 5 seconds, press SysRq-O" doesn't sync btrfs.
Quoted 6 lines
Quoted 2 lines
Here is script to reproduce this in Qemu:
https://zerobin.net/? 677f7ff6c348d96f#Ka5RFMytXRmyvrwPVp1wuMAgWzaunkJ1+A+/5ahVn2A=Confirmed the
sync_fs()callback of btrfs is not executed for the global sync.Will take a look at it.
The emergency_sync() is responsible for this sysrq-s handling, and it will sync all filesystems.
However there are several problems:
- sync_inodes_one_sb() will only work for single device fses Where s_bdi is some real devices.
Unfortunately btrfs uses a dummy block device for s_bdi, thus it will skip the writeback of dirty inode pages for btrfs completely.
- do_sync_work() pass @nowait instead of the common @wait Which is the opposite of all the fses I checked (xfs/ext4/btrfs).
Not sure if this is designed or not, will dig into the history to be sure.
- sync_fs_one_sb() is called with @wait == 0.
For btrfs this is critical, with @wait == 0 passed in, btrfs only flush the btree inode, and nothing more.
This means no super block update, thus really no thing is committed.
Although this is more or less the same as xfs/ext4, the problem is the previous sync_inodes_one_sb() won't do anything for btrfs. Thus the wait == 0 call will screw btrfs completely.
I guess the only way to solve it is to handle the @nowait properly for btrfs.
Will try to send out a patch for that. reverting the @nowait bit.
Thanks,
Qu
Quoted 13 lines
Thanks,
QuQuoted 7 lines
- The bug is reproducible on current master (
e53642b87a4f)
- The bug is reproducible with btrfs, but is not reproducible with ext4
- The bug is reproducible both in Qemu and on real hardware
- If I replace SysRq with "sync" or "mount -o remount,ro /disk" command, the bug disappeares
Quoted 18 lines · Qu Wenruo
Quoted 6 lines · Qu Wenruo
Quoted 3 lines · Askar Safin
"Press SysRq-S, wait 5 seconds, press SysRq-U, wait 5 seconds, press SysRq-O" doesn't sync btrfs.
Quoted 6 lines
Quoted 2 lines
Here is script to reproduce this in Qemu:
https://zerobin.net/? 677f7ff6c348d96f#Ka5RFMytXRmyvrwPVp1wuMAgWzaunkJ1+A+/5ahVn2A=Confirmed the
sync_fs()callback of btrfs is not executed for the global sync.Will take a look at it.
The
emergency_sync()is responsible for this sysrq-s handling, and it will sync all filesystems.
Quoted 7 lines
However there are several problems:
-
sync_inodes_one_sb()will only work for single device fses Wheres_bdiis some real devices.Unfortunately btrfs uses a dummy block device for
s_bdi, thus it will skip the writeback of dirty inode pages for btrfs completely.
The above part is incorrect, btrfs will still writeback all dirty pages including data and metadata, just no transaction commit.
Quoted 6 lines
-
do_sync_work()pass @nowait instead of the common @wait Which is the opposite of all the fses I checked (xfs/ext4/btrfs).Not sure if this is designed or not, will dig into the history to be sure.
This is just a way to indicate if it's doing waiting or not. This indeed looks pretty weird, but I guess that's the code style that VFS follows.
Quoted 9 lines
-
sync_fs_one_sb()is called with @wait == 0.
For btrfs this is critical, with @wait == 0 passed in, btrfs only flush the btree inode, and nothing more.This means no super block update, thus really no thing is committed.
Although this is more or less the same as xfs/ext4, the problem is the previous
sync_inodes_one_sb()won't do anything for btrfs.
The difference is the superblock writeback, not sync_inodes_one_sb().
sync_bdevs() will writeback any super block that's dirty but not yet submitted in the bdev's page cache.
But btrfs doesn't go that path, we only dirty and immediately submit the super block during transaction commit.
So sync_bdevs() won't sync our super blocks, thus as long as sync_fs() is called with wait == 0, btrfs won't commit the transaction thus still the old data.
Thanks,
Qu
Quoted 25 lines
Thus the wait == 0 call will screw btrfs completely.
I guess the only way to solve it is to handle the @nowait properly for btrfs.
Will try to send out a patch for that. reverting the @nowait bit.
Thanks,
QuQuoted 13 lines
Thanks,
QuQuoted 7 lines
- The bug is reproducible on current master (
e53642b87a4f)
- The bug is reproducible with btrfs, but is not reproducible with ext4
- The bug is reproducible both in Qemu and on real hardware
- If I replace SysRq with "sync" or "mount -o remount,ro /disk" command, the bug disappeares