Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp831032rwl; Thu, 10 Aug 2023 02:11:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGL9wxyreaHobWSa37+wpJ5MyLkcjvJ/b65uoqILzu/LF3k2atZYbadduEfqqvAAznUgkeM X-Received: by 2002:a05:6a20:3d8f:b0:105:6d0e:c046 with SMTP id s15-20020a056a203d8f00b001056d0ec046mr2597552pzi.26.1691658718893; Thu, 10 Aug 2023 02:11:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691658718; cv=none; d=google.com; s=arc-20160816; b=BN5N/IfFAYo1qh+ED0m8ROTkzZUht8TTHpF7sjIEnCcjeOdDUksUokjTzsjwgeZl/U TuSHKJqmYP5B1fcumpqt4WYEQJJo6k1rDZKUP0nEk7lSyKj+c57LvxnDTGinQw1mFZCu s84PepQlWv0xFwxwL+Zaj+SLeM1xWPkv6fgmRrifaSjK8i54gi1eS/q9khrt9mFBIT6k PBJx/rgXBRLMckhoWH57xaICcj03P5R1buuXr1mmchOJ99kEFxsF2AdzfMHC//jYV/jn w2qjPOeoGIHMuahjJanxozJlf1rGocCkwcgT0Fvv3ZXSDYbqvDg8rDNYZCKLGomAGisS VrTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DP4t8yaVyoyw3Y5jtT2faM0Mnfz5z0tQDH4p08Vm9pI=; fh=fTSaBofNXp03thGUSjn2fCTzw7oFshHI80Fe6i8kpiM=; b=G45utZTDPrUA2yo8dSa/TT3qd7yxdjBr4NC6jZEnQ9L5WR56LYrbDjN3t/MjPHEUcJ UGKBxpwf+MnGPFVM9DhZmuJxNcpxpkC0K24BkR95BUuVngPXdmPKfmY6Foh4OTEYpePM WRm2kCFmeawflJLWu1rW3qartRDew3ILoRbGjZIpG7SOwma97k2l83qJWbUYIQY4Onks PEKtWflD4PmcHSjq811C7iQ4xTksxosTAejwE5m8IXsRK5wW2MsBNTZwFzfw10jGysre bPp6PZXxRG1G/Geo+IxyHPDm4bXeAF6/ct3vlSaq/F29F23cstm6qlMBS/WJtldRhs78 9OXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv128-20020a632e86000000b00564fec7cb63si1196984pgb.159.2023.08.10.02.11.45; Thu, 10 Aug 2023 02:11:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233222AbjHJIyu (ORCPT + 99 others); Thu, 10 Aug 2023 04:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233975AbjHJIyl (ORCPT ); Thu, 10 Aug 2023 04:54:41 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14BAB211F for ; Thu, 10 Aug 2023 01:54:38 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RM12K1qHrz4f41Rn for ; Thu, 10 Aug 2023 16:54:33 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.170]) by APP4 (Coremail) with SMTP id gCh0CgD3hqm6pdRkGjJ7AQ--.1500S16; Thu, 10 Aug 2023 16:54:34 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, yukuai3@huawei.com Subject: [PATCH v2 12/12] ext4: ext4_get_{dev}_journal return proper error value Date: Thu, 10 Aug 2023 16:54:17 +0800 Message-Id: <20230810085417.1501293-13-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20230810085417.1501293-1-yi.zhang@huaweicloud.com> References: <20230810085417.1501293-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgD3hqm6pdRkGjJ7AQ--.1500S16 X-Coremail-Antispam: 1UD129KBjvJXoW3Jr4ktr4Dur1kAr4UWry8Krg_yoWxJrWUpF 15GFyfZryj9r1Du3y8Jr4UZFWYg3WIyay8Gr97uwnYyayUtr1IqF1UJr1jqFy8tFWUGw13 JF4UJa17Cw17K37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9K14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUF18BUUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zhang Yi ext4_get_journal() and ext4_get_dev_journal() return NULL if they failed to init journal, making them return proper error value instead, also rename them to ext4_open_{inode,dev}_journal(). Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/super.c | 51 +++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 2f71076f678a..797c5456e9bc 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5752,18 +5752,18 @@ static struct inode *ext4_get_journal_inode(struct super_block *sb, journal_inode = ext4_iget(sb, journal_inum, EXT4_IGET_SPECIAL); if (IS_ERR(journal_inode)) { ext4_msg(sb, KERN_ERR, "no journal found"); - return NULL; + return ERR_CAST(journal_inode); } if (!journal_inode->i_nlink) { make_bad_inode(journal_inode); iput(journal_inode); ext4_msg(sb, KERN_ERR, "journal inode is deleted"); - return NULL; + return ERR_PTR(-EFSCORRUPTED); } if (!S_ISREG(journal_inode->i_mode) || IS_ENCRYPTED(journal_inode)) { ext4_msg(sb, KERN_ERR, "invalid journal inode"); iput(journal_inode); - return NULL; + return ERR_PTR(-EFSCORRUPTED); } ext4_debug("Journal inode found at %p: %lld bytes\n", @@ -5793,21 +5793,21 @@ static int ext4_journal_bmap(journal_t *journal, sector_t *block) return 0; } -static journal_t *ext4_get_journal(struct super_block *sb, - unsigned int journal_inum) +static journal_t *ext4_open_inode_journal(struct super_block *sb, + unsigned int journal_inum) { struct inode *journal_inode; journal_t *journal; journal_inode = ext4_get_journal_inode(sb, journal_inum); - if (!journal_inode) - return NULL; + if (IS_ERR(journal_inode)) + return ERR_CAST(journal_inode); journal = jbd2_journal_init_inode(journal_inode); if (IS_ERR(journal)) { ext4_msg(sb, KERN_ERR, "Could not load journal inode"); iput(journal_inode); - return NULL; + return ERR_CAST(journal); } journal->j_private = sb; journal->j_bmap = ext4_journal_bmap; @@ -5825,6 +5825,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb, ext4_fsblk_t sb_block; unsigned long offset; struct ext4_super_block *es; + int errno; bdev = blkdev_get_by_dev(j_dev, BLK_OPEN_READ | BLK_OPEN_WRITE, sb, &ext4_holder_ops); @@ -5832,7 +5833,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb, ext4_msg(sb, KERN_ERR, "failed to open journal device unknown-block(%u,%u) %ld", MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev)); - return NULL; + return ERR_CAST(bdev); } blocksize = sb->s_blocksize; @@ -5840,6 +5841,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb, if (blocksize < hblock) { ext4_msg(sb, KERN_ERR, "blocksize too small for journal device"); + errno = -EINVAL; goto out_bdev; } @@ -5850,6 +5852,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb, if (!bh) { ext4_msg(sb, KERN_ERR, "couldn't read superblock of " "external journal"); + errno = -EINVAL; goto out_bdev; } @@ -5858,6 +5861,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb, !(le32_to_cpu(es->s_feature_incompat) & EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { ext4_msg(sb, KERN_ERR, "external journal has bad superblock"); + errno = -EFSCORRUPTED; goto out_bh; } @@ -5865,11 +5869,13 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) && es->s_checksum != ext4_superblock_csum(sb, es)) { ext4_msg(sb, KERN_ERR, "external journal has corrupt superblock"); + errno = -EFSCORRUPTED; goto out_bh; } if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { ext4_msg(sb, KERN_ERR, "journal UUID does not match"); + errno = -EFSCORRUPTED; goto out_bh; } @@ -5882,31 +5888,34 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb, brelse(bh); out_bdev: blkdev_put(bdev, sb); - return NULL; + return ERR_PTR(errno); } -static journal_t *ext4_get_dev_journal(struct super_block *sb, - dev_t j_dev) +static journal_t *ext4_open_dev_journal(struct super_block *sb, + dev_t j_dev) { journal_t *journal; ext4_fsblk_t j_start; ext4_fsblk_t j_len; struct block_device *journal_bdev; + int errno = 0; journal_bdev = ext4_get_journal_dev(sb, j_dev, &j_start, &j_len); - if (!journal_bdev) - return NULL; + if (IS_ERR(journal_bdev)) + return ERR_CAST(journal_bdev); journal = jbd2_journal_init_dev(journal_bdev, sb->s_bdev, j_start, j_len, sb->s_blocksize); if (IS_ERR(journal)) { ext4_msg(sb, KERN_ERR, "failed to create device journal"); + errno = PTR_ERR(journal); goto out_bdev; } if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { ext4_msg(sb, KERN_ERR, "External journal has more than one " "user (unsupported) - %d", be32_to_cpu(journal->j_superblock->s_nr_users)); + errno = -EINVAL; goto out_journal; } journal->j_private = sb; @@ -5918,7 +5927,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb, jbd2_journal_destroy(journal); out_bdev: blkdev_put(journal_bdev, sb); - return NULL; + return ERR_PTR(errno); } static int ext4_load_journal(struct super_block *sb, @@ -5950,13 +5959,13 @@ static int ext4_load_journal(struct super_block *sb, } if (journal_inum) { - journal = ext4_get_journal(sb, journal_inum); - if (!journal) - return -EINVAL; + journal = ext4_open_inode_journal(sb, journal_inum); + if (IS_ERR(journal)) + return PTR_ERR(journal); } else { - journal = ext4_get_dev_journal(sb, journal_dev); - if (!journal) - return -EINVAL; + journal = ext4_open_dev_journal(sb, journal_dev); + if (IS_ERR(journal)) + return PTR_ERR(journal); } journal_dev_ro = bdev_read_only(journal->j_dev); -- 2.34.3