From patchwork Mon Sep 17 07:28:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10602117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3DA41508 for ; Mon, 17 Sep 2018 07:22:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90468295FF for ; Mon, 17 Sep 2018 07:22:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 821EA29608; Mon, 17 Sep 2018 07:22:09 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 265C8295FF for ; Mon, 17 Sep 2018 07:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728243AbeIQMsO (ORCPT ); Mon, 17 Sep 2018 08:48:14 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:17617 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727099AbeIQMsO (ORCPT ); Mon, 17 Sep 2018 08:48:14 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="44983903" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Sep 2018 15:21:59 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id CBC394B6EC8D for ; Mon, 17 Sep 2018 15:21:59 +0800 (CST) Received: from archlinux.g08.fujitsu.local (10.167.226.31) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 17 Sep 2018 15:22:01 +0800 From: Su Yue To: CC: Subject: [PATCH v3 2/7] btrfs-progs: make btrfs_unlink() lookup inode_extref Date: Mon, 17 Sep 2018 15:28:47 +0800 Message-ID: <20180917072852.25831-3-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180917072852.25831-1-suy.fnst@cn.fujitsu.com> References: <20180917072852.25831-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.31] X-yoursite-MailScanner-ID: CBC394B6EC8D.AEA23 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suy.fnst@cn.fujitsu.com 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 btrfs_unlink() uses btrfs_lookup_inode_ref() to look up inode_ref but forget inode_extref case. Let btrfs_unlink() call btrfs_lookup_inode_extref() if inode_ref is found and EXTENDED_IREF feature is enabled. Fixes: 0cc75eddd093 ("btrfs-progs: Add btrfs_unlink() and btrfs_add_link() functions.") Signed-off-by: Su Yue Reviewed-by: Qu Wenruo --- inode.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/inode.c b/inode.c index 2398bca4a109..598ad0ab6b4c 100644 --- a/inode.c +++ b/inode.c @@ -277,6 +277,7 @@ int btrfs_unlink(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_key key; struct btrfs_inode_item *inode_item; struct btrfs_inode_ref *inode_ref; + struct btrfs_inode_extref *inode_extref = NULL; struct btrfs_dir_item *dir_item; u64 inode_size; u32 nlinks; @@ -296,7 +297,18 @@ int btrfs_unlink(struct btrfs_trans_handle *trans, struct btrfs_root *root, ret = PTR_ERR(inode_ref); goto out; } - if (inode_ref) + + if (!inode_ref && btrfs_fs_incompat(root->fs_info, EXTENDED_IREF)) { + btrfs_release_path(path); + inode_extref = btrfs_lookup_inode_extref(trans, root, path, + name, namelen, ino, parent_ino, 0); + if (IS_ERR(inode_extref)) { + ret = PTR_ERR(inode_extref); + goto out; + } + } + + if (inode_ref || inode_extref) del_inode_ref = 1; btrfs_release_path(path);