Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3527533pxf; Mon, 15 Mar 2021 11:32:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjU02L8KBHxqI6XZq/6ympHJqjtXiLihfKKiKdXBArDfb5G7EjWsfUjwAN6ZfpxUZh9bkY X-Received: by 2002:a17:906:9152:: with SMTP id y18mr25360835ejw.19.1615833168905; Mon, 15 Mar 2021 11:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833168; cv=none; d=google.com; s=arc-20160816; b=mWHsAXxz29Ag7/nc/FmsRtNNqxhIBTfN+n0AcpOIOwrGr3tV/UURHRFB3Rm9EeQaSH VSUeYER3xiZOdV0+2zdni3WetF4Kh8PfHW5TW6ik7/o/vuI1JVcl/UmlZkhftyFjbIIS x8xVK2PGgJjYyvzaaLT5qgJgGqgQjJBliht5zD50CIfQGQDx9aIari0WGscH/rsve2jK LTncCj9f2GVblvfMKkvARQUxl7AiqWaxkkYdr3c7szdGYqM2N3x9mqYVYP7+Jxj7nBeY qARzbmuHRLfROlwLZgRCQ7KwSAsk8RDhKXKtDcq54wdYcR54N3hR0baKSixtBbLlGJBK Skjg== 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=qle2ti+4M9/+MKB4cDKME6Wr0Pb7UGIAhRUy67W2dAg=; b=kAa0shYe6BkTlVwAEIDkrpCd5CwfvV0I48KgLMAWLO6VjOMjjRmW2aTR+rl2hquwz5 cyMGuc8JigAJkCU4iwKqvuT936y/SkBhw+hw9ZWI/sKaj7+4Fwe6gazlCnRpO/xujx4u 1xUNlWA5v4bfKvz+ouBPwwnawSiNA1G59EqM9JIbl8ZiAGY8B8QMNcRXsQGa6tXxUn+j hY04BlAYcNx3w+5ho0UT3MPoRqe0yM/CEguZnPPDuKNK9uEGPs8HbCh3kYZfltt83/jr CY2JoZos2MUkpmNIwWwvo1dgQPvIjXpcBLTbdo31suFIDDbfl14mFGIBXTgR/Kpe2ALl BEPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A3ej6tPp; 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 b21si11126360eju.469.2021.03.15.11.32.26; Mon, 15 Mar 2021 11:32:48 -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=A3ej6tPp; 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 S240693AbhCOOiR (ORCPT + 99 others); Mon, 15 Mar 2021 10:38:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:48330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233506AbhCOOBx (ORCPT ); Mon, 15 Mar 2021 10:01:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE35064DAD; Mon, 15 Mar 2021 14:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816913; bh=M7EsEqAtFnvfj5oU+YriwkvpIGcbhpNTnd6ThIj0qoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A3ej6tPpwysDnlV1ZqXEH3rIjv+bONzlYf8cSMEH/KMIFgBuE2KX1X5IhoYMScshM EPGd5R7EwnEK5+F2VT3Jsj6/H8ojC7ocTRE10MBiDu9DuRf43dEY/aMiwsLYomZLki KNmOi7nMMqVnMizluA7vsM9M5g7z27Yxxq4NJh+0= 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.10 185/290] block: Try to handle busy underlying device on discard Date: Mon, 15 Mar 2021 14:54:38 +0100 Message-Id: <20210315135548.169358717@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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 @@ -123,12 +123,21 @@ int truncate_bdev_range(struct block_dev err = bd_prepare_to_claim(bdev, claimed_bdev, truncate_bdev_range); if (err) - return err; + goto invalidate; } truncate_inode_pages_range(bdev->bd_inode->i_mapping, lstart, lend); if (claimed_bdev) bd_abort_claiming(bdev, claimed_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);