Skip to contentSkip to conversation

ext4: disable defrag for metadata_csum file systems

PATCH In review Theodore Ts'o 3 participants 5 messages Apr 18, 2013 – Apr 19, 2013 ext4 file system

lore
Share & tools
lore

Theodore Ts'o

author maintainer
#0 lore raw

PATCH 1/1 ext4: disable defrag for metadata_csum file systems

It looks like there is absolutely no support for metadata checksums in fs/ext4/move_extent.c. So if you try to defrag a file on a metadata_csum, it leaves the file system corrupted.

We really, really should get this fixed ASAP, but until we do, let's disable e4defrag on metadata_csum file systems so we avoid corrupting file systems.

Cc "Darrick J. Wong" <[email protected]>
---
 fs/ext4/ioctl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ext4/ioctl.c +9 -0
index 9491ac0..2d043da 100644
@@ -450,6 +450,15 @@ group_extend_out:
 			goto mext_out;
 		}
 
+		if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
+			EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
+			ext4_msg(sb, KERN_ERR,
+				 "Online defrag not supported with "
+				 "metadata_csum");
+			err = -EOPNOTSUPP;
+			goto mext_out;
+		}
+
 		err = mnt_want_write_file(filp);
 		if (err)
 			goto mext_out;
Signature · 1 line
1.7.12.rc0.22.gcdd159b
Reviewed-by on v1 1/1
#1 lore raw

[Sorry, it seems that I got a delivery error. So send again]

Quoted 10 lines · Theodore Ts'o

It looks like there is absolutely no support for metadata checksums in fs/ext4/move_extent.c. So if you try to defrag a file on a metadata_csum, it leaves the file system corrupted.

We really, really should get this fixed ASAP, but until we do, let's disable e4defrag on metadata_csum file systems so we avoid corrupting file systems.

Cc "Darrick J. Wong" <[email protected]>

Yes, I also notice this problem. So currently it seems that the best choice is to disable defrag for metadata_csum.

Thanks,
- Zheng

Quoted 25 lines
---
 fs/ext4/ioctl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ext4/ioctl.c +9 -0
index 9491ac0..2d043da 100644
@@ -450,6 +450,15 @@ group_extend_out:
 			goto mext_out;
 		}
 
+		if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
+			EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
+			ext4_msg(sb, KERN_ERR,
+				 "Online defrag not supported with "
+				 "metadata_csum");
+			err = -EOPNOTSUPP;
+			goto mext_out;
+		}
+
 		err = mnt_want_write_file(filp);
 		if (err)
 			goto mext_out;
#2 lore raw
Quoted 11 lines · Zheng Liu

[Sorry, it seems that I got a delivery error. So send again]

Quoted 8 lines · Theodore Ts'o

It looks like there is absolutely no support for metadata checksums in fs/ext4/move_extent.c. So if you try to defrag a file on a metadata_csum, it leaves the file system corrupted.

We really, really should get this fixed ASAP, but until we do, let's disable e4defrag on metadata_csum file systems so we avoid corrupting file systems.

Quoted 5 lines
Quoted 2 lines
Cc "Darrick J. Wong" <[email protected]>

Yes, I also notice this problem. So currently it seems that the best choice is to disable defrag for metadata_csum.

I think this happens because mext_insert_extents() open-codes the metadata dirtying and forgets to update the extent block header. It should call ext4_ext_dirty() at the end, instead. :(

I should see if there are any other sites that dirty metadata without making the proper csum_set calls. Will send a fix shortly, so NAK.

--D

Quoted 36 lines

Thanks,
- Zheng

Quoted 15 lines
---
 fs/ext4/ioctl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ext4/ioctl.c +2 -0
index 9491ac0..2d043da 100644
@@ -450,6 +450,15 @@ group_extend_out:
 			goto mext_out;
 		}
 
+		if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
+			EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {

fs/ext4/ioctl.c group_extend_out: · line 464

Quoted 10 lines
fs/ext4/ioctl.c +7 -0
+			ext4_msg(sb, KERN_ERR,
+				 "Online defrag not supported with "
+				 "metadata_csum");
+			err = -EOPNOTSUPP;
+			goto mext_out;
+		}
+
 		err = mnt_want_write_file(filp);
 		if (err)
 			goto mext_out;

--
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

author maintainer
#3 lore raw
Quoted 4 lines · Darrick J. Wong

I think this happens because mext_insert_extents() open-codes the metadata dirtying and forgets to update the extent block header. It should call ext4_ext_dirty() at the end, instead. :(

Yes. The following patch seems to fix the problem.

I'm wondering if we could significantly simplify the move_extent.c file by allocating two tmp_inodes and then using ext4_ext_insert_extent() the same way fs/ext4/migrate.c handles things. But that's a potential cleanup for later....

- Ted

commit fa3a0fc57b3d3c885dd7354508c9f20fc0c4a184

Author: Theodore Ts'o <[email protected]>
Date:   Fri Apr 19 02:14:18 2013 -0400

ext4: set the extent leaf checksum when processing EXT4_IOC_MOVE_EXT

The EXT4_IOC_MOVE_EXT which is used by the e4defrag program was not properly setting the checksum in the extent leaf block. Fix this.

fs/ext4/ext4.h +5 -0
index 779d26b..269122e 100644
@@ -2574,6 +2574,11 @@ extern int ext4_check_blockref(const char *, unsigned int,
 struct ext4_ext_path;
 struct ext4_extent;
 
+#define ext4_ext_dirty(handle, inode, path) \
+		ext4__ext_dirty(__func__, __LINE__, (handle), (inode), (path))
+extern int ext4__ext_dirty(const char *where, unsigned int line,
+			   handle_t *handle, struct inode *inode,
+			   struct ext4_ext_path *path);
 extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
 extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
 extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks,
fs/ext4/extents.c +2 -5
index 6fcb375..ff019ed 100644
@@ -157,11 +157,8 @@ static int ext4_ext_get_access(handle_t *handle, struct inode *inode,
  *  - ENOMEM
  *  - EIO
  */
-#define ext4_ext_dirty(handle, inode, path) \
-		__ext4_ext_dirty(__func__, __LINE__, (handle), (inode), (path))
-static int __ext4_ext_dirty(const char *where, unsigned int line,
-			    handle_t *handle, struct inode *inode,
-			    struct ext4_ext_path *path)
+int ext4__ext_dirty(const char *where, unsigned int line, handle_t *handle,
+		    struct inode *inode, struct ext4_ext_path *path)
 {
 	int err;
 	if (path->p_bh) {
fs/ext4/move_extent.c +1 -2
index 309ca89..a05a622 100644
@@ -410,8 +410,7 @@ mext_insert_extents(handle_t *handle, struct inode *orig_inode,
 						end_ext, eh, range_to_move);
 
 	if (depth) {
-		ret = ext4_handle_dirty_metadata(handle, orig_inode,
-						 orig_path->p_bh);
+		ret = ext4_ext_dirty(handle, orig_inode, orig_path);
 		if (ret)
 			return ret;
 	} else {
author maintainer
#4 lore raw
Quoted 7 lines · Theodore Ts'o
Quoted 4 lines · Darrick J. Wong

I think this happens because mext_insert_extents() open-codes the metadata dirtying and forgets to update the extent block header. It should call ext4_ext_dirty() at the end, instead. :(

Yes. The following patch seems to fix the problem.

Ah, I see you posted a similar patch. I'll take yours, since it's cleaner.

- Ted