Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1691218ybs; Tue, 26 May 2020 00:56:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF6o6vcBW5i1++fXYQa0pnNiRllD/XehqAhLOb5boaee2knNS3HID5BsUp5saOIx60uEa2 X-Received: by 2002:a50:bf04:: with SMTP id f4mr18031942edk.91.1590479808517; Tue, 26 May 2020 00:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590479808; cv=none; d=google.com; s=arc-20160816; b=WIrYZpQ8hHdsvQI/6XN1iOL1FnML2Jth0t3NwZH55Q0ZorLYWUtXxxnw5Y0dHtO99D b2w4TYmEy1dlfgCLuJl+VW/vtCZxaZEXUfFH0lXGjF0VTVImoLBIeOckRdYUruMf7Ipb KhJKV2pc+VFcaf/HOUN4SdR2F+vM2UwE48p/Gj98Rf9lPjs2/jlALs4aN65CaP1thHDq ZR4T6VCM9G3NZ8GMHA6ci2QrA+u7bW4GDXYd0g2ikH9HuHbx1f0kUkRzsGmpvdQTW+gs MyMlIA4mjWHViR4D2nu9MYiOH/a4zHOpKknpk0/I6FTAlWgn0wLZ3D6FqtTgdQ51OEqD at+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=iqq53jmxHi5kXunwQToZ2cWqQFhq+4v3+UXEQkNfOOo=; b=oLdZOPfIw4aar9fJOlqtUmyI3Fx5VHAZJOretDP6+tsVqzo1hM+ZOmVCHZaZlAA7TF 12iIhmu1yFuRNt3gG1ps6BCiZYhNu9VJ3nm1iqy8pKhB4eXfA5l3lAEMitikqhK2nXLx miMxW6OxnnCk7W1tZXv64bPfZ2H43sUrWdtQ2y2nNZTh5u//AVbtNuxScA4tt7lIFj8Z GD20uktcJ1LNvdOnf+wKzc+bl2wQM7Mu69ObetR0G1zxoNBwGVy+M1N2DzozzDY5QCcN BbOHntsApNMCTvxF5Ifynqa9mDTPQtcb5w7Wwexp1emrzphCYT5gLXQibaJ1EmlGYH7x 6DCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j17si6283283edh.365.2020.05.26.00.56.24; Tue, 26 May 2020 00:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726809AbgEZHTW (ORCPT + 99 others); Tue, 26 May 2020 03:19:22 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51104 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726641AbgEZHTV (ORCPT ); Tue, 26 May 2020 03:19:21 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E4E1D8E00C4CC26B7F8E; Tue, 26 May 2020 15:19:14 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Tue, 26 May 2020 15:19:09 +0800 From: "zhangyi (F)" To: CC: , , , , Subject: [PATCH 05/10] ext4: replace sb_bread*() with ext4_sb_bread*() Date: Tue, 26 May 2020 15:17:49 +0800 Message-ID: <20200526071754.33819-6-yi.zhang@huawei.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200526071754.33819-1-yi.zhang@huawei.com> References: <20200526071754.33819-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org For the cases of sb_bread() and sb_bread_unmovable(), we also need to check the buffer is actually uptodate or not and fix the uptodate flag. Add a wrapper function ext4_sb_bread_unmovable() and replace all sb_bread*() with ext4_sb_bread*(). Signed-off-by: zhangyi (F) --- fs/ext4/ext4.h | 17 +++++++++++++++-- fs/ext4/indirect.c | 6 +++--- fs/ext4/resize.c | 12 ++++++------ fs/ext4/super.c | 33 +++++++++++++++++++-------------- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2ee76efd029b..609c2b555d29 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2763,8 +2763,9 @@ extern struct buffer_head *__ext4_sb_getblk_gfp(struct super_block *sb, gfp_t gfp); extern struct buffer_head *__ext4_sb_getblk(struct super_block *sb, sector_t block, bool lock); -extern struct buffer_head *ext4_sb_bread(struct super_block *sb, - sector_t block, int op_flags); +extern struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb, + sector_t block, int op_flags, + gfp_t gfp); extern int ext4_seq_options_show(struct seq_file *seq, void *offset); extern int ext4_calculate_overhead(struct super_block *sb); extern void ext4_superblock_csum_set(struct super_block *sb); @@ -2969,6 +2970,18 @@ ext4_sb_getblk_locked(struct super_block *sb, sector_t block) return __ext4_sb_getblk(sb, block, true); } +static inline struct buffer_head * +ext4_sb_bread(struct super_block *sb, sector_t block, int op_flags) +{ + return __ext4_sb_bread_gfp(sb, block, op_flags, __GFP_MOVABLE); +} + +static inline struct buffer_head * +ext4_sb_bread_unmovable(struct super_block *sb, sector_t block) +{ + return __ext4_sb_bread_gfp(sb, block, 0, 0); +} + static inline int ext4_has_metadata_csum(struct super_block *sb) { WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb) && diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 8dcbf21439c1..bd4d86211ab8 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -1012,14 +1012,14 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode, } /* Go read the buffer for the next level down */ - bh = sb_bread(inode->i_sb, nr); + bh = ext4_sb_bread(inode->i_sb, nr, 0); /* * A read failure? Report error and clear slot * (should be rare). */ - if (!bh) { - ext4_error_inode_block(inode, nr, EIO, + if (IS_ERR(bh)) { + ext4_error_inode_block(inode, nr, PTR_ERR(bh), "Read failure"); continue; } diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index 414198e4d873..ff018e63bb55 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1806,10 +1806,10 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, o_blocks_count + add, add); /* See if the device is actually as big as what was requested */ - bh = sb_bread(sb, o_blocks_count + add - 1); - if (!bh) { + bh = ext4_sb_bread(sb, o_blocks_count + add - 1, 0); + if (IS_ERR(bh)) { ext4_warning(sb, "can't read last block, resize aborted"); - return -ENOSPC; + return PTR_ERR(bh); } brelse(bh); @@ -1932,10 +1932,10 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count) int meta_bg; /* See if the device is actually as big as what was requested */ - bh = sb_bread(sb, n_blocks_count - 1); - if (!bh) { + bh = ext4_sb_bread(sb, n_blocks_count - 1, 0); + if (IS_ERR(bh)) { ext4_warning(sb, "can't read last block, resize aborted"); - return -ENOSPC; + return PTR_ERR(bh); } brelse(bh); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 111fff55fada..b9aab334a5d0 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -194,17 +194,18 @@ __ext4_sb_getblk(struct super_block *sb, sector_t block, bool lock) } /* - * This works like sb_bread() except it uses ERR_PTR for error - * returns. Currently with sb_bread it's impossible to distinguish - * between ENOMEM and EIO situations (since both result in a NULL - * return. + * This works like __bread_gfp() except it allow to pass op_flags and + * uses ERR_PTR for error returns. Currently with sb_bread it's + * impossible to distinguish between ENOMEM and EIO situations (since + * both result in a NULL return. */ struct buffer_head * -ext4_sb_bread(struct super_block *sb, sector_t block, int op_flags) +__ext4_sb_bread_gfp(struct super_block *sb, sector_t block, + int op_flags, gfp_t gfp) { struct buffer_head *bh; - bh = ext4_sb_getblk_locked(sb, block); + bh = ext4_sb_getblk_locked_gfp(sb, block, gfp); if (bh == NULL) return ERR_PTR(-ENOMEM); if (buffer_uptodate(bh)) @@ -3777,8 +3778,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) logical_sb_block = sb_block; } - if (!(bh = sb_bread_unmovable(sb, logical_sb_block))) { - ext4_msg(sb, KERN_ERR, "unable to read superblock"); + bh = ext4_sb_bread_unmovable(sb, logical_sb_block); + if (IS_ERR(bh)) { + ext4_msg(sb, KERN_ERR, + "unable to read superblock: %ld", PTR_ERR(bh)); goto out_fail; } /* @@ -4175,10 +4178,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) brelse(bh); logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; offset = do_div(logical_sb_block, blocksize); - bh = sb_bread_unmovable(sb, logical_sb_block); - if (!bh) { + bh = ext4_sb_bread_unmovable(sb, logical_sb_block); + if (IS_ERR(bh)) { ext4_msg(sb, KERN_ERR, - "Can't read superblock on 2nd try"); + "Can't read superblock on 2nd try: %ld", + PTR_ERR(bh)); goto failed_mount; } es = (struct ext4_super_block *)(bh->b_data + offset); @@ -4398,10 +4402,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) struct buffer_head *bh; block = descriptor_loc(sb, logical_sb_block, i); - bh = sb_bread_unmovable(sb, block); - if (!bh) { + bh = ext4_sb_bread_unmovable(sb, block); + if (IS_ERR(bh)) { ext4_msg(sb, KERN_ERR, - "can't read group descriptor %d", i); + "can't read group descriptor %d: %ld", + i, PTR_ERR(bh)); db_count = i; goto failed_mount2; } -- 2.21.3