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 CB467C2D0DA for ; Sun, 29 Dec 2019 17:28:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9BCBE208E4 for ; Sun, 29 Dec 2019 17:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640487; bh=2AgzNFGDqkQM8/zPWuaEzLdcOC5DwNgXkhI5m7l8VAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=BcN64EGHN6NK1qGMfHdcuovKysdWsk7OVboIK22wGJRIwH1WIguMTVH8SPhiyKX7v YTf+xVnAGc7B4/12q1df5JIblY4wp3UyEkKeAaSyVYpjiBGf9MiPcCK9VChscLMftk +pkPs7l37Sm6kGE0sTsCmdAWThCJKUHJeDjqWQAw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728184AbfL2R2F (ORCPT ); Sun, 29 Dec 2019 12:28:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:50928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728522AbfL2R2B (ORCPT ); Sun, 29 Dec 2019 12:28:01 -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 4B28F21744; Sun, 29 Dec 2019 17:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640480; bh=2AgzNFGDqkQM8/zPWuaEzLdcOC5DwNgXkhI5m7l8VAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jcNzKT9LLEimadupJ86qUt/sRJGK6XuMdIasLgbLfjW54VLXwasQZEp55hTFjPlqS qr84EPxV0Jn3sC6/qj+zAgxkCpOlq189t6I3DVBTClOMemhoAkQaWfj+mzPNFiS7T0 HQx4gey915Ei28+pIqEmYafoMy+IHpajrR07zlAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 4.19 014/219] btrfs: dont double lock the subvol_sem for rename exchange Date: Sun, 29 Dec 2019 18:16:56 +0100 Message-Id: <20191229162511.066433726@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162508.458551679@linuxfoundation.org> References: <20191229162508.458551679@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 @@ -9491,9 +9491,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); /* @@ -9727,9 +9726,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));