diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a55d1998631129cb20d43ba6c0f65063089fbd9f..0f1ade1331112c82be7eca17a26df4d614c5eb53 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3473,7 +3473,9 @@ void btrfs_subvolume_release_metadata(struct btrfs_root *root, int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes); void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes); int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes); +int __btrfs_delalloc_reserve_space(struct inode *inode, u64 start, u64 len); void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes); +void __btrfs_delalloc_release_space(struct inode *inode, u64 start, u64 len); void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type); struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root, unsigned short type); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 3c58fc34aa107660e04d634d935a4dbb0b7f540d..8c8d8b386cada17185d5f24787defbea8dacccc2 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5714,6 +5714,44 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes) to_free); } +/** + * __btrfs_delalloc_reserve_space - reserve data and metadata space for + * delalloc + * @inode: inode we're writing to + * @start: start range we are writing to + * @len: how long the range we are writing to + * + * TODO: This function will finally replace old btrfs_delalloc_reserve_space() + * + * This will do the following things + * + * o reserve space in data space info for num bytes + * and reserve precious corresponding qgroup space + * (Done in check_data_free_space) + * + * o reserve space for metadata space, based on the number of outstanding + * extents and how much csums will be needed + * also reserve metadata space in a per root over-reserve method. + * o add to the inodes->delalloc_bytes + * o add it to the fs_info's delalloc inodes list. + * (Above 3 all done in delalloc_reserve_metadata) + * + * Return 0 for success + * Return <0 for error(-ENOSPC or -EQUOT) + */ +int __btrfs_delalloc_reserve_space(struct inode *inode, u64 start, u64 len) +{ + int ret; + + ret = __btrfs_check_data_free_space(inode, start, len); + if (ret < 0) + return ret; + ret = btrfs_delalloc_reserve_metadata(inode, len); + if (ret < 0) + __btrfs_free_reserved_data_space(inode, start, len); + return ret; +} + /** * btrfs_delalloc_reserve_space - reserve data and metadata space for delalloc * @inode: inode we're writing to @@ -5746,6 +5784,27 @@ int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes) return 0; } +/** + * __btrfs_delalloc_release_space - release data and metadata space for delalloc + * @inode: inode we're releasing space for + * @start: start position of the space already reserved + * @len: the len of the space already reserved + * + * This must be matched with a call to btrfs_delalloc_reserve_space. This is + * called in the case that we don't need the metadata AND data reservations + * anymore. So if there is an error or we insert an inline extent. + * + * This function will release the metadata space that was not used and will + * decrement ->delalloc_bytes and remove it from the fs_info delalloc_inodes + * list if there are no delalloc bytes left. + * Also it will handle the qgroup reserved space. + */ +void __btrfs_delalloc_release_space(struct inode *inode, u64 start, u64 len) +{ + btrfs_delalloc_release_metadata(inode, len); + __btrfs_free_reserved_data_space(inode, start, len); +} + /** * btrfs_delalloc_release_space - release data and metadata space for delalloc * @inode: inode we're releasing space for