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 99C3EC433F5 for ; Thu, 24 Mar 2022 07:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348636AbiCXHxX (ORCPT ); Thu, 24 Mar 2022 03:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242403AbiCXHxW (ORCPT ); Thu, 24 Mar 2022 03:53:22 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68ACB99686 for ; Thu, 24 Mar 2022 00:51:51 -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=WVzkkbrxtQ7e/ZumjaGTdVP8sQaRQ+9gjayHQfTr2lE=; b=GlOWFf7KKR+j6StPylKHqpEMsU 5X+HbqcAuKwk6+bS6/qoe34uLCWSDi5pdXKh8sdxK3YPXjK32NkGeeTDFNRP8TLly9nupeqtYL091 wlTUwz1874MDEM1IdfY9JLQffz/W7AxRDBgfNQLVr0Jiayi/wcMGYmAciIuuDVLXn0x+qHARAVruB ZCs5vxZVbz5e4jYEOCgDETAwloulx/A4SDTErqZi8UcUafe125DXulbGCGEn7QdD4mfV1eCSOlqN1 qN9BUACl2XNLPZWUy8XEtahhtV5DXvN5FA8vWGUFbyTQ7PzGyhiYWQcOuZpymErU/wD2aIeIVpS2t ziJlUYAQ==; Received: from [2001:4bb8:19a:b822:f71:16c0:5841:924e] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXIG2-00FzaJ-KX; Thu, 24 Mar 2022 07:51:47 +0000 From: Christoph Hellwig To: Jens Axboe , Josef Bacik , Minchan Kim , Nitin Gupta Cc: Tetsuo Handa , Jan Kara , "Darrick J . Wong" , Ming Lei , linux-block@vger.kernel.org, nbd@other.debian.org Subject: [PATCH 10/13] loop: only freeze the queue in __loop_clr_fd when needed Date: Thu, 24 Mar 2022 08:51:16 +0100 Message-Id: <20220324075119.1556334-11-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220324075119.1556334-1-hch@lst.de> References: <20220324075119.1556334-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 c57acbcf9be6a..a5dd259958ee2 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); -- 2.30.2