Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp512165rdb; Tue, 19 Sep 2023 02:07:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH731SeiplsC61CTfuK5aokRFCCsxr6VwshpKaEIMAihld1oy7/NXVoLzg2O3vYDTkMTPyS X-Received: by 2002:a05:6358:9190:b0:13a:319f:a56b with SMTP id j16-20020a056358919000b0013a319fa56bmr10857227rwa.20.1695114430905; Tue, 19 Sep 2023 02:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695114430; cv=none; d=google.com; s=arc-20160816; b=NWS1WK87QsGpBsS2C+KCvSCAovdRsyTzSQMwXnTB/NGtCT4hnFFLzKQ0EK4WMfmk7f MRp9bW1SY6jQ45//XneZgsjnY4Q9k0F9c3iIyKAl8AgXaENe5iJyGeYAnc3dBumCBWU5 PyvRtBE8mrcPJhJwZ3rWKlKZEiitCfAD5ajE0ftCaMGojnDjw4vd7XvU2kXvXVwofcbl Ht7j+V457w8yEpJE+RxqUBQolBrsFi5kntllIMpughMQVMrL0k8Egq1gFk6Uk2aGDcrF 7TqQeIhPOreBU8dU/sAuJHSdz9z0bGuAowPJq3BPRvbdRDuaTqc5vUkbqogx+H7F5rjV 3eSQ== 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=ldS2aUIQCjDABU+D+8IHhilomSTYcSJOhSaAgOfY7jc=; fh=6iIdDMHM3xs7FqY7rwk7A+QeZqkhrispzuMT8+1se1M=; b=RKrcZRHpsNN+SQ7OIXhIDK35DFUm5epWPa0RZiDaUHZeoA+8vfd2Wejg3h/WHXTV0F 15UbfJWmmr4CfHGXTbgq8vy8afcNac+UYtSJ4Ho8v1Gn9GSgKiUZPCXyja2bauhpoNjz KqCKOMEfl+BUjlEZ9oQL979MofAG8SIZLCoVGaq0jLXZZxSpj/mkFrpPSKc8p8E6YQ6u U5nehYWxf0pZuHHWwkk4Ti18kHwdAj1y6aYLlvy/LCvXd8mTwKLxEXLJTeIZHBi8O39w Nssgvdd74rIL+h15xP3Wn707Ot/bdhbZYug1fUwRT2JfWuoPcI8wPUY6QU/jYzuVFjwX WufQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id d3-20020a633603000000b0057750d57806si9275909pga.136.2023.09.19.02.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 02:07:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 90756801B98A; Tue, 19 Sep 2023 02:02:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbjISJCo (ORCPT + 99 others); Tue, 19 Sep 2023 05:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231167AbjISJCm (ORCPT ); Tue, 19 Sep 2023 05:02:42 -0400 Received: from omta002.cacentral1.a.cloudfilter.net (omta002.cacentral1.a.cloudfilter.net [3.97.99.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7ACF114 for ; Tue, 19 Sep 2023 02:02:36 -0700 (PDT) Received: from shw-obgw-4001a.ext.cloudfilter.net ([10.228.9.142]) by cmsmtp with ESMTP id iE0mqXQGt6NwhiWcuqy4X0; Tue, 19 Sep 2023 09:02:36 +0000 Received: from webber.adilger.int ([70.77.221.9]) by cmsmtp with ESMTP id iWcpqDHfQHFsOiWctqzzIi; Tue, 19 Sep 2023 09:02:36 +0000 X-Authority-Analysis: v=2.4 cv=XZqaca15 c=1 sm=1 tr=0 ts=650963ac a=2Y6h5+ypAxmHcsumz2f7Og==:117 a=2Y6h5+ypAxmHcsumz2f7Og==:17 a=pGLkceISAAAA:8 a=RPJ6JBhKAAAA:8 a=dfo8dvEvvyXEL6sKrXEA:9 a=fa_un-3J20JGBB2Tu-mn:22 From: Andreas Dilger To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, Alexey Lyashkov , Andreas Dilger Subject: [PATCH 2/7] [v2] lib: move journal checksum code to libsupport Date: Tue, 19 Sep 2023 03:02:22 -0600 Message-Id: <20230919090227.25363-2-adilger@dilger.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230919090227.25363-1-adilger@dilger.ca> References: <20230919090227.25363-1-adilger@dilger.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfCFrFAH+z6isUIhskf+mF6rYn24YdyRjD9fBCpSvkCykdGjFYHE9qqrNcBfhGMsN86HBvgA9GFigoH7Frs2W519/0q2zI+1fO7zJqmJnHirlHIIIUWZ4 pqA3xAjTIysqglNgiJh+g+UwBrXmTOEBnhnVDmM+30rmHngYpO4pH+2a+CuJjrVhjMDGICT/eTXhT5UIgQYRBfVF33DrNedTqh0hKKt/gCW9gTQZi1DqqKaA YHw+oCh3q/fnuA5k0iFVfH6saNfAcL/sB669kB6EUJntrMutp+mW3IXr7Y6AB12i X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:02:47 -0700 (PDT) From: Alexey Lyashkov e2fsck and debugfs have their own copy journal checksum functions, kill duplicates and move into support library. Signed-off-by: Alexey Lyashkov Reviewed-by: Andreas Dilger --- debugfs/journal.c | 50 ---------------------------------- e2fsck/journal.c | 60 ++++------------------------------------- lib/support/Android.bp | 1 + lib/support/Makefile.in | 4 +++ lib/support/jbd2_user.h | 6 +++++ 5 files changed, 16 insertions(+), 105 deletions(-) diff --git a/debugfs/journal.c b/debugfs/journal.c index 5bac0d3b..bf199699 100644 --- a/debugfs/journal.c +++ b/debugfs/journal.c @@ -43,56 +43,6 @@ static int bh_count = 0; */ #undef USE_INODE_IO -/* Checksumming functions */ -static int ext2fs_journal_verify_csum_type(journal_t *j, - journal_superblock_t *jsb) -{ - if (!jbd2_journal_has_csum_v2or3(j)) - return 1; - - return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM; -} - -static __u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb) -{ - __u32 crc, old_crc; - - old_crc = jsb->s_checksum; - jsb->s_checksum = 0; - crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb, - sizeof(journal_superblock_t)); - jsb->s_checksum = old_crc; - - return crc; -} - -static int ext2fs_journal_sb_csum_verify(journal_t *j, - journal_superblock_t *jsb) -{ - __u32 provided, calculated; - - if (!jbd2_journal_has_csum_v2or3(j)) - return 1; - - provided = ext2fs_be32_to_cpu(jsb->s_checksum); - calculated = ext2fs_journal_sb_csum(jsb); - - return provided == calculated; -} - -static errcode_t ext2fs_journal_sb_csum_set(journal_t *j, - journal_superblock_t *jsb) -{ - __u32 crc; - - if (!jbd2_journal_has_csum_v2or3(j)) - return 0; - - crc = ext2fs_journal_sb_csum(jsb); - jsb->s_checksum = ext2fs_cpu_to_be32(crc); - return 0; -} - /* Kernel compatibility functions for handling the journal. These allow us * to use the recovery.c file virtually unchanged from the kernel, so we * don't have to do much to keep kernel and user recovery in sync. diff --git a/e2fsck/journal.c b/e2fsck/journal.c index 26927cde..bc3c699a 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -38,56 +38,6 @@ static int bh_count = 0; */ #undef USE_INODE_IO -/* Checksumming functions */ -static int e2fsck_journal_verify_csum_type(journal_t *j, - journal_superblock_t *jsb) -{ - if (!jbd2_journal_has_csum_v2or3(j)) - return 1; - - return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM; -} - -static __u32 e2fsck_journal_sb_csum(journal_superblock_t *jsb) -{ - __u32 crc, old_crc; - - old_crc = jsb->s_checksum; - jsb->s_checksum = 0; - crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb, - sizeof(journal_superblock_t)); - jsb->s_checksum = old_crc; - - return crc; -} - -static int e2fsck_journal_sb_csum_verify(journal_t *j, - journal_superblock_t *jsb) -{ - __u32 provided, calculated; - - if (!jbd2_journal_has_csum_v2or3(j)) - return 1; - - provided = ext2fs_be32_to_cpu(jsb->s_checksum); - calculated = e2fsck_journal_sb_csum(jsb); - - return provided == calculated; -} - -static errcode_t e2fsck_journal_sb_csum_set(journal_t *j, - journal_superblock_t *jsb) -{ - __u32 crc; - - if (!jbd2_journal_has_csum_v2or3(j)) - return 0; - - crc = e2fsck_journal_sb_csum(jsb); - jsb->s_checksum = ext2fs_cpu_to_be32(crc); - return 0; -} - /* Kernel compatibility functions for handling the journal. These allow us * to use the recovery.c file virtually unchanged from the kernel, so we * don't have to do much to keep kernel and user recovery in sync. @@ -1347,8 +1297,8 @@ static errcode_t e2fsck_journal_load(journal_t *journal) jbd2_has_feature_checksum(journal)) return EXT2_ET_CORRUPT_JOURNAL_SB; - if (!e2fsck_journal_verify_csum_type(journal, jsb) || - !e2fsck_journal_sb_csum_verify(journal, jsb)) + if (!ext2fs_journal_verify_csum_type(journal, jsb) || + !ext2fs_journal_sb_csum_verify(journal, jsb)) return EXT2_ET_CORRUPT_JOURNAL_SB; if (jbd2_journal_has_csum_v2or3(journal)) @@ -1436,7 +1386,7 @@ static void e2fsck_journal_reset_super(e2fsck_t ctx, journal_superblock_t *jsb, for (i = 0; i < 4; i ++) new_seq ^= u.val[i]; jsb->s_sequence = htonl(new_seq); - e2fsck_journal_sb_csum_set(journal, jsb); + ext2fs_journal_sb_csum_set(journal, jsb); mark_buffer_dirty(journal->j_sb_buffer); ll_rw_block(REQ_OP_WRITE, 0, 1, &journal->j_sb_buffer); @@ -1476,7 +1426,7 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, jsb->s_sequence = htonl(journal->j_tail_sequence); if (reset) jsb->s_start = 0; /* this marks the journal as empty */ - e2fsck_journal_sb_csum_set(journal, jsb); + ext2fs_journal_sb_csum_set(journal, jsb); mark_buffer_dirty(journal->j_sb_buffer); } brelse(journal->j_sb_buffer); @@ -1619,7 +1569,7 @@ no_has_journal: ctx->fs->super->s_state |= EXT2_ERROR_FS; ext2fs_mark_super_dirty(ctx->fs); journal->j_superblock->s_errno = 0; - e2fsck_journal_sb_csum_set(journal, journal->j_superblock); + ext2fs_journal_sb_csum_set(journal, journal->j_superblock); mark_buffer_dirty(journal->j_sb_buffer); } diff --git a/lib/support/Android.bp b/lib/support/Android.bp index af9b28df..260f4b31 100644 --- a/lib/support/Android.bp +++ b/lib/support/Android.bp @@ -30,6 +30,7 @@ cc_library { "quotaio.c", "quotaio_tree.c", "quotaio_v2.c", + "jbd2_user.c" ], shared_libs: [ "libext2fs", diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in index b6229091..284fde85 100644 --- a/lib/support/Makefile.in +++ b/lib/support/Makefile.in @@ -14,6 +14,7 @@ MKDIR_P = @MKDIR_P@ all:: OBJS= cstring.o \ + jbd2_user.o \ mkquota.o \ plausible.o \ profile.o \ @@ -29,6 +30,7 @@ OBJS= cstring.o \ SRCS= $(srcdir)/argv_parse.c \ $(srcdir)/cstring.c \ + $(srcdir)/jbd2_user.c \ $(srcdir)/mkquota.c \ $(srcdir)/parse_qtype.c \ $(srcdir)/plausible.c \ @@ -110,6 +112,8 @@ argv_parse.o: $(srcdir)/argv_parse.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/argv_parse.h cstring.o: $(srcdir)/cstring.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/cstring.h +jbd2_user.o: $(srcdir)/jbd2_user.c $(top_builddir)/lib/config.h \ + $(srcdir)/jbd2_user.h mkquota.o: $(srcdir)/mkquota.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ diff --git a/lib/support/jbd2_user.h b/lib/support/jbd2_user.h index 5928a8a8..22f8cb7e 100644 --- a/lib/support/jbd2_user.h +++ b/lib/support/jbd2_user.h @@ -251,6 +251,12 @@ _INLINE_ void jbd2_descriptor_block_csum_set(journal_t *j, #undef _INLINE_ #endif +/* Checksumming functions */ +int ext2fs_journal_verify_csum_type(journal_t *j, journal_superblock_t *jsb); +__u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb); +int ext2fs_journal_sb_csum_verify(journal_t *j, journal_superblock_t *jsb); +errcode_t ext2fs_journal_sb_csum_set(journal_t *j, journal_superblock_t *jsb); + /* * Kernel compatibility functions are defined in journal.c */ -- 2.25.1