From patchwork Tue Apr 5 11:56:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8750081 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 B1EADC0553 for ; Tue, 5 Apr 2016 11:58:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C88C2203AB for ; Tue, 5 Apr 2016 11:58:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E91DD203A4 for ; Tue, 5 Apr 2016 11:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757729AbcDEL63 (ORCPT ); Tue, 5 Apr 2016 07:58:29 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34381 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755803AbcDEL61 (ORCPT ); Tue, 5 Apr 2016 07:58:27 -0400 Received: by mail-pf0-f196.google.com with SMTP id d184so1168653pfc.1; Tue, 05 Apr 2016 04:58:26 -0700 (PDT) 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=/erId7OvK57/CxIo1yPnoNWcbkOBzg542H54uBtOw4w=; b=VeHpzhisxBlZ3+Csbl+QrQXe88BPajOvJi7W6+RWlpBBT6xYJMGqsm5ztxR/0/ZdSX 5DpnSr0HPO2Z7MRTCLTJs3Kwf5oQ9eFK6htLP+JByA+GPqryNGD3xMcVRylkmxeVvmDO snr+NVD3GR+PIWRnx3dY3102p35Jss2fvbZE9PjxAXNZptrkOtWSv7gplTjgCE1V3Cb0 chCkXVYMdWNAuR3tmF6G5A08Jtno0d10e74vEOKYgEdTZE5tIKa7GONNoxuhk4GfMw8P d2DW7Lam0t1AfYpsCiIdTo0yTNFWtU3Y4FFhorBMhQNZjZiUmQhiT+q9vLnsTi/ME85k b5mg== 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=/erId7OvK57/CxIo1yPnoNWcbkOBzg542H54uBtOw4w=; b=Z9fdyTlw7Rho/qDjEczc0ej0JX8Iy4u8+banMebGpVajlSMOVc5fVWt0KGUknPzYsl d1GgiI32qWYDuvzamkLyB4n0lIuPxt6YdlOCr/p6Vfux6f9CcSoPT4390p1BAO3ylutW MEdUOHcyqb/vsF1GBgjIBXQ2bvYS64uu1zEiKqTKXuKOVRTwnKgN7SYuuECkkZtxSazd iXWGH+bWl5Yj8hcSR6OODeqXEbv5ZNI3v4cF8urDN9+FNKKQAuwQnMtodvrE1k9d1MSu BD/ZsLeitdWioMhHS0uyKfNC6ATgw5L/IXss5DXO9+As6zdAKRtGeo3DXptDf02fxVKG h7lw== X-Gm-Message-State: AD7BkJJLJEyhiVKZBHJVypJ7zZzaw2YnwLLXATNZsUl8owp45hODyb8rCCL+zmnZZ/N6eQ== X-Received: by 10.98.18.212 with SMTP id 81mr29175818pfs.104.1459857506473; Tue, 05 Apr 2016 04:58:26 -0700 (PDT) Received: from localhost (56.34.213.162.lcy-01.canonistack.canonical.com. [162.213.34.56]) by smtp.gmail.com with ESMTPSA id p8sm30856675pfa.71.2016.04.05.04.58.23 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 05 Apr 2016 04:58:25 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Boaz Harrosh , Ming Lei , Jan Kara , Kent Overstreet , Keith Busch , Tejun Heo , Mike Snitzer Subject: [PATCH 01/27] block: bio: introduce 4 helpers for cleanup Date: Tue, 5 Apr 2016 19:56:46 +0800 Message-Id: <1459857443-20611-2-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459857443-20611-1-git-send-email-tom.leiming@gmail.com> References: <1459857443-20611-1-git-send-email-tom.leiming@gmail.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=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Some drivers access bio->bi_vcnt and bio->bi_io_vec directly, firstly it isn't a good practice, secondly it may cause trouble for converting to multipage bvecs. So this patches introduces 4 helpers for cleaning up this kind of usage. Both bio_pages() and bio_is_full() can be convertd to support multipage bvecs easily. For bio_get_base_vec() and bio_set_vec_table(), they are often used during initializing a new bio or in case of single bvec bio. With the two new helpers, it becomes easy to audit access of .bi_io_vec and .bi_vcnt. Signed-off-by: Ming Lei --- include/linux/bio.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 88bc64f..2179bc4 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -310,6 +310,34 @@ static inline void bio_clear_flag(struct bio *bio, unsigned int bit) bio->bi_flags &= ~(1U << bit); } +static inline bool bio_is_full(struct bio *bio) +{ + WARN_ONCE(bio_flagged(bio, BIO_CLONED), "cloned bio"); + + return bio->bi_vcnt >= bio->bi_max_vecs; +} + +static inline struct bio_vec *bio_get_base_vec(struct bio *bio) +{ + return __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); +} + +/* This helper should be used for setting bvec table on a new bio */ +static inline void bio_set_vec_table(struct bio *bio, struct bio_vec *table, + unsigned max_vecs) +{ + bio->bi_io_vec = table; + bio->bi_max_vecs = max_vecs; +} + +/* For singlepage bvecs, one segment includes one page */ +static inline unsigned bio_pages(struct bio *bio) +{ + if (!bio_flagged(bio, BIO_CLONED)) + return bio->bi_vcnt; + return bio_segments(bio); +} + static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv) { *bv = bio_iovec(bio);