Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3427313imu; Sun, 11 Nov 2018 14:51:44 -0800 (PST) X-Google-Smtp-Source: AJdET5exilr7qv3PrBJ+Bhj7T1tH0YnJilndXmWMICXTknziTIWBtcUA8N9FjyqFXfZKPdkYFuyN X-Received: by 2002:a63:3703:: with SMTP id e3mr8028137pga.348.1541976703964; Sun, 11 Nov 2018 14:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976703; cv=none; d=google.com; s=arc-20160816; b=hD7IdcE+8cG1ALzVeb3Qn3eH087WWxCMung6VAK+6ZdOSGS8jOB3Lxf4fGqwJtWO/w 2R/L/f/hLRfkQl703yvdhAe2AyfDZWNLQYyZi6NzCwHlY/rfI8hJ+Y1ual0y+w3zsug/ UlIm/f3SB7Jx5O/pQfvEeBF/UvX83+/nWzyrWFujQZ1mzwxwrPpcUeolu/hoQb8ysVd+ mbyjix4xdjyej0cA/VO6juNSHR/SmZAVkEGebr5IsxxvaePy39wSiyuRwDp2mrFOLbNK 8HvRIck517vKmBvCCRkUZ81d8L9XHVSHYx1HEAwOemgBGY/74zBDd9mayTgPrGvFMMx/ dQXQ== 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=ClF+qaP4UpusHQr8DbZ9CqSvVpgce6zpRNb4PKOxuPw=; b=VtDPLHV4HWEpDDQReOjuSr0fSz+2pQG7f/CmuhendIUs9rBm8AHSGAbQgs7GAi45Gz u5S6Qi9LXzXHd20ZVnqs7sRusQ3R3yHEfGNnda4gpykT3xOtVXhxptmswu/Je+jbvJue O+eJnTBbGOM6pA7hoIKqx3iage4jdheXwcTbPmrjZbDgjsb+eCwvm3WQY20kuHy3hxhu outIltpWRCPv/swM3JsW/31Yh/HUyoU5pnH8uCdKFZgpzjFMJe6R5p5MI0bRSBaypbrg oV7LVl1juqjsBgibqO9nOty9ziCM51YTzFGIIaa6C4I2Zl1kbn6+Uq1FKrGPiI04iX8z gi1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pLyKzJ6a; 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 f10si14801955pgl.528.2018.11.11.14.51.29; Sun, 11 Nov 2018 14:51:43 -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=pLyKzJ6a; 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 S2404292AbeKLIlK (ORCPT + 99 others); Mon, 12 Nov 2018 03:41:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:54772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404185AbeKLIXH (ORCPT ); Mon, 12 Nov 2018 03:23:07 -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 A0240208A3; Sun, 11 Nov 2018 22:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975590; bh=XHXCuyRArfCsWOYZHBugDMC+gn+Xo0b0Mh98SBSJUVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pLyKzJ6a2xu4rJKKwydebVfU2XFGWPHWcrISeTcTAZpviIPIQGR2D7rEtaQxionyx lr/37S1bjuxZp7uah9HogW3tC8OHyyYxxHle/hQOafjD9+6cDaDOR2MM6WKCiO5mb0 +JUkc2UOXnGNdZaF09aUBBeovCClaiGaj3Z4c62E= 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.14 202/222] btrfs: iterate all devices during trim, instead of fs_devices::alloc_list Date: Sun, 11 Nov 2018 14:24:59 -0800 Message-Id: <20181111221704.785792567@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -11107,8 +11107,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) {