btrfs: qgroup: Return actually freed bytes for qgroup release or free data
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 27 Feb 2017 07:10:36 +0000 (15:10 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 29 Jun 2017 18:17:02 +0000 (20:17 +0200)
btrfs_qgroup_release/free_data() only returns 0 or a negative error
number (ENOMEM is the only possible error).

This is normally good enough, but sometimes we need the exact byte
count it freed/released.

Change it to return actually released/freed bytenr number instead of 0
for success.
And slightly modify related extent_changeset structure, since in btrfs
one no-hole data extent won't be larger than 128M, so "unsigned int"
is large enough for the use case.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c
fs/btrfs/extent_io.h
fs/btrfs/qgroup.c

index f2a6a59da20ae5d8309d301aa9861b03b97aa3a1..b0b02c6c71aa2ca8cab78242bcab5b0e02fb85f5 100644 (file)
@@ -4347,7 +4347,7 @@ int btrfs_check_data_free_space(struct inode *inode, u64 start, u64 len)
 
        /* Use new btrfs_qgroup_reserve_data to reserve precious data space. */
        ret = btrfs_qgroup_reserve_data(inode, start, len);
-       if (ret)
+       if (ret < 0)
                btrfs_free_reserved_data_space_noquota(inode, start, len);
        return ret;
 }
index 1e508a8f876edc2bd5119ccd6dea4feb8cd092c6..ce670d213913a6cd550c786b3d600717f2bd6e20 100644 (file)
@@ -209,7 +209,7 @@ struct extent_buffer {
  */
 struct extent_changeset {
        /* How many bytes are set/cleared in this operation */
-       u64 bytes_changed;
+       unsigned int bytes_changed;
 
        /* Changed ranges */
        struct ulist range_changed;
index fc226035921156cdcdd7e6a4aca232c14b873a4a..475d53c492c88d77aeae5b693c6d50e9ce161b2d 100644 (file)
@@ -2897,6 +2897,7 @@ static int __btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len,
                btrfs_qgroup_free_refroot(BTRFS_I(inode)->root->fs_info,
                                BTRFS_I(inode)->root->objectid,
                                changeset.bytes_changed);
+       ret = changeset.bytes_changed;
 out:
        ulist_release(&changeset.range_changed);
        return ret;