btrfs: handle errors while updating refcounts in update_ref_for_cow

Since commit fb235dc06fa (btrfs: qgroup: Move half of the qgroup
accounting time out of commit trans) the assumption that
btrfs_add_delayed_{data,tree}_ref can only return 0 or -ENOMEM has
been false. The qgroup operations call into btrfs_search_slot
and friends and can now return the full spectrum of error codes.

Fortunately, the fix here is easy since update_ref_for_cow failing
is already handled so we just need to bail early with the error
code.

Fixes: fb235dc06fa (btrfs: qgroup: Move half of the qgroup accounting ...)
Cc: <stable@vger.kernel.org> # v4.11+
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Edmund Nadolski <enadolski@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by Jeff Mahoney and committed by David Sterba 692826b2 b430b775

+12 -6
+12 -6
fs/btrfs/ctree.c
··· 1032 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) && 1033 !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) { 1034 ret = btrfs_inc_ref(trans, root, buf, 1); 1035 - BUG_ON(ret); /* -ENOMEM */ 1036 1037 if (root->root_key.objectid == 1038 BTRFS_TREE_RELOC_OBJECTID) { 1039 ret = btrfs_dec_ref(trans, root, buf, 0); 1040 - BUG_ON(ret); /* -ENOMEM */ 1041 ret = btrfs_inc_ref(trans, root, cow, 1); 1042 - BUG_ON(ret); /* -ENOMEM */ 1043 } 1044 new_flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF; 1045 } else { ··· 1052 ret = btrfs_inc_ref(trans, root, cow, 1); 1053 else 1054 ret = btrfs_inc_ref(trans, root, cow, 0); 1055 - BUG_ON(ret); /* -ENOMEM */ 1056 } 1057 if (new_flags != 0) { 1058 int level = btrfs_header_level(buf); ··· 1072 ret = btrfs_inc_ref(trans, root, cow, 1); 1073 else 1074 ret = btrfs_inc_ref(trans, root, cow, 0); 1075 - BUG_ON(ret); /* -ENOMEM */ 1076 ret = btrfs_dec_ref(trans, root, buf, 1); 1077 - BUG_ON(ret); /* -ENOMEM */ 1078 } 1079 clean_tree_block(fs_info, buf); 1080 *last_ref = 1;
··· 1032 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) && 1033 !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) { 1034 ret = btrfs_inc_ref(trans, root, buf, 1); 1035 + if (ret) 1036 + return ret; 1037 1038 if (root->root_key.objectid == 1039 BTRFS_TREE_RELOC_OBJECTID) { 1040 ret = btrfs_dec_ref(trans, root, buf, 0); 1041 + if (ret) 1042 + return ret; 1043 ret = btrfs_inc_ref(trans, root, cow, 1); 1044 + if (ret) 1045 + return ret; 1046 } 1047 new_flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF; 1048 } else { ··· 1049 ret = btrfs_inc_ref(trans, root, cow, 1); 1050 else 1051 ret = btrfs_inc_ref(trans, root, cow, 0); 1052 + if (ret) 1053 + return ret; 1054 } 1055 if (new_flags != 0) { 1056 int level = btrfs_header_level(buf); ··· 1068 ret = btrfs_inc_ref(trans, root, cow, 1); 1069 else 1070 ret = btrfs_inc_ref(trans, root, cow, 0); 1071 + if (ret) 1072 + return ret; 1073 ret = btrfs_dec_ref(trans, root, buf, 1); 1074 + if (ret) 1075 + return ret; 1076 } 1077 clean_tree_block(fs_info, buf); 1078 *last_ref = 1;