From patchwork Thu Aug 24 07:03:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9919145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 147F460327 for ; Thu, 24 Aug 2017 07:03:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 066E828B48 for ; Thu, 24 Aug 2017 07:03:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFB4628B51; Thu, 24 Aug 2017 07:03:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9291628B50 for ; Thu, 24 Aug 2017 07:03:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751259AbdHXHD6 (ORCPT ); Thu, 24 Aug 2017 03:03:58 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:38819 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751183AbdHXHD5 (ORCPT ); Thu, 24 Aug 2017 03:03:57 -0400 Received: by mail-pg0-f54.google.com with SMTP id m133so12452232pga.5 for ; Thu, 24 Aug 2017 00:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ECY2QPVs7mWSPgyZBkqkdJKT5foSa7sp/eWWmrdrHMI=; b=hd5ZyfOr5kwfaih5mSeWYWX0Xj0G9Vg3OzGfn/OlPZz7tRtYrwcjQQqL9winvQag6J 2U04vjh7OHw063VP74O59KoGcKxhrsBIFycGOIUdaXSVbLjtOIUHJjW7/1IgrwHM2Qyf sHPmTj6BwyTJwspt5pkv1H7pIE4v3U9df493MdjwBNtoZ9/QVAWl1ffJFwaonBtwv1Fr 7cBoduJw+lSj2T8FT8vvhl790qVGlVAw0y/jDC+LP1n7bwRDPFYsL3/y1Z+1xgxJ2bpC AxO1SlQfegk3wphiexN/4/Fg1mw9PkVI2JLMwISU772/Ev5sQCT0cD+QPLjkrq8l5mee w6+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ECY2QPVs7mWSPgyZBkqkdJKT5foSa7sp/eWWmrdrHMI=; b=uoNqg81e7uvkxaQ+XapB2ghXlCUPNIxdnuPpHxguxDrGlHuONyCSLASR+D6b9PmOYT Z6yK2RqAud/j19yzk38pUVxVqYhYwNVLrtN+C/6wIPjyumLDRljb+oK06aQ+v0Vkjs51 nov3X6ovS8yjAxzz2ABeAmpaUpBlypdd+0ugi386930on4OFVAX7XJZcPhXeCGqyLLlj VcEK2LVbCc+CAwLCZNCRO7teE5OV/Iey1vem3Bb6VPblhDIPGQWN2Yb2TCulJIRXp+Nc kiE9QjOZg1hKfUGDdDTuGJQrA5lPFf/aWnp9k6CSbWn5KSEYLHp26QHON+4mfURaB6q2 0NMA== X-Gm-Message-State: AHYfb5guGp0f7bEh8wMr/uvullOEkOmKLYw4UbYEzGs55/u8gfWKt1ZE Sfxch2E9yCGTKefYij6Bow== X-Received: by 10.98.158.133 with SMTP id f5mr5463605pfk.295.1503558236724; Thu, 24 Aug 2017 00:03:56 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:90fd]) by smtp.gmail.com with ESMTPSA id g2sm6187459pgu.86.2017.08.24.00.03.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Aug 2017 00:03:56 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: kernel-team@fb.com, Hannes Reinecke , Ming Lei , Karel Zak , Milan Broz Subject: [PATCH 4/4] loop: fold loop_switch() into callers Date: Thu, 24 Aug 2017 00:03:44 -0700 Message-Id: <1f86996dec0b19370c4be16e0ec6399f6c8eeb5a.1503558155.git.osandov@fb.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval The comments here are really outdated, and blk-mq made flushing much simpler, so just fold the two cases into the callers. Signed-off-by: Omar Sandoval Reviewed-by: Hannes Reinecke --- drivers/block/loop.c | 76 ++++++++-------------------------------------------- 1 file changed, 11 insertions(+), 65 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 6b1d932028e3..e60b4ac77577 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -546,72 +546,12 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) } } -struct switch_request { - struct file *file; - struct completion wait; -}; - static inline void loop_update_dio(struct loop_device *lo) { __loop_update_dio(lo, io_is_direct(lo->lo_backing_file) | lo->use_dio); } -/* - * Do the actual switch; called from the BIO completion routine - */ -static void do_loop_switch(struct loop_device *lo, struct switch_request *p) -{ - struct file *file = p->file; - struct file *old_file = lo->lo_backing_file; - struct address_space *mapping; - - /* if no new file, only flush of queued bios requested */ - if (!file) - return; - - mapping = file->f_mapping; - mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); - lo->lo_backing_file = file; - lo->old_gfp_mask = mapping_gfp_mask(mapping); - mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); - loop_update_dio(lo); -} - -/* - * loop_switch performs the hard work of switching a backing store. - * First it needs to flush existing IO, it does this by sending a magic - * BIO down the pipe. The completion of this BIO does the actual switch. - */ -static int loop_switch(struct loop_device *lo, struct file *file) -{ - struct switch_request w; - - w.file = file; - - /* freeze queue and wait for completion of scheduled requests */ - blk_mq_freeze_queue(lo->lo_queue); - - /* do the switch action */ - do_loop_switch(lo, &w); - - /* unfreeze */ - blk_mq_unfreeze_queue(lo->lo_queue); - - return 0; -} - -/* - * Helper to flush the IOs in loop, but keeping loop thread running - */ -static int loop_flush(struct loop_device *lo) -{ - /* loop not yet configured, no running thread, nothing to flush */ - if (lo->lo_state != Lo_bound) - return 0; - return loop_switch(lo, NULL); -} - static void loop_reread_partitions(struct loop_device *lo, struct block_device *bdev) { @@ -676,9 +616,14 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, goto out_putf; /* and ... switch */ - error = loop_switch(lo, file); - if (error) - goto out_putf; + blk_mq_freeze_queue(lo->lo_queue); + mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); + lo->lo_backing_file = file; + lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping); + mapping_set_gfp_mask(file->f_mapping, + lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); + loop_update_dio(lo); + blk_mq_unfreeze_queue(lo->lo_queue); fput(old_file); if (lo->lo_flags & LO_FLAGS_PARTSCAN) @@ -1601,12 +1546,13 @@ static void lo_release(struct gendisk *disk, fmode_t mode) err = loop_clr_fd(lo); if (!err) return; - } else { + } else if (lo->lo_state == Lo_bound) { /* * Otherwise keep thread (if running) and config, * but flush possible ongoing bios in thread. */ - loop_flush(lo); + blk_mq_freeze_queue(lo->lo_queue); + blk_mq_unfreeze_queue(lo->lo_queue); } mutex_unlock(&lo->lo_ctl_mutex);