linux/fs/btrfs
Boris Burkov cd1d270e3e btrfs: detect nocow for swap after snapshot delete
commit a84d5d429f upstream.

can_nocow_extent and btrfs_cross_ref_exist both rely on a heuristic for
detecting a must cow condition which is not exactly accurate, but saves
unnecessary tree traversal. The incorrect assumption is that if the
extent was created in a generation smaller than the last snapshot
generation, it must be referenced by that snapshot. That is true, except
the snapshot could have since been deleted, without affecting the last
snapshot generation.

The original patch claimed a performance win from this check, but it
also leads to a bug where you are unable to use a swapfile if you ever
snapshotted the subvolume it's in. Make the check slower and more strict
for the swapon case, without modifying the general cow checks as a
compromise. Turning swap on does not seem to be a particularly
performance sensitive operation, so incurring a possibly unnecessary
btrfs_search_slot seems worthwhile for the added usability.

Note: Until the snapshot is competely cleaned after deletion,
check_committed_refs will still cause the logic to think that cow is
necessary, so the user must until 'btrfs subvolu sync' finished before
activating the swapfile swapon.

CC: stable@vger.kernel.org # 5.4+
Suggested-by: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-09-03 11:27:02 +02:00
..
tests
Kconfig
Makefile
acl.c
async-thread.c Btrfs: fix crash during unmount due to race with delayed inode workers 2020-04-17 10:50:15 +02:00
async-thread.h Btrfs: fix crash during unmount due to race with delayed inode workers 2020-04-17 10:50:15 +02:00
backref.c btrfs: fix double free on ulist after backref resolution failure 2020-07-29 10:18:30 +02:00
backref.h
block-group.c btrfs: add wrapper for transaction abort predicate 2020-08-26 10:40:49 +02:00
block-group.h
block-rsv.c btrfs: force chunk allocation if our global rsv is larger than metadata 2020-06-22 09:31:13 +02:00
block-rsv.h
btrfs_inode.h
check-integrity.c
check-integrity.h
compression.c
compression.h
ctree.c
ctree.h btrfs: detect nocow for swap after snapshot delete 2020-09-03 11:27:02 +02:00
delalloc-space.c
delalloc-space.h
delayed-inode.c btrfs: add wrapper for transaction abort predicate 2020-08-26 10:40:49 +02:00
delayed-inode.h
delayed-ref.c
delayed-ref.h
dev-replace.c
dev-replace.h
dir-item.c
disk-io.c btrfs: fix space cache memory leak after transaction abort 2020-09-03 11:27:02 +02:00
disk-io.h
export.c btrfs: export helpers for subvolume name/id resolution 2020-08-26 10:40:49 +02:00
export.h btrfs: export helpers for subvolume name/id resolution 2020-08-26 10:40:49 +02:00
extent-tree.c btrfs: detect nocow for swap after snapshot delete 2020-09-03 11:27:02 +02:00
extent_io.c btrfs: return EROFS for BTRFS_FS_STATE_ERROR cases 2020-08-26 10:40:49 +02:00
extent_io.h
extent_map.c
extent_map.h
file-item.c btrfs: do not ignore error from btrfs_next_leaf() when inserting checksums 2020-06-22 09:30:55 +02:00
file.c btrfs: detect nocow for swap after snapshot delete 2020-09-03 11:27:02 +02:00
free-space-cache.c btrfs: fix space cache memory leak after transaction abort 2020-09-03 11:27:02 +02:00
free-space-cache.h
free-space-tree.c
free-space-tree.h
inode-item.c
inode-map.c
inode-map.h
inode.c btrfs: detect nocow for swap after snapshot delete 2020-09-03 11:27:02 +02:00
ioctl.c btrfs: add missing check for nocow and compression inode flags 2020-08-21 13:05:22 +02:00
locking.c
locking.h
lzo.c
misc.h
ordered-data.c
ordered-data.h
orphan.c
print-tree.c
print-tree.h
props.c
props.h
qgroup.c btrfs: make btrfs_qgroup_check_reserved_leak take btrfs_inode 2020-09-03 11:26:47 +02:00
qgroup.h btrfs: make btrfs_qgroup_check_reserved_leak take btrfs_inode 2020-09-03 11:26:47 +02:00
raid56.c
raid56.h
rcu-string.h
reada.c
ref-verify.c btrfs: ref-verify: fix memory leak in add_block_entry 2020-08-21 13:05:21 +02:00
ref-verify.h
relocation.c btrfs: relocation: review the call sites which can be interrupted by signal 2020-08-21 13:05:22 +02:00
root-tree.c
scrub.c btrfs: return EROFS for BTRFS_FS_STATE_ERROR cases 2020-08-26 10:40:49 +02:00
send.c btrfs: send: emit file capabilities after chown 2020-06-22 09:31:12 +02:00
send.h
space-info.c btrfs: fix lockdep splat from btrfs_dump_space_info 2020-08-19 08:16:01 +02:00
space-info.h btrfs: improve global reserve stealing logic 2020-06-22 09:31:08 +02:00
struct-funcs.c
super.c btrfs: reset compression level for lzo on remount 2020-09-03 11:27:02 +02:00
sysfs.c btrfs: sysfs: use NOFS for device creation 2020-08-21 13:05:22 +02:00
sysfs.h
transaction.c btrfs: add wrapper for transaction abort predicate 2020-08-26 10:40:49 +02:00
transaction.h btrfs: add wrapper for transaction abort predicate 2020-08-26 10:40:49 +02:00
tree-checker.c
tree-checker.h
tree-defrag.c
tree-log.c btrfs: check the right error variable in btrfs_del_dir_entries_in_log 2020-09-03 11:27:02 +02:00
tree-log.h
ulist.c
ulist.h
uuid-tree.c
volumes.c btrfs: relocation: review the call sites which can be interrupted by signal 2020-08-21 13:05:22 +02:00
volumes.h
xattr.c
xattr.h
zlib.c
zstd.c