From: Alexander Shishkin Subject: [PATCH] [RFC] mkjournal: zero journal blocks only when necessary Date: Wed, 29 Jul 2009 18:58:16 +0300 Message-ID: <1248883096-2294-1-git-send-email-alexander.shishckin@gmail.com> References: <71a0d6ff0905120549h628146d8p3def31b09b79199a@mail.gmail.com> Cc: linux-ext4@vger.kernel.org, Alexander Shishkin To: Theodore Tso Return-path: Received: from smtp.nokia.com ([192.100.122.230]:19843 "EHLO mgw-mx03.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750977AbZG2P7U (ORCPT ); Wed, 29 Jul 2009 11:59:20 -0400 In-Reply-To: <71a0d6ff0905120549h628146d8p3def31b09b79199a@mail.gmail.com> Sender: linux-ext4-owner@vger.kernel.org List-ID: Will something like this do? The only blocks that might theoretically (although very unlikely) be dangerous for newly-created filesystem's integrity are those that still contain valid signatures, others can be safely skipped. Since reads are generally faster (or at least, not slower), this gives some performance increase during mkfs run. Signed-off-by: Alexander Shishkin --- lib/ext2fs/mkjournal.c | 49 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 43 insertions(+), 6 deletions(-) diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index f5a9dba..bb6e748 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -144,6 +144,44 @@ errout: * attempt to free the static zeroizing buffer. (This is to keep * programs that check for memory leaks happy.) */ +static errcode_t jzero_blocks(io_channel channel, unsigned long long block, + int count) +{ + errcode_t retval; + unsigned long long n; + static void *__buf = NULL; + struct unix_private_data *data; + + data = channel->private_data; + if (!__buf) + __buf = malloc(channel->block_size); + if (!__buf) + return -1; + + for (n = block; n < block + count; n++) { + journal_header_t *jr; + + retval = io_channel_read_blk(channel, n, 1, __buf); + if (retval) + goto out_err; + continue; + + jr = __buf; + if (jr->h_magic == htonl(JFS_MAGIC_NUMBER) && + jr->h_blocktype == htonl(JFS_REVOKE_BLOCK)) { + memset(__buf, 0, channel->block_size); + retval = io_channel_write_blk(channel, n, 1, __buf); + } + + if (retval) + goto out_err; + } + + return 0; +out_err: + return -1; +} + #define STRIDE_LENGTH 8 errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num, blk_t *ret_blk, int *ret_count) @@ -238,10 +276,9 @@ static int mkjournal_proc(ext2_filsys fs, (es->zero_count < 1024)) es->zero_count++; else { - retval = ext2fs_zero_blocks(fs, - es->blk_to_zero, - es->zero_count, - 0, 0); + retval = jzero_blocks(fs->io, + es->blk_to_zero, + es->zero_count); es->zero_count = 0; } } @@ -339,8 +376,8 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, goto errout; } if (es.zero_count) { - retval = ext2fs_zero_blocks(fs, es.blk_to_zero, - es.zero_count, 0, 0); + retval = jzero_blocks(fs->io, es.blk_to_zero, + es.zero_count); if (retval) goto errout; } -- 1.6.3.3