From: "Darrick J. Wong" Subject: [PATCH 19/51] tune2fs: Enable extent tree checksums Date: Tue, 13 Dec 2011 17:15:24 -0800 Message-ID: <20111214011524.20947.10013.stgit@elm3c44.beaverton.ibm.com> References: <20111214011316.20947.13706.stgit@elm3c44.beaverton.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: Sunil Mushran , Amir Goldstein , Andi Kleen , Mingming Cao , Joel Becker , linux-ext4@vger.kernel.org, Coly Li To: Andreas Dilger , Theodore Tso , "Darrick J. Wong" Return-path: Received: from e7.ny.us.ibm.com ([32.97.182.137]:35010 "EHLO e7.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756424Ab1LNBQW (ORCPT ); Tue, 13 Dec 2011 20:16:22 -0500 Received: from /spool/local by e7.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Dec 2011 20:16:21 -0500 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBE1FRa1202830 for ; Tue, 13 Dec 2011 20:15:27 -0500 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBE1FPrB008138 for ; Tue, 13 Dec 2011 23:15:27 -0200 In-Reply-To: <20111214011316.20947.13706.stgit@elm3c44.beaverton.ibm.com> Sender: linux-ext4-owner@vger.kernel.org List-ID: Add to tune2fs the ability to recalculate extent tree checksums when altering the metadata checksum feature flag. Signed-off-by: Darrick J. Wong --- misc/tune2fs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-) diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 12a22ed..c7b9fd3 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -376,6 +376,48 @@ static void request_fsck_afterwards(ext2_filsys fs) printf(_("(and reboot afterwards!)\n")); } +/* Rewrite extents */ +static errcode_t rewrite_extents(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode) +{ + ext2_extent_handle_t handle; + struct ext2fs_extent extent; + int op = EXT2_EXTENT_ROOT; + errcode_t errcode; + + if (!(inode->i_flags & EXT4_EXTENTS_FL)) + return 0; + + errcode = ext2fs_extent_open(fs, ino, &handle); + if (errcode) + return errcode; + + while (1) { + errcode = ext2fs_extent_get(handle, op, &extent); + if (errcode) + break; + + /* Root node is in the separately checksummed inode */ + if (op == EXT2_EXTENT_ROOT) { + op = EXT2_EXTENT_NEXT; + continue; + } + op = EXT2_EXTENT_NEXT; + + /* Only visit the first extent in each extent block */ + if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT) + continue; + errcode = ext2fs_extent_replace(handle, 0, &extent); + if (errcode) + break; + } + + /* Ok if we run off the end */ + if (errcode == EXT2_ET_EXTENT_NO_NEXT) + errcode = 0; + return errcode; +} + /* * Forcibly set checksums in all inodes. */ @@ -416,6 +458,13 @@ static void rewrite_inodes(ext2_filsys fs) com_err("set_csum", retval, "while writing inode"); exit(1); } + + retval = rewrite_extents(fs, ino, inode); + if (retval) { + com_err("rewrite_extents", retval, + "while rewriting extents"); + exit(1); + } } while (ino); ext2fs_free_mem(&inode);