Btrfs: rework O_DIRECT enospc handling
authorChris Mason <chris.mason@oracle.com>
Wed, 26 May 2010 00:56:50 +0000 (20:56 -0400)
committerChris Mason <chris.mason@oracle.com>
Wed, 26 May 2010 01:52:08 +0000 (21:52 -0400)
commit4845e44ffdb26be9b25610664228e8ecaf949a0d
tree8852e175b6b02a36df6b47c54d574f3365ddb34f
parenteaf25d933e64c2bf3c79b83e8820404f36fdfc52
Btrfs: rework O_DIRECT enospc handling

This changes O_DIRECT write code to mark extents as delalloc
while it is processing them.  Yan Zheng has reworked the
enospc accounting based on tracking delalloc extents and
this makes it much easier to track enospc in the O_DIRECT code.

There are a few space cases with the O_DIRECT code though,
it only sets the EXTENT_DELALLOC bits, instead of doing
EXTENT_DELALLOC | EXTENT_DIRTY | EXTENT_UPTODATE, because
we don't want to mess with clearing the dirty and uptodate
bits when things go wrong.  This is important because there
are no pages in the page cache, so any extent state structs
that we put in the tree won't get freed by releasepage.  We have
to clear them ourselves as the DIO ends.

With this commit, we reserve space at in btrfs_file_aio_write,
and then as each btrfs_direct_IO call progresses it sets
EXTENT_DELALLOC on the range.

btrfs_get_blocks_direct is responsible for clearing the delalloc
at the same time it drops the extent lock.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/extent_io.c
fs/btrfs/extent_io.h
fs/btrfs/file.c
fs/btrfs/inode.c