ext4: fix EXT4_IOC_CHECKPOINT
Subsystems (7)
Christoph Hellwig
maintainerPATCH 1/1 ext4: fix EXT4_IOC_CHECKPOINT
Issuing a discard for any kind of "contention deletion SLO" is highly dangerous as discard as defined by Linux (as well the underlying NVMe, SCSI, ATA, eMMC and virtio primitivies) are defined to not guarantee erasing of data but just allow optional and nondeterministic reclamation of space. Instead issuing write zeroes is the only think to perform such an operation. Remove the highly dangerous and misleading discard mode for EXT4_IOC_CHECKPOINT and only support the write zeroes based on, and clean up the resulting mess including the dry run mode.
This is an ABI change and must go into Linus' tree before 5.14 is released or the offending commits need to be reverted.
--- Documentation/filesystems/ext4/journal.rst | 17 +++----- fs/ext4/ext4.h | 7 +--- fs/ext4/ioctl.c | 26 ++---------- fs/jbd2/journal.c | 47 +++++----------------- include/linux/jbd2.h | 6 +-- 5 files changed, 22 insertions(+), 81 deletions(-)
Documentation/filesystems/ext4/journal.rst +5 -12
@@ -742,15 +742,8 @@ the filesystem including journal recovery, filesystem resizing, and freeing of the journal_t structure. A journal checkpoint can be triggered from userspace via the ioctl -EXT4_IOC_CHECKPOINT. This ioctl takes a single, u64 argument for flags. -Currently, three flags are supported. First, EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN -can be used to verify input to the ioctl. It returns error if there is any -invalid input, otherwise it returns success without performing -any checkpointing. This can be used to check whether the ioctl exists on a -system and to verify there are no issues with arguments or flags. The -other two flags are EXT4_IOC_CHECKPOINT_FLAG_DISCARD and -EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT. These flags cause the journal blocks to be -discarded or zero-filled, respectively, after the journal checkpoint is -complete. EXT4_IOC_CHECKPOINT_FLAG_DISCARD and EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT -cannot both be set. The ioctl may be useful when snapshotting a system or for -complying with content deletion SLOs. +EXT4_IOC_CHECKPOINT. This ioctl takes a u64 argument for flags. +The only supported flags is EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT. This flag cause +the journal blocks to be zero-filled after the journal checkpoint is complete. +The ioctl may be useful when snapshotting a system or for complying with +content deletion SLOs.
fs/ext4/ext4.h +1 -6
@@ -743,12 +743,7 @@ enum {#define EXT4_STATE_FLAG_DA_ALLOC_CLOSE 0x00000008/* flags for ioctl EXT4_IOC_CHECKPOINT */ -#define EXT4_IOC_CHECKPOINT_FLAG_DISCARD 0x1 -#define EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT 0x2 -#define EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN 0x4 -#define EXT4_IOC_CHECKPOINT_FLAG_VALID (EXT4_IOC_CHECKPOINT_FLAG_DISCARD | \ - EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT | \ - EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN) +#define EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT 0x1#if defined(__KERNEL__) && defined(CONFIG_COMPAT )/*
fs/ext4/ioctl.c +4 -22
@@ -798,42 +798,24 @@ static int ext4_ioctl_checkpoint(struct file *filp, unsigned long arg)__u32 flags =0 ;unsigned int flush_flags =0 ;struct super_block *sb =file_inode (filp)->i_sb; -struct request_queue *q; -if (copy_from_user (&flags, (__u32 __user *)arg, -sizeof (__u32))) +if (copy_from_user (&flags, (__u32 __user *)arg,sizeof (__u32)))return -EFAULT ;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;/* check for invalid bits set */ -if ((flags & ~EXT4_IOC_CHECKPOINT_FLAG_VALID ) || - ((flags &JBD2_JOURNAL_FLUSH_DISCARD ) && - (flags &JBD2_JOURNAL_FLUSH_ZEROOUT ))) +if (flags & ~EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT )return -EINVAL ;if (!EXT4_SB (sb)->s_journal)return -ENODEV ; -if (flags & ~JBD2_JOURNAL_FLUSH_VALID ) -return -EINVAL ; - - q =bdev_get_queue (EXT4_SB (sb)->s_journal->j_dev); -if (!q) -return -ENXIO ; -if ((flags &JBD2_JOURNAL_FLUSH_DISCARD ) && !blk_queue_discard (q)) -return -EOPNOTSUPP ; - -if (flags &EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN ) -return 0 ; - -if (flags &EXT4_IOC_CHECKPOINT_FLAG_DISCARD ) - flush_flags |=JBD2_JOURNAL_FLUSH_DISCARD ; -if (flags &EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT ) { flush_flags |=JBD2_JOURNAL_FLUSH_ZEROOUT ; -pr_info_ratelimited ("warning: checkpointing journal with EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT can be slow" ); +if (!bdev_write_zeroes_sectors (EXT4_SB (sb)->s_journal->j_dev)) +pr_info_ratelimited ("warning: checkpointing journal with EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT can be slow" ); }jbd2_journal_lock_updates (EXT4_SB (sb)->s_journal);
fs/jbd2/journal.c +10 -37
77 lines not on this page · raw message
include/linux/jbd2.h +2 -4
@@ -1398,10 +1398,8 @@ JBD2_FEATURE_INCOMPAT_FUNCS(fast_commit, FAST_COMMIT)* mode */ #define JBD2_FAST_COMMIT_ONGOING 0x100/* Fast commit is ongoing */ #define JBD2_FULL_COMMIT_ONGOING 0x200/* Full commit is ongoing */ -#define JBD2_JOURNAL_FLUSH_DISCARD 0x0001 -#define JBD2_JOURNAL_FLUSH_ZEROOUT 0x0002 -#define JBD2_JOURNAL_FLUSH_VALID (JBD2_JOURNAL_FLUSH_DISCARD | \ - JBD2_JOURNAL_FLUSH_ZEROOUT) + +#define JBD2_JOURNAL_FLUSH_ZEROOUT 0x0001/* Zero log on flush */ /* * Journal atomic flag definitions
Signature · 1 line
2.30.2
Theodore Ts'o
maintainerQuoted 8 lines · Christoph Hellwig
Issuing a discard for any kind of "contention deletion SLO" is highly dangerous as discard as defined by Linux (as well the underlying NVMe, SCSI, ATA, eMMC and virtio primitivies) are defined to not guarantee erasing of data but just allow optional and nondeterministic reclamation of space. Instead issuing write zeroes is the only think to perform such an operation. Remove the highly dangerous and misleading discard mode for
EXT4_IOC_CHECKPOINTand only support the write zeroes based on, and clean up the resulting mess including the dry run mode.
A discard is not "dangerous"; how it behaves is simply not necessarily guaranteed by the standards specification. The userspace which uses the ioctl simply needs to know how a particular block device might react when it is given a discard.
I'll note that there is a similar issue with "WRITE SAME" or "ZEROOUT. A WRITE SAME might take a fraction of a second --- or it might take days --- depending on how the storage device is implemented. It is similarly unspecified by the various standards specification. Hence, userspace needs to know something about the block device before deciding whether or not it would be good idea to issue a "WRITE SAME" operation for large number of blocks.
This is why the API is implemented in terms of what command will be issued to the block device, and not what the semantic meaning is for that particular command. That's up to the userspace application to know out of band, and we should be able to give the privileged application the freedom to decide which command makes the most amount of sense.
- Ted
Christoph Hellwig
maintainerQuoted 4 lines · Theodore Ts'o
A discard is not "dangerous"; how it behaves is simply not necessarily guaranteed by the standards specification. The userspace which uses the ioctl simply needs to know how a particular block device might react when it is given a discard.
A discard itself is indeed not dangerous at all. Using it to imply any kind of data erasure OTOH is extremely dangerous, and that is what this interface does.
Quoted 7 lines
I'll note that there is a similar issue with "WRITE SAME" or "ZEROOUT. A WRITE SAME might take a fraction of a second --- or it might take days --- depending on how the storage device is implemented. It is similarly unspecified by the various standards specification. Hence, userspace needs to know something about the block device before deciding whether or not it would be good idea to issue a "WRITE SAME" operation for large number of blocks.
The same is true of discard. There are plenty of devices where discards are horrible slow. There also are plenty of devices where discard is a complete no-op. Especially on NVMe where the discard command (DSM deallocate) is mandatory to implement.
Quoted 6 lines
This is why the API is implemented in terms of what command will be issued to the block device, and not what the semantic meaning is for that particular command. That's up to the userspace application to know out of band, and we should be able to give the privileged application the freedom to decide which command makes the most amount of sense.
Stop claiming you actively misleading users with broken interfaces freedom.
Quoted 2 lines
- Ted
---end quoted text---