From patchwork Fri May 11 20:13:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10395315 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 6469760236 for ; Fri, 11 May 2018 20:14:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B78F28D2D for ; Fri, 11 May 2018 20:14:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F87E28FAF; Fri, 11 May 2018 20:14:21 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 DA1EC28D2D for ; Fri, 11 May 2018 20:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752023AbeEKUOS (ORCPT ); Fri, 11 May 2018 16:14:18 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:43807 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751756AbeEKUN6 (ORCPT ); Fri, 11 May 2018 16:13:58 -0400 Received: by mail-pf0-f196.google.com with SMTP id j20-v6so3199989pff.10 for ; Fri, 11 May 2018 13:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=tYty8WpjkItN7XXhv9FRzqqVUeLgEY1F3C+x0wVld+c=; b=1lpk4AJD+NCleRQpZYJzMx6lRwkGiXd6397Yku9SYQKfyqwU4bc4dQC9L4+WffyB5f PkSoquiLvpIHJXTkV9cIILI1QsAjFsuA/lTncB4D/5yBu6DRyZ9fTOiCdiEpF+ab/PDM SZEZqC4fZ9HWAX2box3oT/dtghSgck7NT5DyxK2YoovqE10blaSF84Uefy+P8p221pul RtR6nTVEm1caA3agELzi0VfzLW1zWiEmxtfoRxOavzG0/4sLzccBCApQE7H32HiUeczb pBZ2bL5RPTjfcB4OIWalWUjqRMOFPN8eefLeTKeAIjEwtoRLwX/TUBv1UvvxY386+7Iu F9Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=tYty8WpjkItN7XXhv9FRzqqVUeLgEY1F3C+x0wVld+c=; b=dLK65n0bSoo7G25bQQYaSH8WZGNSPpaojCZEe212FvkdXQLRr3VRhATXrqh0+oeE79 xVfT5va0XyIL4HAH1qIeWA59vY7llKhVpmTgnPSvKzlVekjlu3TThkUrpPaX+Fszon88 0GKd2XPJxbr8UucUw1TMNOpZdaOYPM6Dvmi7GLUqyNicaB6F19AdlDST+t6NHwKRSokH sInXbxKbjcv3o8v4tUV+pLPHFdaCcaQc1as1YRauWreM+SKn4cbFhIOanmrM1Nr6uD3v +T0Mg6sXBnbcfqpZZXS4dpaW0SjeuSh3CFp0I2rbnWPR1aFbz1q4eGa+1UdsCzx62Dmv /Lfg== X-Gm-Message-State: ALKqPwdqyqnLosN32jL9Xl+ZoZ48l6ACgnzs8kx25rNCSrFoTR3HEei8 SIG68Xii+HLN8uX3MfXb8lNUhTlQX1A= X-Google-Smtp-Source: AB8JxZqLOfUyjNwfFOPj+0SaV+hepabb0s/xxsfu1LNDJTe189ynD0yix+tRh3P0KKoZ85aJdjBdWw== X-Received: by 2002:a63:2bc4:: with SMTP id r187-v6mr357452pgr.231.1526069637811; Fri, 11 May 2018 13:13:57 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::7:51e4]) by smtp.gmail.com with ESMTPSA id x84-v6sm10088457pfi.160.2018.05.11.13.13.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 13:13:56 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Chris Mason , Josef Bacik , Nikolay Borisov , David Sterba Subject: [PATCH v4 07/12] Btrfs: don't return ino to ino cache if inode item removal fails Date: Fri, 11 May 2018 13:13:35 -0700 Message-Id: <8ab1a62a0b297c117395cf31e89a0673b4618d24.1526069051.git.osandov@fb.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: 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 From: Omar Sandoval In btrfs_evict_inode(), if btrfs_truncate_inode_items() fails, the inode item will still be in the tree but we still return the ino to the ino cache. That will blow up later when someone tries to allocate that ino, so don't return it to the cache. Fixes: 581bb050941b ("Btrfs: Cache free inode numbers in memory") Reviewed-by: Josef Bacik Signed-off-by: Omar Sandoval --- fs/btrfs/inode.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 84d7dd3a30f9..ad4b7fb62f46 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5330,13 +5330,18 @@ void btrfs_evict_inode(struct inode *inode) trans->block_rsv = rsv; ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0); - if (ret != -ENOSPC && ret != -EAGAIN) + if (ret) { + trans->block_rsv = &fs_info->trans_block_rsv; + btrfs_end_transaction(trans); + btrfs_btree_balance_dirty(fs_info); + if (ret != -ENOSPC && ret != -EAGAIN) { + btrfs_orphan_del(NULL, BTRFS_I(inode)); + btrfs_free_block_rsv(fs_info, rsv); + goto no_delete; + } + } else { break; - - trans->block_rsv = &fs_info->trans_block_rsv; - btrfs_end_transaction(trans); - trans = NULL; - btrfs_btree_balance_dirty(fs_info); + } } btrfs_free_block_rsv(fs_info, rsv); @@ -5345,12 +5350,8 @@ void btrfs_evict_inode(struct inode *inode) * Errors here aren't a big deal, it just means we leave orphan items * in the tree. They will be cleaned up on the next mount. */ - if (ret == 0) { - trans->block_rsv = root->orphan_block_rsv; - btrfs_orphan_del(trans, BTRFS_I(inode)); - } else { - btrfs_orphan_del(NULL, BTRFS_I(inode)); - } + trans->block_rsv = root->orphan_block_rsv; + btrfs_orphan_del(trans, BTRFS_I(inode)); trans->block_rsv = &fs_info->trans_block_rsv; if (!(root == fs_info->tree_root ||