Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3525995pxf; Mon, 15 Mar 2021 11:30:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnHzyk423Sos8PD63eoVq7Y1W2029cvPGRbx3BrflcCgr4NzI96AZhQowaWA17V1NvWoVp X-Received: by 2002:a50:ec0e:: with SMTP id g14mr31776224edr.264.1615833046246; Mon, 15 Mar 2021 11:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833046; cv=none; d=google.com; s=arc-20160816; b=xNzCr8MpD6lZH7NROlhqAqoKSHlxfEM8dTCIZwefXJob4cYPiqB0kbcXG7OtSWJEur dC56I7CVJjY3dyHgmSiM/pIejgi3YBRxu9yvAiGfiLG+N7n6/HStHBr3oyecvUyQPGGs whcrWq2PecGiOHF2cEFlSgo+3eFr6oyQ3sgGH1vHkqidpOS8vNYEgy/6bbdN+awAMh9c gkrKlcugScz4OMZr0FrSmYNlY8l4ZzwKS+bkdKPhNyJynvOr3e7xDmqca/IW8baZ5ObE VDQbopYan6CIXOk0QwsUxL9/LMmANZMvRmCeSDkBEFGCGJ7LbkmEWVgL/3UH1sPlizno cyWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZBqeGwoH+exi/GkAR3NQS5zV7spmWv5nPfGP8v7v+tw=; b=KTtI3qVEhoDlGoNgf1XEEJ0xAOff4RKOmX8LVKiFRYEeevvoggTIkgRHywqESpbpnv 9Vpn8Qdwl8wGz3IatZuE19QiZxmbhEPERTp5YAbU+dqyhIPSNueWFt+oZ93uQ1l5zWFb UqmSecsYCKUemBdA74xR5F0N1VesRu3VTLyp3Sgcy/mKn4OPXsvy0Wa8qyFCAAZ/pCud NVVmDn5VrDQof5iIBtCBAWeTXJdIhgQhxYpbrpjfCoxD8afkK7Px4gfVp4mrXqGOT+pE oQGG3BOPR2SG+jbyB7GiOSfyb5i1MrPbnZ4xAO0JwLrAKlqqTKKzkuZ9E6ULnPWYvluk ocmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjJNbrdz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d22si12132455ejk.139.2021.03.15.11.30.08; Mon, 15 Mar 2021 11:30:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjJNbrdz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236107AbhCOOee (ORCPT + 99 others); Mon, 15 Mar 2021 10:34:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:35904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233424AbhCOOBk (ORCPT ); Mon, 15 Mar 2021 10:01:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1095F64EED; Mon, 15 Mar 2021 14:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816878; bh=o9XoxA6cgpzYrjnJoBJUj3JeOPg7fchmVOJ0RcS6UT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HjJNbrdzZRjDIde8JFIxue/k+qQ56/IBID3MKM1rua6o8CTp38zv/aMfMGKa0cVVG WGrVs9RzWFmf0Ccga+a1XefzVtdFiO0XuPj7N6Xirb+D6g2VRysvKFK4bopmTjQtSt 2S7KFWvOoJCKKzMn4vrFEPQsVI6OOW5PUtltqKdE= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Christoph Hellwig , Jens Axboe Subject: [PATCH 5.11 179/306] block: Try to handle busy underlying device on discard Date: Mon, 15 Mar 2021 14:54:02 +0100 Message-Id: <20210315135513.663989986@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Jan Kara commit 56887cffe946bb0a90c74429fa94d6110a73119d upstream. Commit 384d87ef2c95 ("block: Do not discard buffers under a mounted filesystem") made paths issuing discard or zeroout requests to the underlying device try to grab block device in exclusive mode. If that failed we returned EBUSY to userspace. This however caused unexpected fallout in userspace where e.g. FUSE filesystems issue discard requests from userspace daemons although the device is open exclusively by the kernel. Also shrinking of logical volume by LVM issues discard requests to a device which may be claimed exclusively because there's another LV on the same PV. So to avoid these userspace regressions, fall back to invalidate_inode_pages2_range() instead of returning EBUSY to userspace and return EBUSY only of that call fails as well (meaning that there's indeed someone using the particular device range we are trying to discard). Link: https://bugzilla.kernel.org/show_bug.cgi?id=211167 Fixes: 384d87ef2c95 ("block: Do not discard buffers under a mounted filesystem") CC: stable@vger.kernel.org Signed-off-by: Jan Kara Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/block_dev.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -118,13 +118,22 @@ int truncate_bdev_range(struct block_dev if (!(mode & FMODE_EXCL)) { int err = bd_prepare_to_claim(bdev, truncate_bdev_range); if (err) - return err; + goto invalidate; } truncate_inode_pages_range(bdev->bd_inode->i_mapping, lstart, lend); if (!(mode & FMODE_EXCL)) bd_abort_claiming(bdev, truncate_bdev_range); return 0; + +invalidate: + /* + * Someone else has handle exclusively open. Try invalidating instead. + * The 'end' argument is inclusive so the rounding is safe. + */ + return invalidate_inode_pages2_range(bdev->bd_inode->i_mapping, + lstart >> PAGE_SHIFT, + lend >> PAGE_SHIFT); } EXPORT_SYMBOL(truncate_bdev_range);