remarkable-linux/fs/btrfs
Miao Xie 60d2adbb1e Btrfs: fix race between multi-task space allocation and caching space
The task may fail to get free space though it is enough when multi-task
space allocation and caching space happen at the same time.

	Task1			Caching Thread		Task2
	------------------------------------------------------------------------
	find_free_extent
	  The space has not
	  be cached, and start
	  caching thread. And
	  wait for it.
				cache space, if
				the space is > 2MB
				wake up Task1
							find_free_extent
							  get all the space that
							  is cached.
	  try to allocate space,
	  but there is no space
	  now.
	trigger BUG_ON()

The message is following:
btrfs allocation failed flags 1, wanted 4096
space_info has 1040187392 free, is not full
space_info total=1082130432, used=4096, pinned=41938944, reserved=0, may_use=40828928, readonly=0
block group 12582912 has 8388608 bytes, 0 used 8388608 pinned 0 reserved
block group has cluster?: no
0 blocks of free space at or bigger than bytes is
block group 1103101952 has 1073741824 bytes, 4096 used 33550336 pinned 0 reserved
block group has cluster?: no
0 blocks of free space at or bigger than bytes is
------------[ cut here ]------------
kernel BUG at fs/btrfs/inode.c:835!
 [<ffffffffa031261b>] __extent_writepage+0x1bf/0x5ce [btrfs]
 [<ffffffff810cbcb8>] ? __set_page_dirty_nobuffers+0xfe/0x108
 [<ffffffffa02f8ada>] ? wait_current_trans+0x23/0xec [btrfs]
 [<ffffffff810c3fbf>] ? find_get_pages_tag+0x73/0xe2
 [<ffffffffa0312d12>] extent_write_cache_pages.clone.0+0x176/0x29a [btrfs]
 [<ffffffffa0312e74>] extent_writepages+0x3e/0x53 [btrfs]
 [<ffffffff8110ad2c>] ? do_sync_write+0xc6/0x103
 [<ffffffffa0302d6e>] ? btrfs_submit_direct+0x414/0x414 [btrfs]
 [<ffffffff811380fa>] ? fsnotify+0x236/0x266
 [<ffffffffa02fc930>] btrfs_writepages+0x22/0x24 [btrfs]
 [<ffffffff810cc215>] do_writepages+0x1c/0x25
 [<ffffffff810c4958>] __filemap_fdatawrite_range+0x4e/0x50
 [<ffffffff810c4982>] filemap_write_and_wait_range+0x28/0x51
 [<ffffffffa0306b2e>] btrfs_sync_file+0x7d/0x198 [btrfs]
 [<ffffffff8110aa26>] ? fsnotify_modify+0x5d/0x65
 [<ffffffff8112d150>] vfs_fsync_range+0x18/0x21
 [<ffffffff8112d170>] vfs_fsync+0x17/0x19
 [<ffffffff8112d316>] do_fsync+0x29/0x3e
 [<ffffffff8112d348>] sys_fsync+0xb/0xf
 [<ffffffff81468352>] system_call_fastpath+0x16/0x1b
[SNIP]
RIP  [<ffffffffa02fe08c>] cow_file_range+0x1c4/0x32b [btrfs]

We fix this bug by trying to allocate the space again if there are block groups
in caching.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2011-10-20 18:10:49 +02:00
..
acl.c Btrfs: fix return value of btrfs_get_acl() 2011-10-20 18:10:47 +02:00
async-thread.c
async-thread.h
btrfs_inode.h Btrfs: calculate checksum space correctly 2011-10-19 15:12:31 -04:00
compat.h
compression.c Btrfs: check the nodatasum flag when writing compressed files 2011-08-01 14:30:46 -04:00
compression.h
ctree.c Btrfs: fix array bound checking 2011-10-20 18:10:41 +02:00
ctree.h Btrfs: seperate out btrfs_block_rsv_check out into 2 different functions 2011-10-19 15:12:59 -04:00
delayed-inode.c Btrfs: switch the btrfs tree locks to reader/writer 2011-07-27 12:46:46 -04:00
delayed-inode.h atomic: use <linux/atomic.h> 2011-07-26 16:49:47 -07:00
delayed-ref.c
delayed-ref.h
dir-item.c Btrfs: remove redundant code for dir item lookup 2011-08-01 14:30:48 -04:00
disk-io.c Btrfs: allow us to overcommit our enospc reservations 2011-10-19 15:12:50 -04:00
disk-io.h Btrfs: make a lockdep class for each root 2011-07-27 12:46:46 -04:00
export.c
export.h
extent-tree.c Btrfs: fix race between multi-task space allocation and caching space 2011-10-20 18:10:49 +02:00
extent_io.c Btrfs: do not set EXTENT_DIRTY along with EXTENT_DELALLOC 2011-10-20 18:10:45 +02:00
extent_io.h Btrfs: stop using write_one_page 2011-10-19 15:12:48 -04:00
extent_map.c Btrfs: clean up code for merging extent maps 2011-08-01 14:30:50 -04:00
extent_map.h
file-item.c Btrfs: skip locking if searching the commit root in csum lookup 2011-09-11 10:52:24 -04:00
file.c Btrfs: use the inode's mapping mask for allocating pages 2011-10-19 15:12:45 -04:00
free-space-cache.c Btrfs: don't flush the cache inode before writing it 2011-10-19 15:13:01 -04:00
free-space-cache.h
hash.h
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: handle enospc accounting for free space inodes 2011-10-19 15:12:42 -04:00
inode-map.h
inode.c Btrfs: fix direct-io vs nodatacow 2011-10-20 18:10:44 +02:00
ioctl.c btrfs: return EINVAL if start > total_bytes in fitrim ioctl 2011-10-20 18:10:40 +02:00
ioctl.h Btrfs: add mount -o auto_defrag 2011-05-26 17:52:15 -04:00
Kconfig
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
Makefile Btrfs: make acl functions really no-op if acl is not enabled 2011-08-01 14:30:48 -04:00
ordered-data.c
ordered-data.h
orphan.c
print-tree.c
print-tree.h
relocation.c btrfs: check file extent backref offset underflow 2011-10-20 18:10:31 +02:00
root-tree.c btrfs: make btrfs_set_root_node void 2011-08-01 14:30:44 -04:00
scrub.c btrfs: remove unneeded includes from scrub.c 2011-06-10 14:59:52 +02:00
struct-funcs.c Btrfs: stop using highmem for extent_buffers 2011-07-27 12:46:45 -04:00
super.c btrfs: trivial fix, a potential memory leak in btrfs_parse_early_options() 2011-10-20 18:10:38 +02:00
sysfs.c btrfs: Remove unused sysfs code 2011-06-17 14:54:18 -04:00
transaction.c Btrfs: seperate out btrfs_block_rsv_check out into 2 different functions 2011-10-19 15:12:59 -04:00
transaction.h Merge branch 'for-chris' of 2011-05-28 07:00:39 -04:00
tree-defrag.c
tree-log.c Btrfs: fix an oops of log replay 2011-08-16 21:09:15 -04:00
tree-log.h
version.h
volumes.c Btrfs: allow us to overcommit our enospc reservations 2011-10-19 15:12:50 -04:00
volumes.h Btrfs: detect wether a device supports discard 2011-08-16 21:09:15 -04:00
xattr.c Btrfs: fix regression in re-setting a large xattr 2011-10-19 15:12:56 -04:00
xattr.h
zlib.c