Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3469313imu; Sun, 11 Nov 2018 15:49:33 -0800 (PST) X-Google-Smtp-Source: AJdET5ev5dXIQOkqLktViG69W+T1XiE0RQNQGI9V5UR21+qB1V+fWlUuZWTnJUdTxxulmpnWQyRw X-Received: by 2002:a63:235f:: with SMTP id u31mr15352928pgm.122.1541980173132; Sun, 11 Nov 2018 15:49:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980173; cv=none; d=google.com; s=arc-20160816; b=q75M/yG+fAc/kKvGXihb+3QdH/xXXrxTKJAN4B8eK1g1ofOK5GgVSbwntFSzWiZG3k DLLvhb9Gj/senxoeVJNFJMl4eM/JUctxAGxkxQHFBYicN+eCzMQI2z0HZzDzLO+RqinX SV6Ca9ViVFl/Dbk3DISupJC4csE/AfSzUe9IKBUVLhDPTOZEZKLQZkhp4fn3mxZpWS4L KTwPdaxrH4bOhq2/KsFsKWkQc0EhvoGA7vz4/wzDjbnuCVkX7m7SKgZCVOByRWlYje1O naqCIqljSmD52U0hKKk6oFvNPeakBeDtt8lU3HQNjyJLwqNCIO+baD1iB5+UfelDYbWK oW6A== 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=k7uA2w5bqrOnk+TZymjYzVxzM6m5F5prIrHpvniADqk=; b=UTxjn08+B0bVtEFHPTfxP+Ma+ROy57OWYce+jWhjvQtV1shaqlysyVxEFHdQjq/757 c9o4/QPfqyEB22ZTa1QF28YH6fKH8jx8CBVOkef1DFmX0rXzjI/Pa6G45VwLTQ7m//DV 89P5OjndnjATbl8h/VSXsJxwAF/1Aq2jH2+3WgL0CbMt4Nt30xGpkmwpOBgwTIcuL93d +GTy43S9aj4mw+mCfL4ynCltoKIfcvJR5CQVQ/8Fpbetd4u4jBk54F+nzw/Ath6GPSd8 yRG0Sgw6qJlhQGch5stRVFZ4tf73gEglchxN/s7MI2GZeTDuhuqZGgLc/rmJvawFuFoc 5alA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="zFO/qfvX"; 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 s4si14258450pga.377.2018.11.11.15.49.18; Sun, 11 Nov 2018 15:49:33 -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="zFO/qfvX"; 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 S1733083AbeKLISm (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:38130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733057AbeKLISl (ORCPT ); Mon, 12 Nov 2018 03:18:41 -0500 Received: from localhost (unknown [206.108.79.134]) (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 B85D3224E0; Sun, 11 Nov 2018 22:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975325; bh=CbwmYYGSjGQUuzIgWKvMqv8F0tX9IR6YffgnGqrZD74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zFO/qfvXvz/Q05FAyJU0P17cRjWq13BCgP71sd431gro/xbF9bl2iasu8nJk0TXez rCDBMALWNjgLU/Q1aWNOTpP2L/0BUV2bsIMUH1dskx9Z25Y0MWEXCkRbzH3QM8lijc rmhynosQbYOokYonam0wzOFCEV6zS7XqaKtRSuBc= 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.19 333/361] btrfs: iterate all devices during trim, instead of fs_devices::alloc_list Date: Sun, 11 Nov 2018 14:21:20 -0800 Message-Id: <20181111221700.078760322@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -10920,8 +10920,8 @@ int btrfs_trim_fs(struct btrfs_fs_info * "failed to trim %llu block group(s), last error %d", bg_failed, bg_ret); mutex_lock(&fs_info->fs_devices->device_list_mutex); - devices = &fs_info->fs_devices->alloc_list; - list_for_each_entry(device, devices, dev_alloc_list) { + devices = &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) {