From patchwork Thu Feb 16 11:45:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9576963 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 09D17600C5 for ; Thu, 16 Feb 2017 11:51:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07862285B7 for ; Thu, 16 Feb 2017 11:51:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEC63285BD; Thu, 16 Feb 2017 11:51:54 +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 B07E3285B7 for ; Thu, 16 Feb 2017 11:51:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754664AbdBPLqP (ORCPT ); Thu, 16 Feb 2017 06:46:15 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33902 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754648AbdBPLqN (ORCPT ); Thu, 16 Feb 2017 06:46:13 -0500 Received: by mail-pf0-f193.google.com with SMTP id o64so1484376pfb.1; Thu, 16 Feb 2017 03:46:13 -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=BQgZusUdHKuxUb9m/MZ5sb+hN7ob3ObLUnP4FNm4n9DocmwHeve3Nzgl58Aln7c9Xc GEqf3OyMDNRUMk37yyfoybQyxuiRPJGqZGws1NfV00HVOW+qS8JIC1zDkmD/mnBk69/Z lSjaUIJEtZ2x7nu11rasBCvf6iAcdcftDEC3DkfFulwnYFRExVv/symdBqhuMX1qWuM7 iUdudYTAgXlEAPXgXRtpswjKgHOKavCh8SQFs4Bcamm6vmjtSpwOr90ZxzYGwhuXhQbf OYy75hcYPVdCLJ28umbxaZ6tn6w0resIrUBG+anLi0H+flTXZNojw/h5YC14xqW6WD6w tGQg== 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=s5gVtWO4z9n2xn7Kf2pGU4cC2uh1h8cz+Ac1Jeq2UloWXTSlvINgqH+1y5lRBcFDqU mtGNecELjelpDn1cDehg09GsOPbW6bCwQUvO9Y2Da/3G6GGJfWQ5bx3yu6q+MWebvDSA 6/Swo0Y/Xq2F3w81W+TiyqY0Mna69arpWgkT9PI9f15hGVCWiPgh1owakMsVDvTUHAps 3ZLxqu3M81n3gQ5NucSCnUmH6oFLxSf4IBHG3nA7+qtEgfvSDyvE3WBiHHqb/l8O9Nqx DTRQUSSHYAikgA+T5krxfChJIS8YNAXm07bOo1+GIL1quKD6Q9urUlkvGFnBNKKRZOVx oeIA== X-Gm-Message-State: AMke39k86Nxm/okrrprI7pF0Jn8No+vZpVMo7DeDxfrukq+L0CUMurSbgExeEscMEU0KKw== X-Received: by 10.84.141.1 with SMTP id 1mr807153plu.178.1487245572595; Thu, 16 Feb 2017 03:46:12 -0800 (PST) Received: from localhost (li405-222.members.linode.com. [106.187.53.222]) by smtp.gmail.com with ESMTPSA id 75sm13270712pfp.80.2017.02.16.03.46.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 03:46:11 -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 , NeilBrown Cc: Ming Lei Subject: [PATCH 02/17] block: introduce bio_remove_last_page() Date: Thu, 16 Feb 2017 19:45:32 +0800 Message-Id: <1487245547-24384-3-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487245547-24384-1-git-send-email-tom.leiming@gmail.com> References: <1487245547-24384-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);