From patchwork Fri Feb 24 15:42:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9590601 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 287E86020A for ; Fri, 24 Feb 2017 15:48:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C78922BF1 for ; Fri, 24 Feb 2017 15:48:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11163286CC; Fri, 24 Feb 2017 15:48:26 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 C7D5C22BF1 for ; Fri, 24 Feb 2017 15:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751582AbdBXPoO (ORCPT ); Fri, 24 Feb 2017 10:44:14 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34725 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751344AbdBXPnQ (ORCPT ); Fri, 24 Feb 2017 10:43:16 -0500 Received: by mail-pg0-f68.google.com with SMTP id s67so3458283pgb.1; Fri, 24 Feb 2017 07:43:15 -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=8nXAUjpW8Tfv6iYbgGXbyH9JEB4Yahc7ruU/2hiU8j4=; b=tTfnkuctyl2Q3Ua+Vrvd2nyxUOjHQgFvvhO1Hi9odAZtThvhiFgYPtSbnvatAbghKa fZW2EZDlSOZlxLoXLEjbzSN/AUL2TS52vUHQ96NyYi0WDYIcHIw3vkdwvciZe8kC+j17 DUUeVOqghhRIjPpQQBx4jOd0DnpR49jWrUegwyTwprKc5oi9eHnTmdkGTFPTybSSJ/Ji 8ypjhxXd5BTMYtgnXlmbtMPDL5KTsNLCx6/Rx5Xz0GDa0+YJB47z9apg8tdm95WTD3jQ AyMbM/FbyJzjTriZjSDZ7UYAMlTHKlu4NuiFDwTx5sn/kHK88Id4+GwWZ1ngqCeVNr0u IxIQ== 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=8nXAUjpW8Tfv6iYbgGXbyH9JEB4Yahc7ruU/2hiU8j4=; b=mfyXF0pzLMZ5+FGD59Zv86cwlvWuVizvnZ1zW8B1ZGUCbX0Cu+iMuazhz4TDdLFhQE 6zOaXHfHM85s2LEJ9h1dJbT6VLpP7whp8aIfRU5FAN1XNmFhKjlWpKU7eOVcqSdFB279 IT6HAlOe8TVCK5eHtINz7GwGoYmQDQpX6qYgSvBi68iT0o9Ere8h4Afez88Mvt5r+jfV Ho7COlJCYgdLgawC9z2kfmq1UjGUjDYgtRUw15+q9qLKUTmz2yTHmddBK7D+mlT7SPXI 8RDvqeYTfh7mmndOCOwlROksLdpvuDKobYSw/1O5/TnKVbjM2ZGbci/db2ML+VJimD0X Bp4g== X-Gm-Message-State: AMke39l9DMLj/bsTBHQZeVL28PFFsCRD1gZ89YX+VJQGUnO8spQKMh+OLfCDzZmSBL+Kdg== X-Received: by 10.98.217.67 with SMTP id s64mr1301334pfg.119.1487950995517; Fri, 24 Feb 2017 07:43:15 -0800 (PST) Received: from localhost (li405-222.members.linode.com. [106.187.53.222]) by smtp.gmail.com with ESMTPSA id i10sm15928309pgd.37.2017.02.24.07.43.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 07:43:14 -0800 (PST) From: Ming Lei To: Shaohua Li , Jens Axboe , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig Cc: Ming Lei Subject: [PATCH v1 02/14] block: introduce bio_remove_last_page() Date: Fri, 24 Feb 2017 23:42:39 +0800 Message-Id: <1487950971-1131-3-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487950971-1131-1-git-send-email-tom.leiming@gmail.com> References: <1487950971-1131-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 MD need this helper to remove the last added page, so introduce it. Signed-off-by: Ming Lei --- block/bio.c | 23 +++++++++++++++++++++++ include/linux/bio.h | 1 + 2 files changed, 24 insertions(+) diff --git a/block/bio.c b/block/bio.c index 5eec5e08417f..0ce7ffcd7939 100644 --- a/block/bio.c +++ b/block/bio.c @@ -837,6 +837,29 @@ int bio_add_pc_page(struct request_queue *q, struct bio *bio, struct page EXPORT_SYMBOL(bio_add_pc_page); /** + * bio_remove_last_page - remove the last added page + * @bio: destination bio + * + * Attempt to remove the last added page from the bio_vec maplist. + */ +void bio_remove_last_page(struct bio *bio) +{ + /* + * cloned bio must not modify vec list + */ + if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED))) + return; + + if (bio->bi_vcnt > 0) { + struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1]; + + bio->bi_iter.bi_size -= bv->bv_len; + bio->bi_vcnt--; + } +} +EXPORT_SYMBOL(bio_remove_last_page); + +/** * bio_add_page - attempt to add page to bio * @bio: destination bio * @page: page to add diff --git a/include/linux/bio.h b/include/linux/bio.h index 3364b3ed90e7..32aeb493d1fe 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -443,6 +443,7 @@ extern void bio_init(struct bio *bio, struct bio_vec *table, extern void bio_reset(struct bio *); void bio_chain(struct bio *, struct bio *); +extern void bio_remove_last_page(struct bio *bio); extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int); extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, unsigned int, unsigned int);