Skip to contentSkip to conversation

ext4: setattr: Forbid setting data journalling when delalloc enabled

PATCH In review Lukas Czerner 2 participants 3 messages Jan 9, 2012 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: setattr: Forbid setting data journalling when delalloc enabled

Ext4 does not support data journalling with delayed allocation enabled. We even does not allow to mount the file system with delayed allocation and data journalling enabled, but it can be set via FS_IOC_SETFLAGS which is wrong.

When data journalling and delayed allocation is enabled it can lead to troubles. Here is one example how to reproduce an oops:

mkfs.ext4 /dev/sdd
mount /dev/sdd /mnt/test1
dd if=/dev/zero of=/mnt/test1/file bs=1M count=4 chattr +j /mnt/test1/file
dd if=/dev/zero of=/mnt/test1/file bs=1M count=4 conv=notrunc chattr -j /mnt/test1/file

---
 fs/ext4/ioctl.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
fs/ext4/ioctl.c +14 -0
index a567968..f1b8226 100644
@@ -126,7 +126,21 @@ flags_err:
 		if (err)
 			goto flags_out;
 
+		/*
+		 * We absolutely can not journal data when delayed allocation
+		 * is enabled. This is not possible to do via mount option
+		 * and it should not be possible to do via setattr as well.
+		 * Delayed allocation with data=journal is simply not
+		 * supported.
+		 */
 		if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
+			if (test_opt(sb, DELALLOC)) {
+				ext4_msg(sb, KERN_ERR,
+					 "Data journalling not supported "
+					 "with delayed allocation.");
+				err = -EOPNOTSUPP;
+				goto flags_out;
+			}
 			err = ext4_change_inode_journal_flag(inode, jflag);
 		if (err)
 			goto flags_out;
Signature · 1 line
1.7.4.4
maintainer
#1 lore raw
Quoted 8 lines · Lukas Czerner

Ext4 does not support data journalling with delayed allocation enabled. We even does not allow to mount the file system with delayed allocation and data journalling enabled, but it can be set via FS_IOC_SETFLAGS which is wrong.

When data journalling and delayed allocation is enabled it can lead to troubles. Here is one example how to reproduce an oops:

Quoted 8 lines

mkfs.ext4 /dev/sdd
mount /dev/sdd /mnt/test1
dd if=/dev/zero of=/mnt/test1/file bs=1M count=4 chattr +j /mnt/test1/file
dd if=/dev/zero of=/mnt/test1/file bs=1M count=4 conv=notrunc chattr -j /mnt/test1/file

Don't we also need to add a check in ext4_should_journal_data() in fs/ext4/ext4_jbd2.h? Otherwise we could get in trouble if the data journalling flag had been set previously when the file system was mounted nodelalloc.

In fact it could be argued that we don't need to return EOPNOSUPP, or printk a message, but simply make sure that the data journal flag is ignored in if delayed allocation is enabled. If that's true, we can allow the user to set or clear the journal flag as much as they like; it would just be ignored.

Thanks,

- Ted

#2 lore raw
Quoted 16 lines · Ted Ts'o
Quoted 15 lines · Lukas Czerner

Ext4 does not support data journalling with delayed allocation enabled. We even does not allow to mount the file system with delayed allocation and data journalling enabled, but it can be set via FS_IOC_SETFLAGS which is wrong.

When data journalling and delayed allocation is enabled it can lead to troubles. Here is one example how to reproduce an oops:

mkfs.ext4 /dev/sdd
mount /dev/sdd /mnt/test1
dd if=/dev/zero of=/mnt/test1/file bs=1M count=4 chattr +j /mnt/test1/file
dd if=/dev/zero of=/mnt/test1/file bs=1M count=4 conv=notrunc chattr -j /mnt/test1/file

Quoted 6 lines
Quoted 1 line

Don't we also need to add a check in ext4_should_journal_data() in fs/ext4/ext4_jbd2.h? Otherwise we could get in trouble if the data journalling flag had been set previously when the file system was mounted nodelalloc.

Ah, of course you're right. We should add a check into ext4_should_journal_data().

Quoted 6 lines

In fact it could be argued that we don't need to return EOPNOSUPP, or printk a message, but simply make sure that the data journal flag is ignored in if delayed allocation is enabled. If that's true, we can allow the user to set or clear the journal flag as much as they like; it would just be ignored.

I am fine with ignoring the flag silently without any information for the user that the flag will be ignored when delalloc is enabled. After all it should be clear from documentation that we do not allow data journalling and delayed allocation together.

Thanks!

-Lukas

Quoted 5 lines

Thanks,

- Ted