From patchwork Sat Jan 7 08:33:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 134793 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A4A06B6F74 for ; Sat, 7 Jan 2012 19:34:24 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759221Ab2AGIeS (ORCPT ); Sat, 7 Jan 2012 03:34:18 -0500 Received: from e37.co.us.ibm.com ([32.97.110.158]:41271 "EHLO e37.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759027Ab2AGIeO (ORCPT ); Sat, 7 Jan 2012 03:34:14 -0500 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 7 Jan 2012 01:34:13 -0700 Received: from d03relay04.boulder.ibm.com (9.17.195.106) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 7 Jan 2012 01:33:26 -0700 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q078XPQp172196 for ; Sat, 7 Jan 2012 01:33:25 -0700 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q078XOSh032733 for ; Sat, 7 Jan 2012 01:33:25 -0700 Received: from elm3c44.beaverton.ibm.com (elm3c44.beaverton.ibm.com [9.47.69.44]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q078XNjM032709; Sat, 7 Jan 2012 01:33:23 -0700 Subject: [PATCH 04/51] libext2fs: Precompute FS UUID checksum seed To: Andreas Dilger , Theodore Tso , "Darrick J. Wong" From: "Darrick J. Wong" Cc: Sunil Mushran , Amir Goldstein , Andi Kleen , Mingming Cao , Joel Becker , linux-ext4@vger.kernel.org, Coly Li Date: Sat, 07 Jan 2012 00:33:23 -0800 Message-ID: <20120107083323.25788.32820.stgit@elm3c44.beaverton.ibm.com> In-Reply-To: <20120107083256.25788.41238.stgit@elm3c44.beaverton.ibm.com> References: <20120107083256.25788.41238.stgit@elm3c44.beaverton.ibm.com> User-Agent: StGit/0.15 MIME-Version: 1.0 x-cbid: 12010708-7408-0000-0000-000001B976DE Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Precompute the FS UUID checksum seed that is used for all metadata checksumming operations and store it in ext2_filsys. Signed-off-by: Darrick J. Wong --- e2fsck/super.c | 1 + lib/ext2fs/ext2fs.h | 14 ++++++++++++++ lib/ext2fs/openfs.c | 2 ++ misc/mke2fs.c | 1 + 4 files changed, 18 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/e2fsck/super.c b/e2fsck/super.c index afec4b4..99c0b84 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -719,6 +719,7 @@ void check_super_block(e2fsck_t ctx) if (!(ctx->options & E2F_OPT_READONLY) && uuid_is_null(sb->s_uuid)) { if (fix_problem(ctx, PR_0_ADD_UUID, &pctx)) { uuid_generate(sb->s_uuid); + ext2fs_init_csum_seed(fs); fs->flags |= EXT2_FLAG_DIRTY; fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; } diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 16c4567..c00032e 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -279,6 +279,9 @@ struct struct_ext2_filsys { * Time at which e2fsck last updated the MMP block. */ long mmp_last_written; + + /* Precomputed FS UUID checksum for seeding other checksums */ + __u32 csum_seed; }; #if EXT2_FLAT_INCLUDES @@ -1424,6 +1427,7 @@ extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list, /* inline functions */ +extern void ext2fs_init_csum_seed(ext2_filsys fs); extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr); extern errcode_t ext2fs_get_memalign(unsigned long size, unsigned long align, void *ptr); @@ -1476,6 +1480,16 @@ extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf); #ifndef EXT2_CUSTOM_MEMORY_ROUTINES #include +_INLINE_ void ext2fs_init_csum_seed(ext2_filsys fs) +{ + if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) + return; + + fs->csum_seed = ext2fs_crc32c_le(~0, fs->super->s_uuid, + sizeof(fs->super->s_uuid)); +} + /* * Allocate memory */ diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 40a52c5..6cb629e 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -298,6 +298,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } + /* Precompute the FS UUID to seed other checksums */ + ext2fs_init_csum_seed(fs); /* * Read group descriptors diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 0ef2531..f2d7c81 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -2315,6 +2315,7 @@ int main (int argc, char *argv[]) } } else uuid_generate(fs->super->s_uuid); + ext2fs_init_csum_seed(fs); /* * Initialize the directory index variables