From patchwork Sat Oct 29 08:08:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9403239 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 17DA160588 for ; Sat, 29 Oct 2016 08:16:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01C0D29BA7 for ; Sat, 29 Oct 2016 08:16:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6F7229CE9; Sat, 29 Oct 2016 08:16:46 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 93BF229B67 for ; Sat, 29 Oct 2016 08:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933080AbcJ2IQ2 (ORCPT ); Sat, 29 Oct 2016 04:16:28 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36153 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966390AbcJ2IQZ (ORCPT ); Sat, 29 Oct 2016 04:16:25 -0400 Received: by mail-pf0-f196.google.com with SMTP id n85so3392211pfi.3; Sat, 29 Oct 2016 01:16:25 -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=7hSqylXAHvJ1cg13VA2gtMTy06NR16sCTWNUcDYSNQA=; b=K+KEXNbOHWM0+MWOIfOW4/EoBWSEXlKaiMPzrWV9Oo6EDlnjmkFcjFP2xz/tGPVxM8 ZEiRs2xGKpDOXPheF1KUrqUXD6TaJMB54rvPJlT0gy70K7YrkPAv+aHBWwhAEj930B4W LWq2uNoPgRxkT9dbWkkCBlSsx+10kGyk+Ar3FFid2rWDl98z9zqenakYF3iOV6b6e4Tv 4zew1aNDyekYveR5lqxTgNIpt8ZLjm9qBsL9AMlYw9Hsm6DCl6hRVEA+tAyOc3H6DIEL cn2W4z4hLlVg4vuMNXVfWQef0BnW6ZuoudBEeVQ1MuKlwqslKnirjEdEXCqi9D4OcQK8 QKKA== 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=7hSqylXAHvJ1cg13VA2gtMTy06NR16sCTWNUcDYSNQA=; b=EFy29Lwv9+KdjIatISVebnhiSIehKpiNsuAljZXmEjC2CmCFpZKz82IE65D7k8YvbX OMlvF08xSWrn+43UjD2qgm9xY39FryNcjJVmba5livElGgO8DCsNcS8+H3ID3U0+dQvf mF6Sgrn2d+MsJiCXQSgCcEFenf3zXgQwV1sqFP771HkHJLmJxJkA4D8/klFYQWTNkHM8 87spm5GuAUg7PcHZ4bOb3zmVRmOxIaYoUPQzEJ3hTxeTqWbv//4kgirKvnQNbi5gddQ1 VK4Nml2RIQpXzqasQpnK13u0VuhLdfOxjHEyR/HCZwoNtsZN6SlKdVwuYb1luFLgvpUZ Az+Q== X-Gm-Message-State: ABUngve4HkAFBS6kDyW4K8fYh+9M9UYvmJWlAz8QAnW7BohbUBYTqul+YkcLoL7vnMLrlQ== X-Received: by 10.98.149.74 with SMTP id p71mr31650110pfd.126.1477728984680; Sat, 29 Oct 2016 01:16:24 -0700 (PDT) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id x1sm23611827pax.7.2016.10.29.01.16.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2016 01:16:24 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , "Kirill A . Shutemov" , Ming Lei , Alexander Viro Subject: [PATCH 59/60] fs/buffer.c: use bvec iterator to truncate the bio Date: Sat, 29 Oct 2016 16:08:58 +0800 Message-Id: <1477728600-12938-60-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477728600-12938-1-git-send-email-tom.leiming@gmail.com> References: <1477728600-12938-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 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 81c3793948b4..293e081a4b5f 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -3021,8 +3021,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]; @@ -3045,15 +3044,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,