ocfs2:freeze-thaw: make it work -v2
PATCH 3/3 ocfs2:freeze-thaw: make it work -v2
This patch adds freeze_fs()/unfreeze_fs() for ocfs2 so that it supports freeze/thaw.
Signed-off-by Wengang Wang <[email protected]>
--- fs/ocfs2/dlmglue.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++- fs/ocfs2/dlmglue.h | 2 + fs/ocfs2/journal.c | 1 + fs/ocfs2/ocfs2.h | 12 +++++ fs/ocfs2/super.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 257 insertions(+), 2 deletions(-)
fs/ocfs2/dlmglue.c +114 -1
@@ -3891,10 +3891,123 @@ void ocfs2_refcount_unlock(struct ocfs2_refcount_tree *ref_tree, int ex)ocfs2_cluster_unlock (osb, lockres, level); } +/* +* This is only ever run on behalf of another node. +*/ +void ocfs2_freeze_worker (struct work_struct *work) +{ +struct super_block *sb; +int ret, do_unlock =0 ; + struct ocfs2_super *osb = container_of(work, struct ocfs2_super, + osb_freeze_work); + +mlog (0 ,"flags=0x%lx, frozen=%d\n" , osb->osb_flags, osb->sb->s_frozen); + +/* If umount is in progress, wait it to complete. */ + ret =ocfs2_test_osb_flag (osb,OCFS2_OSB_UMOUNT_INPROG ); +if (ret) { +mlog (0 ,"Unmount in progress, make the freeze request pending\n" ); +/* Leave FREEZE_INPROG there so not queue the worker again */ +return ; + } + + sb =freeze_bdev (osb->sb->s_bdev); +if (IS_ERR (sb)) { +/* ocfs2_freeze_fs() shouldn't return any error in the remote +* box. If it does it's a bug. But we deal with it gracefully. +*/ + ret =PTR_ERR (sb); +mlog_errno (ret); +ocfs2_clear_osb_flag (osb,OCFS2_OSB_FREEZE_INPROG ); +return ; + } + +spin_lock (&osb->osb_lock); + osb->osb_flags &= ~OCFS2_OSB_FREEZE_INPROG ; + osb->osb_flags |=OCFS2_OSB_FROZEN_BY_REMOTE ; +spin_unlock (&osb->osb_lock); + +ocfs2_wake_downconvert_thread (osb); + +/* Waits for thaw */ +wait_thaw: +/* thaws the fs if unmount is in progress. */ + ret =ocfs2_test_osb_flag (osb,OCFS2_OSB_UMOUNT_INPROG ); +if (ret) { +/* Leave FREEZE_INPROG there so not queue the worker again */ + goto thaw_dev; + + } + + ret =ocfs2_freeze_lock_timeout (osb,0 ,50 ); +if (ret == -EBUSY ) { +/* We suppose when it returns -EBUSY when timeout is hit. +* Change me if it's not. +*/ + goto wait_thaw; + }else if (ret) { +mlog (ML_ERROR ,"Getting PR on freeze_lock failed," +"but going to thaw block device %s\n" , osb->dev_str); + }else { + do_unlock =1 ; + } + +thaw_dev: + ret =thaw_bdev (osb->sb->s_bdev, osb->sb); +if (ret) { +/* this shouldn't happen */ +mlog_errno (ret); +printk (KERN_WARNING "ocfs2: Thawing %s failed\n" , osb->dev_str); + } + +ocfs2_clear_osb_flag (osb,OCFS2_OSB_FROZEN_BY_REMOTE ); + +if (do_unlock) +ocfs2_freeze_unlock (osb,0 ); +} + +static void ocfs2_queue_freeze_worker (struct ocfs2_super *osb) +{ +int queue_it =0 ; + +spin_lock (&osb->osb_lock); +if (!(osb->osb_flags &OCFS2_OSB_FREEZE_INPROG )) { + osb->osb_flags |=OCFS2_OSB_FREEZE_INPROG ; + queue_it =1 ; + } +spin_unlock (&osb->osb_lock); + +if (queue_it) +queue_work (ocfs2_wq, &osb->osb_freeze_work); +} +static int ocfs2_check_freeze_downconvert (struct ocfs2_lock_res *lockres,int new_level) { -return 1 ;/* change me */ +struct ocfs2_super *osb =ocfs2_get_lockres_osb (lockres); +struct super_block *sb = osb->sb; +int frozen_by_remote; + +mlog (0 ,"flags=0x%lx, frozen=%d, level=%d, newlevel=%d\n" , + osb->osb_flags, sb->s_frozen, lockres->l_level, new_level); + +if (new_level ==LKM_PRMODE ) { +/* other node is during mount or is waiting for thaw. */ +if (sb->s_frozen) +return 0 ; +else +return 1 ; + } + +/* now new_level is NL. other node wants to freeze cluster. */ + frozen_by_remote =ocfs2_test_osb_flag (osb,OCFS2_OSB_FROZEN_BY_REMOTE ); + +/* ok, this node is frozen for the request. */ +if (frozen_by_remote) +return 1 ; + +ocfs2_queue_freeze_worker (osb); +return 0 ; }/*
fs/ocfs2/dlmglue.h +2 -0
@@ -169,6 +169,8 @@ void ocfs2_wake_downconvert_thread(struct ocfs2_super *osb);struct ocfs2_dlm_debug *ocfs2_new_dlm_debug (void );void ocfs2_put_dlm_debug (struct ocfs2_dlm_debug *dlm_debug); +void ocfs2_freeze_worker (struct work_struct *work); +/* To set the locking protocol on module initialization */ void ocfs2_set_locking_protocol (void );#endif /* DLMGLUE_H */
fs/ocfs2/journal.c +1 -0
@@ -355,6 +355,7 @@ handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs)if (ocfs2_is_hard_readonly (osb))return ERR_PTR (-EROFS ); +vfs_check_frozen (osb->sb,SB_FREEZE_TRANS );BUG_ON (osb->journal->j_state ==OCFS2_JOURNAL_FREE );BUG_ON (max_buffs <=0 );
fs/ocfs2/ocfs2.h +12 -0
@@ -254,6 +254,9 @@ enum ocfs2_mount_options#define OCFS2_OSB_HARD_RO 0x0002#define OCFS2_OSB_ERROR_FS 0x0004#define OCFS2_OSB_DROP_DENTRY_LOCK_IMMED 0x0008 +#define OCFS2_OSB_FREEZE_INPROG 0x0010 +#define OCFS2_OSB_UMOUNT_INPROG 0x0020 +#define OCFS2_OSB_FROZEN_BY_REMOTE 0x0040/* frozen by remote node */ #define OCFS2_DEFAULT_ATIME_QUANTUM 60
@@ -394,6 +397,8 @@ struct ocfs2_superunsigned int *osb_orphan_wipes;wait_queue_head_t osb_wipe_event; +/* osb_freeze_work is protected by osb->s_bdev->bd_fsfreeze_mutex */ +struct work_struct osb_freeze_work;struct ocfs2_orphan_scan osb_orphan_scan;/* used to protect metaecc calculation check of xattr. */
@@ -531,6 +536,13 @@ static inline void ocfs2_set_osb_flag(struct ocfs2_super *osb,spin_unlock (&osb->osb_lock); } +static inline void ocfs2_clear_osb_flag (struct ocfs2_super *osb, +unsigned long flag) +{ +spin_lock (&osb->osb_lock); + osb->osb_flags &= ~flag; +spin_unlock (&osb->osb_lock); +}static inline unsigned long ocfs2_test_osb_flag (struct ocfs2_super *osb,unsigned long flag)
fs/ocfs2/super.c +128 -1
170 lines not on this page · raw message
Signature · 1 line
1.6.6