From patchwork Tue Dec 27 16:04:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9489539 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 DC52A62AB6 for ; Tue, 27 Dec 2016 16:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE956200E7 for ; Tue, 27 Dec 2016 16:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C356825F3E; Tue, 27 Dec 2016 16:09:17 +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 5E936223B2 for ; Tue, 27 Dec 2016 16:09:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933206AbcL0QJL (ORCPT ); Tue, 27 Dec 2016 11:09:11 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35119 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932573AbcL0QHP (ORCPT ); Tue, 27 Dec 2016 11:07:15 -0500 Received: by mail-pg0-f66.google.com with SMTP id i5so12804530pgh.2; Tue, 27 Dec 2016 08:07: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=lbVoUIqcf8QPdqTCQTzO8UPvvHKNVaOAo6AHp4qkg2U=; b=C6/FJ5vMLAwF99N2sWgHzozLDBzamRGbzE1JgKPQ0rBajGp3gEVu5SbizwcqIPXq52 n/+3IC2VkynOy+bGWuQP2pew1gPdZ4DDrmn2Q0+VbPiFmjWHfTXqq3qKcatgbDhaKAeG ZSnhc6vLN1Aoiy82g1egU5TcQxUUAheCy1b6yhcrcCB4Efk81bybOpWrhXXlYjcAHfyd 9eRohC/e7Ink2gcMvdqxwDUY6JvPyjgORBtn4f6bpQORtyLiikvFuSpaPrPmFK16IktC 9EEN5WbmUyxOpnFZLbJb1iEIAO88uSz2w6tGk5ItpboPZMtQU9vYNS2q3QTFCrFpO9az MsvA== 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=lbVoUIqcf8QPdqTCQTzO8UPvvHKNVaOAo6AHp4qkg2U=; b=cK84ycEaWnDNTnw0f2TGPm+vC0HrBOsthpkyfZbFl1Ko9q8i7pShjwUm0ryt8JObQw DVYdF4mP14OGTb9+xpg93vs7VUomrv4p+sqTrn+sUttZzxqcPyUsn8Iza9ISjLkszUsd Aqr6SYONpmn69nBxG2JvmaYeCg+WbTPsVODdkWjOuQgxwu/BOYmMJe27emLcOeiRSWwS QWJtpLkik0qovIPJVMuffNHB7wDIwtHZmkaHg1Phqpiz4xpjMcRmcR/jzCh4yMBcHEyi +xqaCkBePt8yFfPaoOONPexNsxIqyeC04xA+L0Uh3RacISZd5NCvBExxlCUU5tuNeHUV UkYw== X-Gm-Message-State: AIkVDXLkDXE3PXptwE2cw/qYrXrhxDWpY1dsNzlYC+nRHwrKk+BhtC0GsDsMwBSzQZNLMA== X-Received: by 10.99.130.72 with SMTP id w69mr58871721pgd.139.1482854834602; Tue, 27 Dec 2016 08:07:14 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id 64sm90764606pfu.17.2016.12.27.08.07.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Dec 2016 08:07:13 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Alexander Viro , linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)) Subject: [PATCH v1 50/54] fs/buffer.c: use bvec iterator to truncate the bio Date: Wed, 28 Dec 2016 00:04:59 +0800 Message-Id: <1482854706-14128-19-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482854706-14128-1-git-send-email-tom.leiming@gmail.com> References: <1482854706-14128-1-git-send-email-tom.leiming@gmail.com> 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 For making multipage bvec working well. Signed-off-by: Ming Lei --- fs/buffer.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 63d2f40c21fd..014892593f57 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -3063,8 +3063,7 @@ void guard_bio_eod(int op, struct bio *bio) unsigned truncated_bytes; /* * It is safe to truncate the last bvec in the following way - * even though multipage bvec is supported, but we need to - * fix the parameters passed to zero_user(). + * even though multipage bvec is supported. */ struct bio_vec *bvec = &bio->bi_io_vec[bio->bi_vcnt - 1]; @@ -3087,15 +3086,21 @@ void guard_bio_eod(int op, struct bio *bio) /* Uhhuh. We've got a bio that straddles the device size! */ truncated_bytes = bio->bi_iter.bi_size - (maxsector << 9); - /* Truncate the bio.. */ - bio->bi_iter.bi_size -= truncated_bytes; - bvec->bv_len -= truncated_bytes; - /* ..and clear the end of the buffer for reads */ if (op == REQ_OP_READ) { - zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len, - truncated_bytes); + struct bvec_iter start = BVEC_ITER_ALL_INIT; + struct bvec_iter iter; + struct bio_vec bv; + + start.bi_bvec_done = bvec->bv_len - truncated_bytes; + + __bvec_for_each_sp_bvec(bv, bvec, iter, start) + zero_user(bv.bv_page, bv.bv_offset, bv.bv_len); } + + /* Truncate the bio.. */ + bio->bi_iter.bi_size -= truncated_bytes; + bvec->bv_len -= truncated_bytes; } static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,