Skip to content

Commit 50a472b

Browse files
author
Jaegeuk Kim
committed
f2fs: do not return EFSCORRUPTED, but try to run online repair
If we return the error, there's no way to recover the status as of now, since fsck does not fix the xattr boundary issue. Cc: [email protected] Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent a5e80e1 commit 50a472b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

fs/f2fs/node.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,9 @@ int f2fs_recover_xattr_data(struct inode *inode, struct page *page)
27502750
f2fs_update_inode_page(inode);
27512751

27522752
/* 3: update and set xattr node page dirty */
2753-
memcpy(F2FS_NODE(xpage), F2FS_NODE(page), VALID_XATTR_BLOCK_SIZE);
2753+
if (page)
2754+
memcpy(F2FS_NODE(xpage), F2FS_NODE(page),
2755+
VALID_XATTR_BLOCK_SIZE);
27542756

27552757
set_page_dirty(xpage);
27562758
f2fs_put_page(xpage, 1);

fs/f2fs/xattr.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
364364

365365
*xe = __find_xattr(cur_addr, last_txattr_addr, NULL, index, len, name);
366366
if (!*xe) {
367-
f2fs_err(F2FS_I_SB(inode), "inode (%lu) has corrupted xattr",
367+
f2fs_err(F2FS_I_SB(inode), "lookup inode (%lu) has corrupted xattr",
368368
inode->i_ino);
369369
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
370-
err = -EFSCORRUPTED;
370+
err = -ENODATA;
371371
f2fs_handle_error(F2FS_I_SB(inode),
372372
ERROR_CORRUPTED_XATTR);
373373
goto out;
@@ -584,13 +584,12 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
584584

585585
if ((void *)(entry) + sizeof(__u32) > last_base_addr ||
586586
(void *)XATTR_NEXT_ENTRY(entry) > last_base_addr) {
587-
f2fs_err(F2FS_I_SB(inode), "inode (%lu) has corrupted xattr",
587+
f2fs_err(F2FS_I_SB(inode), "list inode (%lu) has corrupted xattr",
588588
inode->i_ino);
589589
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
590-
error = -EFSCORRUPTED;
591590
f2fs_handle_error(F2FS_I_SB(inode),
592591
ERROR_CORRUPTED_XATTR);
593-
goto cleanup;
592+
break;
594593
}
595594

596595
if (!prefix)
@@ -650,7 +649,7 @@ static int __f2fs_setxattr(struct inode *inode, int index,
650649

651650
if (size > MAX_VALUE_LEN(inode))
652651
return -E2BIG;
653-
652+
retry:
654653
error = read_all_xattrs(inode, ipage, &base_addr);
655654
if (error)
656655
return error;
@@ -660,7 +659,14 @@ static int __f2fs_setxattr(struct inode *inode, int index,
660659
/* find entry with wanted name. */
661660
here = __find_xattr(base_addr, last_base_addr, NULL, index, len, name);
662661
if (!here) {
663-
f2fs_err(F2FS_I_SB(inode), "inode (%lu) has corrupted xattr",
662+
if (!F2FS_I(inode)->i_xattr_nid) {
663+
f2fs_notice(F2FS_I_SB(inode),
664+
"recover xattr in inode (%lu)", inode->i_ino);
665+
f2fs_recover_xattr_data(inode, NULL);
666+
kfree(base_addr);
667+
goto retry;
668+
}
669+
f2fs_err(F2FS_I_SB(inode), "set inode (%lu) has corrupted xattr",
664670
inode->i_ino);
665671
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
666672
error = -EFSCORRUPTED;

0 commit comments

Comments
 (0)