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(-)
--
2.0.1
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.
Signed-off-by: Azat Khuzhin <[email protected]>
Reviewed-by: Andreas Dilger <[email protected]>
---
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(-)
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 9be52cd..3b40e00 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -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
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 33b2519..ab57534 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -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,
diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c
index e8316a7..96b6d36 100644
--- a/lib/ext2fs/mkjournal.c
+++ b/lib/ext2fs/mkjournal.c
@@ -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);
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index ad0b05f..ff50f37 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -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;
--
2.0.1
Signed-off-by: Azat Khuzhin <[email protected]>
Reviewed-by: Andreas Dilger <[email protected]>
---
misc/tune2fs.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index ff50f37..1df655a 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -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;
--
2.0.1
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/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 **********
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(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 1df655a..74e57ae 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -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) {
--
2.0.1
When 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-2f949d6a1e37
After:
$ 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-000000000000
Also add some consts to avoid *magic numbers*:
- UUID_STR_SIZE
- UUID_SIZE
- JFS_USERS_MAX
- JFS_USERS_SIZE
Proposed-by: Andreas Dilger <[email protected]>
Signed-off-by: Azat Khuzhin <[email protected]>
---
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(-)
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index ab57534..d3a34d5 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -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.
diff --git a/lib/ext2fs/kernel-jbd.h b/lib/ext2fs/kernel-jbd.h
index 059bf8f..2baae73 100644
--- a/lib/ext2fs/kernel-jbd.h
+++ b/lib/ext2fs/kernel-jbd.h
@@ -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;
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 74e57ae..0c1feb1 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -207,6 +207,18 @@ static int get_journal_sb(ext2_filsys jfs, char buf[SUPERBLOCK_SIZE])
return 0;
}
+static void *
+journal_user(char uuid[UUID_SIZE], char s_users[JFS_USERS_SIZE], int nr_users)
+{
+ int i;
+ for (i = 0; i < nr_users; i++) {
+ if (memcmp(uuid, &s_users[i * UUID_SIZE], UUID_SIZE) == 0)
+ return &s_users[i * UUID_SIZE];
+ }
+
+ return NULL;
+}
+
/*
* Remove an external journal from the filesystem
*/
@@ -261,11 +273,8 @@ static int remove_journal_device(ext2_filsys fs)
jsb = (journal_superblock_t *) buf;
/* Find the filesystem UUID */
nr_users = ntohl(jsb->s_nr_users);
- for (i = 0; i < nr_users; i++) {
- if (memcmp(fs->super->s_uuid, &jsb->s_users[i * 16], 16) == 0)
- break;
- }
- if (i >= nr_users) {
+
+ if (!journal_user(fs->super->s_uuid, jsb->s_users, nr_users)) {
fputs(_("Filesystem's UUID not found on journal device.\n"),
stderr);
commit_remove_journal = 1;
@@ -1915,6 +1924,68 @@ static int tune2fs_setup_tdb(const char *name, io_manager *io_ptr)
return retval;
}
+int
+fs_update_journal_user(struct ext2_super_block *sb, char old_uuid[UUID_SIZE])
+{
+ int retval, nr_users, start;
+ journal_superblock_t *jsb;
+ ext2_filsys jfs;
+ char *j_uuid, *journal_path;
+ char uuid[UUID_STR_SIZE];
+ char buf[SUPERBLOCK_SIZE];
+
+ if (!(sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) ||
+ uuid_is_null(sb->s_journal_uuid))
+ return 0;
+
+ uuid_unparse(sb->s_journal_uuid, uuid);
+ journal_path = blkid_get_devname(NULL, "UUID", uuid);
+ if (!journal_path)
+ return 0;
+
+ retval = ext2fs_open2(journal_path, io_options,
+ EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_RW,
+ 0, 0, unix_io_manager, &jfs);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while trying to open %s"),
+ journal_path);
+ return retval;
+ }
+
+ if ((retval = get_journal_sb(jfs, buf))) {
+ if (retval == EXT2_ET_UNSUPP_FEATURE)
+ fprintf(stderr, _("%s is not a journal device.\n"),
+ journal_path);
+ return retval;
+ }
+
+ jsb = (journal_superblock_t *) buf;
+ /* Find the filesystem UUID */
+ nr_users = ntohl(jsb->s_nr_users);
+
+ if (!(j_uuid = journal_user(old_uuid, jsb->s_users, nr_users))) {
+ fputs(_("Filesystem's UUID not found on journal device.\n"),
+ stderr);
+ return EXT2_ET_LOAD_EXT_JOURNAL;
+ }
+
+ memcpy(j_uuid, sb->s_uuid, UUID_SIZE);
+
+ start = ext2fs_journal_sb_start(jfs->blocksize);
+ /* Write back the journal superblock */
+ if ((retval = io_channel_write_blk64(jfs->io, start,
+ -SUPERBLOCK_SIZE, buf))) {
+ com_err(program_name, retval,
+ "while writing journal superblock.");
+ return retval;
+ }
+
+ ext2fs_close(jfs);
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
errcode_t retval;
@@ -2203,6 +2274,7 @@ retry_open:
int set_csum = 0;
dgrp_t i;
char buf[SUPERBLOCK_SIZE];
+ char old_uuid[UUID_SIZE];
if (sb->s_feature_ro_compat &
EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
@@ -2230,6 +2302,8 @@ retry_open:
if (i >= fs->group_desc_count)
set_csum = 1;
}
+
+ memcpy(old_uuid, sb->s_uuid, UUID_SIZE);
if ((strcasecmp(new_UUID, "null") == 0) ||
(strcasecmp(new_UUID, "clear") == 0)) {
uuid_clear(sb->s_uuid);
@@ -2264,9 +2338,13 @@ retry_open:
goto closefs;
} else if (rc != EXT2_ET_UNSUPP_FEATURE)
goto closefs;
- else
+ else {
rc = 0; /** Reset rc to avoid ext2fs_mmp_stop() */
+ if ((rc = fs_update_journal_user(sb, old_uuid)))
+ goto closefs;
+ }
+
ext2fs_mark_super_dirty(fs);
}
if (I_flag) {
diff --git a/misc/uuidd.c b/misc/uuidd.c
index 5a53138..02ca6be 100644
--- a/misc/uuidd.c
+++ b/misc/uuidd.c
@@ -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;
--
2.0.1
On Jul 28, 2014, at 1:43 AM, Azat Khuzhin <[email protected]> wrote:
> 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
On Mon, Jul 28, 2014 at 02:07:44PM -0600, Andreas Dilger wrote:
> On Jul 28, 2014, at 1:43 AM, Azat Khuzhin <[email protected]> wrote:
> > 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?
I don't want to make big changes like that until after we've released
1.43.0.
- Ted
On Mon, Jul 28, 2014 at 11:43:21AM +0400, Azat Khuzhin wrote:
>
> 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
On 7/28/14, 2:43 AM, Azat Khuzhin wrote:
> 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/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 **********
>
> 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(-)
>
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index 1df655a..74e57ae 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -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);
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
On Thu, Jul 31, 2014 at 10:16:44AM -0500, Eric Sandeen wrote:
> On 7/28/14, 2:43 AM, Azat Khuzhin wrote:
> > 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/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 **********
> >
> > 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(-)
> >
> > diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> > index 1df655a..74e57ae 100644
> > --- a/misc/tune2fs.c
> > +++ b/misc/tune2fs.c
> > @@ -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);
>
> 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
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(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 0c1feb1..044daaf 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -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,
--
2.0.1
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(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 0c1feb1..639809d 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -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;
--
2.0.0
On Jul 31, 2014, at 17:53, Theodore Ts'o <[email protected]> wrote:
>
> 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(-)
>
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index 0c1feb1..639809d 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -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))) {
Better to also remove assignment in conditional check.
Cheers, Andreas
> com_err(program_name, retval,
> "while writing journal superblock.");
> goto no_valid_journal;
> --
> 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
I already fixed that in my recent patch:
http://marc.info/?l=linux-ext4&m=140667665421773&w=2
Cheers, Andreas
> On Jul 31, 2014, at 17:45, Azat Khuzhin <[email protected]> wrote:
>
>> On Thu, Jul 31, 2014 at 10:16:44AM -0500, Eric Sandeen wrote:
>>> On 7/28/14, 2:43 AM, Azat Khuzhin wrote:
>>> 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/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 **********
>>>
>>> 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(-)
>>>
>>> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
>>> index 1df655a..74e57ae 100644
>>> --- a/misc/tune2fs.c
>>> +++ b/misc/tune2fs.c
>>> @@ -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);
>>
>> 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
>
> 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(-)
>
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index 0c1feb1..044daaf 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -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,
> --
> 2.0.1
>
On Fri, Aug 01, 2014 at 08:38:30AM +0200, Andreas Dilger wrote:
> > /* 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.
Good point, done.
- Ted