Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp742029imm; Thu, 13 Sep 2018 07:06:45 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbz4ymKXanSCJxy7kPLyIgpfal3np8kNkQOBSg6XSocZ2Wz2T8bDY7GkZRGOVzeaV2fPbp3 X-Received: by 2002:a17:902:708a:: with SMTP id z10-v6mr7579150plk.229.1536847605735; Thu, 13 Sep 2018 07:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847605; cv=none; d=google.com; s=arc-20160816; b=DvfdNt/A9IQRx+JC3qj4OIh4WsV9zOWbYzTx0yhMz2phgjm06ScyRjQwadOkafswmN 7YBKOeANIfFd0tpzgu4ems0OFrvtScFhfG6xiFOAjj2RmlSM3slyOvxaDO95EhMcMQtJ yt6YK8z6IQjYInzYIFShQBzRZbtntB01B0jGPqQWap1UXKWee6N1UsqisKs/PbebBrIW f7iJ46z3l7cDLn7bFaRjPBfEDW616nLxRGFWAkZly88TSobG4aSnB+o+33SCWFCBqny5 BI7suj7muSmKuIZJZ+wAitp0w8bfiw5c9PyTlzFfH9y9ddBctqkzfryxzqfHY+bh9d10 YP7w== 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; bh=YE5ZYgAF4YidWslgkuYHQ0VgKzxxViL5nQyuaO6xX88=; b=APHpGDrQSisYmBlcW3v25ukNAlHt2FDJh8xIeytA8/yNoBQ9RPcyx06pN+UbNFAF4D s8Y0DiQIvCQDwxzqMDz+SSM67iGW0yXN3YO+1GRlu2C1OJyI+u/cc2Gkvj1EkO39ainx H4870L3UwyT2lM+lnZ4TwB5aSxhf2EjwL6JFH5TcuZ3yqvsFMFcqNLee+Lm0r6w/jbHR jYy8qCq+Iu1SsQRHwbZWg8Y/O2ysRQVjGR1lXa5MVe0/yLt8bff0cL2mJntBYOU6yIsD Idqwrgw90awcXBkrFQYs4VXxCq3P0lCaqmNJsOr+oll4J0P37269RbY7qPcAWIlJNA/p bznA== 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 p23-v6si4188675pgl.394.2018.09.13.07.06.21; Thu, 13 Sep 2018 07:06:45 -0700 (PDT) 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 S1727566AbeIMTO2 (ORCPT + 99 others); Thu, 13 Sep 2018 15:14:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35422 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728565AbeIMTO1 (ORCPT ); Thu, 13 Sep 2018 15:14:27 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 12B3ED35; Thu, 13 Sep 2018 14:04:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand Jain , David Sterba , Sasha Levin Subject: [PATCH 4.18 150/197] btrfs: reorder initialization before the mount locks uuid_mutex Date: Thu, 13 Sep 2018 15:31:39 +0200 Message-Id: <20180913131847.549276005@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Sterba [ Upstream commit 399f7f4c42e8a58c8456264d5112287aefe44cf4 ] In preparation to take a big lock, move resource initialization before the critical section. It's not obvious from the diff, the desired order is: - initialize mount security options - allocate temporary fs_info - allocate superblock buffers Reviewed-by: Anand Jain Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/super.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1528,14 +1528,6 @@ static struct dentry *btrfs_mount_root(s if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - mutex_lock(&uuid_mutex); - error = btrfs_parse_early_options(data, mode, fs_type, - &fs_devices); - mutex_unlock(&uuid_mutex); - if (error) { - return ERR_PTR(error); - } - security_init_mnt_opts(&new_sec_opts); if (data) { error = parse_security_options(data, &new_sec_opts); @@ -1543,12 +1535,6 @@ static struct dentry *btrfs_mount_root(s return ERR_PTR(error); } - mutex_lock(&uuid_mutex); - error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices); - mutex_unlock(&uuid_mutex); - if (error) - goto error_sec_opts; - /* * Setup a dummy root and fs_info for test/set super. This is because * we don't actually fill this stuff out until open_ctree, but we need @@ -1561,8 +1547,6 @@ static struct dentry *btrfs_mount_root(s goto error_sec_opts; } - fs_info->fs_devices = fs_devices; - fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); security_init_mnt_opts(&fs_info->security_opts); @@ -1572,6 +1556,20 @@ static struct dentry *btrfs_mount_root(s } mutex_lock(&uuid_mutex); + error = btrfs_parse_early_options(data, mode, fs_type, &fs_devices); + mutex_unlock(&uuid_mutex); + if (error) + goto error_fs_info; + + mutex_lock(&uuid_mutex); + error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices); + mutex_unlock(&uuid_mutex); + if (error) + goto error_fs_info; + + fs_info->fs_devices = fs_devices; + + mutex_lock(&uuid_mutex); error = btrfs_open_devices(fs_devices, mode, fs_type); mutex_unlock(&uuid_mutex); if (error)