Skip to contentSkip to conversation

f2fs: support follword recovery for compressed files

RFC PATCH In review Fengnan Chang via Linux-f2fs-devel 1 participant 2 messages Apr 24, 2022 F2FS file system

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 f2fs: support follword recovery for compressed files

Try support follword recovery for compressed files, this is a rough version, need more test to improve it.

---
 fs/f2fs/node.c     |  7 +++++++
 fs/f2fs/recovery.c | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
fs/f2fs/node.c +7 -0
index c280f482c741..50211e8e7ec3 100644
@@ -2803,6 +2803,13 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
 			dst->i_crtime = src->i_crtime;
 			dst->i_crtime_nsec = src->i_crtime_nsec;
 		}
+		if (f2fs_sb_has_compression(sbi) && src->i_flags & F2FS_COMPR_FL
+			&& F2FS_FITS_IN_INODE(src, src->i_extra_isize, i_log_cluster_size)) {
+			dst->i_blocks = src->i_blocks;
+			dst->i_compress_algorithm = src->i_compress_algorithm;
+			dst->i_compr_blocks = src->i_compr_blocks;
+			dst->i_log_cluster_size = src->i_log_cluster_size;
+		}
 	}
 
 	new_ni = old_ni;
fs/f2fs/recovery.c +9 -1
index 3cb7f8a43b4d..c01d3a3e5410 100644
@@ -636,7 +636,6 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
 
 		src = f2fs_data_blkaddr(&dn);
 		dest = data_blkaddr(dn.inode, page, dn.ofs_in_node);
-
 		if (__is_valid_data_blkaddr(src) &&
 			!f2fs_is_valid_blkaddr(sbi, src, META_POR)) {
 			err = -EFSCORRUPTED;
@@ -669,6 +668,11 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
 		 * and then reserve one new block in dnode page.
 		 */
 		if (dest == NEW_ADDR) {
+			if (f2fs_compressed_file(inode)) {
+				recovered++;
+				f2fs_update_data_blkaddr(&dn, dest);
+				continue;
+			}
 			f2fs_truncate_data_blocks_range(&dn, 1);
 			f2fs_reserve_new_block(&dn);
 			continue;
@@ -702,6 +706,10 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
 			f2fs_replace_block(sbi, &dn, src, dest,
 						ni.version, false, false);
 			recovered++;
+		} else if (f2fs_compressed_file(inode) &&
+				(dest == COMPRESS_ADDR)) {
+			recovered++;
+			f2fs_update_data_blkaddr(&dn, dest);
 		}
 	}
 
Signature · 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

Please ignore this...
I'll send a new version.

Thanks.

Quoted 67 lines

-----Original Message-----
From: 常凤楠
Sent: Sunday, April 24, 2022 11:21 AM
To: [email protected]; [email protected]
Cc: [email protected]; 常凤楠 <[email protected]>
Subject: [RFC PATCH] f2fs: support follword recovery for compressed files

Try support follword recovery for compressed files, this is a rough version, need more test to improve it.

---
 fs/f2fs/node.c     |  7 +++++++
 fs/f2fs/recovery.c | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
fs/f2fs/node.c index renamed from fs/f2fs/node.c +0 -0

c280f482c741..50211e8e7ec3 100644

fs/f2fs/node.c +1 -0
@@ -2803,6 +2803,13 @@ int f2fs_recover_inode_page(struct f2fs_sb_info
 *sbi, struct page *page)
 			dst->i_crtime = src->i_crtime;
 			dst->i_crtime_nsec = src->i_crtime_nsec;
 		}
+		if (f2fs_sb_has_compression(sbi) && src->i_flags &

F2FS_COMPR_FL

fs/f2fs/node.c +1 -0
+			&& F2FS_FITS_IN_INODE(src, src->i_extra_isize,

i_log_cluster_size)) {

fs/f2fs/node.c +5 -0
+			dst->i_blocks = src->i_blocks;
+			dst->i_compress_algorithm = src->i_compress_algorithm;
+			dst->i_compr_blocks = src->i_compr_blocks;
+			dst->i_log_cluster_size = src->i_log_cluster_size;
+		}
 	}
 
 	new_ni = old_ni;
fs/f2fs/recovery.c index renamed from fs/f2fs/recovery.c +0 -0

3cb7f8a43b4d..c01d3a3e5410 100644

fs/f2fs/recovery.c +0 -1
@@ -636,7 +636,6 @@ static int do_recover_data(struct f2fs_sb_info *sbi,
 struct inode *inode,
 
 		src = f2fs_data_blkaddr(&dn);
 		dest = data_blkaddr(dn.inode, page, dn.ofs_in_node);
-
 		if (__is_valid_data_blkaddr(src) &&
 			!f2fs_is_valid_blkaddr(sbi, src, META_POR)) {
fs/f2fs/recovery.c +5 -0
 			err = -EFSCORRUPTED;
@@ -669,6 +668,11 @@ static int do_recover_data(struct f2fs_sb_info *sbi,
 struct inode *inode,
 		 * and then reserve one new block in dnode page.
 		 */
 		if (dest == NEW_ADDR) {
+			if (f2fs_compressed_file(inode)) {
+				recovered++;
+				f2fs_update_data_blkaddr(&dn, dest);
+				continue;
+			}
 			f2fs_truncate_data_blocks_range(&dn, 1);
 			f2fs_reserve_new_block(&dn);
fs/f2fs/recovery.c +0 -0
 			continue;
@@ -702,6 +706,10 @@ static int do_recover_data(struct f2fs_sb_info *sbi,
 struct inode *inode,
 			f2fs_replace_block(sbi, &dn, src, dest,

fs/f2fs/recovery.c static int do_recover_data(struct f2fs_sb_info *sbi,

Quoted 10 lines
fs/f2fs/recovery.c +4 -1
 						ni.version, false, false);
 			recovered++;
+		} else if (f2fs_compressed_file(inode) &&
+				(dest == COMPRESS_ADDR)) {
+			recovered++;
+			f2fs_update_data_blkaddr(&dn, dest);
 		}
 	}
 
--

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel