Skip to content

Commit 7be6845

Browse files
Jaegeuk Kimgtpitch
authored andcommitted
f2fs: fix lost xattrs of directories
This patch enhances the xattr consistency of dirs from suddern power-cuts. Possible scenario would be: 1. dir->setxattr used by per-file encryption 2. file->setxattr goes into inline_xattr 3. file->fsync In that case, we should do checkpoint for Grarak#1. Otherwise we'd lose dir's key information for the file given Grarak#2. Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent b1440f8 commit 7be6845

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
11511151

11521152
clear_prefree_segments(sbi, cpc);
11531153
clear_sbi_flag(sbi, SBI_IS_DIRTY);
1154+
clear_sbi_flag(sbi, SBI_NEED_CP);
11541155

11551156
return 0;
11561157
}

fs/f2fs/f2fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ enum {
794794
SBI_NEED_FSCK, /* need fsck.f2fs to fix */
795795
SBI_POR_DOING, /* recovery is doing or not */
796796
SBI_NEED_SB_WRITE, /* need to recover superblock */
797+
SBI_NEED_CP, /* need to checkpoint */
797798
};
798799

799800
enum {

fs/f2fs/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ static inline bool need_do_checkpoint(struct inode *inode)
136136

137137
if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1)
138138
need_cp = true;
139+
else if (is_sbi_flag_set(sbi, SBI_NEED_CP))
140+
need_cp = true;
139141
else if (file_enc_name(inode) && need_dentry_mark(sbi, inode->i_ino))
140142
need_cp = true;
141143
else if (file_wrong_pino(inode))

fs/f2fs/xattr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ static int __f2fs_setxattr(struct inode *inode, int index,
589589
!strcmp(name, F2FS_XATTR_NAME_ENCRYPTION_CONTEXT))
590590
f2fs_set_encrypted_inode(inode);
591591
f2fs_mark_inode_dirty_sync(inode);
592+
if (!error && S_ISDIR(inode->i_mode))
593+
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_CP);
592594
exit:
593595
kzfree(base_addr);
594596
return error;

0 commit comments

Comments
 (0)