e2fsprogs journal fixes (UUID and 1k block size issue)
v3 cover e2fsprogs journal fixes (UUID and 1k block size issue)
Hi all,
Here is patchset with some fixes for journal code in e2fsprogs. I've removed first patch from previous version "lib: add EXT2_ prefix for SUPERBLOCK_{OFFSET,SIZE}", and rebase other patches on top of the maint branch.
I've tested it using "make check" and commands from commits.
I do want to add tests for this cases, but they requires some extra capabilities (CAP_SYS_ADMIN for mount(2)), while right now tests don't have such cases, if somebody have proposal how to do this tests without extra mount(2) I will be happy to hear (for more info about possible test cases see "tune2fs: update journal super block when changing UUID for fs." and "tune2fs:
update journal users while updating fs UUID (with external journal)")
Thanks.
Azat.
Azat Khuzhin (4):
journal: use consts instead of 1024 and add helper for journal with 1k
blocksize
tune2fs: remove_journal_device(): use the correct block to find jsb
tune2fs: update journal super block when changing UUID for fs.
tune2fs: update journal users while updating fs UUID (with external
journal)
e2fsck/journal.c | 5 +- lib/ext2fs/ext2fs.h | 3 + lib/ext2fs/kernel-jbd.h | 6 +- lib/ext2fs/mkjournal.c | 28 ++++---- misc/tune2fs.c | 166 +++++++++++++++++++++++++++++++++++++++++------- misc/uuidd.c | 3 +- 6 files changed, 171 insertions(+), 40 deletions(-)
Signature · 1 line
2.0.1
PATCH v3 1/4 journal: use consts instead of 1024 and add helper for journal with 1k blocksize
Use EXT2_MIN_BLOCK_SIZE/JFS_MIN_JOURNAL_BLOCKS/SUPERBLOCK_SIZE/SUPERBLOCK_OFFSET instead of hardcoded 1024 when it is okay, and also add a helper ext2fs_journal_sb_start() that will return start of journal sb with special case for fs with 1k block size.
--- e2fsck/journal.c | 5 ++--- lib/ext2fs/ext2fs.h | 1 + lib/ext2fs/mkjournal.c | 28 ++++++++++++++++------------ misc/tune2fs.c | 6 +++--- 4 files changed, 22 insertions(+), 18 deletions(-)
e2fsck/journal.c +2 -3
@@ -393,8 +393,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)if (ext_journal) {blk64_t maxlen; -if (ctx->fs->blocksize ==1024 ) - start =1 ; + start =ext2fs_journal_sb_start (ctx->fs->blocksize) -1 ; bh =getblk (dev_journal, start, ctx->fs->blocksize);if (!bh) { retval =EXT2_ET_NO_MEMORY ;
@@ -405,7 +404,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)brelse (bh); goto errout; } -memcpy (&jsuper, start ? bh->b_data : bh->b_data +1024 , +memcpy (&jsuper, start ? bh->b_data : bh->b_data +SUPERBLOCK_OFFSET ,sizeof (jsuper));brelse (bh);#ifdef WORDS_BIGENDIAN
lib/ext2fs/ext2fs.h +1 -0
@@ -1377,6 +1377,7 @@ extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks,extern errcode_t ext2fs_add_journal_inode2 (ext2_filsys fs,blk_t num_blocks,blk64_t goal,int flags);extern int ext2fs_default_journal_size (__u64 num_blocks); +extern int ext2fs_journal_sb_start (int blocksize);/* openfs.c */ extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
lib/ext2fs/mkjournal.c +16 -12
@@ -49,7 +49,7 @@ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,errcode_t retval;journal_superblock_t *jsb; -if (num_blocks <1024 ) +if (num_blocks <JFS_MIN_JOURNAL_BLOCKS )return EXT2_ET_JOURNAL_TOO_SMALL ;if ((retval =ext2fs_get_mem (fs->blocksize, &jsb)))
@@ -75,10 +75,7 @@ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,if (fs->super->s_feature_incompat &EXT3_FEATURE_INCOMPAT_JOURNAL_DEV ) { jsb->s_nr_users =0 ; -if (fs->blocksize ==1024 ) - jsb->s_first =htonl (3 ); -else - jsb->s_first =htonl (2 ); + jsb->s_first =htonl (ext2fs_journal_sb_start (fs->blocksize) +1 ); } *ret_jsb = (char *) jsb;
@@ -428,6 +425,13 @@ int ext2fs_default_journal_size(__u64 num_blocks)return 32768 ; } +int ext2fs_journal_sb_start (int blocksize) +{ +if (blocksize ==EXT2_MIN_BLOCK_SIZE ) +return 2 ; +return 1 ; +} +/* * This function adds a journal device to a filesystem */
@@ -435,7 +439,7 @@ errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev) {struct stat st;errcode_t retval; -char buf[1024 ]; +char buf[SUPERBLOCK_SIZE ];journal_superblock_t *jsb;int start;__u32 i, nr_users;
@@ -448,10 +452,9 @@ errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev)return EXT2_ET_JOURNAL_NOT_BLOCK ;/* Must be a block device */ /* Get the journal superblock */ - start =1 ; -if (journal_dev->blocksize ==1024 ) - start++; -if ((retval =io_channel_read_blk64 (journal_dev->io, start,-1024 , + start =ext2fs_journal_sb_start (journal_dev->blocksize); +if ((retval =io_channel_read_blk64 (journal_dev->io, start, + -SUPERBLOCK_SIZE , buf)))return retval;
@@ -477,7 +480,8 @@ errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev) }/* Writeback the journal superblock */ -if ((retval =io_channel_write_blk64 (journal_dev->io, start,-1024 , buf))) +if ((retval =io_channel_write_blk64 (journal_dev->io, start, + -SUPERBLOCK_SIZE , buf)))return retval; fs->super->s_journal_inum =0 ;
@@ -630,7 +634,7 @@ main(int argc, char **argv)exit (1 ); } - retval =ext2fs_add_journal_inode (fs,1024 ,0 ); + retval =ext2fs_add_journal_inode (fs,JFS_MIN_JOURNAL_BLOCKS ,0 );if (retval) {com_err (argv[0 ], retval,"while adding journal to %s" , device_name);
misc/tune2fs.c +3 -3
@@ -182,7 +182,7 @@ static int remove_journal_device(ext2_filsys fs) {char *journal_path;ext2_filsys jfs; -char buf[1024 ]; +char buf[SUPERBLOCK_SIZE ];journal_superblock_t *jsb;int i, nr_users;errcode_t retval;
@@ -225,7 +225,7 @@ static int remove_journal_device(ext2_filsys fs) }/* Get the journal superblock */ -if ((retval =io_channel_read_blk64 (jfs->io,1 ,-1024 , buf))) { +if ((retval =io_channel_read_blk64 (jfs->io,1 , -SUPERBLOCK_SIZE , buf))) {com_err (program_name, retval,"%s" ,_ ("while reading journal superblock" )); goto no_valid_journal;
@@ -256,7 +256,7 @@ static int remove_journal_device(ext2_filsys fs) jsb->s_nr_users =htonl (nr_users);/* Write back the journal superblock */ -if ((retval =io_channel_write_blk64 (jfs->io,1 ,-1024 , buf))) { +if ((retval =io_channel_write_blk64 (jfs->io,1 , -SUPERBLOCK_SIZE , buf))) {com_err (program_name, retval,"while writing journal superblock." ); goto no_valid_journal;
Signature · 1 line
2.0.1
PATCH v3 2/4 tune2fs: remove_journal_device(): use the correct block to find jsb
In reply to Azat Khuzhin--- misc/tune2fs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
misc/tune2fs.c +6 -2
@@ -188,6 +188,7 @@ static int remove_journal_device(ext2_filsys fs)errcode_t retval;int commit_remove_journal =0 ;io_manager io_ptr; +int start;if (f_flag) commit_remove_journal =1 ;/* force removal even if error */
@@ -224,8 +225,10 @@ static int remove_journal_device(ext2_filsys fs) goto no_valid_journal; } + start =ext2fs_journal_sb_start (fs->blocksize);/* Get the journal superblock */ -if ((retval =io_channel_read_blk64 (jfs->io,1 , -SUPERBLOCK_SIZE , buf))) { +if ((retval =io_channel_read_blk64 (jfs->io, start, + -SUPERBLOCK_SIZE , buf))) {com_err (program_name, retval,"%s" ,_ ("while reading journal superblock" )); goto no_valid_journal;
@@ -256,7 +259,8 @@ static int remove_journal_device(ext2_filsys fs) jsb->s_nr_users =htonl (nr_users);/* Write back the journal superblock */ -if ((retval =io_channel_write_blk64 (jfs->io,1 , -SUPERBLOCK_SIZE , buf))) { +if ((retval =io_channel_write_blk64 (jfs->io, start, + -SUPERBLOCK_SIZE , buf))) {com_err (program_name, retval,"while writing journal superblock." ); goto no_valid_journal;
Signature · 1 line
2.0.1
PATCH v3 3/4 tune2fs: update journal super block when changing UUID for fs.
In reply to Azat KhuzhinUsing -U option you can change the UUID for fs, however it will not work for journal device, since it have a copy of this UUID inside jsb (i.e. journal super block). So copy UUID on change into that block.
Here is the initial thread:
http://comments.gmane.org/gmane.comp.file-systems.ext4/44532
You can reproduce this by executing following commands:
$ fallocate -l100M /tmp/dev $ fallocate -l100M /tmp/journal $ sudo /sbin/losetup /dev/loop1 /tmp/dev $ sudo /sbin/losetup /dev/loop0 /tmp/journal $ mke2fs -O journal_dev /tmp/journal $ tune2fs -U da1f2ed0-60f6-aaaa-92fd-738701418523 /tmp/journal $ sudo mke2fs -t ext4 -J device=/dev/loop0 /dev/loop1 $ dumpe2fs -h /tmp/dev | fgrep UUID dumpe2fs 1.43-WIP (18-May-2014) Filesystem UUID: 8a776be9-12eb-411f-8e88-b873575ecfb6 Journal UUID: e3d02151-e776-4865-af25-aecb7291e8e5 $ sudo e2fsck /dev/vdc e2fsck 1.43-WIP (18-May-2014) External journal does not support this filesystem
/dev/loop1: ********** WARNING: Filesystem still has errors **********
--- misc/tune2fs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 18 deletions(-)
misc/tune2fs.c +56 -18
@@ -175,6 +175,38 @@ static __u32 clear_ok_features[3] = {EXT4_FEATURE_RO_COMPAT_GDT_CSUM }; +/** +* Try to get journal super block if any +*/ +static int get_journal_sb (ext2_filsys jfs,char buf[SUPERBLOCK_SIZE ]) +{ +int retval; +int start; +journal_superblock_t *jsb; + +if (!(jfs->super->s_feature_incompat & +EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { +return EXT2_ET_UNSUPP_FEATURE ; + } + +/* Get the journal superblock */ +if ((retval =io_channel_read_blk64 (jfs->io, +ext2fs_journal_sb_start (jfs->blocksize), -SUPERBLOCK_SIZE , buf))) { +com_err (program_name, retval,"%s" , +_ ("while reading journal superblock" )); +return retval; + } + + jsb = (journal_superblock_t *) buf; +if ((jsb->s_header.h_magic != (unsigned )ntohl (JFS_MAGIC_NUMBER )) || + (jsb->s_header.h_blocktype != (unsigned )ntohl (JFS_SUPERBLOCK_V2 ))) { +fputs (_ ("Journal superblock not found!\n" ), stderr); +return EXT2_ET_BAD_MAGIC ; + } + +return 0 ; +} +/* * Remove an external journal from the filesystem */
@@ -218,29 +250,15 @@ static int remove_journal_device(ext2_filsys fs) _("while trying to open external journal")); goto no_valid_journal; } -if (!(jfs->super->s_feature_incompat & -EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { -fprintf (stderr,_ ("%s is not a journal device.\n" ), - journal_path); - goto no_valid_journal; - } - start =ext2fs_journal_sb_start (fs->blocksize); -/* Get the journal superblock */ -if ((retval =io_channel_read_blk64 (jfs->io, start, - -SUPERBLOCK_SIZE , buf))) { -com_err (program_name, retval,"%s" , -_ ("while reading journal superblock" )); +if ((retval =get_journal_sb (jfs, buf))) { +if (retval ==EXT2_ET_UNSUPP_FEATURE ) +fprintf (stderr,_ ("%s is not a journal device.\n" ), + journal_path); goto no_valid_journal; } jsb = (journal_superblock_t *) buf; -if ((jsb->s_header.h_magic != (unsigned )ntohl (JFS_MAGIC_NUMBER )) || - (jsb->s_header.h_blocktype != (unsigned )ntohl (JFS_SUPERBLOCK_V2 ))) { -fputs (_ ("Journal superblock not found!\n" ), stderr); - goto no_valid_journal; - } -/* Find the filesystem UUID */ nr_users =ntohl (jsb->s_nr_users);for (i =0 ; i < nr_users; i++) {
@@ -2184,6 +2202,7 @@ retry_open:if (U_flag) {int set_csum =0 ;dgrp_t i; +char buf[SUPERBLOCK_SIZE ];if (sb->s_feature_ro_compat &EXT4_FEATURE_RO_COMPAT_GDT_CSUM ) {
@@ -2229,6 +2248,25 @@ retry_open:ext2fs_group_desc_csum_set (fs, i); fs->flags &= ~EXT2_FLAG_SUPER_ONLY ; } + +/* If this is a journal dev, we need to copy UUID into jsb */ +if (!(rc =get_journal_sb (fs, buf))) { +journal_superblock_t *jsb; + + jsb = (journal_superblock_t *) buf; +fputs (_ ("Need to update journal superblock.\n" ), stdout); +memcpy (jsb->s_uuid, sb->s_uuid,sizeof (sb->s_uuid)); + +/* Writeback the journal superblock */ +if ((rc =io_channel_write_blk64 (fs->io, +ext2fs_journal_sb_start (fs->blocksize), + -SUPERBLOCK_SIZE , buf))) + goto closefs; + }else if (rc !=EXT2_ET_UNSUPP_FEATURE ) + goto closefs; +else + rc =0 ;/** Reset rc to avoid ext2fs_mmp_stop() */ +ext2fs_mark_super_dirty (fs); }if (I_flag) {
Signature · 1 line
2.0.1
Re: [PATCH 3/4 v3] tune2fs: update journal super block when changing UUID for fs.
Quoted 77 lines · Azat Khuzhin
Using -U option you can change the UUID for fs, however it will not work for journal device, since it have a copy of this UUID inside jsb (i.e. journal super block). So copy UUID on change into that block.
Here is the initial thread:
http://comments.gmane.org/gmane.comp.file-systems.ext4/44532You can reproduce this by executing following commands:
$ fallocate -l100M /tmp/dev $ fallocate -l100M /tmp/journal $ sudo /sbin/losetup /dev/loop1 /tmp/dev $ sudo /sbin/losetup /dev/loop0 /tmp/journal $ mke2fs -O journal_dev /tmp/journal $ tune2fs -U da1f2ed0-60f6-aaaa-92fd-738701418523 /tmp/journal $ sudo mke2fs -t ext4 -J device=/dev/loop0 /dev/loop1 $ dumpe2fs -h /tmp/dev | fgrep UUID dumpe2fs 1.43-WIP (18-May-2014) Filesystem UUID: 8a776be9-12eb-411f-8e88-b873575ecfb6 Journal UUID: e3d02151-e776-4865-af25-aecb7291e8e5 $ sudo e2fsck /dev/vdc e2fsck 1.43-WIP (18-May-2014) External journal does not support this filesystem
/dev/loop1: ********** WARNING: Filesystem still has errors **********Reported-by Chin Tzung Cheng <[email protected]>Signed-off-by Azat Khuzhin <[email protected]>Reviewed-by Andreas Dilger <[email protected]>--- misc/tune2fs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 18 deletions(-)misc/tune2fs.c +32
-0@@ -175,6 +175,38 @@ static __u32 clear_ok_features[3] = {EXT4_FEATURE_RO_COMPAT_GDT_CSUM }; +/** +* Try to get journal super block if any +*/ +static int get_journal_sb (ext2_filsys jfs,char buf[SUPERBLOCK_SIZE ]) +{ +int retval; +int start; +journal_superblock_t *jsb; + +if (!(jfs->super->s_feature_incompat & +EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { +return EXT2_ET_UNSUPP_FEATURE ; + } + +/* Get the journal superblock */ +if ((retval =io_channel_read_blk64 (jfs->io, +ext2fs_journal_sb_start (jfs->blocksize), -SUPERBLOCK_SIZE , buf))) { +com_err (program_name, retval,"%s" , +_ ("while reading journal superblock" )); +return retval; + } + + jsb = (journal_superblock_t *) buf; +if ((jsb->s_header.h_magic != (unsigned )ntohl (JFS_MAGIC_NUMBER )) || + (jsb->s_header.h_blocktype != (unsigned )ntohl (JFS_SUPERBLOCK_V2 ))) { +fputs (_ ("Journal superblock not found!\n" ), stderr); +return EXT2_ET_BAD_MAGIC ; + } + +return 0 ; +} +/* * Remove an external journal from the filesystem */ @@ -218,29 +250,15 @@ static int remove_journal_device(ext2_filsys fs) _("while trying to open external journal"));
misc/tune2fs.c static int remove_journal_device(ext2_filsys fs) · line 228
Quoted 10 lines
misc/tune2fs.c +0
-7goto no_valid_journal; } -if (!(jfs->super->s_feature_incompat & -EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { -fprintf (stderr,_ ("%s is not a journal device.\n" ), - journal_path); - goto no_valid_journal; - } - start =ext2fs_journal_sb_start (fs->blocksize);
This is already committed (which is why Coverity whined about it), but:
removing this assignment causes an uninitialized use of "start" later in this function:
/* Write back the journal superblock */
if ((retval = io_channel_write_blk64(jfs->io, start,
-SUPERBLOCK_SIZE, buf)))-Eric
Re: [PATCH 3/4 v3] tune2fs: update journal super block when changing UUID for fs.
Quoted 93 lines · Eric Sandeen
Quoted 77 lines · Azat Khuzhin
Using -U option you can change the UUID for fs, however it will not work for journal device, since it have a copy of this UUID inside jsb (i.e. journal super block). So copy UUID on change into that block.
Here is the initial thread:
http://comments.gmane.org/gmane.comp.file-systems.ext4/44532You can reproduce this by executing following commands:
$ fallocate -l100M /tmp/dev $ fallocate -l100M /tmp/journal $ sudo /sbin/losetup /dev/loop1 /tmp/dev $ sudo /sbin/losetup /dev/loop0 /tmp/journal $ mke2fs -O journal_dev /tmp/journal $ tune2fs -U da1f2ed0-60f6-aaaa-92fd-738701418523 /tmp/journal $ sudo mke2fs -t ext4 -J device=/dev/loop0 /dev/loop1 $ dumpe2fs -h /tmp/dev | fgrep UUID dumpe2fs 1.43-WIP (18-May-2014) Filesystem UUID: 8a776be9-12eb-411f-8e88-b873575ecfb6 Journal UUID: e3d02151-e776-4865-af25-aecb7291e8e5 $ sudo e2fsck /dev/vdc e2fsck 1.43-WIP (18-May-2014) External journal does not support this filesystem
/dev/loop1: ********** WARNING: Filesystem still has errors **********Reported-by Chin Tzung Cheng <[email protected]>Signed-off-by Azat Khuzhin <[email protected]>Reviewed-by Andreas Dilger <[email protected]>--- misc/tune2fs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 18 deletions(-)misc/tune2fs.c +32
-0@@ -175,6 +175,38 @@ static __u32 clear_ok_features[3] = {EXT4_FEATURE_RO_COMPAT_GDT_CSUM }; +/** +* Try to get journal super block if any +*/ +static int get_journal_sb (ext2_filsys jfs,char buf[SUPERBLOCK_SIZE ]) +{ +int retval; +int start; +journal_superblock_t *jsb; + +if (!(jfs->super->s_feature_incompat & +EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { +return EXT2_ET_UNSUPP_FEATURE ; + } + +/* Get the journal superblock */ +if ((retval =io_channel_read_blk64 (jfs->io, +ext2fs_journal_sb_start (jfs->blocksize), -SUPERBLOCK_SIZE , buf))) { +com_err (program_name, retval,"%s" , +_ ("while reading journal superblock" )); +return retval; + } + + jsb = (journal_superblock_t *) buf; +if ((jsb->s_header.h_magic != (unsigned )ntohl (JFS_MAGIC_NUMBER )) || + (jsb->s_header.h_blocktype != (unsigned )ntohl (JFS_SUPERBLOCK_V2 ))) { +fputs (_ ("Journal superblock not found!\n" ), stderr); +return EXT2_ET_BAD_MAGIC ; + } + +return 0 ; +} +/* * Remove an external journal from the filesystem */ @@ -218,29 +250,15 @@ static int remove_journal_device(ext2_filsys fs) _("while trying to open external journal"));misc/tune2fs.c static int remove_journal_device(ext2_filsys fs) · line 228
Quoted 10 lines
misc/tune2fs.c +0
-7goto no_valid_journal; } -if (!(jfs->super->s_feature_incompat & -EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { -fprintf (stderr,_ ("%s is not a journal device.\n" ), - journal_path); - goto no_valid_journal; - } - start =ext2fs_journal_sb_start (fs->blocksize);This is already committed (which is why Coverity whined about it), but:
removing this assignment causes an uninitialized use of "start" later in this function:
Quoted 5 lines
/* Write back the journal superblock */ if ((retval = io_channel_write_blk64(jfs->io, start, -SUPERBLOCK_SIZE, buf)))-Eric
Hi Eric,
Thanks for catching this.
Patch in attachment must fix this issue.
I maked with -Wall to catch more bugs like this. And there is one more note:
expected ‘char *’ but argument is of type ‘__u8 *’ journal_user()
I will send a patch later.
From 903f251e1ebce3d666a8b2af04b812d4f6751056 Mon Sep 17 00:00:00 2001
From: Azat Khuzhin <[email protected]>
Date: Thu, 31 Jul 2014 19:26:16 +0400
Subject: [PATCH] tune2fs: initialize start block in remove_journal_device()
--- misc/tune2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
misc/tune2fs.c +1 -1
@@ -181,7 +181,6 @@ static __u32 clear_ok_features[3] = {static int get_journal_sb (ext2_filsys jfs,char buf[SUPERBLOCK_SIZE ]) {int retval; -int start;journal_superblock_t *jsb; if (!(jfs->super->s_feature_incompat &
@@ -286,6 +285,7 @@ static int remove_journal_device(ext2_filsys fs) jsb->s_nr_users =htonl (nr_users);/* Write back the journal superblock */ + start =ext2fs_journal_sb_start (jfs->blocksize);if ((retval =io_channel_write_blk64 (jfs->io, start, -SUPERBLOCK_SIZE , buf))) { com_err(program_name, retval,
Signature · 6 lines
2.0.1 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4 v3] tune2fs: update journal super block when changing UUID for fs.
I already fixed that in my recent patch:
http://marc.info/?l=linux-ext4&m=140667665421773&w=2
Cheers, Andreas
Quoted 146 lines · Azat Khuzhin
Quoted 95 lines · Eric Sandeen
Quoted 78 lines · Azat Khuzhin
Using -U option you can change the UUID for fs, however it will not work for journal device, since it have a copy of this UUID inside jsb (i.e. journal super block). So copy UUID on change into that block.
Here is the initial thread:
http://comments.gmane.org/gmane.comp.file-systems.ext4/44532You can reproduce this by executing following commands:
$ fallocate -l100M /tmp/dev $ fallocate -l100M /tmp/journal $ sudo /sbin/losetup /dev/loop1 /tmp/dev $ sudo /sbin/losetup /dev/loop0 /tmp/journal $ mke2fs -O journal_dev /tmp/journal $ tune2fs -U da1f2ed0-60f6-aaaa-92fd-738701418523 /tmp/journal $ sudo mke2fs -t ext4 -J device=/dev/loop0 /dev/loop1 $ dumpe2fs -h /tmp/dev | fgrep UUID dumpe2fs 1.43-WIP (18-May-2014) Filesystem UUID: 8a776be9-12eb-411f-8e88-b873575ecfb6 Journal UUID: e3d02151-e776-4865-af25-aecb7291e8e5 $ sudo e2fsck /dev/vdc e2fsck 1.43-WIP (18-May-2014) External journal does not support this filesystem
/dev/loop1: ********** WARNING: Filesystem still has errors **********Reported-by Chin Tzung Cheng <[email protected]>Signed-off-by Azat Khuzhin <[email protected]>Reviewed-by Andreas Dilger <[email protected]>---
misc/tune2fs.c| 74 ++++++++++++++++++++++++++++++++++++++++++++--------------1 file changed, 56 insertions(+), 18 deletions(-)misc/tune2fs.c +32
-0@@ -175,6 +175,38 @@ static __u32 clear_ok_features[3] = {EXT4_FEATURE_RO_COMPAT_GDT_CSUM }; +/** +* Try to get journal super block if any +*/ +static int get_journal_sb (ext2_filsys jfs,char buf[SUPERBLOCK_SIZE ]) +{ +int retval; +int start; +journal_superblock_t *jsb; + +if (!(jfs->super->s_feature_incompat & +EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { +return EXT2_ET_UNSUPP_FEATURE ; + } + +/* Get the journal superblock */ +if ((retval =io_channel_read_blk64 (jfs->io, +ext2fs_journal_sb_start (jfs->blocksize), -SUPERBLOCK_SIZE , buf))) { +com_err (program_name, retval,"%s" , +_ ("while reading journal superblock" )); +return retval; + } + + jsb = (journal_superblock_t *) buf; +if ((jsb->s_header.h_magic != (unsigned )ntohl (JFS_MAGIC_NUMBER )) || + (jsb->s_header.h_blocktype != (unsigned )ntohl (JFS_SUPERBLOCK_V2 ))) { +fputs (_ ("Journal superblock not found!\n" ), stderr); +return EXT2_ET_BAD_MAGIC ; + } + +return 0 ; +} +/* * Remove an external journal from the filesystem */ @@ -218,29 +250,15 @@ static int remove_journal_device(ext2_filsys fs) _("while trying to open external journal"));misc/tune2fs.c static int remove_journal_device(ext2_filsys fs) · line 228
Quoted 10 lines
misc/tune2fs.c +0
-7goto no_valid_journal; } -if (!(jfs->super->s_feature_incompat & -EXT3_FEATURE_INCOMPAT_JOURNAL_DEV )) { -fprintf (stderr,_ ("%s is not a journal device.\n" ), - journal_path); - goto no_valid_journal; - } - start =ext2fs_journal_sb_start (fs->blocksize);This is already committed (which is why Coverity whined about it), but:
removing this assignment causes an uninitialized use of "start" later in this function:Quoted 5 lines
/* Write back the journal superblock */ if ((retval = io_channel_write_blk64(jfs->io, start, -SUPERBLOCK_SIZE, buf)))-Eric
Hi Eric,
Thanks for catching this.
Patch in attachment must fix this issue.I maked with -Wall to catch more bugs like this. And there is one more note:
expected ‘char *’ but argument is of type ‘__u8 *’journal_user()
I will send a patch later.From
903f251e1ebce3d666a8b2af04b812d4f6751056Mon Sep 17 00:00:00 2001
From: Azat Khuzhin <[email protected]>
Date: Thu, 31 Jul 2014 19:26:16 +0400
Subject: [PATCH] tune2fs: initialize start block inremove_journal_device()---
misc/tune2fs.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)misc/tune2fs.c +1
-1@@ -181,7 +181,6 @@ static __u32 clear_ok_features[3] = {static int get_journal_sb (ext2_filsys jfs,char buf[SUPERBLOCK_SIZE ]) {int retval; -int start;journal_superblock_t *jsb; if (!(jfs->super->s_feature_incompat &@@ -286,6 +285,7 @@ static int remove_journal_device(ext2_filsys fs) jsb->s_nr_users =htonl (nr_users);/* Write back the journal superblock */ + start =ext2fs_journal_sb_start (jfs->blocksize);if ((retval =io_channel_write_blk64 (jfs->io, start, -SUPERBLOCK_SIZE , buf))) { com_err(program_name, retval,Signature · 1 line
2.0.1
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 tune2fs: fix uninitialized variable in remove_journal_device
In reply to Eric SandeenThis bug was introduced by commit 7dfefaf413bbd ("tune2fs: update journal super block when changing UUID for fs").
Fixes-Coverity-Bug: 1229243
--- misc/tune2fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
misc/tune2fs.c +3 -3
@@ -232,7 +232,6 @@ static int remove_journal_device(ext2_filsys fs)errcode_t retval;int commit_remove_journal =0 ;io_manager io_ptr; -int start;if (f_flag) commit_remove_journal =1 ;/* force removal even if error */
@@ -286,8 +285,9 @@ static int remove_journal_device(ext2_filsys fs) jsb->s_nr_users =htonl (nr_users);/* Write back the journal superblock */ -if ((retval =io_channel_write_blk64 (jfs->io, start, - -SUPERBLOCK_SIZE , buf))) { +if ((retval =io_channel_write_blk64 (jfs->io, +ext2fs_journal_sb_start (fs->blocksize), + -SUPERBLOCK_SIZE , buf))) {com_err (program_name, retval,"while writing journal superblock." ); goto no_valid_journal;
Signature · 1 line
2.0.0
Re: [PATCH] tune2fs: fix uninitialized variable in remove_journal_device
Quoted 25 lines · Theodore Ts'o
This bug was introduced by commit
7dfefaf413bbd("tune2fs: update journal super block when changing UUID for fs").Fixes-Coverity-Bug: 1229243
Reported-by Eric Sandeen <[email protected]>Signed-off-by Theodore Ts'o <[email protected]>---
misc/tune2fs.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)misc/tune2fs.c +0
-1@@ -232,7 +232,6 @@ static int remove_journal_device(ext2_filsys fs)errcode_t retval;int commit_remove_journal =0 ;io_manager io_ptr; -int start;if (f_flag) commit_remove_journal =1 ;/* force removal even if error */
misc/tune2fs.c static int remove_journal_device(ext2_filsys fs) · line 290
Quoted 8 lines
misc/tune2fs.c +3
-2@@ -286,8 +285,9 @@ static int remove_journal_device(ext2_filsys fs) jsb->s_nr_users =htonl (nr_users);/* Write back the journal superblock */ -if ((retval =io_channel_write_blk64 (jfs->io, start, - -SUPERBLOCK_SIZE , buf))) { +if ((retval =io_channel_write_blk64 (jfs->io, +ext2fs_journal_sb_start (fs->blocksize), + -SUPERBLOCK_SIZE , buf))) {
Better to also remove assignment in conditional check.
Cheers, Andreas
Quoted 10 lines
misc/tune2fs.c +0
-0com_err (program_name, retval,"while writing journal superblock." ); goto no_valid_journal;Signature · 6 lines
2.0.0 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] tune2fs: fix uninitialized variable in remove_journal_device
Quoted 8 lines · Andreas Dilger
misc/tune2fs.c static int remove_journal_device(ext2_filsys fs) · line 290
Quoted 6 lines
/* Write back the journal superblock */misc/tune2fs.c +3
-2-if ((retval =io_channel_write_blk64 (jfs->io, start, - -SUPERBLOCK_SIZE , buf))) { +if ((retval =io_channel_write_blk64 (jfs->io, +ext2fs_journal_sb_start (fs->blocksize), + -SUPERBLOCK_SIZE , buf))) {Better to also remove assignment in conditional check.
Good point, done.
- Ted
PATCH v3 4/4 tune2fs: update journal users while updating fs UUID (with external journal)
In reply to Azat KhuzhinWhen we have fs with external journal device, and updating it's UUID, we should update UUID in users list for that external journal device.
Before:
$ tune2fs -U clear /tmp/dev
tune2fs 1.42.10 (18-May-2014)
$ dumpe2fs /tmp/dev | fgrep UUID
dumpe2fs 1.42.10 (18-May-2014)
Filesystem UUID: <none>
Journal UUID: da1f2ed0-60f6-aaaa-92fd-738701418523
$ dumpe2fs /tmp/journal | fgrep users -A10
dumpe2fs 1.42.10 (18-May-2014)
Journal number of users: 2
Journal users: 0707762d-638e-4bc6-944e-ae8ee7a3359e
0ad849df-1041-4f0a-b1c1-2f949d6a1e37After:
$ sudo tune2fs -U clear /tmp/dev
tune2fs 1.43-WIP (18-May-2014)
$ dumpe2fs /tmp/dev | fgrep UUID
dumpe2fs 1.42.10 (18-May-2014)
Filesystem UUID: <none>
Journal UUID: da1f2ed0-60f6-aaaa-92fd-738701418523
$ dumpe2fs /tmp/journal | fgrep users -A10
dumpe2fs 1.42.10 (18-May-2014)
Journal number of users: 2
Journal users: 0707762d-638e-4bc6-944e-ae8ee7a3359e
00000000-0000-0000-0000-000000000000Also add some consts to avoid *magic numbers*:
- UUID_STR_SIZE
- UUID_SIZE
- JFS_USERS_MAX
- JFS_USERS_SIZE
--- lib/ext2fs/ext2fs.h | 2 ++ lib/ext2fs/kernel-jbd.h | 6 +++- misc/tune2fs.c | 90 +++++++++++++++++++++++++++++++++++++++++++++---- misc/uuidd.c | 3 +- 4 files changed, 93 insertions(+), 8 deletions(-)
lib/ext2fs/ext2fs.h +2 -0
@@ -39,6 +39,8 @@ extern "C" {#define SUPERBLOCK_OFFSET 1024#define SUPERBLOCK_SIZE 1024 +#define UUID_STR_SIZE 37 +/* * The last ext2fs revision level that this version of the library is * able to support.
lib/ext2fs/kernel-jbd.h +5 -1
@@ -164,6 +164,9 @@ typedef struct journal_revoke_header_s#define JFS_FLAG_LAST_TAG 8/* last tag in this descriptor block */ +#define UUID_SIZE 16 +#define JFS_USERS_MAX 48 +#define JFS_USERS_SIZE (UUID_SIZE * JFS_USERS_MAX)/* * The journal superblock. All fields are in big-endian byte order. */
@@ -208,7 +211,8 @@ typedef struct journal_superblock_s__u32 s_padding[44 ];/* 0x0100 */ -__u8 s_users[16 *48 ];/* ids of all fs'es sharing the log */ +__u8 s_users[JFS_USERS_SIZE ];/* ids of all fs'es sharing the log */ +/* 0x0400 */ } journal_superblock_t;
misc/tune2fs.c +84 -6
128 lines not on this page · raw message
misc/uuidd.c +2 -1
@@ -36,6 +36,7 @@ extern int optind;#include "uuid/uuid.h" #include "uuid/uuidd.h" #include "nls-enable.h" +#include "ext2fs/ext2fs.h" #ifdef __GNUC__#define CODE_ATTR (x) __attribute__(x)
@@ -236,7 +237,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,uuid_t uu;mode_t save_umask;char reply_buf[1024 ], *cp; -char op, str[37 ]; +char op, str[UUID_STR_SIZE ];int i, s, ns, len, num;int fd_pidfile, ret;
Signature · 1 line
2.0.1
Quoted 3 lines · Azat Khuzhin
Here is patchset with some fixes for journal code in e2fsprogs. I've removed first patch from previous version "lib: add
EXT2_prefix for SUPERBLOCK_{OFFSET,SIZE}", and rebase other patches on top of the maint branch.
Any reason you removed that first patch? I thought the only negative feedback was because you renamed GFS_SUPERBLOCK_SIZE accidentally?
Cheers, Andreas
Quoted 7 lines · Andreas Dilger
Quoted 3 lines · Azat Khuzhin
Here is patchset with some fixes for journal code in e2fsprogs. I've removed first patch from previous version "lib: add
EXT2_prefix for SUPERBLOCK_{OFFSET,SIZE}", and rebase other patches on top of the maint branch.Any reason you removed that first patch? I thought the only negative feedback was because you renamed
GFS_SUPERBLOCK_SIZEaccidentally?
I don't want to make big changes like that until after we've released 1.43.0.
- Ted
Quoted 8 lines · Azat Khuzhin
Azat Khuzhin (4):
journal: use consts instead of 1024 and add helper for journal with 1k
blocksize
tune2fs:remove_journal_device(): use the correct block to find jsb
tune2fs: update journal super block when changing UUID for fs.
tune2fs: update journal users while updating fs UUID (with external
journal)
Thanks for working on this! I've applied these patches to the maint branch.
- Ted