From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2AFDC2D0DA for ; Sun, 29 Dec 2019 18:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3DB120748 for ; Sun, 29 Dec 2019 18:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577643111; bh=TVdX3zz8LfYu6keNAI1r0ixzJ4OerZJm7a1LpSXOrek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=txrMn5QJ1wSeFoakiAEHkKjkfMwp2y+THa9iKxuELMqR5QN1K2rg5yAquNytuHmeR rLEe7ZWjPcbWsJp01+22DMCqLTuMvZTwNhpb0Ipom7XZz/oddUVV1A5iHN0JAcPWAP FsKxcK8rYhuZp1RRBPpgc3/KK7FmR8v2Hq/i6b/c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730330AbfL2Rmj (ORCPT ); Sun, 29 Dec 2019 12:42:39 -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));