f2fs: use inode mutex to keep atomicity of f2fs_falloc
Subsystems (2)
PATCH 1/1 f2fs: use inode mutex to keep atomicity of f2fs_falloc
Previously without protection of inode mutex, f2fs_falloc and other data correlated operations will interfere with each other.
So let's use inode mutex to keep atomicity of f2fs_falloc.
--- fs/f2fs/file.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/f2fs/file.c +5 -0
@@ -559,6 +559,8 @@ static long f2fs_fallocate(struct file *file, int mode,if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ; +mutex_lock (&inode->i_mutex); +if (mode &FALLOC_FL_PUNCH_HOLE ) ret =punch_hole (inode, offset, len);else
@@ -568,6 +570,9 @@ static long f2fs_fallocate(struct file *file, int mode, inode->i_mtime = inode->i_ctime =CURRENT_TIME ;mark_inode_dirty (inode); } + +mutex_unlock (&inode->i_mutex); +trace_f2fs_fallocate (inode, mode, offset, len, ret);return ret; }
Signature · 1 line
1.7.9.5
Hi,
2014-01-28 (화), 10:29 +0800, Chao Yu:
Quoted 2 lines
Previously without protection of inode mutex,
f2fs_fallocand other data correlated operations will interfere with each other.
Could you explain a little bit more what kind of scenarios wrt this?
Quoted 30 lines
So let's use inode mutex to keep atomicity of
f2fs_falloc.Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 5 +++++ 1 file changed, 5 insertions(+)fs/f2fs/file.c +5
-0@@ -559,6 +559,8 @@ static long f2fs_fallocate(struct file *file, int mode,if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ; +mutex_lock (&inode->i_mutex); +if (mode &FALLOC_FL_PUNCH_HOLE ) ret =punch_hole (inode, offset, len);else @@ -568,6 +570,9 @@ static long f2fs_fallocate(struct file *file, int mode, inode->i_mtime = inode->i_ctime =CURRENT_TIME ;mark_inode_dirty (inode); } + +mutex_unlock (&inode->i_mutex); +trace_f2fs_fallocate (inode, mode, offset, len, ret);return ret; }
Signature · 2 lines
Jaegeuk Kim Samsung
Hi,
Quoted 8 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, January 28, 2014 2:00 PM
To: Chao Yu
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [f2fs-dev] [PATCH] f2fs: use inode mutex to keep atomicity off2fs_falloc
Quoted 7 lines
Hi,
2014-01-28 (화), 10:29 +0800, Chao Yu:
Quoted 2 lines
Previously without protection of inode mutex,
f2fs_fallocand other data correlated operations will interfere with each other.Could you explain a little bit more what kind of scenarios wrt this?
1. Without protection of i_mutex, status(e.g. i_size) of inode could be changed by other operation(e.g. vfs_write()/vfs_truncate()) when we fallocate a file, it may cause us walk into wrong branch code after we check these status of inode, and vice versa.
2. i_size_write()/inode_newsize_ok() is called in f2fs_fallocate(), usually we use i_mutex to protect these functions.
Quoted 36 lines
Quoted 23 lines
So let's use inode mutex to keep atomicity of
f2fs_falloc.Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 5 +++++ 1 file changed, 5 insertions(+)fs/f2fs/file.c +2
-0@@ -559,6 +559,8 @@ static long f2fs_fallocate(struct file *file, int mode,if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ; +mutex_lock (&inode->i_mutex); +if (mode &FALLOC_FL_PUNCH_HOLE ) ret =punch_hole (inode, offset, len);else fs/f2fs/file.c static long f2fs_fallocate(struct file *file, int mode, · line 578
Quoted 9 lines
fs/f2fs/file.c +3
-0@@ -568,6 +570,9 @@ static long f2fs_fallocate(struct file *file, int mode, inode->i_mtime = inode->i_ctime =CURRENT_TIME ;mark_inode_dirty (inode); } + +mutex_unlock (&inode->i_mutex); +trace_f2fs_fallocate (inode, mode, offset, len, ret);return ret; }--
Jaegeuk Kim
Samsung