OCFS2 freeze/thaw support
Tiger Yang <tiger.yang@oracle.com>
April 10, 2007
Goals
Support freeze/thaw OCFS2 file system for backup purpose.
- "Freeze" will flush all dirty data, metadata to disk and prevent any writes to the file system.
- "Thaw" will unlock the file system and allow writes to the file system.
User interaction
freeze.ocfs2 is the tools to freeze/thaw ocfs2 file system.
#freeze.ocfs2 usage: freeze.ocfs2 [-f] [-u] mountpoint -f freeze filesystem -u unfreeze filesystem
freeze.ocfs2 invoke ioctl( OCFS2_IOC_FREEZE / OCFS2_IOC_THAW) send requests about freeze/thaw file system on one node.
Implementation
- Add a lock resource osb_freeze_lockres in struct ocfs2_super and add ocfs2_freeze_lock/unlock() to take/release that lock.
- Every node in cluster got a PR mode freeze lock and then unlock them during mount. In this way we got the lock at PR level in cache and setup to get dlm callbacks(downconvert_worker and post_unlock). If one node could not get PR freeze lock when doing mount, it means the file system is frozen, so it could not mount on at that time.
- When one node freeze the file system it will get EX level freeze lock in ocfs2_ioctl() and other nodes will down-convert freeze lock from PR to NL. That will fire dlm downconvert callbacks. In callbacks we will queue a worker in ocfs2_wq which call freeze_bdev and try to get PR level lock. They will suspend on the lock because one node already hold EX level lock.
- When one node who freeze the filesystem before thaw ocfs2 it will unlock EX freeze lock in ocfs2_iocal() and the worker on other nodes will get PR level lock. After they got PR level lock, they will thaw the file system and then unlock PR level lock for get it back to the original situation.
In ocfs2_file_aio_write(), vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE) will prevent write file data when file system is frozen. For setattr stuff, such as chown,chmod,mkdir... We add vfs_check_frozen(inode->i_sb, SB_FREEZE_TRANS) in ocfs2_start_trans() to prevent write meta data.
ocfs2_iocal will handle freeze/thaw file system requests. freeze_bdev will set super_blcok->s_frozen with SB_FREEZE_WRITE/TRANS. ocfs2_ioctl { case OCFS2_IOC_FREEZE: ocfs2_freeze_fs(); case OCFS2_IOC_THAW: ocfs2_thaw_fs(); } ocfs2_freeze_fs() { ocfs2_freeze_lock(EX); freeze_bdev(); } ocfs2_thaw_fs() { ocfs2_freeze_unlock(EX); thaw_bdev(); } static struct ocfs2_lock_res_ops ocfs2_freeze_lops = { .check_downconvert = ocfs2_check_freeze_downconvert, .flags = 0, }; ocfs2_freeze_convert_worker() { ocfs2_queue_freeze_worker(); } ocfs2_freeze_worker() { freeze_bdev(osb->sb->s_bdev); ocfs2_freeze_lock(osb, 0); thaw_bdev(osb->sb->s_bdev, osb->sb); ocfs2_freeze_unlock(osb, 0); }
Testing
Test case 1
One process freeze the ocfs2, another process try to create a file on frozen ocfs2 on one node.
Patches
Todo
We must keeping the fd (mountpoint) open after we frozen ocfs2 and close it until thaw ocfs2. Otherwise we could not open the mount point in thaw if some write operation hanging.