Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13471534ybl; Sun, 29 Dec 2019 12:42:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxJmeNJass7Dg80JsCdhbExoKfr51JsRYWMGNHPGdnvXA9xEd3Ux/Vga03tovN6mAxXzCkf X-Received: by 2002:a05:6830:1691:: with SMTP id k17mr72829465otr.282.1577652143009; Sun, 29 Dec 2019 12:42:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652143; cv=none; d=google.com; s=arc-20160816; b=RysfZDWRnfxTirv3rOBz45rY8jfipLe3p7ZLDJhP81anO1ZQv52aPhr+NigkbGKNFa tiDU67isn/s0pDINK/8NNWBa9oTkXAQ5UHdeerZXp2o+9XEtznFVxgUugEdXG2qkcQAJ dpee3F0/uM30ws/9Yc/vZ9gTjKFjnfNtZLFfq8whoVZaiLE6sU7CqbRxWwHn0Nxq0zNY HCN+sFZcP/Xam2CngDQoj6VKqo6hH9oI+uEgGuY8MfTmZsvvWW8l6XE1e2GpyGYTFquN RaJ+L3ld1PbT/bXkVxDbv4nGosEwIMk6rwEiidtYYYUF9fH+ypVqcYJQN62v7+8ZDsjS lJlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VVx+dmY3UXmYfz3IK58dag15jl2u112Qq/meuBJAdYU=; b=GzuW1n+K60evLXKah1cVd0Nwyejk12Bej54LdT+PtYzl2+MtaGNdzHNfxZ+GkYenvG KyiJAroDvBY6jkbsXM9063wehr7beVYWgMakkDtJsE7i69JT7CYY3ZO6VpCAjq3krXen XHjdJKmP+CWv7+GE+YndCCbqMmYz6EuNjJYZNJ+uvrSD/JwtiJ2T9Y1P8l2IO7PuaLaf N4yOVOgUIarB2JZ/LMNQGQZljwkLzFJz61llxOq/xzGOHgU6Bc9ogSiKEq/uv1VcZrWF 7yManz2DZ+7mdJsZenMCqiG7OcNhlvty9BeOSj0UFnpDFji2w6rgpAmbvJ2WS7dD2SD/ Nklw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MQW51YQ9; 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 h22si18352182otk.18.2019.12.29.12.42.11; Sun, 29 Dec 2019 12:42:22 -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; dkim=pass header.i=@kernel.org header.s=default header.b=MQW51YQ9; 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 S1730328AbfL2Rmh (ORCPT + 99 others); Sun, 29 Dec 2019 12:42:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:48684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730291AbfL2Rm0 (ORCPT ); Sun, 29 Dec 2019 12:42:26 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7421F207FD; Sun, 29 Dec 2019 17:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641345; bh=TVdX3zz8LfYu6keNAI1r0ixzJ4OerZJm7a1LpSXOrek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MQW51YQ9bawzRNZModxjv2FI3aN0oFmcmGFQXsgMJF26yDPYwYkQ0KnRvVuGOLYd8 y5VzVoCWCVoHoUJjs97sy+7xGVI1TWYLqXnq1+KtP+kXVAXNNCsAPjjAcv6Dvy1PQo BXThFjkMX7CdcrnLM+8VPe0YiaziwdUJjIakGCnU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 5.4 028/434] btrfs: dont double lock the subvol_sem for rename exchange Date: Sun, 29 Dec 2019 18:21:21 +0100 Message-Id: <20191229172703.929761617@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik commit 943eb3bf25f4a7b745dd799e031be276aa104d82 upstream. If we're rename exchanging two subvols we'll try to lock this lock twice, which is bad. Just lock once if either of the ino's are subvols. Fixes: cdd1fedf8261 ("btrfs: add support for RENAME_EXCHANGE and RENAME_WHITEOUT") CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9535,9 +9535,8 @@ static int btrfs_rename_exchange(struct btrfs_init_log_ctx(&ctx_dest, new_inode); /* close the race window with snapshot create/destroy ioctl */ - if (old_ino == BTRFS_FIRST_FREE_OBJECTID) - down_read(&fs_info->subvol_sem); - if (new_ino == BTRFS_FIRST_FREE_OBJECTID) + if (old_ino == BTRFS_FIRST_FREE_OBJECTID || + new_ino == BTRFS_FIRST_FREE_OBJECTID) down_read(&fs_info->subvol_sem); /* @@ -9771,9 +9770,8 @@ out_fail: ret = ret ? ret : ret2; } out_notrans: - if (new_ino == BTRFS_FIRST_FREE_OBJECTID) - up_read(&fs_info->subvol_sem); - if (old_ino == BTRFS_FIRST_FREE_OBJECTID) + if (new_ino == BTRFS_FIRST_FREE_OBJECTID || + old_ino == BTRFS_FIRST_FREE_OBJECTID) up_read(&fs_info->subvol_sem); ASSERT(list_empty(&ctx_root.list));