From patchwork Fri Nov 11 12:05:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9422897 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 1568560233 for ; Fri, 11 Nov 2016 12:08:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06EAC299EE for ; Fri, 11 Nov 2016 12:08:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC82529A14; Fri, 11 Nov 2016 12:08:44 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 D31D6299EE for ; Fri, 11 Nov 2016 12:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932845AbcKKMG5 (ORCPT ); Fri, 11 Nov 2016 07:06:57 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33273 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932818AbcKKMGz (ORCPT ); Fri, 11 Nov 2016 07:06:55 -0500 Received: by mail-pf0-f196.google.com with SMTP id 144so2418549pfv.0; Fri, 11 Nov 2016 04:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L3ZAa35RkWTeSJIhSYW4W19+gzvPYhHKHt+lmMA7DJ4=; b=SGxumdv1yZKjW0rcouwtSfZ0ynGPaY7z0VK56vpktX2aWADnRdJVfajZxxtmATflnY TOduoZ4QGU5T2aA2vWiuJhbaBmHZe5iwc4SMjtTDcrfrwuuijhthPD8+QjszbVHBPV0p I/HkWvBvddoMsJ91ToAqH1iYn0KAknfvPKX9T8imCFeXAuEDebFURCH1P1YN75ktKAQt p9WUNBq4vq1IANlpdSauRUL0aD1jXIuiP/HMUkixAa269+rKVEp5fw8N0+8XyI2/3FFw 59Su1Cz4qinqoT4iq9EXX+4gCsuRbo340W5CaCEm7/dvSUSktx0sZDwMDu2Cqc1VvwU7 gFqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L3ZAa35RkWTeSJIhSYW4W19+gzvPYhHKHt+lmMA7DJ4=; b=AJVFYPk0sKRsDKnRj5aKMqut/+QeefYZlHKiLvCgUdtbeV/RMFVMlYKZQ/v1rOSHES MAsWxWhlr9Pk8SKmTaI/7w3sM8BReAOGLh+kRVyS+zup/MukDSjBOknsyzPtMG6seLpu S9dz3Hc5ne52AyyZ3W5p8pJCr2ndOUbJO19uj5GcMmgfEkvmTJaId5a0FRCnFcf1pHW6 L1Ro8sAR9vt10KZ5vs5CPnDEYCmpjB7LnxGFprB3L6HT4H3B7wGca1mDOnKnEJroU8sT bBKkAsKvow5IgbnfUb8hLjyT69ZM7eDGWR4WKW3AE5qLEhvPJc3q4bA7ls5KtBOjxisL 4MNw== X-Gm-Message-State: ABUngvczSJX4THmHCPHgKVJWHOs9IE7FwOShkjqp7cR2T8S1psEoMgahtoLHS+pocXfaKQ== X-Received: by 10.99.8.133 with SMTP id 127mr4359622pgi.76.1478866014712; Fri, 11 Nov 2016 04:06:54 -0800 (PST) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id j68sm14691193pfk.95.2016.11.11.04.06.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 04:06:54 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , Ming Lei , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com (maintainer:DEVICE-MAPPER (LVM)), Shaohua Li , linux-raid@vger.kernel.org (open list:SOFTWARE RAID (Multiple Disks) SUPPORT) Subject: [PATCH 07/12] dm: use bvec iterator helpers to implement .get_page and .next_page Date: Fri, 11 Nov 2016 20:05:35 +0800 Message-Id: <1478865957-25252-8-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478865957-25252-1-git-send-email-tom.leiming@gmail.com> References: <1478865957-25252-1-git-send-email-tom.leiming@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Firstly we have mature bvec/bio iterator helper for iterate each page in one bio, not necessary to reinvent a wheel to do that. Secondly the coming multipage bvecs requires this patch. Also add comments about the direct access to bvec table. Signed-off-by: Ming Lei --- drivers/md/dm-io.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c index 0bf1a12e35fe..2ef573c220fc 100644 --- a/drivers/md/dm-io.c +++ b/drivers/md/dm-io.c @@ -162,7 +162,10 @@ struct dpages { struct page **p, unsigned long *len, unsigned *offset); void (*next_page)(struct dpages *dp); - unsigned context_u; + union { + unsigned context_u; + struct bvec_iter context_bi; + }; void *context_ptr; void *vma_invalidate_address; @@ -204,25 +207,36 @@ static void list_dp_init(struct dpages *dp, struct page_list *pl, unsigned offse static void bio_get_page(struct dpages *dp, struct page **p, unsigned long *len, unsigned *offset) { - struct bio_vec *bvec = dp->context_ptr; - *p = bvec->bv_page; - *len = bvec->bv_len - dp->context_u; - *offset = bvec->bv_offset + dp->context_u; + struct bio_vec bv = bvec_iter_bvec((struct bio_vec *)dp->context_ptr, + dp->context_bi); + + *p = bv.bv_page; + *len = bv.bv_len; + *offset = bv.bv_offset; + + /* avoid to figure out it in bio_next_page() again */ + dp->context_bi.bi_sector = (sector_t)bv.bv_len; } static void bio_next_page(struct dpages *dp) { - struct bio_vec *bvec = dp->context_ptr; - dp->context_ptr = bvec + 1; - dp->context_u = 0; + unsigned int len = (unsigned int)dp->context_bi.bi_sector; + + bvec_iter_advance((struct bio_vec *)dp->context_ptr, + &dp->context_bi, len); } static void bio_dp_init(struct dpages *dp, struct bio *bio) { dp->get_page = bio_get_page; dp->next_page = bio_next_page; - dp->context_ptr = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); - dp->context_u = bio->bi_iter.bi_bvec_done; + + /* + * We just use bvec iterator to retrieve pages, so it is ok to + * access the bvec table directly here + */ + dp->context_ptr = bio->bi_io_vec; + dp->context_bi = bio->bi_iter; } /*