From patchwork Wed May 10 15:20:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Monakhov X-Patchwork-Id: 9720057 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 2A8F360236 for ; Wed, 10 May 2017 15:21:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B8F528608 for ; Wed, 10 May 2017 15:21:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ED8228610; Wed, 10 May 2017 15:21:29 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 AE72D28608 for ; Wed, 10 May 2017 15:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753586AbdEJPVN (ORCPT ); Wed, 10 May 2017 11:21:13 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35752 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753533AbdEJPVK (ORCPT ); Wed, 10 May 2017 11:21:10 -0400 Received: by mail-wm0-f68.google.com with SMTP id v4so535864wmb.2; Wed, 10 May 2017 08:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=I2OFyJElb5hg34QUT250zjVY8Z3y7OIwER2k2FR69GQ=; b=eANQjc9SD6dktFwk6fSyK6SL77lOxQWLEDXtLkBviXyywncZoFE6LY9OcVJOdNOLLt vneyzFYKPY/tkkbe047snAlZ7pTN7Uen3jiyeYVw2ORgv/IQXiOfPyq4TRgJfOZTtOLu qU2JR2TE8shy/LJ4umZXxOB5AyTA3gSbkaFf5qryAPRZvD78knCylSCYO85K/y6FcMd2 2htw3g4kKbx6TvjMCF16vmntD+gCFCqP7B2f2+JaEeCKwwg/D+YjK5TfMwvhpm5aPkyD 4gmuhVkiSnkEjA+AcZaNOSmluMU9WY9rsasVU9ZswipyibAcIz6BWjtxRWCkPxpyM7Qc xnDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=I2OFyJElb5hg34QUT250zjVY8Z3y7OIwER2k2FR69GQ=; b=HnkU6aF6+72q1rkQ7u/J05q8P6gWiYQvqjHfRnugQPD5v+DapWUn1xDmdnyYsXNaTg /jzdLYB5ZdDRIVu9+q4+fosR6hK+HH+bXU8yd+G/2W6D7SkukHpe4oTBDTeAdoGMySDG V9+GOHSt5XldGqdr6V7TKSlYX603ZIoW6UfqLqSV0P6byM5bMYmmaFcRbKWKB/eAGSpJ Snja7hLvsDdJRHSLCLAwVoDCVnXbl/m7dChT6gDY/b6QpvmjUTGVEKetU8IxImdzCkXu sXlAVDDmJWIAyZHmk+fUIuLuNuFd3TCknrgSLOgnzPETV2SUTnc8Aev9PmQq8tEGAWhY Pwng== X-Gm-Message-State: AODbwcDgA/3XKTaJMiNUiQUgTmW35201c6Lpc/xy9VxwoFHqlUjWK3TD tS+CNUA/DO9qYFokOmo= X-Received: by 10.25.145.78 with SMTP id y14mr3222402lfj.182.1494429667325; Wed, 10 May 2017 08:21:07 -0700 (PDT) Received: from smtp.gmail.com (msk-vpn.virtuozzo.com. [195.214.232.6]) by smtp.gmail.com with ESMTPSA id l7sm367292ljb.44.2017.05.10.08.21.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 May 2017 08:21:06 -0700 (PDT) From: Dmitry Monakhov To: fstests@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Dmitry Monakhov Subject: [PATCH 8/9] bio: add bvec_iter rewind API Date: Wed, 10 May 2017 19:20:51 +0400 Message-Id: <1494429652-9488-9-git-send-email-dmonakhov@openvz.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1494429652-9488-1-git-send-email-dmonakhov@openvz.org> References: <1494429652-9488-1-git-send-email-dmonakhov@openvz.org> 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 Some ->bi_end_io handlers (for example: pi_verify or decrypt handlers) need to know original data vector, but after bio traverse io-stack it may be advanced, splited and relocated many times so it is hard to guess original iterator. Let's add 'bi_done' conter which accounts number of bytes iterator was advanced during it's evolution. Later end_io handler may easily restore original iterator by rewinding iterator to iter->bi_done. Note: this change makes sizeof (struct bvec_iter) multiple to 8 Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Dmitry Monakhov --- include/linux/bio.h | 21 +++++++++++++++++++-- include/linux/bvec.h | 27 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index 643ecba..ab812a0 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -166,9 +166,10 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, { iter->bi_sector += bytes >> 9; - if (bio_no_advance_iter(bio)) + if (bio_no_advance_iter(bio)) { iter->bi_size -= bytes; - else { + iter->bi_done += bytes; + } else { int err; err = bvec_iter_advance(bio->bi_io_vec, iter, bytes); @@ -176,6 +177,22 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, } } +static inline int bio_rewind_iter(struct bio *bio, struct bvec_iter *iter, + unsigned int bytes) +{ + int err = 0; + + iter->bi_sector -= bytes >> 9; + + if (bio_no_advance_iter(bio)) { + iter->bi_size += bytes; + iter->bi_done -= bytes; + } else { + err = bvec_iter_rewind(bio->bi_io_vec, iter, bytes); + } + return err; +} + #define __bio_for_each_segment(bvl, bio, iter, start) \ for (iter = (start); \ (iter).bi_size && \ diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 984a7a8..8cfe4d6 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -40,6 +40,8 @@ struct bvec_iter { unsigned int bi_idx; /* current index into bvl_vec */ + unsigned int bi_done; /* number of bytes completed */ + unsigned int bi_bvec_done; /* number of bytes completed in current bvec */ }; @@ -84,6 +86,7 @@ static inline int bvec_iter_advance(const struct bio_vec *bv, bytes -= len; iter->bi_size -= len; iter->bi_bvec_done += len; + iter->bi_done += len; if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { iter->bi_bvec_done = 0; @@ -93,6 +96,30 @@ static inline int bvec_iter_advance(const struct bio_vec *bv, return 0; } +static inline int bvec_iter_rewind(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned int bytes) +{ + while (bytes) { + unsigned len = min(bytes, iter->bi_bvec_done); + + if (iter->bi_bvec_done == 0) { + if (WARN_ONCE(iter->bi_idx == 0, + "Attempted to rewind iter beyond " + "bvec's boundaries\n")) { + return -EINVAL; + } + iter->bi_idx--; + iter->bi_bvec_done = __bvec_iter_bvec(bv, *iter)->bv_len; + continue; + } + bytes -= len; + iter->bi_size += len; + iter->bi_bvec_done -= len; + } + return 0; +} + #define for_each_bvec(bvl, bio_vec, iter, start) \ for (iter = (start); \ (iter).bi_size && \