From patchwork Wed Jul 12 08:29:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9836231 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 5E9AC60363 for ; Wed, 12 Jul 2017 08:29:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5165E284FE for ; Wed, 12 Jul 2017 08:29:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46558285F2; Wed, 12 Jul 2017 08:29:30 +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 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 9F1CF284FE for ; Wed, 12 Jul 2017 08:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933791AbdGLI32 (ORCPT ); Wed, 12 Jul 2017 04:29:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46142 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933243AbdGLI30 (ORCPT ); Wed, 12 Jul 2017 04:29:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03E10C0467D6; Wed, 12 Jul 2017 08:29:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 03E10C0467D6 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ming.lei@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 03E10C0467D6 Received: from localhost (ovpn-12-138.pek2.redhat.com [10.72.12.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id 546A917AE8; Wed, 12 Jul 2017 08:29:15 +0000 (UTC) From: Ming Lei To: Shaohua Li , linux-raid@vger.kernel.org Cc: NeilBrown , linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Ming Lei Subject: [PATCH 2/2] md: raid1/raid10: initialize bvec table via bio_add_page() Date: Wed, 12 Jul 2017 16:29:12 +0800 Message-Id: <20170712082912.491-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Jul 2017 08:29:26 +0000 (UTC) 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 We will support multipage bvec soon, so initialize bvec table using the standardy way instead of writing the talbe directly. Otherwise it won't work any more once multipage bvec is enabled. Acked-by: Guoqing Jiang Signed-off-by: Ming Lei --- drivers/md/md.c | 21 +++++++++++++++++++++ drivers/md/md.h | 3 +++ drivers/md/raid1.c | 16 ++-------------- drivers/md/raid10.c | 4 ++-- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 8cdca0296749..cc8dcd928dde 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -9130,6 +9130,27 @@ void md_reload_sb(struct mddev *mddev, int nr) } EXPORT_SYMBOL(md_reload_sb); +/* generally called after bio_reset() for reseting bvec */ +void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp, + int size) +{ + int idx = 0; + + /* initialize bvec table again */ + do { + struct page *page = resync_fetch_page(rp, idx); + int len = min_t(int, size, PAGE_SIZE); + + /* + * won't fail because the vec table is big + * enough to hold all these pages + */ + bio_add_page(bio, page, len, 0); + size -= len; + } while (idx++ < RESYNC_PAGES && size > 0); +} +EXPORT_SYMBOL(md_bio_reset_resync_pages); + #ifndef MODULE /* diff --git a/drivers/md/md.h b/drivers/md/md.h index 2c780aa8d07f..efb32ce7a2f1 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -782,4 +782,7 @@ static inline struct page *resync_fetch_page(struct resync_pages *rp, return NULL; return rp->pages[idx]; } + +void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp, + int size); #endif /* _MD_MD_H */ diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 7901ddc3362f..5dc3fda2fdf7 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -2085,10 +2085,7 @@ static void process_checks(struct r1bio *r1_bio) /* Fix variable parts of all bios */ vcnt = (r1_bio->sectors + PAGE_SIZE / 512 - 1) >> (PAGE_SHIFT - 9); for (i = 0; i < conf->raid_disks * 2; i++) { - int j; - int size; blk_status_t status; - struct bio_vec *bi; struct bio *b = r1_bio->bios[i]; struct resync_pages *rp = get_resync_pages(b); if (b->bi_end_io != end_sync_read) @@ -2097,8 +2094,6 @@ static void process_checks(struct r1bio *r1_bio) status = b->bi_status; bio_reset(b); b->bi_status = status; - b->bi_vcnt = vcnt; - b->bi_iter.bi_size = r1_bio->sectors << 9; b->bi_iter.bi_sector = r1_bio->sector + conf->mirrors[i].rdev->data_offset; b->bi_bdev = conf->mirrors[i].rdev->bdev; @@ -2106,15 +2101,8 @@ static void process_checks(struct r1bio *r1_bio) rp->raid_bio = r1_bio; b->bi_private = rp; - size = b->bi_iter.bi_size; - bio_for_each_segment_all(bi, b, j) { - bi->bv_offset = 0; - if (size > PAGE_SIZE) - bi->bv_len = PAGE_SIZE; - else - bi->bv_len = size; - size -= PAGE_SIZE; - } + /* initialize bvec table again */ + md_bio_reset_resync_pages(b, rp, r1_bio->sectors << 9); } for (primary = 0; primary < conf->raid_disks * 2; primary++) if (r1_bio->bios[primary]->bi_end_io == end_sync_read && diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index e594ca610f27..cb8e803cd1c2 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -2086,8 +2086,8 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio) rp = get_resync_pages(tbio); bio_reset(tbio); - tbio->bi_vcnt = vcnt; - tbio->bi_iter.bi_size = fbio->bi_iter.bi_size; + md_bio_reset_resync_pages(tbio, rp, fbio->bi_iter.bi_size); + rp->raid_bio = r10_bio; tbio->bi_private = rp; tbio->bi_iter.bi_sector = r10_bio->devs[i].addr;