Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp743884imm; Thu, 13 Sep 2018 07:08:08 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZb/0ahquyzGrIXDjDKQebmGBDXJmRnpxmLF5xhCYmDA33q7VcxciH8xwK/IOhPr0QshVF3 X-Received: by 2002:a63:b812:: with SMTP id p18-v6mr7282732pge.156.1536847688475; Thu, 13 Sep 2018 07:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847688; cv=none; d=google.com; s=arc-20160816; b=nyKao8SjOcW3Iq7t9fCaA6cdN/cKQnUwhEl+4SRK9vjSfIp+ObnqTaMmntjWtmkEsC GPyCFaexS2cKrnTql3pTNYXLpmv6bCrXNtoNTatvKycBLoH6kASCIZCxzZ0IqMwhxLS1 zP5GnhEXs2LyFPXWOftZF+OEG/rtgglR5oecnWgHshBLHc+7mQLUc1bnPu0Ec3EOiCzj McSdH4meV04C5LgBgUQT6GJkrxBDnHmnXb67qx3cb0l7IrEPbB29GpZD9udYK4t+prjG HMAJ118bHLl6qJYaHIBoZ+VqTYiwXZqOa40TL4XD8SJte86AA0vWaLYisk+H9pKuVAS9 qXFw== 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=wYLf1V5tU34nGLS3JOrhfOaZVWirwtwrhJoG2iWC8+s=; b=uUVJZjyyQOtRk4P/7fZAjSX9ST8l1TiOvwREzvUPC3Jnj0Uey/bZCQh+mqNPDeQ1WU ulyaJOSHytIk7+eUP4PBMW4L9Oqef7kyuUrbqFooLzohZAhdgEoSHLQE4p+3iP0Hxq0t LY6GMpIHWKW+dyP0xPMKiUcn17Vi4dZNhVevqYhOqqPwnXx+9tdj51wPo0q6v7J0I4xR ACHseam9b4TrVeqfecfhfW0jRFV2xTILMs7gXrGtxoLrxAKobZeaWn7NAZxGfMwkoGDJ DMrBZj35YcKRGSdM0VnCzKh5lCnXjUkArbIT+WZuA1oVmIEzn1GMERnTWRBchD37n0mD JlNQ== 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 d9-v6si4402519pfk.166.2018.09.13.07.07.53; Thu, 13 Sep 2018 07:08:08 -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 S1731792AbeIMTP4 (ORCPT + 99 others); Thu, 13 Sep 2018 15:15:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35568 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729111AbeIMTPz (ORCPT ); Thu, 13 Sep 2018 15:15:55 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 64F9FD36; Thu, 13 Sep 2018 14:06:15 +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 147/197] btrfs: use device_list_mutex when removing stale devices Date: Thu, 13 Sep 2018 15:31:36 +0200 Message-Id: <20180913131847.435319298@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: Anand Jain [ Upstream commit 7bcb8164ad9435068d9bc3b83b8a002c64d63ff6 ] btrfs_free_stale_devices() finds a stale (not opened) device matching path in the fs_uuid list. We are already under uuid_mutex so when we check for each fs_devices, hold the device_list_mutex too. Signed-off-by: Anand Jain Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/volumes.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -640,8 +640,11 @@ static void btrfs_free_stale_devices(con struct btrfs_device *device, *tmp_device; list_for_each_entry_safe(fs_devices, tmp_fs_devices, &fs_uuids, fs_list) { - if (fs_devices->opened) + mutex_lock(&fs_devices->device_list_mutex); + if (fs_devices->opened) { + mutex_unlock(&fs_devices->device_list_mutex); continue; + } list_for_each_entry_safe(device, tmp_device, &fs_devices->devices, dev_list) { @@ -661,16 +664,18 @@ static void btrfs_free_stale_devices(con continue; /* delete the stale device */ - if (fs_devices->num_devices == 1) { - btrfs_sysfs_remove_fsid(fs_devices); - list_del(&fs_devices->fs_list); - free_fs_devices(fs_devices); + fs_devices->num_devices--; + list_del(&device->dev_list); + btrfs_free_device(device); + + if (fs_devices->num_devices == 0) break; - } else { - fs_devices->num_devices--; - list_del(&device->dev_list); - btrfs_free_device(device); - } + } + mutex_unlock(&fs_devices->device_list_mutex); + if (fs_devices->num_devices == 0) { + btrfs_sysfs_remove_fsid(fs_devices); + list_del(&fs_devices->fs_list); + free_fs_devices(fs_devices); } } }