From patchwork Mon Sep 18 07:21:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9955587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3ED7A60568 for ; Mon, 18 Sep 2017 07:22:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E5B128A52 for ; Mon, 18 Sep 2017 07:22:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22EC328BAD; Mon, 18 Sep 2017 07:22:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A855928AEF for ; Mon, 18 Sep 2017 07:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751890AbdIRHV4 (ORCPT ); Mon, 18 Sep 2017 03:21:56 -0400 Received: from mout.gmx.net ([212.227.17.22]:51098 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751700AbdIRHVx (ORCPT ); Mon, 18 Sep 2017 03:21:53 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0M6fXs-1dWnFb0eLU-00wRUA; Mon, 18 Sep 2017 09:21:51 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v3 05/14] btrfs-progs: Avoid BUG_ON for chunk allocation when ENOSPC happens Date: Mon, 18 Sep 2017 16:21:30 +0900 Message-Id: <20170918072139.6300-6-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> References: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:SjdPZ8ftr2GZBH6Gr6akc3nShpiA6dGQJF/EHjsU1Atdf3EJ7mR URKOD1/I6nQT0eXV6FC4THCtjP86ptTpzvrS/SuMKYMUJMo/+uoBNKlw/154ipJ4MWsEA+L pxeDGn8FLGItZ0L0jqdWxg9Tfes6qngoXAzubtJPXZMDZL15IK6goGHo4fwdz630Dc7YqWE OAxzNt8IVQQzqoNS4PbtA== X-UI-Out-Filterresults: notjunk:1; V01:K0:iZQ3LxavDy8=:AgJylvYmYXUR8yfgFZ8AwU BtOQes2glu95WJObQUIemOTmlugYQyOaTK9wWHptP3mLiWaSvkIZaZL1FGqMnCOxU6afQWjFh uVbVnfjfOflitEolKGCvhy4u3dfkLjZRMNex/a2HYL76Te2aHIgBICGwDTJFiA9nEe3G7fQ3b sKWFpzoh12UqJeO5lrLeSdBqtGNf8qa2yeBQMFsZ2cJgyeSYKU6SBZjEtQD2CHm0y31H8ovi/ hgAl5KJmR67Wb49hivancNTqJVrUUJ9teEjf5S1cPB5zHg0vPGaiOVBq9YCTEonHqr2oF3GGV 2R14NgfUZ6cNisJLoaSa+cHuiOTt9sBcR+u6QulNush1GjW/LygVOiqyDqqegBYuRzdYjaJT/ 937p6fPX4sV+Si34lSzh+d7etVY0S2YhfnNE6kw5T1sU4t3ox30Kjt/Wk0n1R4nipbLAfNas1 F9pWplfDZEJ0RNuUpxUvzyiqLF3ZhV7UDM3MprM/5nrPHMObvpIBrsl/vQhRrZN8x4M2yhD6D i2Q2/39JnNjLXsqCo6WqsL+4oKG0wf4o4uTdr2VK1hW7zpc8lrLcoMZ331BHQ5g3dN042+V9y ijg10sy1vWigtyUTCxlUFZEDcwzdWaMdSYGJItGPTIQ15NBFVM+0Dy57VbQV5yp9VnSgyf+20 Jz07tXeTNN4zCHFKQtVE+ulP1oIo/0sO2DbgYwtdw3fFM8Ghxubmj10EQyKcWTajCo3qTxr8I hw1DT4kVVUXS5q+jH7CA2DKx+PLt5w7nSTTs6xYL3mgvAGTS3w2Wpr/IJLd8hAB79KU2HfC7Q Ypb0mBoYJGB8v63DYVQG+50kysdqg== Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When passing directory larger than block device using --rootdir parameter, we get the following backtrace: ------ extent-tree.c:2693: btrfs_reserve_extent: BUG_ON `ret` triggered, value -28 ./mkfs.btrfs(+0x1a05d)[0x557939e6b05d] ./mkfs.btrfs(btrfs_reserve_extent+0xb5a)[0x557939e710c8] ./mkfs.btrfs(+0xb0b6)[0x557939e5c0b6] ./mkfs.btrfs(main+0x15d5)[0x557939e5de04] /usr/lib/libc.so.6(__libc_start_main+0xea)[0x7f83b101af6a] ./mkfs.btrfs(_start+0x2a)[0x557939e5af5a] ------ Nothing special, just BUG_ON() abusing from ancient code. Fix them by using correct return. Signed-off-by: Qu Wenruo --- extent-tree.c | 3 ++- volumes.c | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/extent-tree.c b/extent-tree.c index 525a237e..055582c3 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -2690,7 +2690,8 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, search_start, search_end, hint_byte, ins, trans->alloc_exclude_start, trans->alloc_exclude_nr, data); - BUG_ON(ret); + if (ret < 0) + return ret; clear_extent_dirty(&info->free_space_cache, ins->objectid, ins->objectid + ins->offset - 1); return ret; diff --git a/volumes.c b/volumes.c index 2209e5a9..e1ee27d5 100644 --- a/volumes.c +++ b/volumes.c @@ -1032,11 +1032,13 @@ again: info->chunk_root->root_key.objectid, BTRFS_FIRST_CHUNK_TREE_OBJECTID, key.offset, calc_size, &dev_offset, 0); - BUG_ON(ret); + if (ret < 0) + goto out_chunk_map; device->bytes_used += calc_size; ret = btrfs_update_device(trans, device); - BUG_ON(ret); + if (ret < 0) + goto out_chunk_map; map->stripes[index].dev = device; map->stripes[index].physical = dev_offset; @@ -1075,16 +1077,24 @@ again: map->ce.size = *num_bytes; ret = insert_cache_extent(&info->mapping_tree.cache_tree, &map->ce); - BUG_ON(ret); + if (ret < 0) + goto out_chunk_map; if (type & BTRFS_BLOCK_GROUP_SYSTEM) { ret = btrfs_add_system_chunk(info, &key, chunk, btrfs_chunk_item_size(num_stripes)); - BUG_ON(ret); + if (ret < 0) + goto out_chunk; } kfree(chunk); return ret; + +out_chunk_map: + kfree(map); +out_chunk: + kfree(chunk); + return ret; } /*