From patchwork Tue Dec 27 15:56:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9489431 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 9E33362AAD for ; Tue, 27 Dec 2016 16:02:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9059C201BC for ; Tue, 27 Dec 2016 16:02:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84D34223B2; Tue, 27 Dec 2016 16:02: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=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 2037A2094F for ; Tue, 27 Dec 2016 16:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755994AbcL0QCe (ORCPT ); Tue, 27 Dec 2016 11:02:34 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35792 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755684AbcL0QB3 (ORCPT ); Tue, 27 Dec 2016 11:01:29 -0500 Received: by mail-pg0-f67.google.com with SMTP id i5so12789252pgh.2; Tue, 27 Dec 2016 08:00:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cA42o/jk9YszqNTnvPO0t0FOkEwTL/Dg5NhuyeOMsJY=; b=X4dCiNMw+2R7auoyRAHdT/pt7mxzXO51M5KkuEjQ3Gg1e7vXMfjuzoOqk5x8mOzAlp E4KKxbSIn2WZK+at3Lxm52sb9+cTjzx0kb3DeaStOVSW99c6IzAK0xv8KXutYjAS1jyH iq32R3VOPm+Pr/PFWuUTj3Euogv3Xl9RpX8F3uypxyVEAfiIQHltrIadsp+P/McXfnfV V8FVUH0/keeIUlhkZK8wiGCs18LHBxTpDx/NLljunKeO8fgIW7PuU0XXOEBF5JPf6ncf KFh2fvKkEvn15aFj3etrwa6fXb8sdmukH3hqLaGAQj9pjf8IR4mNafvnRVUxzRXT+2zY NoBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cA42o/jk9YszqNTnvPO0t0FOkEwTL/Dg5NhuyeOMsJY=; b=NZTJchdEtmd1QXCdiiGeY4UocLm1o8ngS5GxdJbmhnyhzpzEsYjy3uw9FZzROopkIJ xD0ybUvJFgkD5SAHH9JadDpT5P1ff5A5vLXvNo0YsIqXbNTMYviwvc65yNFMaJV0yVOq e9W2SZ7nVmsdXGHyI2ebNxmM346/1ViD2smjDJRA6s+AtjFVGI6HHqljF4wy17D5KyUK nneTS6PV3EXwKy3Airdt8rdcHhhQ3IcddMhRjXTC5jGbDhmZs4yReUB/YkcaO/Voso4U cZAmuwfUp/S4A3TwgFFXAgij/OwKV3/abis3DGuW4rWBysRY4C6DMKsY31dzyckwcIFc 2f+Q== X-Gm-Message-State: AIkVDXJiDC4JkK9rPALgUZQ7A1vKwOfR4Q3F09O8HzKsfWyGQUGjJijZDPozw0TPCaRFtw== X-Received: by 10.84.210.229 with SMTP id a92mr68000904pli.126.1482854450945; Tue, 27 Dec 2016 08:00:50 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id x90sm90612968pfk.73.2016.12.27.08.00.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Dec 2016 08:00:49 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Mike Christie , Hannes Reinecke , Kent Overstreet , Chaitanya Kulkarni Subject: [PATCH v1 21/54] block: introduce bio_can_convert_to_sp() Date: Tue, 27 Dec 2016 23:56:10 +0800 Message-Id: <1482854250-13481-22-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482854250-13481-1-git-send-email-tom.leiming@gmail.com> References: <1482854250-13481-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-Virus-Scanned: ClamAV using ClamSMTP This patch introduces bio_can_convert_to_sp() for checking if one multipage bio can be converted into one singlepage bio. If not, returns how many sectors we need to split for converting the splitted one into singlepage bio. In the following patches, block bounce and bcache will use the helper. Signed-off-by: Ming Lei --- include/linux/bio.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 0f2859f96468..79079bc5a1be 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -262,6 +262,35 @@ static inline unsigned bio_segments_mp(struct bio *bio) } /* + * This helper checks @bio and see if we can convert it into one + * singlepage bvec based bio. Return true if yes, otherwise false + * is returned. + * + * @sectors returns how many sectors we need to split for converting + * the splitted one into a singlepage bio if the whole bio can't be + * converted into a singlepage bio. + */ +static inline bool bio_can_convert_to_sp(struct bio *bio, unsigned *sectors) +{ + struct bio_vec bv; + struct bvec_iter iter; + unsigned len = 0; + bool ret = true; + unsigned segs = 0; + + bio_for_each_segment(bv, bio, iter) { + if (++segs > BIO_MAX_PAGES) { + ret = false; + *sectors = len >> 9; + break; + } + len += bv.bv_len; + } + + return ret; +} + +/* * get a reference to a bio, so it won't disappear. the intended use is * something like: *