tune2fs: forbid changing uuid on an uninit_bg filesystem

The old uninit_bg checksums depend on the UUID, so prohibit changes to
the UUID if a checksumming filesystem is mounted, because this
introduces a nasty race where the kernel and tune2fs are both trying
to rewrite group descriptors at the same time, with different ideas
about what the UUID is.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Darrick J. Wong 2013-12-14 20:51:04 -05:00 committed by Theodore Ts'o
parent a9825cfe94
commit 66457fcb84

View File

@ -358,6 +358,16 @@ static int update_mntopts(ext2_filsys fs, char *mntopts)
return 0;
}
static int check_fsck_needed(ext2_filsys fs)
{
if (fs->super->s_state & EXT2_VALID_FS)
return 0;
printf("\n%s\n", _(please_fsck));
if (mount_flags & EXT2_MF_READONLY)
printf(_("(and reboot afterwards!)\n"));
return 1;
}
static void request_fsck_afterwards(ext2_filsys fs)
{
static int requested = 0;
@ -2146,6 +2156,19 @@ retry_open:
if (sb->s_feature_ro_compat &
EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
/*
* Changing the UUID requires rewriting all metadata,
* which can race with a mounted fs. Don't allow that.
*/
if (mount_flags & EXT2_MF_MOUNTED) {
fputs(_("The UUID may only be "
"changed when the filesystem is "
"unmounted.\n"), stderr);
exit(1);
}
if (check_fsck_needed(fs))
exit(1);
/*
* Determine if the block group checksums are
* correct so we know whether or not to set