f2fs: checkpoint disabling
Subsystems (2)
Jaegeuk Kim
maintainerPATCH 1/1 f2fs: checkpoint disabling
From: Daniel Rosenberg <[email protected]>
Note that, it requires "f2fs: return correct errno in f2fs_gc".
This adds a lightweight non-persistent snapshotting scheme to f2fs.
To use, mount with the option checkpoint=disable, and to return to normal operation, remount with checkpoint=enable. If the filesystem is shut down before remounting with checkpoint=enable, it will revert back to its apparent state when it was first mounted with checkpoint=disable. This is useful for situations where you wish to be able to roll back the state of the disk in case of some critical failure.
--- Documentation/filesystems/f2fs.txt | 5 ++ fs/f2fs/checkpoint.c | 16 ++++ fs/f2fs/data.c | 14 +++- fs/f2fs/debug.c | 3 +- fs/f2fs/f2fs.h | 15 +++- fs/f2fs/file.c | 12 +++ fs/f2fs/gc.c | 9 ++- fs/f2fs/inode.c | 6 +- fs/f2fs/namei.c | 19 +++++ fs/f2fs/segment.c | 75 +++++++++++++++++- fs/f2fs/segment.h | 15 ++++ fs/f2fs/super.c | 119 ++++++++++++++++++++++++++++- include/linux/f2fs_fs.h | 1 + 13 files changed, 296 insertions(+), 13 deletions(-)
Documentation/filesystems/f2fs.txt +5 -0
@@ -212,6 +212,11 @@ fsync_mode=%s Control the policy of fsync. Currently supports "posix", non-atomic files likewise "nobarrier" mount option. test_dummy_encryption Enable dummy encryption, which provides a fake fscrypt context. The fake fscrypt context is used by xfstests. +checkpoint=%s Set to "disable" to turn off checkpointing. Set to "enable" + to reenable checkpointing. Is enabled by default. While + disabled, any unmounting or unexpected shutdowns will cause + the filesystem contents to appear as they did when the + filesystem was mounted with that option. ================================================================================ DEBUGFS ENTRIES
fs/f2fs/checkpoint.c +16 -0
@@ -1214,6 +1214,11 @@ 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_CP_DISABLED )) +__set_ckpt_flags (ckpt,CP_DISABLED_FLAG ); +else +__clear_ckpt_flags (ckpt,CP_DISABLED_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 );
@@ -1421,6 +1426,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 ); + sbi->unusable_block_count =0 ;__set_cp_next_pack (sbi);/*
@@ -1445,6 +1451,16 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned long long ckpt_ver;int err =0 ; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) { +if (cpc->reason !=CP_PAUSE ) { +if (cpc->reason !=CP_UMOUNT ) +f2fs_msg (sbi->sb,KERN_WARNING , +"Wrong disabled checkpoint!" ); +return 0 ; + } +f2fs_msg (sbi->sb,KERN_WARNING , +"Start checkpoint disabled!" ); + }mutex_lock (&sbi->cp_mutex); if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
fs/f2fs/data.c +13 -1
@@ -537,7 +537,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)if (fio->in_list) goto next; out: -if (is_sbi_flag_set (sbi,SBI_IS_SHUTDOWN )) +if (is_sbi_flag_set (sbi,SBI_IS_SHUTDOWN ) || +f2fs_is_checkpoint_ready (sbi))__submit_merged_bio (io);up_write (&io->io_rwsem); }
@@ -1695,6 +1696,10 @@ static inline bool check_inplace_update_policy(struct inode *inode, is_inode_flag_set(inode, FI_NEED_IPU))return true; +if (unlikely (fio &&is_sbi_flag_set (sbi,SBI_CP_DISABLED ) && + !f2fs_is_checkpointed_data (sbi, fio->old_blkaddr))) +return true; +return false; }
@@ -1725,6 +1730,9 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return true;if (IS_ATOMIC_WRITTEN_PAGE (fio->page))return true; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ) && +f2fs_is_checkpointed_data (sbi, fio->old_blkaddr))) +return true; }return false; }
@@ -2345,6 +2353,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,trace_f2fs_write_begin (inode, pos, len, flags); + err =f2fs_is_checkpoint_ready (sbi); +if (err) + goto fail; +if ((f2fs_is_atomic_file (inode) && !f2fs_available_free_memory (sbi,INMEM_PAGES )) ||is_inode_flag_set (inode,FI_ATOMIC_REVOKE_REQUEST )) {
fs/f2fs/debug.c +2 -1
@@ -267,7 +267,8 @@ static int stat_show(struct seq_file *s, void *v)seq_printf (s,"\n=====[ partition info(%pg). #%d, %s, CP: %s]=====\n" , si->sbi->sb->s_bdev, i++,f2fs_readonly (si->sbi->sb) ?"RO" :"RW" , -f2fs_cp_error (si->sbi) ?"Error" :"Good" ); +is_set_ckpt_flags (si->sbi,CP_DISABLED_FLAG ) ? +"Disabled" : (f2fs_cp_error (si->sbi) ?"Error" :"Good" ));seq_printf (s,"[SB: 1] [CP: 2] [SIT: %d] [NAT: %d] " , si->sit_area_segs, si->nat_area_segs); seq_printf(s, "[SSA: %d] [MAIN: %d",
fs/f2fs/f2fs.h +13 -2
@@ -98,6 +98,7 @@ extern char *f2fs_fault_name[FAULT_MAX];#define F2FS_MOUNT_QUOTA 0x00400000#define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000#define F2FS_MOUNT_RESERVE_ROOT 0x01000000 +#define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000#define F2FS_OPTION (sbi) ((sbi)->mount_opt)#define clear_opt (sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
@@ -176,6 +177,7 @@ enum {#define CP_RECOVERY 0x00000008#define CP_DISCARD 0x00000010#define CP_TRIMMED 0x00000020 +#define CP_PAUSE 0x00000040#define MAX_DISCARD_BLOCKS (sbi) BLKS_PER_SEC(sbi)#define DEF_MAX_DISCARD_REQUEST 8/* issue 8 discards per round */
@@ -1089,6 +1091,7 @@ enum {SBI_NEED_CP ,/* need to checkpoint */ SBI_IS_SHUTDOWN ,/* shutdown by ioctl */ SBI_IS_RECOVERED ,/* recovered orphan/data */ + SBI_CP_DISABLED, /* CP was disabled last mount */ }; enum {
@@ -1222,6 +1225,9 @@ struct f2fs_sb_info {block_t reserved_blocks;/* configurable reserved blocks */ block_t current_reserved_blocks;/* current reserved blocks */ +/* Additional tracking for no checkpoint mode */ +block_t unusable_block_count;/* # of blocks saved by last cp */ +unsigned int nquota_files;/* # of quota sysfile */ u32 s_next_generation;/* for NFS support */
@@ -1729,7 +1735,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,if (!__allow_reserved_blocks (sbi, inode, true)) avail_user_block_count -=F2FS_OPTION (sbi).root_reserved_blocks; - +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) + avail_user_block_count -= sbi->unusable_block_count;if (unlikely (sbi->total_valid_block_count > avail_user_block_count)) { diff = sbi->total_valid_block_count - avail_user_block_count;if (diff > *count)
@@ -1936,6 +1943,8 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,if (!__allow_reserved_blocks (sbi, inode, false)) valid_block_count +=F2FS_OPTION (sbi).root_reserved_blocks; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) + valid_block_count += sbi->unusable_block_count;if (unlikely (valid_block_count > sbi->user_block_count)) {spin_unlock (&sbi->stat_lock);
@@ -2939,6 +2948,7 @@ void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi);bool f2fs_wait_discard_bios (struct f2fs_sb_info *sbi);void f2fs_clear_prefree_segments (struct f2fs_sb_info *sbi,struct cp_control *cpc); +void f2fs_dirty_to_prefree (struct f2fs_sb_info *sbi);void f2fs_release_discard_addrs (struct f2fs_sb_info *sbi);int f2fs_npages_for_summary_flush (struct f2fs_sb_info *sbi,bool for_ra);void f2fs_allocate_new_segments (struct f2fs_sb_info *sbi);
@@ -3469,7 +3479,8 @@ static inline bool f2fs_may_encrypt(struct inode *inode)static inline bool f2fs_force_buffered_io (struct inode *inode,int rw) {return (f2fs_post_read_required (inode) || - (rw ==WRITE &&test_opt (F2FS_I_SB (inode),LFS )) || + (rw ==WRITE && (test_opt (F2FS_I_SB (inode),LFS ) || +is_sbi_flag_set (F2FS_I_SB (inode),SBI_CP_DISABLED ))) ||F2FS_I_SB (inode)->s_ndevs); }
fs/f2fs/file.c +12 -0
@@ -146,6 +146,9 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)struct f2fs_sb_info *sbi =F2FS_I_SB (inode);enum cp_reason_type cp_reason =CP_NO_NEEDED ; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) +return CP_NO_NEEDED ; +if (!S_ISREG (inode->i_mode)) cp_reason =CP_NON_REGULAR ;else if (inode->i_nlink !=1 )
@@ -2158,6 +2161,12 @@ static int f2fs_ioc_write_checkpoint(struct file *filp, unsigned long arg)if (f2fs_readonly (sbi->sb))return -EROFS ; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) { +f2fs_msg (sbi->sb,KERN_INFO , +"Skipping Checkpoint. Checkpoints currently disabled." ); +return -EINVAL ; + } + ret =mnt_want_write_file (filp);if (ret)return ret;
@@ -2529,6 +2538,9 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)if (f2fs_readonly (sbi->sb))return -EROFS ; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) +return -EINVAL ; +if (copy_from_user (&range, (struct f2fs_flush_device __user *)arg,sizeof (range)))return -EFAULT ;
fs/f2fs/gc.c +7 -2
@@ -362,6 +362,10 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,if (sec_usage_check (sbi, secno)) goto next; +/* Don't touch checkpointed data */ +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ) && +get_ckpt_valid_blocks (sbi, segno))) + goto next;if (gc_type ==BG_GC &&test_bit (secno, dirty_i->victim_secmap)) goto next;
@@ -1169,7 +1173,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) && + !is_sbi_flag_set (sbi,SBI_CP_DISABLED )) { ret =f2fs_write_checkpoint (sbi, &cpc);if (ret) goto stop;
@@ -1221,7 +1226,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, segno =NULL_SEGNO ; goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC && !is_sbi_flag_set (sbi,SBI_CP_DISABLED )) ret =f2fs_write_checkpoint (sbi, &cpc); } stop:
fs/f2fs/inode.c +5 -1
@@ -607,6 +607,9 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)if (!is_inode_flag_set (inode,FI_DIRTY_INODE ))return 0 ; +if (f2fs_is_checkpoint_ready (sbi)) +return -ENOSPC ; +/* * We need to balance fs here to prevent from producing dirty node pages * during the urgent cleaning time when runing out of free sections.
@@ -688,7 +691,8 @@ void f2fs_evict_inode(struct inode *inode)stat_dec_inline_dir (inode);stat_dec_inline_inode (inode); -if (likely (!is_set_ckpt_flags (sbi,CP_ERROR_FLAG ))) +if (likely (!is_set_ckpt_flags (sbi,CP_ERROR_FLAG ) && + !is_sbi_flag_set (sbi,SBI_CP_DISABLED )))f2fs_bug_on (sbi,is_inode_flag_set (inode,FI_DIRTY_INODE ));else f2fs_inode_synced (inode);
fs/f2fs/namei.c +19 -0
@@ -16,6 +16,7 @@#include "f2fs.h" #include "node.h" +#include "segment.h" #include "xattr.h" #include "acl.h" #include <trace/events/f2fs.h>
@@ -269,6 +270,9 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =dquot_initialize (dir);if (err)
@@ -315,6 +319,9 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =fscrypt_prepare_link (old_dentry, dir, dentry);if (err)
@@ -561,6 +568,9 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =fscrypt_prepare_symlink (dir, symname, len, dir->i_sb->s_blocksize, &disk_link);
@@ -690,6 +700,9 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =dquot_initialize (dir);if (err)
@@ -824,6 +837,9 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && (!projid_eq(F2FS_I(new_dir)->i_projid,
@@ -1014,6 +1030,9 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && !projid_eq(F2FS_I(new_dir)->i_projid,
fs/f2fs/segment.c +71 -4
136 lines not on this page · raw message
fs/f2fs/segment.h +15 -0
@@ -339,6 +339,12 @@ static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi,return get_seg_entry (sbi, segno)->valid_blocks; } +static inline unsigned int get_ckpt_valid_blocks (struct f2fs_sb_info *sbi, +unsigned int segno) +{ +return get_seg_entry (sbi, segno)->ckpt_valid_blocks; +} +static inline void seg_info_from_raw_sit (struct seg_entry *se,struct f2fs_sit_entry *rs) {
@@ -576,6 +582,15 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, reserved_sections(sbi) + needed); } +static inline int f2fs_is_checkpoint_ready (struct f2fs_sb_info *sbi) +{ +if (likely (!is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) +return 0 ; +if (likely (!has_not_enough_free_secs (sbi,0 ,0 ))) +return 0 ; +return -ENOSPC ; +} +static inline bool excess_prefree_segs (struct f2fs_sb_info *sbi) {return prefree_segments (sbi) >SM_I (sbi)->rec_prefree_segments;
fs/f2fs/super.c +117 -2
221 lines not on this page · raw message
include/linux/f2fs_fs.h +1 -0
@@ -115,6 +115,7 @@ struct f2fs_super_block {/* * For checkpoint */ +#define CP_DISABLED_FLAG 0x00001000#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400#define CP_NOCRC_RECOVERY_FLAG 0x00000200#define CP_TRIMMED_FLAG 0x00000100
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
Jaegeuk Kim
maintainerNote that, it requires "f2fs: return correct errno in f2fs_gc".
This adds a lightweight non-persistent snapshotting scheme to f2fs.
To use, mount with the option checkpoint=disable, and to return to normal operation, remount with checkpoint=enable. If the filesystem is shut down before remounting with checkpoint=enable, it will revert back to its apparent state when it was first mounted with checkpoint=disable. This is useful for situations where you wish to be able to roll back the state of the disk in case of some critical failure.
---
Change log from v1:
- fix fsync loop
Documentation/filesystems/f2fs.txt | 5 ++ fs/f2fs/checkpoint.c | 16 ++++ fs/f2fs/data.c | 14 +++- fs/f2fs/debug.c | 3 +- fs/f2fs/f2fs.h | 15 +++- fs/f2fs/file.c | 12 ++- fs/f2fs/gc.c | 9 ++- fs/f2fs/inode.c | 6 +- fs/f2fs/namei.c | 19 +++++ fs/f2fs/segment.c | 75 +++++++++++++++++- fs/f2fs/segment.h | 15 ++++ fs/f2fs/super.c | 118 ++++++++++++++++++++++++++++- include/linux/f2fs_fs.h | 1 + 13 files changed, 294 insertions(+), 14 deletions(-)
Documentation/filesystems/f2fs.txt +5 -0
@@ -212,6 +212,11 @@ fsync_mode=%s Control the policy of fsync. Currently supports "posix", non-atomic files likewise "nobarrier" mount option. test_dummy_encryption Enable dummy encryption, which provides a fake fscrypt context. The fake fscrypt context is used by xfstests. +checkpoint=%s Set to "disable" to turn off checkpointing. Set to "enable" + to reenable checkpointing. Is enabled by default. While + disabled, any unmounting or unexpected shutdowns will cause + the filesystem contents to appear as they did when the + filesystem was mounted with that option. ================================================================================ DEBUGFS ENTRIES
fs/f2fs/checkpoint.c +16 -0
@@ -1214,6 +1214,11 @@ 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_CP_DISABLED )) +__set_ckpt_flags (ckpt,CP_DISABLED_FLAG ); +else +__clear_ckpt_flags (ckpt,CP_DISABLED_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 );
@@ -1421,6 +1426,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 ); + sbi->unusable_block_count =0 ;__set_cp_next_pack (sbi);/*
@@ -1445,6 +1451,16 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned long long ckpt_ver;int err =0 ; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) { +if (cpc->reason !=CP_PAUSE ) { +if (cpc->reason !=CP_UMOUNT ) +f2fs_msg (sbi->sb,KERN_WARNING , +"Wrong disabled checkpoint!" ); +return 0 ; + } +f2fs_msg (sbi->sb,KERN_WARNING , +"Start checkpoint disabled!" ); + }mutex_lock (&sbi->cp_mutex); if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
fs/f2fs/data.c +13 -1
@@ -537,7 +537,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)if (fio->in_list) goto next; out: -if (is_sbi_flag_set (sbi,SBI_IS_SHUTDOWN )) +if (is_sbi_flag_set (sbi,SBI_IS_SHUTDOWN ) || +f2fs_is_checkpoint_ready (sbi))__submit_merged_bio (io);up_write (&io->io_rwsem); }
@@ -1695,6 +1696,10 @@ static inline bool check_inplace_update_policy(struct inode *inode, is_inode_flag_set(inode, FI_NEED_IPU))return true; +if (unlikely (fio &&is_sbi_flag_set (sbi,SBI_CP_DISABLED ) && + !f2fs_is_checkpointed_data (sbi, fio->old_blkaddr))) +return true; +return false; }
@@ -1725,6 +1730,9 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return true;if (IS_ATOMIC_WRITTEN_PAGE (fio->page))return true; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ) && +f2fs_is_checkpointed_data (sbi, fio->old_blkaddr))) +return true; }return false; }
@@ -2345,6 +2353,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,trace_f2fs_write_begin (inode, pos, len, flags); + err =f2fs_is_checkpoint_ready (sbi); +if (err) + goto fail; +if ((f2fs_is_atomic_file (inode) && !f2fs_available_free_memory (sbi,INMEM_PAGES )) ||is_inode_flag_set (inode,FI_ATOMIC_REVOKE_REQUEST )) {
fs/f2fs/debug.c +2 -1
@@ -267,7 +267,8 @@ static int stat_show(struct seq_file *s, void *v)seq_printf (s,"\n=====[ partition info(%pg). #%d, %s, CP: %s]=====\n" , si->sbi->sb->s_bdev, i++,f2fs_readonly (si->sbi->sb) ?"RO" :"RW" , -f2fs_cp_error (si->sbi) ?"Error" :"Good" ); +is_set_ckpt_flags (si->sbi,CP_DISABLED_FLAG ) ? +"Disabled" : (f2fs_cp_error (si->sbi) ?"Error" :"Good" ));seq_printf (s,"[SB: 1] [CP: 2] [SIT: %d] [NAT: %d] " , si->sit_area_segs, si->nat_area_segs); seq_printf(s, "[SSA: %d] [MAIN: %d",
fs/f2fs/f2fs.h +13 -2
@@ -98,6 +98,7 @@ extern char *f2fs_fault_name[FAULT_MAX];#define F2FS_MOUNT_QUOTA 0x00400000#define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000#define F2FS_MOUNT_RESERVE_ROOT 0x01000000 +#define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000#define F2FS_OPTION (sbi) ((sbi)->mount_opt)#define clear_opt (sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
@@ -176,6 +177,7 @@ enum {#define CP_RECOVERY 0x00000008#define CP_DISCARD 0x00000010#define CP_TRIMMED 0x00000020 +#define CP_PAUSE 0x00000040#define MAX_DISCARD_BLOCKS (sbi) BLKS_PER_SEC(sbi)#define DEF_MAX_DISCARD_REQUEST 8/* issue 8 discards per round */
@@ -1089,6 +1091,7 @@ enum {SBI_NEED_CP ,/* need to checkpoint */ SBI_IS_SHUTDOWN ,/* shutdown by ioctl */ SBI_IS_RECOVERED ,/* recovered orphan/data */ + SBI_CP_DISABLED, /* CP was disabled last mount */ }; enum {
@@ -1222,6 +1225,9 @@ struct f2fs_sb_info {block_t reserved_blocks;/* configurable reserved blocks */ block_t current_reserved_blocks;/* current reserved blocks */ +/* Additional tracking for no checkpoint mode */ +block_t unusable_block_count;/* # of blocks saved by last cp */ +unsigned int nquota_files;/* # of quota sysfile */ u32 s_next_generation;/* for NFS support */
@@ -1729,7 +1735,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,if (!__allow_reserved_blocks (sbi, inode, true)) avail_user_block_count -=F2FS_OPTION (sbi).root_reserved_blocks; - +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) + avail_user_block_count -= sbi->unusable_block_count;if (unlikely (sbi->total_valid_block_count > avail_user_block_count)) { diff = sbi->total_valid_block_count - avail_user_block_count;if (diff > *count)
@@ -1936,6 +1943,8 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,if (!__allow_reserved_blocks (sbi, inode, false)) valid_block_count +=F2FS_OPTION (sbi).root_reserved_blocks; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) + valid_block_count += sbi->unusable_block_count;if (unlikely (valid_block_count > sbi->user_block_count)) {spin_unlock (&sbi->stat_lock);
@@ -2939,6 +2948,7 @@ void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi);bool f2fs_wait_discard_bios (struct f2fs_sb_info *sbi);void f2fs_clear_prefree_segments (struct f2fs_sb_info *sbi,struct cp_control *cpc); +void f2fs_dirty_to_prefree (struct f2fs_sb_info *sbi);void f2fs_release_discard_addrs (struct f2fs_sb_info *sbi);int f2fs_npages_for_summary_flush (struct f2fs_sb_info *sbi,bool for_ra);void f2fs_allocate_new_segments (struct f2fs_sb_info *sbi);
@@ -3469,7 +3479,8 @@ static inline bool f2fs_may_encrypt(struct inode *inode)static inline bool f2fs_force_buffered_io (struct inode *inode,int rw) {return (f2fs_post_read_required (inode) || - (rw ==WRITE &&test_opt (F2FS_I_SB (inode),LFS )) || + (rw ==WRITE && (test_opt (F2FS_I_SB (inode),LFS ) || +is_sbi_flag_set (F2FS_I_SB (inode),SBI_CP_DISABLED ))) ||F2FS_I_SB (inode)->s_ndevs); }
fs/f2fs/file.c +11 -1
@@ -211,7 +211,8 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, };unsigned int seq_id =0 ; -if (unlikely (f2fs_readonly (inode->i_sb))) +if (unlikely (f2fs_readonly (inode->i_sb) || +is_sbi_flag_set (sbi,SBI_CP_DISABLED )))return 0 ;trace_f2fs_sync_file_enter (inode);
@@ -2158,6 +2159,12 @@ static int f2fs_ioc_write_checkpoint(struct file *filp, unsigned long arg)if (f2fs_readonly (sbi->sb))return -EROFS ; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) { +f2fs_msg (sbi->sb,KERN_INFO , +"Skipping Checkpoint. Checkpoints currently disabled." ); +return -EINVAL ; + } + ret =mnt_want_write_file (filp);if (ret)return ret;
@@ -2529,6 +2536,9 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)if (f2fs_readonly (sbi->sb))return -EROFS ; +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) +return -EINVAL ; +if (copy_from_user (&range, (struct f2fs_flush_device __user *)arg,sizeof (range)))return -EFAULT ;
fs/f2fs/gc.c +7 -2
@@ -362,6 +362,10 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,if (sec_usage_check (sbi, secno)) goto next; +/* Don't touch checkpointed data */ +if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED ) && +get_ckpt_valid_blocks (sbi, segno))) + goto next;if (gc_type ==BG_GC &&test_bit (secno, dirty_i->victim_secmap)) goto next;
@@ -1169,7 +1173,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) && + !is_sbi_flag_set (sbi,SBI_CP_DISABLED )) { ret =f2fs_write_checkpoint (sbi, &cpc);if (ret) goto stop;
@@ -1221,7 +1226,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, segno =NULL_SEGNO ; goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC && !is_sbi_flag_set (sbi,SBI_CP_DISABLED )) ret =f2fs_write_checkpoint (sbi, &cpc); } stop:
fs/f2fs/inode.c +5 -1
@@ -607,6 +607,9 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)if (!is_inode_flag_set (inode,FI_DIRTY_INODE ))return 0 ; +if (f2fs_is_checkpoint_ready (sbi)) +return -ENOSPC ; +/* * We need to balance fs here to prevent from producing dirty node pages * during the urgent cleaning time when runing out of free sections.
@@ -688,7 +691,8 @@ void f2fs_evict_inode(struct inode *inode)stat_dec_inline_dir (inode);stat_dec_inline_inode (inode); -if (likely (!is_set_ckpt_flags (sbi,CP_ERROR_FLAG ))) +if (likely (!is_set_ckpt_flags (sbi,CP_ERROR_FLAG ) && + !is_sbi_flag_set (sbi,SBI_CP_DISABLED )))f2fs_bug_on (sbi,is_inode_flag_set (inode,FI_DIRTY_INODE ));else f2fs_inode_synced (inode);
fs/f2fs/namei.c +19 -0
@@ -16,6 +16,7 @@#include "f2fs.h" #include "node.h" +#include "segment.h" #include "xattr.h" #include "acl.h" #include <trace/events/f2fs.h>
@@ -269,6 +270,9 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =dquot_initialize (dir);if (err)
@@ -315,6 +319,9 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =fscrypt_prepare_link (old_dentry, dir, dentry);if (err)
@@ -561,6 +568,9 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =fscrypt_prepare_symlink (dir, symname, len, dir->i_sb->s_blocksize, &disk_link);
@@ -690,6 +700,9 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; err =dquot_initialize (dir);if (err)
@@ -824,6 +837,9 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && (!projid_eq(F2FS_I(new_dir)->i_projid,
@@ -1014,6 +1030,9 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,if (unlikely (f2fs_cp_error (sbi)))return -EIO ; + err =f2fs_is_checkpoint_ready (sbi); +if (err) +return err; if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && !projid_eq(F2FS_I(new_dir)->i_projid,
fs/f2fs/segment.c +71 -4
136 lines not on this page · raw message
fs/f2fs/segment.h +15 -0
@@ -339,6 +339,12 @@ static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi,return get_seg_entry (sbi, segno)->valid_blocks; } +static inline unsigned int get_ckpt_valid_blocks (struct f2fs_sb_info *sbi, +unsigned int segno) +{ +return get_seg_entry (sbi, segno)->ckpt_valid_blocks; +} +static inline void seg_info_from_raw_sit (struct seg_entry *se,struct f2fs_sit_entry *rs) {
@@ -576,6 +582,15 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, reserved_sections(sbi) + needed); } +static inline int f2fs_is_checkpoint_ready (struct f2fs_sb_info *sbi) +{ +if (likely (!is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) +return 0 ; +if (likely (!has_not_enough_free_secs (sbi,0 ,0 ))) +return 0 ; +return -ENOSPC ; +} +static inline bool excess_prefree_segs (struct f2fs_sb_info *sbi) {return prefree_segments (sbi) >SM_I (sbi)->rec_prefree_segments;
fs/f2fs/super.c +116 -2
214 lines not on this page · raw message
include/linux/f2fs_fs.h +1 -0
@@ -115,6 +115,7 @@ struct f2fs_super_block {/* * For checkpoint */ +#define CP_DISABLED_FLAG 0x00001000#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400#define CP_NOCRC_RECOVERY_FLAG 0x00000200#define CP_TRIMMED_FLAG 0x00000100
Signature · 1 line
2.19.0.605.g01d371f741-goog