Implement generic freeze feature
Subsystems (3)
PATCH 2/3 Implement generic freeze feature
The ioctls for the generic freeze feature are below.
o Freeze the filesystem
int ioctl(int fd, int FIFREEZE, arg)
fd: The file descriptor of the mountpoint
FIFREEZE: request code for the freeze
arg: Ignored
Return value: 0 if the operation succeeds. Otherwise, -1
o Unfreeze the filesystem
int ioctl(int fd, int FITHAW, arg)
fd: The file descriptor of the mountpoint
FITHAW: request code for unfreeze
arg: Ignored
Return value: 0 if the operation succeeds. Otherwise, -1 Error number: If the filesystem has already been unfrozen,
errno is set to EINVAL.
--- fs/block_dev.c | 2 + fs/buffer.c | 74 ++++++++++++++++++++++++++++++++++++++------ fs/ioctl.c | 46 +++++++++++++++++++++++++++ include/linux/buffer_head.h | 2 - include/linux/fs.h | 7 ++++ 5 files changed, 121 insertions(+), 10 deletions(-)
diff -uprN -X linux-2.6.28-rc2-lockfs/Documentation/dontdiff linux-2.6.28-rc2-lockfs/fs/block_dev.c linux-2.6.28-rc2-fre eze/fs/block_dev.c
fs/block_dev.c +2 -0
@@ -285,6 +285,8 @@ static void init_once(void *foo)INIT_LIST_HEAD (&bdev->bd_holder_list);#endif inode_init_once (&ei->vfs_inode); +/* Initialize mutex for freeze. */ +mutex_init (&bdev->bd_fsfreeze_mutex); }static inline void __bd_forget (struct inode *inode)
diff -uprN -X linux-2.6.28-rc2-lockfs/Documentation/dontdiff linux-2.6.28-rc2-lockfs/fs/buffer.c linux-2.6.28-rc2-freeze /fs/buffer.c
fs/buffer.c +65 -9
106 lines not on this page · raw message
diff -uprN -X linux-2.6.28-rc2-lockfs/Documentation/dontdiff linux-2.6.28-rc2-lockfs/fs/ioctl.c linux-2.6.28-rc2-freeze/ fs/ioctl.c
fs/ioctl.c +46 -0
58 lines not on this page · raw message
diff -uprN -X linux-2.6.28-rc2-lockfs/Documentation/dontdiff linux-2.6.28-rc2-lockfs/include/linux/buffer_head.h linux-2 .6.28-rc2-freeze/include/linux/buffer_head.h
include/linux/buffer_head.h +1 -1
@@ -170,7 +170,7 @@ void __wait_on_buffer(struct buffer_headwait_queue_head_t *bh_waitq_head (struct buffer_head *bh);int fsync_bdev (struct block_device *);struct super_block *freeze_bdev (struct block_device *); -void thaw_bdev (struct block_device *,struct super_block *); +int thaw_bdev (struct block_device *,struct super_block *);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.28-rc2-lockfs/Documentation/dontdiff linux-2.6.28-rc2-lockfs/include/linux/fs.h linux-2.6.28-rc2 -freeze/include/linux/fs.h
include/linux/fs.h +7 -0
@@ -234,6 +234,8 @@ extern int dir_notify_enable;#define BMAP_IOCTL 1/* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1)/* bmap access */ #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 FS_IOC_GETFLAGS _IOR('f', 1, long)#define FS_IOC_SETFLAGS _IOW('f', 2, long)
@@ -584,6 +586,11 @@ struct block_device {* care to not mess up bd_private for that case. */ unsigned long bd_private; + +/* The counter of freeze processes */ +int bd_fsfreeze_count; +/* Mutex for freeze */ +struct mutex bd_fsfreeze_mutex; };/*
fs/buffer.c EXPORT_SYMBOL(freeze_bdev); · line 267
Quoted 9 lines · On Mon, 27 Oct 2008 21:58:54 +0900 Takashi Sato <[email protected]> wrote:
fs/buffer.c +7
-1-void thaw_bdev (struct block_device *bdev,struct super_block *sb) +int thaw_bdev (struct block_device *bdev,struct super_block *sb) { +int error =0 ; + +mutex_lock (&bdev->bd_fsfreeze_mutex); +if (!bdev->bd_fsfreeze_count) { +mutex_unlock (&bdev->bd_fsfreeze_mutex); +return -EINVAL ;
This would be a programming error, yes?
If so, a WARN_ON is more appropriate than a silent runtime error.
Quoted 1 line
(quoted diff) +1
-0+ }
Hi,
Quoted 11 lines
fs/buffer.c EXPORT_SYMBOL(freeze_bdev); · line 267
Quoted 9 lines
fs/buffer.c +7
-1-void thaw_bdev (struct block_device *bdev,struct super_block *sb) +int thaw_bdev (struct block_device *bdev,struct super_block *sb) { +int error =0 ; + +mutex_lock (&bdev->bd_fsfreeze_mutex); +if (!bdev->bd_fsfreeze_count) { +mutex_unlock (&bdev->bd_fsfreeze_mutex); +return -EINVAL ;This would be a programming error, yes?
This is not a kernel programming error but a user's. thaw_bdev() is called via the unfreeze ioctl. If a user calls the unfreeze ioctl for an unfrozen filesystem, this error will be returned. So a WARN_ON isn't needed.
Quoted 3 lines
If so, a
WARN_ONis more appropriate than a silent runtime error.Quoted 1 line
+ }
Cheers, Takashi