f2fs: guarantee journalled quota data by checkpoint
Chao Yu
maintainerPATCH v8 1/1 f2fs: guarantee journalled quota data by checkpoint
From: Chao Yu <[email protected]>
For journalled quota mode, let checkpoint to flush dquot dirty data and quota file data to guarntee persistence of all quota sysfile in last checkpoint, by this way, we can avoid corrupting quota sysfile when encountering SPO.
The implementation is as below:
1. add a global state SBI_QUOTA_NEED_FLUSH to indicate that there is cached dquot metadata changes in quota subsystem, and later checkpoint should:
a) flush dquot metadata into quota file.
b) flush quota file to storage to keep file usage be consistent.
2. add a global state SBI_QUOTA_NEED_REPAIR to indicate that quota operation failed due to -EIO or -ENOSPC, so later,
a) checkpoint will skip syncing dquot metadata.
b) CP_QUOTA_NEED_FSCK_FLAG will be set in last cp pack to give a hint for fsck repairing.
3. add a global state SBI_QUOTA_SKIP_FLUSH, in checkpoint, if quota data updating is very heavy, it may cause hungtask in block_operation(). To avoid this, if our retry time exceed threshold, let's just skip flushing and retry in next checkpoint().
---
v8:
- don't set DQUOT_NOLIST_DIRTY.
fs/f2fs/checkpoint.c | 45 ++++++++++++++-- fs/f2fs/data.c | 8 ++- fs/f2fs/f2fs.h | 7 +++ fs/f2fs/super.c | 110 ++++++++++++++++++++++++++++++++++++---- include/linux/f2fs_fs.h | 1 + 5 files changed, 154 insertions(+), 17 deletions(-)
fs/f2fs/checkpoint.c +41 -4
@@ -1086,6 +1086,15 @@ static void __prepare_cp_block(struct f2fs_sb_info *sbi) ckpt->next_free_nid =cpu_to_le32 (last_nid); } +static bool __need_flush_quota (struct f2fs_sb_info *sbi) +{ +if (is_sbi_flag_set (sbi,SBI_QUOTA_SKIP_FLUSH )) +return false; +if (is_sbi_flag_set (sbi,SBI_QUOTA_NEED_REPAIR )) +return false; +return is_sbi_flag_set (sbi,SBI_QUOTA_NEED_FLUSH ); +} +/* * Freeze all the FS-operations for checkpoint. */
@@ -1097,12 +1106,31 @@ static int block_operations(struct f2fs_sb_info *sbi) .for_reclaim = 0, };struct blk_plug plug; -int err =0 ; +int err =0 , cnt =0 ;blk_start_plug (&plug); -retry_flush_dents: +retry_flush_quotas: +if (__need_flush_quota (sbi)) { +if (++cnt >DEFAULT_RETRY_QUOTA_FLUSH_COUNT ) { +set_sbi_flag (sbi,SBI_QUOTA_SKIP_FLUSH ); +f2fs_lock_all (sbi); + goto retry_flush_dents; + } +clear_sbi_flag (sbi,SBI_QUOTA_NEED_FLUSH ); + err =f2fs_quota_sync (sbi->sb,-1 ); +if (err) + goto out; + } +f2fs_lock_all (sbi); +if (__need_flush_quota (sbi)) { +f2fs_unlock_all (sbi); +cond_resched (); + goto retry_flush_quotas; + } + +retry_flush_dents:/* write all the dirty dentry pages */ if (get_pages (sbi,F2FS_DIRTY_DENTS )) {f2fs_unlock_all (sbi);
@@ -1110,7 +1138,7 @@ static int block_operations(struct f2fs_sb_info *sbi)if (err) goto out;cond_resched (); - goto retry_flush_dents; + goto retry_flush_quotas; }/*
@@ -1126,7 +1154,7 @@ static int block_operations(struct f2fs_sb_info *sbi)if (err) goto out;cond_resched (); - goto retry_flush_dents; + goto retry_flush_quotas; } retry_flush_nodes:
@@ -1217,6 +1245,14 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)if (is_sbi_flag_set (sbi,SBI_NEED_FSCK ))__set_ckpt_flags (ckpt,CP_FSCK_FLAG ); +if (is_sbi_flag_set (sbi,SBI_QUOTA_SKIP_FLUSH )) +__set_ckpt_flags (ckpt,CP_QUOTA_NEED_FSCK_FLAG ); +else +__clear_ckpt_flags (ckpt,CP_QUOTA_NEED_FSCK_FLAG ); + +if (is_sbi_flag_set (sbi,SBI_QUOTA_NEED_REPAIR )) +__set_ckpt_flags (ckpt,CP_QUOTA_NEED_FSCK_FLAG ); +/* set this flag to activate crc|cp_ver for recovery */ __set_ckpt_flags (ckpt,CP_CRC_RECOVERY_FLAG );__clear_ckpt_flags (ckpt,CP_NOCRC_RECOVERY_FLAG );
@@ -1424,6 +1460,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)clear_sbi_flag (sbi,SBI_IS_DIRTY );clear_sbi_flag (sbi,SBI_NEED_CP ); +clear_sbi_flag (sbi,SBI_QUOTA_SKIP_FLUSH );__set_cp_next_pack (sbi);/*
fs/f2fs/data.c +6 -2
@@ -49,7 +49,7 @@ static bool __is_cp_guaranteed(struct page *page) inode->i_ino ==F2FS_NODE_INO (sbi) ||S_ISDIR (inode->i_mode) || (S_ISREG (inode->i_mode) && -is_inode_flag_set (inode,FI_ATOMIC_FILE )) || + (f2fs_is_atomic_file (inode) ||IS_NOQUOTA (inode))) || is_cold_data(page)) return true;return false;
@@ -1713,6 +1713,8 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return true;if (S_ISDIR (inode->i_mode))return true; +if (IS_NOQUOTA (inode)) +return true;if (f2fs_is_atomic_file (inode))return true;if (fio) {
@@ -1957,7 +1959,7 @@ static int __write_data_page(struct page *page, bool *submitted, }unlock_page (page); -if (!S_ISDIR (inode->i_mode)) +if (!S_ISDIR (inode->i_mode) && !IS_NOQUOTA (inode))f2fs_balance_fs (sbi, need_balance_fs);if (unlikely (f2fs_cp_error (sbi))) {
@@ -2148,6 +2150,8 @@ static inline bool __should_serialize_io(struct inode *inode, {if (!S_ISREG (inode->i_mode))return false; +if (IS_NOQUOTA (inode)) +return false;if (wbc->sync_mode !=WB_SYNC_ALL )return true;if (get_dirty_pages (inode) >=SM_I (F2FS_I_SB (inode))->min_seq_blocks)
fs/f2fs/f2fs.h +7 -0
@@ -527,6 +527,9 @@ enum {#define DEFAULT_RETRY_IO_COUNT 8/* maximum retry read IO count */ +/* maximum retry quota flush count */ +#define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 +#define F2FS_LINK_MAX 0xffffffff/* maximum link count per file */ #define MAX_DIR_RA_PAGES 4/* maximum ra pages of dir */
@@ -1089,6 +1092,9 @@ enum {SBI_NEED_CP ,/* need to checkpoint */ SBI_IS_SHUTDOWN ,/* shutdown by ioctl */ SBI_IS_RECOVERED ,/* recovered orphan/data */ +SBI_QUOTA_NEED_FLUSH ,/* need to flush quota info in CP */ +SBI_QUOTA_SKIP_FLUSH ,/* skip flushing quota in current CP */ + SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ }; enum {
@@ -2828,6 +2834,7 @@ static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)int f2fs_inode_dirtied (struct inode *inode,bool sync);void f2fs_inode_synced (struct inode *inode);int f2fs_enable_quota_files (struct f2fs_sb_info *sbi,bool rdonly); +int f2fs_quota_sync (struct super_block *sb,int type);void f2fs_quota_off_umount (struct super_block *sb);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover);int f2fs_sync_fs (struct super_block *sb,int sync);
fs/f2fs/super.c +99 -11
174 lines not on this page · raw message
include/linux/f2fs_fs.h +1 -0
@@ -118,6 +118,7 @@ struct f2fs_super_block {/* * For checkpoint */ +#define CP_QUOTA_NEED_FSCK_FLAG 0x00000800#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400#define CP_NOCRC_RECOVERY_FLAG 0x00000200#define CP_TRIMMED_FLAG 0x00000100
Signature · 1 line
2.18.0