Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp386230imm; Thu, 26 Jul 2018 05:30:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeicwGfbBr+SsLxj7wUcy4tjvGyskyRFjnK6ZUWEvx8QI8Lv4gNO9Em7PqdzxEIZxz1/2qt X-Received: by 2002:a63:1a49:: with SMTP id a9-v6mr1786136pgm.423.1532608210758; Thu, 26 Jul 2018 05:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532608210; cv=none; d=google.com; s=arc-20160816; b=DdVgirCfZo8zqOHoQKXj9g+scndxEuzjDQiWSAxsaTts684MMCNehQSUiebESVvcgf 85dWoBKyRsnBJUmpJnx9B2wi6VFNLTs5aBMD06oqSkmv/AYpSzVD8oSinMW2UcpMXK0s IGPDgdJRMl/zS9xfb/4MVl+N4N5mGEdZy274C5frXVv8lauavVbFN/Qsv73kiEQBzLpI Mwo7/wrUfeDiBC+BYz7wjyhG+IZCrXTInJRFncl4uoZwmCmJMV0wr4KHYDgpqhAzhi8A UvAuFsk4TClB0k4mFB5BawWhC3s2/nY0zo72Y7GwCYrNZW4//nZ73lVwrPMvFbebjtVl Zgfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=J8qRH57Z/5XBZxvD9pQ6ZDxG52aHfASqQ/DFL3OdB58=; b=tYbo+0UgHzziGwa1qcRNrSavYx1fctdZkpMrO05pAeOl59IorUPObMMUoYQyMEfOy6 SwsMH+xpdchJb/UrQ09xFOm4Wa1HMkK3Oh/i5O4G2B1ZF7baKeNXnRgO45V1kMS84/nW yTViYxmyn9csysSeiudSpeCRp6PSA8H/nCbmrR65BAZ5RRLFJ4gLH/cDhVWaNqjj2cco 2p7VGE/BTZHdbgLwwl60Kdew0m/HPyqpB9fEC9vPeNNM02JB3Jao5kUjzzJ2EBN/LjfP fbA3nZ1XGrGh/VkfRWxVClVjVwrUVEkQLkeiXL51n8Md+kwvOMCjTt2Rgn8GCzvwuO13 aC/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w25-v6si1264750pga.58.2018.07.26.05.29.55; Thu, 26 Jul 2018 05:30:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730697AbeGZNpF (ORCPT + 99 others); Thu, 26 Jul 2018 09:45:05 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10134 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730178AbeGZNnr (ORCPT ); Thu, 26 Jul 2018 09:43:47 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A7E8F2F7EA116; Thu, 26 Jul 2018 20:27:06 +0800 (CST) Received: from szvp000100637.huawei.com (10.162.55.131) by smtp.huawei.com (10.3.19.208) with Microsoft SMTP Server (TLS) id 14.3.382.0; Thu, 26 Jul 2018 20:27:01 +0800 From: Gao Xiang To: Greg Kroah-Hartman , CC: , , , , , , , , Gao Xiang Subject: [PATCH 17/25] staging: erofs: globalize prepare_bio and __submit_bio Date: Thu, 26 Jul 2018 20:22:00 +0800 Message-ID: <1532607728-103372-18-git-send-email-gaoxiang25@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532607728-103372-1-git-send-email-gaoxiang25@huawei.com> References: <1527764767-22190-1-git-send-email-gaoxiang25@huawei.com> <1532607728-103372-1-git-send-email-gaoxiang25@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.162.55.131] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The unzip subsystem also uses these functions, let's export them to internal.h. Signed-off-by: Gao Xiang --- drivers/staging/erofs/data.c | 34 +++++++++------------------------- drivers/staging/erofs/internal.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c index 163bfe6..ac263a1 100644 --- a/drivers/staging/erofs/data.c +++ b/drivers/staging/erofs/data.c @@ -38,26 +38,6 @@ static inline void read_endio(struct bio *bio) bio_put(bio); } -static void __submit_bio(struct bio *bio, unsigned op, unsigned op_flags) -{ - bio_set_op_attrs(bio, op, op_flags); - submit_bio(bio); -} - -static struct bio *prepare_bio(struct super_block *sb, - erofs_blk_t blkaddr, unsigned nr_pages) -{ - struct bio *bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, nr_pages); - - BUG_ON(bio == NULL); - - bio->bi_end_io = read_endio; - bio_set_dev(bio, sb->s_bdev); - bio->bi_iter.bi_sector = blkaddr << LOG_SECTORS_PER_BLOCK; - - return bio; -} - /* prio -- true is used for dir */ struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr, bool prio) @@ -80,7 +60,7 @@ struct page *erofs_get_meta_page(struct super_block *sb, struct bio *bio; int err; - bio = prepare_bio(sb, blkaddr, 1); + bio = prepare_bio(sb, blkaddr, 1, read_endio); err = bio_add_page(bio, page, PAGE_SIZE, 0); BUG_ON(err != PAGE_SIZE); @@ -236,6 +216,8 @@ static inline struct bio *erofs_read_raw_page( struct erofs_map_blocks map = { .m_la = blknr_to_addr(current_block), }; + erofs_blk_t blknr; + unsigned blkoff; err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); if (unlikely(err)) @@ -253,6 +235,9 @@ static inline struct bio *erofs_read_raw_page( /* for RAW access mode, m_plen must be equal to m_llen */ BUG_ON(map.m_plen != map.m_llen); + blknr = erofs_blknr(map.m_pa); + blkoff = erofs_blkoff(map.m_pa); + /* deal with inline page */ if (map.m_flags & EROFS_MAP_META) { void *vsrc, *vto; @@ -260,8 +245,7 @@ static inline struct bio *erofs_read_raw_page( BUG_ON(map.m_plen > PAGE_SIZE); - ipage = erofs_get_meta_page(inode->i_sb, - erofs_blknr(map.m_pa), 0); + ipage = erofs_get_meta_page(inode->i_sb, blknr, 0); if (IS_ERR(ipage)) { err = PTR_ERR(ipage); @@ -270,7 +254,7 @@ static inline struct bio *erofs_read_raw_page( vsrc = kmap_atomic(ipage); vto = kmap_atomic(page); - memcpy(vto, vsrc + erofs_blkoff(map.m_pa), map.m_plen); + memcpy(vto, vsrc + blkoff, map.m_plen); memset(vto + map.m_plen, 0, PAGE_SIZE - map.m_plen); kunmap_atomic(vto); kunmap_atomic(vsrc); @@ -294,7 +278,7 @@ static inline struct bio *erofs_read_raw_page( if (nblocks > BIO_MAX_PAGES) nblocks = BIO_MAX_PAGES; - bio = prepare_bio(inode->i_sb, erofs_blknr(map.m_pa), nblocks); + bio = prepare_bio(inode->i_sb, blknr, nblocks, read_endio); } err = bio_add_page(bio, page, PAGE_SIZE, 0); diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h index 210ab6c..6a0f045 100644 --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -285,6 +285,39 @@ struct erofs_map_blocks { #define EROFS_GET_BLOCKS_RAW 0x0001 /* data.c */ +static inline struct bio *prepare_bio( + struct super_block *sb, + erofs_blk_t blkaddr, unsigned nr_pages, + bio_end_io_t endio) +{ + gfp_t gfp = GFP_NOIO; + struct bio *bio = bio_alloc(gfp, nr_pages); + + if (unlikely(bio == NULL) && + (current->flags & PF_MEMALLOC)) { + do { + nr_pages /= 2; + if (unlikely(!nr_pages)) { + bio = bio_alloc(gfp | __GFP_NOFAIL, 1); + BUG_ON(bio == NULL); + break; + } + bio = bio_alloc(gfp, nr_pages); + } while (bio == NULL); + } + + bio->bi_end_io = endio; + bio_set_dev(bio, sb->s_bdev); + bio->bi_iter.bi_sector = blkaddr << LOG_SECTORS_PER_BLOCK; + return bio; +} + +static inline void __submit_bio(struct bio *bio, unsigned op, unsigned op_flags) +{ + bio_set_op_attrs(bio, op, op_flags); + submit_bio(bio); +} + extern struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr, bool prio); extern int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int); -- 1.9.1