linux-hardened/fs/btrfs
Josef Bacik 660d3f6cde Btrfs: fix how we do delalloc reservations and how we free reservations on error
Running xfstests 269 with some tracing my scripts kept spitting out errors about
releasing bytes that we didn't actually have reserved.  This took me down a huge
rabbit hole and it turns out the way we deal with reserved_extents is wrong,
we need to only be setting it if the reservation succeeds, otherwise the free()
method will come in and unreserve space that isn't actually reserved yet, which
can lead to other warnings and such.  The math was all working out right in the
end, but it caused all sorts of other issues in addition to making my scripts
yell and scream and generally make it impossible for me to track down the
original issue I was looking for.  The other problem is with our error handling
in the reservation code.  There are two cases that we need to deal with

1) We raced with free.  In this case free won't free anything because csum_bytes
is modified before we dro the lock in our reservation path, so free rightly
doesn't release any space because the reservation code may be depending on that
reservation.  However if we fail, we need the reservation side to do the free at
that point since that space is no longer in use.  So as it stands the code was
doing this fine and it worked out, except in case #2

2) We don't race with free.  Nobody comes in and changes anything, and our
reservation fails.  In this case we didn't reserve anything anyway and we just
need to clean up csum_bytes but not free anything.  So we keep track of
csum_bytes before we drop the lock and if it hasn't changed we know we can just
decrement csum_bytes and carry on.

