Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp825221rdg; Fri, 11 Aug 2023 00:20:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUY/m6eXGRTaajTRhxlwCOfVWMzf5XS/VgZcg0SNDhmtib6A6yqy/BtiOAWxqAFh58hrYe X-Received: by 2002:a05:6808:d8:b0:3a7:7559:ff4f with SMTP id t24-20020a05680800d800b003a77559ff4fmr1452981oic.59.1691738446053; Fri, 11 Aug 2023 00:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691738446; cv=none; d=google.com; s=arc-20160816; b=LgMPKP1szTGg++XgIuZHA6VHf7mnqLLkBlzWAniZEFvOzr/09Sy5TZWAaEM27LJDlO rF5MKCcKiZxweTv1ErPklXqR6LUd7zWecZVzi67VgpFOUsxC4xQFtrX+FINT7Juc0i6F u1J9WAnpmcInHhdJeqdEZ8ReQVmZLDzjFpO19sbFyAg6MNGddiSJQlvGDb4Abf8Exe0u FLASJbp+WvY/0RL1D8yCtWceCzyHOZk9sMbPivvYpbfOVbLqRnHdyjcbATibjngqHXMr vcrsOo0NL4tfG9/x3erhPtWxRIFE0SKvGpd9lViqeqhM2NIJRmo4tnzu9nHluOd5/vXC GLMA== 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=qFYTfKd6b8iKKq2Fu1haSu391BnaEw0KayNwtrxLbr8=; fh=fTSaBofNXp03thGUSjn2fCTzw7oFshHI80Fe6i8kpiM=; b=H0hzLjjOHQ0ucAAdIXoY1rTwqMs4Od+3zeeHmEoNLMg2oAeC5BT/ZwJvj4CiXDxVs4 aWFEoz1dUw+CMuCpvMtIqjl6of8JBd+PV95HGPCb7/i9B2m6JswjJPWcAvpcact/Zv/2 t96w4D8DgJSf5mX9TGMkbyKGJkt6DoKyhvJdqU44EVMVHGekNbzFPpLUxpOmol1DqsKp OrQcNZ7W0kA5r7vnozfncFi09IyajhA2Yriu4TLBBKG4xbJRKmPWMQ0KYUNi2xjNuUIr lBZaGT2ApL8TpVJ4cs+GskKuJWiZIcneXotSWxRB6P/kK6Xtz3iaFMz4M2shlLph8srs fNmA== 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 z16-20020a634c10000000b005653316de71si2854299pga.835.2023.08.11.00.20.32; Fri, 11 Aug 2023 00:20:46 -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 S232278AbjHKGgh (ORCPT + 99 others); Fri, 11 Aug 2023 02:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232671AbjHKGga (ORCPT ); Fri, 11 Aug 2023 02:36:30 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E25752694 for ; Thu, 10 Aug 2023 23:36:29 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RMYwS2kTwz4f3v7G for ; Fri, 11 Aug 2023 14:36:24 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.170]) by APP4 (Coremail) with SMTP id gCh0CgA3x6na1tVkKEbDAQ--.35746S12; Fri, 11 Aug 2023 14:36:27 +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 v3 08/12] jbd2: cleanup journal_init_common() Date: Fri, 11 Aug 2023 14:36:06 +0800 Message-Id: <20230811063610.2980059-9-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20230811063610.2980059-1-yi.zhang@huaweicloud.com> References: <20230811063610.2980059-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgA3x6na1tVkKEbDAQ--.35746S12 X-Coremail-Antispam: 1UD129KBjvJXoWxZryfJryUCr4kur15Ar45trb_yoWrWr47pr y7KasxArW8Zr47Xr4fJF4kJrWjqay09FyUGr9rCwnYyw4UtrnxXw1Utw1xJayqvFW0g3Wr XF1fC34xCw1UK3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9K14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUOBTYUUUUU 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 Adjust the initialization sequence and error handle of journal_t, moving load superblock to the begin, and classify others initialization. Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/jbd2/journal.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 261483976924..708d58d69592 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1533,6 +1533,16 @@ static journal_t *journal_init_common(struct block_device *bdev, if (!journal) return NULL; + journal->j_blocksize = blocksize; + journal->j_dev = bdev; + journal->j_fs_dev = fs_dev; + journal->j_blk_offset = start; + journal->j_total_len = len; + + err = journal_load_superblock(journal); + if (err) + goto err_cleanup; + init_waitqueue_head(&journal->j_wait_transaction_locked); init_waitqueue_head(&journal->j_wait_done_commit); init_waitqueue_head(&journal->j_wait_commit); @@ -1544,12 +1554,15 @@ static journal_t *journal_init_common(struct block_device *bdev, mutex_init(&journal->j_checkpoint_mutex); spin_lock_init(&journal->j_revoke_lock); spin_lock_init(&journal->j_list_lock); + spin_lock_init(&journal->j_history_lock); rwlock_init(&journal->j_state_lock); journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE); journal->j_min_batch_time = 0; journal->j_max_batch_time = 15000; /* 15ms */ atomic_set(&journal->j_reserved_credits, 0); + lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle", + &jbd2_trans_commit_key, 0); /* The journal is marked for error until we succeed with recovery! */ journal->j_flags = JBD2_ABORT; @@ -1559,18 +1572,10 @@ static journal_t *journal_init_common(struct block_device *bdev, if (err) goto err_cleanup; - spin_lock_init(&journal->j_history_lock); - - lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle", - &jbd2_trans_commit_key, 0); - - /* journal descriptor can store up to n blocks -bzzz */ - journal->j_blocksize = blocksize; - journal->j_dev = bdev; - journal->j_fs_dev = fs_dev; - journal->j_blk_offset = start; - journal->j_total_len = len; - /* We need enough buffers to write out full descriptor block. */ + /* + * journal descriptor can store up to n blocks, we need enough + * buffers to write out full descriptor block. + */ n = journal->j_blocksize / jbd2_min_tag_size(); journal->j_wbufsize = n; journal->j_fc_wbuf = NULL; @@ -1579,7 +1584,8 @@ static journal_t *journal_init_common(struct block_device *bdev, if (!journal->j_wbuf) goto err_cleanup; - err = journal_load_superblock(journal); + err = percpu_counter_init(&journal->j_checkpoint_jh_count, 0, + GFP_KERNEL); if (err) goto err_cleanup; @@ -1588,21 +1594,18 @@ static journal_t *journal_init_common(struct block_device *bdev, journal->j_shrinker.count_objects = jbd2_journal_shrink_count; journal->j_shrinker.seeks = DEFAULT_SEEKS; journal->j_shrinker.batch = journal->j_max_transaction_buffers; - - if (percpu_counter_init(&journal->j_checkpoint_jh_count, 0, GFP_KERNEL)) + err = register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)", + MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); + if (err) goto err_cleanup; - if (register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev))) { - percpu_counter_destroy(&journal->j_checkpoint_jh_count); - goto err_cleanup; - } return journal; err_cleanup: - brelse(journal->j_sb_buffer); + percpu_counter_destroy(&journal->j_checkpoint_jh_count); kfree(journal->j_wbuf); jbd2_journal_destroy_revoke(journal); + journal_fail_superblock(journal); kfree(journal); return NULL; } -- 2.34.3