From patchwork Fri May 11 20:13:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10395313 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 2D43760236 for ; Fri, 11 May 2018 20:14:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 229F028D2D for ; Fri, 11 May 2018 20:14:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16F2328FAF; Fri, 11 May 2018 20:14:19 +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 76F1828D2D for ; Fri, 11 May 2018 20:14:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751881AbeEKUN6 (ORCPT ); Fri, 11 May 2018 16:13:58 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:39902 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751756AbeEKUN4 (ORCPT ); Fri, 11 May 2018 16:13:56 -0400 Received: by mail-pg0-f66.google.com with SMTP id e1-v6so2867891pga.6 for ; Fri, 11 May 2018 13:13:56 -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=lrgaR9rYk4zuPo7Uj12Z9QfXP/MmWOMf7m8Ms6DFIDk=; b=mtmZ+8p3OuTih3g8oOdZvoNAUXWUQKvRj50s9y3UEFSQOoS1kzNqg2ynGVQhtccTYc FqKa0nAeEMQt0/BEIiS2nKvk2X/l5tgBbeUX3OPehhG41z46s8drte13+dHLszKWYNkQ KumRltLIkBNWW5KWrpCtPljw7KY8JwVEj7XsiLSdj6bdTf190jCx6n/Jmx4ttDHqzUpz 0LbjeZyCnTSDVrNHJ2v5ADlG8+0f9zpWh5Nnt5PZH0UxEFgaF0PSQuXIp1jcHPqFWI9B zHkEwc/HgFcmvTS2tjXJJeofoAYdQBRjYgrS7XvrMyiGUAhCJ7Kjf58fIsFFWw7jTXUl dCjg== 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=lrgaR9rYk4zuPo7Uj12Z9QfXP/MmWOMf7m8Ms6DFIDk=; b=SeEsctHkFkfMojgueLCzdZNtViX2ZDjhp0rDOdi9F8B9+Qq78/KFoIzmtf5qKF3EHc /aYgb/7QmcVHkRHuhhOwqLN74AelHhjDbB7G/I7wKpdVIhE69ubJoFx5teSXDnn+ElUF OD3oTFrnoE5DcHWuFFCZop3dFOwHXCvtthMgdyzGJxrcxcUS1XlBYcaUpknhou1ItIow mwJv7IXs70ve2X4aylETN9q5qxEqwS0kdYzLAn0PPd5vZVILl4a66uGQUMHNu0K6XEuO Lcj0+zVdc1Od5IqZee84Of+SqC9JoVKAI88XKLXQBcVlrBPzKw/bPs1DHtCbxxOhipBb hMzg== X-Gm-Message-State: ALKqPwfZ7q3KoC7Se2Wu/2XgMQMMbMJmmo0xWRg/42ANBRmY6F7kHpl0 vGw0n8l868iFEmtL6MudnVz3YAoeOwQ= X-Google-Smtp-Source: AB8JxZpOjU9vnC2nuXWy4ULseEnQeMD63ld61XueHwaW4qVKepdGB662QivAV0NyV5oPFnG3QAXIeQ== X-Received: by 2002:a63:a06a:: with SMTP id u42-v6mr335916pgn.389.1526069635482; Fri, 11 May 2018 13:13:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 13:13:54 -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 05/12] Btrfs: get rid of BTRFS_INODE_HAS_ORPHAN_ITEM Date: Fri, 11 May 2018 13:13:33 -0700 Message-Id: <3e3b0eeb0a0a67714d97c3e61ca3e0e491900a59.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 Now that we don't add orphan items for truncate, there can't be races on adding or deleting an orphan item, so this bit is unnecessary. Reviewed-by: Nikolay Borisov Signed-off-by: Omar Sandoval --- fs/btrfs/btrfs_inode.h | 1 - fs/btrfs/inode.c | 76 +++++++++++------------------------------- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 234bae55b85d..cb7dc0aa4253 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -23,7 +23,6 @@ #define BTRFS_INODE_ORPHAN_META_RESERVED 1 #define BTRFS_INODE_DUMMY 2 #define BTRFS_INODE_IN_DEFRAG 3 -#define BTRFS_INODE_HAS_ORPHAN_ITEM 4 #define BTRFS_INODE_HAS_ASYNC_EXTENT 5 #define BTRFS_INODE_NEEDS_FULL_SYNC 6 #define BTRFS_INODE_COPY_EVERYTHING 7 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 110ccd40987e..9ef20d28fa9e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3354,7 +3354,6 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct btrfs_root *root = inode->root; struct btrfs_block_rsv *block_rsv = NULL; int reserve = 0; - bool insert = false; int ret; if (!root->orphan_block_rsv) { @@ -3364,10 +3363,6 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, return -ENOMEM; } - if (!test_and_set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, - &inode->runtime_flags)) - insert = true; - if (!test_and_set_bit(BTRFS_INODE_ORPHAN_META_RESERVED, &inode->runtime_flags)) reserve = 1; @@ -3381,8 +3376,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, block_rsv = NULL; } - if (insert) - atomic_inc(&root->orphan_inodes); + atomic_inc(&root->orphan_inodes); spin_unlock(&root->orphan_lock); /* grab metadata reservation from transaction handle */ @@ -3398,36 +3392,28 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, atomic_dec(&root->orphan_inodes); clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, &inode->runtime_flags); - if (insert) - clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, - &inode->runtime_flags); return ret; } } /* insert an orphan item to track this unlinked file */ - if (insert) { - ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); - if (ret) { - if (reserve) { - clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, - &inode->runtime_flags); - btrfs_orphan_release_metadata(inode); - } - /* - * btrfs_orphan_commit_root may race with us and set - * ->orphan_block_rsv to zero, in order to avoid that, - * decrease ->orphan_inodes after everything is done. - */ - atomic_dec(&root->orphan_inodes); - if (ret != -EEXIST) { - clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, - &inode->runtime_flags); - btrfs_abort_transaction(trans, ret); - return ret; - } + ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); + if (ret) { + if (reserve) { + clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, + &inode->runtime_flags); + btrfs_orphan_release_metadata(inode); + } + /* + * btrfs_orphan_commit_root may race with us and set + * ->orphan_block_rsv to zero, in order to avoid that, + * decrease ->orphan_inodes after everything is done. + */ + atomic_dec(&root->orphan_inodes); + if (ret != -EEXIST) { + btrfs_abort_transaction(trans, ret); + return ret; } - ret = 0; } return 0; @@ -3441,14 +3427,9 @@ static int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct btrfs_inode *inode) { struct btrfs_root *root = inode->root; - int delete_item = 0; int ret = 0; - if (test_and_clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, - &inode->runtime_flags)) - delete_item = 1; - - if (delete_item && trans) + if (trans) ret = btrfs_del_orphan_item(trans, root, btrfs_ino(inode)); if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, @@ -3460,8 +3441,7 @@ static int btrfs_orphan_del(struct btrfs_trans_handle *trans, * to zero, in order to avoid that, decrease ->orphan_inodes after * everything is done. */ - if (delete_item) - atomic_dec(&root->orphan_inodes); + atomic_dec(&root->orphan_inodes); return ret; } @@ -3619,12 +3599,6 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) continue; } - /* - * add this inode to the orphan list so btrfs_orphan_del does - * the proper thing when we hit it - */ - set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, - &BTRFS_I(inode)->runtime_flags); atomic_inc(&root->orphan_inodes); nr_unlink++; @@ -5264,11 +5238,8 @@ void btrfs_evict_inode(struct inode *inode) btrfs_free_io_failure_record(BTRFS_I(inode), 0, (u64)-1); - if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) { - BUG_ON(test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, - &BTRFS_I(inode)->runtime_flags)); + if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) goto no_delete; - } if (inode->i_nlink > 0) { BUG_ON(btrfs_root_refs(&root->root_item) != 0 && @@ -9265,13 +9236,6 @@ void btrfs_destroy_inode(struct inode *inode) if (!root) goto free; - if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, - &BTRFS_I(inode)->runtime_flags)) { - btrfs_info(fs_info, "inode %llu still on the orphan list", - btrfs_ino(BTRFS_I(inode))); - atomic_dec(&root->orphan_inodes); - } - while (1) { ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); if (!ordered)