From patchwork Thu May 10 06:21:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10391261 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 E5BBE60153 for ; Thu, 10 May 2018 06:21:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D582828891 for ; Thu, 10 May 2018 06:21:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA24E288B2; Thu, 10 May 2018 06:21:52 +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 69DAB28891 for ; Thu, 10 May 2018 06:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934010AbeEJGVu (ORCPT ); Thu, 10 May 2018 02:21:50 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39258 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756566AbeEJGVc (ORCPT ); Thu, 10 May 2018 02:21:32 -0400 Received: by mail-pf0-f193.google.com with SMTP id a22-v6so563899pfn.6 for ; Wed, 09 May 2018 23:21:32 -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=7fWtI7QyRQqIlHs8BW3uJ0uB3tY24+sxs+we6bkJrHU=; b=oetFdYRO86RkGQ89mUpduA7EsHsl+JS0kSK1Y0gj/XvBV1bu/UWMARqw0ucJ6/NtB0 AzWhiZhdBK2tiEuaxHrA42r74/XCLsTBy1uBma9PRI2G8Zv5NjscQk/sOtWs4CSRHYma zqCAF7xALz2wprQ1GKJA+uSeS5vNSgwZTWB74KAmIc3ptC5/a8RAp45SJu1SakaD3MYX ZR8tLAmUh7DAnqHAg4oELs3Gx5PQhoBEgeJNfa8/nBdgtBaqld1SNwzhqb+FFbANjvaV 9VfZwMhWz++QXdWN4nMrbbihS2puGU3GFdfxr+yXOD1k/G/IcCAr21vltVDLDy869k8f Aj1g== 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=7fWtI7QyRQqIlHs8BW3uJ0uB3tY24+sxs+we6bkJrHU=; b=ofdBraRYTrB+JAK87mgjrRITSLQkyGDyj5mgP3dwFcZSMFbQcjTT1M4KJ09BXXBJtE UGdXSwolwuDaVtoI4I4UJvPoWPcFOoGRSoslcd090IvG8KdjDlajTdTYyGe5Oj2QJ2HI pjpHTw3nCZ9vFKdvNLdadTU5PiHVfyDkIX7KeXgfByeZTx3PLwjq8bqGq1hpvqCKZ2cL +yXQOLC5tPN1vRB8pZObsz+jufvEp7XIJehQKpOvFWpVFMCeUjCVUERVTIEhO9jSwnpr a8dYBJli+ksfgjGCDeTpoMs6CksLR5HWAQYG3SdU0XL42wrwi3qv8ydAZwB9WYg5MLQ3 cY/A== X-Gm-Message-State: ALKqPwfH7vt/gOtkjvTGp+l0SBDmJzzOu8J0bwu4XcS5pICYzLuAyRpG LImG6Nn8w01tqnOtTU4FxvHE+Y17usU= X-Google-Smtp-Source: AB8JxZrqJ9/gubEw+FNMnCok3gHHnOgNtq/ySgqaWRcuLKSm3mF5DTv7gu2hk/XJmooo3FEYwcNq5A== X-Received: by 2002:a65:5047:: with SMTP id k7-v6mr96337pgo.93.1525933291386; Wed, 09 May 2018 23:21:31 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:65fc]) by smtp.gmail.com with ESMTPSA id 68-v6sm496206pff.35.2018.05.09.23.21.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 23:21:30 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Chris Mason , Josef Bacik Subject: [PATCH 06/10] Btrfs: don't return ino if inode item removal fails Date: Wed, 9 May 2018 23:21:07 -0700 Message-Id: <62232de691b62b5eaf6f6b4912848e1e7bf65ebd.1525932796.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") 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 e77df96de642..9a6a4e626e01 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5368,13 +5368,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); @@ -5383,12 +5388,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 ||