Add timeout feature
Subsystems (4)
PATCH 10/10 Add timeout feature
The timeout feature is added to "freeze ioctl" to solve a deadlock when the freezer accesses a frozen filesystem. And new ioctl to reset the timeout period is added to extend the timeout period. For example, the freezer resets the timeout period to 10 seconds every 5 seconds. In this approach, even if the freezer causes a deadlock by accessing the frozen filesystem, it will be solved by the timeout in 10 seconds and the freezer will be able to recognize that at the next reset of timeout period.
o Freeze the filesystem
int ioctl(int fd, int FIFREEZE, long *timeout_sec)
fd: The file descriptor of the mountpoint
FIFREEZE: request code for the freeze
timeout_sec: the timeout period in seconds
If it's 0 or 1, the timeout isn't set.
This special case of "1" is implemented to keep the compatibility with XFS applications.
Return value: 0 if the operation succeeds. Otherwise, -1
o Reset the timeout period
int ioctl(int fd, int FIFREEZE_RESET_TIMEOUT, long *timeout_sec)
fd:file descriptor of mountpoint
FIFREEZE_RESET_TIMEOUT: request code for reset of timeout period
timeout_sec: new timeout period in seconds
Return value: 0 if the operation succeeds. Otherwise, -1 Error number: If the filesystem has already been unfrozen,
errno is set to EINVAL.
--- drivers/md/dm.c | 2 - fs/block_dev.c | 2 + fs/buffer.c | 44 ++++++++++++++++++++++++--- fs/ioctl.c | 71 ++++++++++++++++++++++++++++++++++++++++++-- fs/super.c | 37 ++++++++++++++++++++++ fs/xfs/xfs_fsops.c | 2 - include/linux/buffer_head.h | 4 +- include/linux/fs.h | 8 ++++ 8 files changed, 159 insertions(+), 11 deletions(-)
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/drivers/md/dm.c linux-2.6.27-rc7-timeout/ drivers/md/dm.c
drivers/md/dm.c +1 -1
@@ -1451,7 +1451,7 @@ static int lock_fs(struct mapped_deviceWARN_ON (md->frozen_sb); - md->frozen_sb =freeze_bdev (md->suspended_bdev); + md->frozen_sb =freeze_bdev (md->suspended_bdev,0 );if (IS_ERR (md->frozen_sb)) { r =PTR_ERR (md->frozen_sb); md->frozen_sb =NULL ;
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/fs/block_dev.c linux-2.6.27-rc7-timeout/f s/block_dev.c
fs/block_dev.c +2 -0
@@ -287,6 +287,8 @@ static void init_once(void *foo)inode_init_once (&ei->vfs_inode);/* Initialize mutex for freeze. */ mutex_init (&bdev->bd_fsfreeze_mutex); +/* Setup freeze timeout function. */ +INIT_DELAYED_WORK (&bdev->bd_fsfreeze_timeout, fsfreeze_timeout); }static inline void __bd_forget (struct inode *inode)
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/fs/buffer.c linux-2.6.27-rc7-timeout/fs/b uffer.c
fs/buffer.c +39 -5
91 lines not on this page · raw message
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/fs/ioctl.c linux-2.6.27-rc7-timeout/fs/io ctl.c
fs/ioctl.c +68 -3
104 lines not on this page · raw message
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/fs/super.c linux-2.6.27-rc7-timeout/fs/su per.c
fs/super.c +37 -0
@@ -981,3 +981,40 @@ struct vfsmount *kern_mount_data(struct }EXPORT_SYMBOL_GPL (kern_mount_data); + +/* +* fsfreeze_timeout - Thaw the filesystem. +* +* @work: work queue (delayed_work.work) +* +* Called by the delayed work when elapsing the timeout period. +* Thaw the filesystem. +*/ +void fsfreeze_timeout (struct work_struct *work) +{ +struct block_device *bd =container_of (work, + struct block_device, bd_fsfreeze_timeout.work); +struct super_block *sb =get_super (bd); + +thaw_bdev_core (bd, sb,0 ); + +if (sb) +drop_super (sb); +} + +/* +* add_fsfreeze_timeout - Add timeout for freeze. +* +* @bdev: block device struct +* @timeout_msec: timeout period +* +* Add the delayed work for freeze timeout to the delayed work queue. +*/ +void add_fsfreeze_timeout (struct block_device *bdev,unsigned int timeout_msec) +{ +s64 timeout_jiffies =msecs_to_jiffies (timeout_msec); + +/* Set delayed work queue */ +cancel_delayed_work_sync (&bdev->bd_fsfreeze_timeout); +schedule_delayed_work (&bdev->bd_fsfreeze_timeout, timeout_jiffies); +}
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/fs/xfs/xfs_fsops.c linux-2.6.27-rc7-timeo ut/fs/xfs/xfs_fsops.c
fs/xfs/xfs_fsops.c +1 -1
@@ -624,7 +624,7 @@ xfs_fs_goingdown( {switch (inflags) {case XFS_FSOP_GOING_FLAGS_DEFAULT : { -struct super_block *sb =freeze_bdev (mp->m_super->s_bdev); +struct super_block *sb =freeze_bdev (mp->m_super->s_bdev,0 );if (sb && !IS_ERR (sb)) {xfs_force_shutdown (mp,SHUTDOWN_FORCE_UMOUNT );
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/include/linux/buffer_head.h linux-2.6.27- rc7-timeout/include/linux/buffer_head.h
include/linux/buffer_head.h +3 -1
@@ -169,8 +169,10 @@ int sync_blockdev(struct block_device *bvoid __wait_on_buffer (struct buffer_head *);wait_queue_head_t *bh_waitq_head (struct buffer_head *bh);int fsync_bdev (struct block_device *); -struct super_block *freeze_bdev (struct block_device *); +struct super_block *freeze_bdev (struct block_device *, +unsigned int timeout_msec);int thaw_bdev (struct block_device *,struct super_block *); +int thaw_bdev_core (struct block_device *,struct super_block *,int );int fsync_super (struct super_block *);int fsync_no_super (struct block_device *); struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block,
diff -uprN -X linux-2.6.27-rc7-xfs/Documentation/dontdiff linux-2.6.27-rc7-xfs/include/linux/fs.h linux-2.6.27-rc7-timeo ut/include/linux/fs.h
include/linux/fs.h +8 -0
@@ -8,6 +8,7 @@#include <linux/limits.h> #include <linux/ioctl.h> +#include <linux/workqueue.h> /* * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
@@ -228,6 +229,7 @@ extern int dir_notify_enable;#define FIGETBSZ _IO(0x00,2)/* get the block size used for bmap */ #define FIFREEZE _IOWR('X', 119, int)/* Freeze */ #define FITHAW _IOWR('X', 120, int)/* Thaw */ +#define FIFREEZE_RESET_TIMEOUT _IO(0x00, 3)/* Reset freeze timeout */ #define FS_IOC_GETFLAGS _IOR('f', 1, long)#define FS_IOC_SETFLAGS _IOW('f', 2, long)
@@ -581,6 +583,8 @@ struct block_device {int bd_fsfreeze_count;/* Mutex for freeze */ struct mutex bd_fsfreeze_mutex; +/* Delayed work for freeze */ +struct delayed_work bd_fsfreeze_timeout; };/*
@@ -2160,5 +2164,9 @@ int proc_nr_files(struct ctl_table *tablint get_filesystem_list (char * buf); +extern void add_fsfreeze_timeout (struct block_device *bdev, +unsigned int timeout_msec); +extern void fsfreeze_timeout (struct work_struct *work); +#endif /* __KERNEL__ */ #endif /* _LINUX_FS_H */