Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1155208imm; Wed, 1 Aug 2018 11:05:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfBG6VCoriahS0L3ymAYE3pkwdr0Wx0vfC19PoP2goAZFAfOMzEAZQtDoH7rw0XQNj7SP0f X-Received: by 2002:a63:b504:: with SMTP id y4-v6mr26113755pge.247.1533146743910; Wed, 01 Aug 2018 11:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533146743; cv=none; d=google.com; s=arc-20160816; b=GL3AS5n6f5uXLdfA/uoEOkd0gwppRqdYnuA7fgIZXZBO/X08Eg22RjOEcIq+ztKwK/ 03kqGGeLBuXDylQFIW7yvGvaokEyjymd3dZNfluP9metnyAPYvDqTxsu3SQOuEFgjnr+ gPSvP0wEpXYJ8X4lxFKXGgHQdNBvS8mvo1H6yT1N+T8TWFOvkN+Fm0Tj4isA4xoUgT6N WoFCNhrxaDaTxIUu2ZnMJ+XQe5wp03aekCAl4cStbxd5Ka20nnoraMYGqqP8fI6Z9fDf iWb+Mb7ISbTS1/1ckq9k7i2E7uuuVMg2Vu5wZOFTfzaZLL29P9Y969tly7DAT0Pc4/0U 6rZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=cbwKMrYQ46ZXvo+Rs2DqZghw2YVibTouaxO2sDQ6nhc=; b=d0pxXJ3TnQMixj4I6JyjFGN0S27qvwyNgcgYbrqX9JGVicj5aCU2f5be4APY0CU9/X V/F+eSSnJiFnvrstACuDs+itqlMFZ5YofJULT06ePv0IQGFfSDvg00ndwJQw74LIzF+e yb/waSSlkPZs3Bg4NkP46IhfTjH5xSAhdc0TBcs9eHart6tp/36AB4Pp7Ij/CJfsLZmg OAY7eUQQn0E6TO2TEeAKMw72JkdjMQFiJ5K/hAz2HA3nPvmnLQvma7JMQ+8UwmFmQKAN a5qNIw80+aISLcKIgfKE3amcxcaauu6+AQWs4FW92f6r0LRVvT4ERtmtDjj5f65uN7VK 6SwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4-v6si15824324pgc.284.2018.08.01.11.05.28; Wed, 01 Aug 2018 11:05:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732302AbeHATuy (ORCPT + 99 others); Wed, 1 Aug 2018 15:50:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49804 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405838AbeHATIh (ORCPT ); Wed, 1 Aug 2018 15:08:37 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1FC1613CB; Wed, 1 Aug 2018 17:15:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Omar Sandoval , David Sterba , Sasha Levin Subject: [PATCH 4.14 082/246] Btrfs: dont return ino to ino cache if inode item removal fails Date: Wed, 1 Aug 2018 18:49:52 +0200 Message-Id: <20180801165015.648707667@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Omar Sandoval [ Upstream commit c08db7d8d295a4f3a10faaca376de011afff7950 ] 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 Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5499,13 +5499,18 @@ void btrfs_evict_inode(struct inode *ino 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); @@ -5514,12 +5519,8 @@ void btrfs_evict_inode(struct inode *ino * 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 ||