From patchwork Wed Mar 16 08:45:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12782448 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5D33C433EF for ; Wed, 16 Mar 2022 08:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354622AbiCPIqy (ORCPT ); Wed, 16 Mar 2022 04:46:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348751AbiCPIqy (ORCPT ); Wed, 16 Mar 2022 04:46:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08FAA63BFA for ; Wed, 16 Mar 2022 01:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=TVeULILu8PMsbwhGhGxYFfPqdzCYqm7aQtjL1Sj6jzY=; b=zRWq90vYZpZFgHvVWmn6ZWwV0s 2pTLGBa7HNmUYOHXQS3g5m2PawKU3VQnWnL6sDHp+oWx/YP0NVEIxCpNZd4naytl1rPrlJ5q4Y50g mFMJH54Zb1hN4r4rW1nBnwWynuzx0DIH4h2KPcazZGG9U1lnRGGbQnIBDo+qKW3CK5yxapzIqbmmZ nO8fBhVa0ZS60Yr1OnsRCaPYd0EllGMQ5XdarOttIIAEH/Fv/1WBuyjvZ6eosbGeUcLjxJdUuBu2B 9hixU0My3WckF+9GX54FvGueaR9OjaWjxny16lI5ZMNlVc4XaWNiyOfpBUfIe5h3uGzuma+ncGi3N liKFisRw==; Received: from [46.140.54.162] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUPHk-00CCDY-FZ; Wed, 16 Mar 2022 08:45:36 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Tetsuo Handa , Jan Kara , "Darrick J . Wong" , linux-block@vger.kernel.org, Ming Lei Subject: [PATCH 5/8] loop: only freeze the queue in __loop_clr_fd when needed Date: Wed, 16 Mar 2022 09:45:16 +0100 Message-Id: <20220316084519.2850118-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220316084519.2850118-1-hch@lst.de> References: <20220316084519.2850118-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org ->release is only called after all outstanding I/O has completed, so only freeze the queue when clearing the backing file of a live loop device. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Tested-by: Darrick J. Wong --- drivers/block/loop.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 87d77464c2800..0813f63d5bbd2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1144,8 +1144,13 @@ static void __loop_clr_fd(struct loop_device *lo, bool release) if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags)) blk_queue_write_cache(lo->lo_queue, false, false); - /* freeze request queue during the transition */ - blk_mq_freeze_queue(lo->lo_queue); + /* + * Freeze the request queue when unbinding on a live file descriptor and + * thus an open device. When called from ->release we are guaranteed + * that there is no I/O in progress already. + */ + if (!release) + blk_mq_freeze_queue(lo->lo_queue); destroy_workqueue(lo->workqueue); loop_free_idle_workers(lo, true); @@ -1170,7 +1175,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release) mapping_set_gfp_mask(filp->f_mapping, gfp); /* This is safe: open() is still holding a reference. */ module_put(THIS_MODULE); - blk_mq_unfreeze_queue(lo->lo_queue); + if (!release) + blk_mq_unfreeze_queue(lo->lo_queue); disk_force_media_change(lo->lo_disk, DISK_EVENT_MEDIA_CHANGE);