Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3016295imu; Mon, 19 Nov 2018 09:23:45 -0800 (PST) X-Google-Smtp-Source: AJdET5cDTerXZvlfvGeSVhQMU9t9/0wEERFAJzEzQ1VUyb2ZyxC4Cyze+Kea1zvmcvJWI5kLXyT/ X-Received: by 2002:a65:5088:: with SMTP id r8mr15135388pgp.15.1542648225161; Mon, 19 Nov 2018 09:23:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542648225; cv=none; d=google.com; s=arc-20160816; b=iibnjJuoTjBuw9PFDUHiOAV7YXSlbE34HzG/KnR6gu9AO+MGazRjVXaz3HTGXV56XG gnDml2rGwGjNYNxs6rZA5X1GkCkSr6qT2e7Lnscme7+AdrDrDGqd98DaJbd+y9Wf2i3I mLnlGVFvxu3XeBUDobGIdcBrOjbJkEam6pB5QL69jy/OtJROMTqPj672H5ykebOOCcsk PXCew2ghSxiBvrxprqe4URV1KV+6/+eRNVCI+tMf8x+IKztcI+Z+NWMlQpTMcGTbCtfe +ce2amnRrt8fKu1DmqlzdydLyV9Pj9GmnJOvvJun+yB2IfqGUiJZD98nYcjGQtVyYOAW +oog== 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=zbPxvEmerU4ZGijrz/9g2MKLaSlNfH3NdOxVmgnp5HQ=; b=vtS+EOUHr4utf32v76WSoH1OWdNft8C8mR6UDl3iFOmlJraZkFmHVC7JM24uEG0hQG zoIdt+W2Fg+K5S4a7zyBvL8ClpPUnJYAYXVC6yi6X4mIoolXAhBB9HAscn42PQOsdmNW hS5Iz7vHv1NoDHBpqL9+Xpv3WxfMuUG6QSI6mMArYnyGo2oqPuEYTItM3CqRBCJ4nthb DFlEzZloCer8e8P3AkWygpzxTdw6ejPCb+pS6yU+WP8Mj/Ftwchqls+hyqnzUIXnV1YD 3gGSA7ySOnmNcAZGzubDQYLCirTqlz0cCGLxVJkMYYaC7dO0prMy13bcOJkO1mXsUuks 7/mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KnWJGO9R; 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 cd2si11627099plb.39.2018.11.19.09.23.28; Mon, 19 Nov 2018 09:23:45 -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=KnWJGO9R; 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 S2405137AbeKTDXy (ORCPT + 99 others); Mon, 19 Nov 2018 22:23:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:36026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404671AbeKTDXx (ORCPT ); Mon, 19 Nov 2018 22:23:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 01454214E0; Mon, 19 Nov 2018 16:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646777; bh=jT9dEe2cWN/dJRx6K52neWHdvQmOpfqgE6OcLQX4JQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KnWJGO9R3nK/OojDnV/TP5NAAfE8wFzrJRVdZ+dVOwmwPihGPgdi9oakdI47hFiU9 KYlR4RnG6GS3lr/leCDkWAiCkD0GKX5qPiBrmVtu6IxMtHZYEOWvafylajt4CK791y fghHV2l6tr2EOM/3Y6jM7yaKYieDg7TePJTmQ4KA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Mahoney , David Sterba Subject: [PATCH 4.4 086/160] btrfs: iterate all devices during trim, instead of fs_devices::alloc_list Date: Mon, 19 Nov 2018 17:28:45 +0100 Message-Id: <20181119162639.583338236@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162630.031306128@linuxfoundation.org> References: <20181119162630.031306128@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeff Mahoney commit d4e329de5e5e21594df2e0dd59da9acee71f133b upstream. btrfs_trim_fs iterates over the fs_devices->alloc_list while holding the device_list_mutex. The problem is that ->alloc_list is protected by the chunk mutex. We don't want to hold the chunk mutex over the trim of the entire file system. Fortunately, the ->dev_list list is protected by the dev_list mutex and while it will give us all devices, including read-only devices, we already just skip the read-only devices. Then we can continue to take and release the chunk mutex while scanning each device. Fixes: 499f377f49f ("btrfs: iterate over unused chunk space in FITRIM") CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Jeff Mahoney Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -10751,8 +10751,8 @@ int btrfs_trim_fs(struct btrfs_root *roo } mutex_lock(&root->fs_info->fs_devices->device_list_mutex); - devices = &root->fs_info->fs_devices->alloc_list; - list_for_each_entry(device, devices, dev_alloc_list) { + devices = &root->fs_info->fs_devices->devices; + list_for_each_entry(device, devices, dev_list) { ret = btrfs_trim_free_extents(device, range->minlen, &group_trimmed); if (ret)