From patchwork Tue May 16 09:39:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 9728693 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 8307C602B4 for ; Tue, 16 May 2017 09:33:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71F6028A0E for ; Tue, 16 May 2017 09:33:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 664B428A0D; Tue, 16 May 2017 09:33:38 +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, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 0FD9B28A0D for ; Tue, 16 May 2017 09:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752048AbdEPJdf (ORCPT ); Tue, 16 May 2017 05:33:35 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:22685 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751656AbdEPJdd (ORCPT ); Tue, 16 May 2017 05:33:33 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v4G9XTZB005702 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 May 2017 09:33:30 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v4G9XToY016707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 May 2017 09:33:29 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v4G9XTP6028132; Tue, 16 May 2017 09:33:29 GMT Received: from tp.sg.oracle.com (/10.186.101.75) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 16 May 2017 02:33:28 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org, linux-block@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 1/2] block: Introduce blkdev_issue_flush_no_wait() Date: Tue, 16 May 2017 17:39:13 +0800 Message-Id: <20170516093914.16035-2-anand.jain@oracle.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170516093914.16035-1-anand.jain@oracle.com> References: <20170516093914.16035-1-anand.jain@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP blkdev_issue_flush() is a blocking function and returns only after the flush bio is completed, so a module handling more than one device can't issue flush for all the devices unless it uses worker thread. This patch adds a new function blkdev_issue_flush_no_wait(), which uses submit_bio() instead of submit_bio_wait(), and accepts the completion function and data from the caller. Signed-off-by: Anand Jain --- block/blk-flush.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 8 ++++++++ 2 files changed, 55 insertions(+) diff --git a/block/blk-flush.c b/block/blk-flush.c index c4e0880b54bb..16b9c61f4cd3 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -488,6 +488,53 @@ void blk_insert_flush(struct request *rq) blk_flush_complete_seq(rq, fq, REQ_FSEQ_ACTIONS & ~policy, 0); } +/* + * blkdev_issue_flush_no_wait - Issue a flush for the given block device + * @bdev: blockdev to issue flush for + * @gfp_mask: memory allocation flags (for bio_alloc) + * @endio_fn: completion function for the flush bio + * @data: flush bio private data + * + * Description: + * Issue a flush for the block device in question. Caller must provide + * the completion function and the private data, to be called when the + * issued flush bio completes. + */ +int blkdev_issue_flush_no_wait(struct block_device *bdev, gfp_t gfp_mask, + bio_end_io_t *endio_fn, void *data) +{ + struct request_queue *q; + struct bio *bio; + + if (bdev->bd_disk == NULL) + return -ENXIO; + + q = bdev_get_queue(bdev); + if (!q) + return -ENXIO; + + /* + * some block devices may not have their queue correctly set up here + * (e.g. loop device without a backing file) and so issuing a flush + * here will panic. Ensure there is a request function before issuing + * the flush. + */ + if (!q->make_request_fn) + return -ENXIO; + + bio = bio_alloc(gfp_mask, 0); + bio->bi_bdev = bdev; + bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC; + bio->bi_end_io = endio_fn; + bio->bi_private = data; + + init_completion(data); + submit_bio(bio); + + return 0; +} +EXPORT_SYMBOL(blkdev_issue_flush_no_wait); + /** * blkdev_issue_flush - queue a flush * @bdev: blockdev to issue flush for diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index b5d1e27631ee..5d2b62239251 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1322,6 +1322,8 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, } extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *); +extern int blkdev_issue_flush_no_wait(struct block_device *bdev, + gfp_t gfp_mask, bio_end_io_t *endio_fn, void *data); extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct page *page); @@ -1994,6 +1996,12 @@ static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask, return 0; } +static inline int blkdev_issue_flush_no_wait(struct block_device *bdev, + gfp_t gfp_mask, bio_end_io_t *endio_fn, void *data) +{ + return 0; +} + #endif /* CONFIG_BLOCK */ #endif