From patchwork Tue Mar 8 11:29:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8532191 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DA3E5C0553 for ; Tue, 8 Mar 2016 11:30:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0AAE20165 for ; Tue, 8 Mar 2016 11:30:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77C7D201D3 for ; Tue, 8 Mar 2016 11:30:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932850AbcCHLa3 (ORCPT ); Tue, 8 Mar 2016 06:30:29 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34428 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933060AbcCHLaX (ORCPT ); Tue, 8 Mar 2016 06:30:23 -0500 Received: by mail-pf0-f196.google.com with SMTP id 184so1063632pff.1; Tue, 08 Mar 2016 03:30:23 -0800 (PST) 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=snwcOOUwWb7Kf0tp5xlkFE7QI3b067ZD1D5WhNQgzwI=; b=Q5oqLhlZwLGthc2TSyXIMeAz3osCGAGBYZfqc2bwGCCOSDcjzxvMlXh4vNwc7pa64V /G7XmW2cGjE6eOcK/be0pYbfTayM49YUzUJr4mYLRIvFyV2pOaLX8Y+TBDyb3Wn4cvsT G/L+Y3lz4jt4Dgz6yNZ+gI2vNOBOFoUlpoxa0CdAFJjs29tnMeXTHH9sEAPQCXo1tKHz JRQaQmY1v7JwDIsD6rFJoriqeAytCO2mMdLFfEtwuOTcL+MXqQDTNJjdlF7WEq2kHrGW A860LqW2G5gUI4tcikHPsMpWlP/Y4zQi5HNtAZ4mg99Zsk2bNkr14N62Jojo+av7OUGA /bWg== X-Gm-Message-State: AD7BkJLQDdACL+dtQlhTj+GX/6+KfMmVXubup6Ssv/3R/skOpD1QLeGj1OLb80Y/Z2CbnQ== X-Received: by 10.98.19.215 with SMTP id 84mr41030754pft.22.1457436622580; Tue, 08 Mar 2016 03:30:22 -0800 (PST) Received: from localhost ([116.251.212.171]) by smtp.gmail.com with ESMTPSA id yh5sm4415115pab.13.2016.03.08.03.30.21 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 08 Mar 2016 03:30:21 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Al Viro , Anton Altaparmakov , Ming Lei Subject: [PATCH 1/4] block: move bvec iterator into include/linux/bvec_iter.h Date: Tue, 8 Mar 2016 19:29:43 +0800 Message-Id: <1457436586-26833-2-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457436586-26833-1-git-send-email-ming.lei@canonical.com> References: <1457436586-26833-1-git-send-email-ming.lei@canonical.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP bvec iterator helpers should be used to implement iterate_bvec():lib/iov_iter.c too, and this patch moves them into the new header, so that we can keep bvec iterator header out of CONFIG_BLOCK. Then we can avoid to reinvent the wheel in iterate_bvec(). Signed-off-by: Ming Lei --- include/linux/bio.h | 55 +-------------------------------- include/linux/bvec_iter.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 54 deletions(-) create mode 100644 include/linux/bvec_iter.h diff --git a/include/linux/bio.h b/include/linux/bio.h index cb68888..1e7248f 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -31,6 +31,7 @@ /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */ #include +#include #define BIO_DEBUG @@ -40,10 +41,6 @@ #define BIO_BUG_ON #endif -#define BIO_MAX_PAGES 256 -#define BIO_MAX_SIZE (BIO_MAX_PAGES << PAGE_CACHE_SHIFT) -#define BIO_MAX_SECTORS (BIO_MAX_SIZE >> 9) - /* * upper 16 bits of bi_rw define the io priority of this bio */ @@ -57,29 +54,6 @@ (bio)->bi_rw |= ((unsigned long) (prio) << BIO_PRIO_SHIFT); \ } while (0) -/* - * various member access, note that bio_data should of course not be used - * on highmem page vectors - */ -#define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx]) - -#define bvec_iter_page(bvec, iter) \ - (__bvec_iter_bvec((bvec), (iter))->bv_page) - -#define bvec_iter_len(bvec, iter) \ - min((iter).bi_size, \ - __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done) - -#define bvec_iter_offset(bvec, iter) \ - (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done) - -#define bvec_iter_bvec(bvec, iter) \ -((struct bio_vec) { \ - .bv_page = bvec_iter_page((bvec), (iter)), \ - .bv_len = bvec_iter_len((bvec), (iter)), \ - .bv_offset = bvec_iter_offset((bvec), (iter)), \ -}) - #define bio_iter_iovec(bio, iter) \ bvec_iter_bvec((bio)->bi_io_vec, (iter)) @@ -193,33 +167,6 @@ static inline void *bio_data(struct bio *bio) #define bio_for_each_segment_all(bvl, bio, i) \ for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) -static inline void bvec_iter_advance(struct bio_vec *bv, struct bvec_iter *iter, - unsigned bytes) -{ - WARN_ONCE(bytes > iter->bi_size, - "Attempted to advance past end of bvec iter\n"); - - while (bytes) { - unsigned len = min(bytes, bvec_iter_len(bv, *iter)); - - bytes -= len; - iter->bi_size -= len; - iter->bi_bvec_done += len; - - if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { - iter->bi_bvec_done = 0; - iter->bi_idx++; - } - } -} - -#define for_each_bvec(bvl, bio_vec, iter, start) \ - for (iter = (start); \ - (iter).bi_size && \ - ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \ - bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len)) - - static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, unsigned bytes) { diff --git a/include/linux/bvec_iter.h b/include/linux/bvec_iter.h new file mode 100644 index 0000000..07c1ffc --- /dev/null +++ b/include/linux/bvec_iter.h @@ -0,0 +1,78 @@ +/* + * bvec iterator + * + * Copyright (C) 2016 Ming Lei + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public Licens + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111- + */ +#ifndef __LINUX_BVEC_ITER_H +#define __LINUX_BVEC_ITER_H + +#include + +#define BIO_MAX_PAGES 256 +#define BIO_MAX_SIZE (BIO_MAX_PAGES << PAGE_CACHE_SHIFT) +#define BIO_MAX_SECTORS (BIO_MAX_SIZE >> 9) + +/* + * various member access, note that bio_data should of course not be used + * on highmem page vectors + */ +#define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx]) + +#define bvec_iter_page(bvec, iter) \ + (__bvec_iter_bvec((bvec), (iter))->bv_page) + +#define bvec_iter_len(bvec, iter) \ + min((iter).bi_size, \ + __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done) + +#define bvec_iter_offset(bvec, iter) \ + (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done) + +#define bvec_iter_bvec(bvec, iter) \ +((struct bio_vec) { \ + .bv_page = bvec_iter_page((bvec), (iter)), \ + .bv_len = bvec_iter_len((bvec), (iter)), \ + .bv_offset = bvec_iter_offset((bvec), (iter)), \ +}) + +static inline void bvec_iter_advance(struct bio_vec *bv, struct bvec_iter *iter, + unsigned bytes) +{ + WARN_ONCE(bytes > iter->bi_size, + "Attempted to advance past end of bvec iter\n"); + + while (bytes) { + unsigned len = min(bytes, bvec_iter_len(bv, *iter)); + + bytes -= len; + iter->bi_size -= len; + iter->bi_bvec_done += len; + + if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { + iter->bi_bvec_done = 0; + iter->bi_idx++; + } + } +} + +#define for_each_bvec(bvl, bio_vec, iter, start) \ + for (iter = (start); \ + (iter).bi_size && \ + ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \ + bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len)) + +#endif /* __LINUX_BVEC_ITER_H */