Received: by 10.223.185.116 with SMTP id b49csp1018561wrg; Wed, 21 Feb 2018 10:39:23 -0800 (PST) X-Google-Smtp-Source: AH8x227O+FECLLaLLpEog4CO7xx6Qe9a1ZKr9Hjn6KHICQ5cI2fJ37tVnRw3z4n5eLJvYGcHV+Nv X-Received: by 2002:a17:902:bc3:: with SMTP id 61-v6mr3929137plr.407.1519238363882; Wed, 21 Feb 2018 10:39:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238363; cv=none; d=google.com; s=arc-20160816; b=s+fuOWF9rLJFmCe0XMxdlIs77RSWiIiVmhcPJw3MX1JEBXnvAGjGq3tSsd5pxgqW5i kyOuCVOWNGixCLAuUXxWq/aCSeip9kmTnft173LiL3hYZfLlKodg6dFCc0SVteLxRllm zxGE9kQ0eRXCXSMajNLHR3xPwRqugMEHFUFI3eamGu9wjMbkyW9MB8rO4n1sfjgcn4Hf gUHVsimVM4cGfbcNNGgqRT3qYlVz/2ngIqtXOdcER1o0mkJfs/NlNJ3i9dTiRZbGyOzO uixZWNyfRTNn12nxdXtXZjMwudUjiv2oc7FLgW92XHesIQ6ie9rKob7ElDIJFs6pWqqu S+mg== 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=fq97V0IvyheZAOsKjczYKWEHIF5XT+saDchIHb6aA/0=; b=Zvwd+5+HhwNmhI4VzOWmJUHlTxIKfq9cj2Vfp8gZL4u6Zi1Y6D+3XAjPouQ/ziOGwr Q8A4djHFu3xwBuqpoTqtXZ60cxA/Lns1ZGeZQ6xefiPs8Rmxw6wlAXx6ZUg6LG1gQIYq RhNEqPcVH1YqXBicTZQBFjdmemVkobBxlD/U2oT2jk2gF+gjjM0rYsGbEEGzWidcSHqA hL0GABRPlAjU3ETHwI5Yay7z0y6Vnnatk4Hl0HZoG+TwQBhJn0wmNlUh3MeBrlr9Jp7A RLS7OYKBEEnzIWGs5tAW2qFaENSjr1V6AhAAcsbq+pCBCWQUurXeVvrHMrmxcLkscQ+O uf/A== 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 z7si17260pgv.91.2018.02.21.10.39.10; Wed, 21 Feb 2018 10:39:23 -0800 (PST) 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 S936447AbeBUNMC (ORCPT + 99 others); Wed, 21 Feb 2018 08:12:02 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:45496 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965590AbeBUNL6 (ORCPT ); Wed, 21 Feb 2018 08:11:58 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6DF40727; Wed, 21 Feb 2018 13:11:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Bo , Josef Bacik , David Sterba Subject: [PATCH 4.15 140/163] Btrfs: fix unexpected -EEXIST when creating new inode Date: Wed, 21 Feb 2018 13:49:29 +0100 Message-Id: <20180221124537.888018974@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Bo commit 900c9981680067573671ecc5cbfa7c5770be3a40 upstream. The highest objectid, which is assigned to new inode, is decided at the time of initializing fs roots. However, in cases where log replay gets processed, the btree which fs root owns might be changed, so we have to search it again for the highest objectid, otherwise creating new inode would end up with -EEXIST. cc: v4.4-rc6+ Fixes: f32e48e92596 ("Btrfs: Initialize btrfs_root->highest_objectid when loading tree root and subvolume roots") Signed-off-by: Liu Bo Reviewed-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -28,6 +28,7 @@ #include "hash.h" #include "compression.h" #include "qgroup.h" +#include "inode-map.h" /* magic values for the inode_only field in btrfs_log_inode: * @@ -5715,6 +5716,23 @@ again: path); } + if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) { + struct btrfs_root *root = wc.replay_dest; + + btrfs_release_path(path); + + /* + * We have just replayed everything, and the highest + * objectid of fs roots probably has changed in case + * some inode_item's got replayed. + * + * root->objectid_mutex is not acquired as log replay + * could only happen during mount. + */ + ret = btrfs_find_highest_objectid(root, + &root->highest_objectid); + } + key.offset = found_key.offset - 1; wc.replay_dest->log_root = NULL; free_extent_buffer(log->node);