From patchwork Tue Dec 27 16:05:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9489507 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 E7C1462AB6 for ; Tue, 27 Dec 2016 16:07:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9D541FE82 for ; Tue, 27 Dec 2016 16:07:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE92A25F3E; Tue, 27 Dec 2016 16:07:51 +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 B14B2201BC for ; Tue, 27 Dec 2016 16:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933128AbcL0QHo (ORCPT ); Tue, 27 Dec 2016 11:07:44 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:32860 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933078AbcL0QHU (ORCPT ); Tue, 27 Dec 2016 11:07:20 -0500 Received: by mail-pf0-f196.google.com with SMTP id 127so8381575pfg.0; Tue, 27 Dec 2016 08:07:20 -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=lx0rupp0LjVQDPZ48FxNlW/O+JcOdaoIuFHkrip0fsg=; b=rJ1q1If787t6xDjYHkuG6XpHOUjvTzz3K4LDVSBdZ2DW4YX52OsplnIYKyFnRUMwPl ttGBefi8A8BwI25sd8sPvz8cfAs6MdA941I9KVL23EjjTh7vPwDhWjwE59RS6OkKcoF0 zANyAG6hT3J5wzo4KqpOJyc9r3cGLWa/m5C3baCd6MBX0ukKm2QQAKH2ho3AnRp/cZ6M fFciCJHWnP7sITRSgGrSGb7k5wLJCvA1uXXq1MAJMgZv+RY/kE+9EIR4jVgVoc2i1HnC MTa1kihaDFYIn90wrLaywhNztrqRfuXfSNzRUyHS0lTa6AvdO7lU+WZfC++bYCEani/t 1ULQ== 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=lx0rupp0LjVQDPZ48FxNlW/O+JcOdaoIuFHkrip0fsg=; b=bVR/jYlU6hX+2uyxSCChOwm1uxCPhEZPOCquwrcE82EtTz06Db5/8gE2qRW0q//ClO vHcYENgs6wTpZOnSggaakZGq0qU/4pTOjoWqRTUTYGHeMZKRuX+ubf8H+SbQqdw6A0W6 uM09hFUptQ/ReY4YYS7RGrPhjtT88SOcgP9Yko85a7DOfmyip1UKyzKpM3jk4vJQrETu +hEA9sLUmVvUxl/MSL3FyGBvyZRfWRKCtofIoqRsnEp8/xaaN1V9ez3xBW/yNj1WSzl4 ik0K3fMSq6wv7zQnpvTphUJEORhF/A8eLuYMaZUsFwbnTPJyHeEEPumTTqGN4Prnq9HN 6Skw== X-Gm-Message-State: AIkVDXL3vjVmo3/gIzldvZendV3dNMqBTqhYmihduayi1Yr99g4BXWrqaMCQ2kIp8BKPkQ== X-Received: by 10.99.54.140 with SMTP id d134mr59211847pga.132.1482854839426; Tue, 27 Dec 2016 08:07:19 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id c15sm90729675pfd.36.2016.12.27.08.07.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Dec 2016 08:07:18 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org (open list:BTRFS FILE SYSTEM) Subject: [PATCH v1 51/54] btrfs: avoid access to .bi_vcnt directly Date: Wed, 28 Dec 2016 00:05:00 +0800 Message-Id: <1482854706-14128-20-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-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP BTRFS uses bio->bi_vcnt to figure out page numbers, this way becomes not correct once we start to support multipage bvec. So use bio_segments_all() instead. Signed-off-by: Ming Lei --- fs/btrfs/check-integrity.c | 7 ++++--- fs/btrfs/extent_io.c | 9 ++++++--- fs/btrfs/extent_io.h | 1 + fs/btrfs/inode.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index e3cc7b18fe8b..9c184a61e098 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c @@ -2829,17 +2829,18 @@ static void __btrfsic_submit_bio(struct bio *bio) int bio_is_patched; char **mapped_datav; struct bvec_iter_all bia; + unsigned num_pages = bio_segments_all(bio); dev_bytenr = 512 * bio->bi_iter.bi_sector; bio_is_patched = 0; if (dev_state->state->print_mask & BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH) pr_info("submit_bio(rw=%d,0x%x, bi_vcnt=%u, bi_sector=%llu (bytenr %llu), bi_bdev=%p)\n", - bio_op(bio), bio->bi_opf, bio->bi_vcnt, + bio_op(bio), bio->bi_opf, num_pages, (unsigned long long)bio->bi_iter.bi_sector, dev_bytenr, bio->bi_bdev); - mapped_datav = kmalloc_array(bio->bi_vcnt, + mapped_datav = kmalloc_array(num_pages, sizeof(*mapped_datav), GFP_NOFS); if (!mapped_datav) goto leave; @@ -2856,7 +2857,7 @@ static void __btrfsic_submit_bio(struct bio *bio) cur_bytenr += bvec->bv_len; } btrfsic_process_written_block(dev_state, dev_bytenr, - mapped_datav, bio->bi_vcnt, + mapped_datav, num_pages, bio, &bio_is_patched, NULL, bio->bi_opf); bio_for_each_segment_all_sp(bvec, bio, i, bia) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 137f95063c85..3c021f4dd8bf 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2273,6 +2273,7 @@ int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end, } int btrfs_check_repairable(struct inode *inode, struct bio *failed_bio, + unsigned num_pages, struct io_failure_record *failrec, int failed_mirror) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); @@ -2296,7 +2297,7 @@ int btrfs_check_repairable(struct inode *inode, struct bio *failed_bio, * a) deliver good data to the caller * b) correct the bad sectors on disk */ - if (failed_bio->bi_vcnt > 1) { + if (num_pages > 1) { /* * to fulfill b), we need to know the exact failing sectors, as * we don't want to rewrite any more than the failed ones. thus, @@ -2390,6 +2391,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, struct bio *bio; int read_mode = 0; int ret; + unsigned num_pages = bio_segments_all(failed_bio); BUG_ON(bio_op(failed_bio) == REQ_OP_WRITE); @@ -2397,13 +2399,14 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, if (ret) return ret; - ret = btrfs_check_repairable(inode, failed_bio, failrec, failed_mirror); + ret = btrfs_check_repairable(inode, failed_bio, num_pages, failrec, + failed_mirror); if (!ret) { free_io_failure(inode, failrec); return -EIO; } - if (failed_bio->bi_vcnt > 1) + if (num_pages > 1) read_mode |= REQ_FAILFAST_DEV; phy_offset >>= inode->i_sb->s_blocksize_bits; diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 17f9ce479ed7..8fce380bc8d7 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -483,6 +483,7 @@ void btrfs_free_io_failure_record(struct inode *inode, u64 start, u64 end); int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end, struct io_failure_record **failrec_ret); int btrfs_check_repairable(struct inode *inode, struct bio *failed_bio, + unsigned num_pages, struct io_failure_record *failrec, int fail_mirror); struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio, struct io_failure_record *failrec, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 544e1cf9a552..fa77cb210907 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7914,7 +7914,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio, return -EIO; } - if ((failed_bio->bi_vcnt > 1) + if ((bio_segments_all(failed_bio) > 1) || (failed_bio->bi_io_vec->bv_len > btrfs_inode_sectorsize(inode))) read_mode |= REQ_FAILFAST_DEV;