Because of the case where we can race with free()'s since we have to drop our
spin_lock to do the reservation, I'm going to serialize all reservations with
the i_mutex.  We already get this for free in the heavy use paths, truncate and
file write all hold the i_mutex, just needed to add it to page_mkwrite and
various ioctl/balance things.  With this patch my space leak scripts no longer
scream bloody murder.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
2011-12-15 11:04:22 -05:00
..
acl.c Btrfs: fix return value of btrfs_get_acl() 2011-10-20 18:10:47 +02:00
async-thread.c Btrfs: fix num_workers_starting bug and other bugs in async thread 2011-12-15 11:04:21 -05:00
async-thread.h Btrfs: fix num_workers_starting bug and other bugs in async thread 2011-12-15 11:04:21 -05:00
backref.c btrfs: Fix up 32/64-bit compatibility for new ioctls 2011-11-20 07:42:13 -05:00
backref.h btrfs: added helper functions to iterate backrefs 2011-09-29 12:54:27 +02:00
btrfs_inode.h Btrfs: fix our reservations for updating an inode when completing io 2011-11-08 15:47:34 -05:00
compat.h Btrfs: drop remaining LINUX_KERNEL_VERSION checks and compat code 2009-01-06 09:38:55 -05:00
compression.c btrfs: separate superblock items out of fs_info 2011-11-06 03:04:01 -05:00
compression.h btrfs: rename variables clashing with global function names 2011-05-02 13:57:19 +02:00
ctree.c Btrfs: fix tree corruption after multi-thread snapshots and inode_cache flush 2011-11-15 09:53:28 -05:00
ctree.h Btrfs: deal with enospc from dirtying inodes properly 2011-12-15 11:04:21 -05:00
delayed-inode.c Btrfs: tweak the delayed inode reservations again 2011-11-10 20:39:08 -05:00
delayed-inode.h atomic: use <linux/atomic.h> 2011-07-26 16:49:47 -07:00
delayed-ref.c btrfs: remove old unused commented out code 2011-05-06 12:34:10 +02:00
delayed-ref.h btrfs: remove all unused functions 2011-05-06 12:34:03 +02:00
dir-item.c Btrfs: remove redundant code for dir item lookup 2011-08-01 14:30:48 -04:00
disk-io.c Btrfs: fix num_workers_starting bug and other bugs in async thread 2011-12-15 11:04:21 -05:00
disk-io.h Merge branch 'for-chris' of git://github.com/sensille/linux into integration 2011-11-06 03:05:08 -05:00
export.c Merge branch 'ino-alloc' of git://repo.or.cz/linux-btrfs-devel into inode_numbers 2011-05-21 09:27:38 -04:00
export.h NFS support for btrfs - v3 2008-09-25 11:04:06 -04:00
extent-tree.c Btrfs: fix how we do delalloc reservations and how we free reservations on error 2011-12-15 11:04:22 -05:00
extent_io.c Btrfs: drop spin lock when memory alloc fails 2011-12-08 08:55:47 -05:00
extent_io.h btrfs: mirror_num should be int, not u64 2011-11-20 07:42:14 -05:00
extent_map.c Btrfs: clean up code for merging extent maps 2011-08-01 14:30:50 -04:00
extent_map.h btrfs: drop gfp parameter from alloc_extent_map 2011-05-02 13:57:21 +02:00
file-item.c btrfs: separate superblock items out of fs_info 2011-11-06 03:04:01 -05:00
file.c Btrfs: deal with enospc from dirtying inodes properly 2011-12-15 11:04:21 -05:00
free-space-cache.c Btrfs: reset cluster's max_size when creating bitmap 2011-11-30 13:43:00 -05:00
free-space-cache.h btrfs: remove all unused functions 2011-05-06 12:34:03 +02:00
hash.h Btrfs: remove crc32c.h and use libcrc32c directly. 2009-06-10 11:29:53 -04:00
inode-item.c Btrfs: BUG_ON is deleted from the caller of btrfs_truncate_item & btrfs_extend_item 2011-05-23 13:24:39 -04:00
inode-map.c Btrfs: fix no reserved space for writing out inode cache 2011-11-10 20:45:04 -05:00
inode-map.h Btrfs: Support reading/writing on disk free ino cache 2011-04-25 16:46:11 +08:00
inode.c Btrfs: fix how we do delalloc reservations and how we free reservations on error 2011-12-15 11:04:22 -05:00
ioctl.c Btrfs: fix how we do delalloc reservations and how we free reservations on error 2011-12-15 11:04:22 -05:00
ioctl.h Btrfs: fix the new inspection ioctls for 32 bit compat 2011-11-06 03:08:49 -05:00
Kconfig btrfs: Add lzo compression support 2010-12-22 23:15:47 +08:00
locking.c Btrfs: switch the btrfs tree locks to reader/writer 2011-07-27 12:46:46 -04:00
locking.h Btrfs: switch the btrfs tree locks to reader/writer 2011-07-27 12:46:46 -04:00
lzo.c Btrfs: Avoid accessing unmapped kernel address 2011-02-16 15:37:58 -05:00
Makefile Merge git://git.jan-o-sch.net/btrfs-unstable into integration 2011-11-06 03:07:10 -05:00
ordered-data.c Btrfs: add initial tracepoint support for btrfs 2011-03-28 05:37:33 -04:00
ordered-data.h btrfs: Allow to add new compression algorithm 2010-12-22 23:15:45 +08:00
orphan.c Btrfs: fixup return code for btrfs_del_orphan_item 2010-12-09 13:57:15 -05:00
print-tree.c btrfs: fix oops on failure path 2011-10-20 18:10:50 +02:00
print-tree.h Btrfs: Create extent_buffer interface for large blocksizes 2008-09-25 11:03:56 -04:00
reada.c Btrfs: rename btrfs_bio multi -> bbio for consistency 2011-11-06 03:11:21 -05:00
relocation.c Btrfs: fix how we do delalloc reservations and how we free reservations on error 2011-12-15 11:04:22 -05:00
root-tree.c btrfs: make btrfs_set_root_node void 2011-08-01 14:30:44 -04:00
scrub.c Btrfs: fix num_workers_starting bug and other bugs in async thread 2011-12-15 11:04:21 -05:00
struct-funcs.c Btrfs: stop using highmem for extent_buffers 2011-07-27 12:46:45 -04:00
super.c Btrfs: deal with enospc from dirtying inodes properly 2011-12-15 11:04:21 -05:00
sysfs.c btrfs: Remove unused sysfs code 2011-06-17 14:54:18 -04:00
transaction.c Btrfs: fix tree corruption after multi-thread snapshots and inode_cache flush 2011-11-15 09:53:28 -05:00
transaction.h Merge branch 'for-chris' of 2011-05-28 07:00:39 -04:00
tree-defrag.c btrfs: drop unused parameter from btrfs_release_path 2011-05-02 13:57:22 +02:00
tree-log.c btrfs: separate superblock items out of fs_info 2011-11-06 03:04:01 -05:00
tree-log.h btrfs: remove unused function prototypes 2011-05-04 14:01:26 +02:00
version.h Update Btrfs files for in-kernel usage 2008-09-25 15:41:59 -04:00
volumes.c Btrfs: fix btrfs_end_bio to deal with write errors to a single mirror 2011-12-09 11:07:37 -05:00
volumes.h Btrfs: fix barrier flushes 2011-11-20 07:21:14 -05:00
xattr.c Btrfs: fix regression in re-setting a large xattr 2011-10-19 15:12:56 -04:00
xattr.h fs/vfs/security: pass last path component to LSM on inode creation 2011-02-01 11:12:29 -05:00
zlib.c zlib: slim down zlib_deflate() workspace when possible 2011-03-22 17:44:17 -07:00