f2fs: rename dio_rwsem to i_gc_rwsem
authorChao Yu <yuchao0@huawei.com>
Tue, 24 Apr 2018 02:55:28 +0000 (10:55 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 31 May 2018 18:31:49 +0000 (11:31 -0700)
RW semphore dio_rwsem in struct f2fs_inode_info is introduced to avoid
race between dio and data gc, but now, it is more wildly used to avoid
foreground operation vs data gc. So rename it to i_gc_rwsem to improve
its readability.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/gc.c
fs/f2fs/super.c

index ac8720fa5868ba1381605e68d7d7f9a678bd55de..72287fa2489cc0e54c0fed9e9c862dcb3b5c4fc0 100644 (file)
@@ -2401,17 +2401,17 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
        if (rw == WRITE && whint_mode == WHINT_MODE_OFF)
                iocb->ki_hint = WRITE_LIFE_NOT_SET;
 
-       if (!down_read_trylock(&F2FS_I(inode)->dio_rwsem[rw])) {
+       if (!down_read_trylock(&F2FS_I(inode)->i_gc_rwsem[rw])) {
                if (iocb->ki_flags & IOCB_NOWAIT) {
                        iocb->ki_hint = hint;
                        err = -EAGAIN;
                        goto out;
                }
-               down_read(&F2FS_I(inode)->dio_rwsem[rw]);
+               down_read(&F2FS_I(inode)->i_gc_rwsem[rw]);
        }
 
        err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio);
-       up_read(&F2FS_I(inode)->dio_rwsem[rw]);
+       up_read(&F2FS_I(inode)->i_gc_rwsem[rw]);
 
        if (rw == WRITE) {
                if (whint_mode == WHINT_MODE_OFF)
index c2d1208b2c87d7cdfadd96546566abd168917789..7d19fd092928e2d574e737650e9b9fab97869598 100644 (file)
@@ -653,7 +653,9 @@ struct f2fs_inode_info {
        struct task_struct *inmem_task; /* store inmemory task */
        struct mutex inmem_lock;        /* lock for inmemory pages */
        struct extent_tree *extent_tree;        /* cached extent_tree entry */
-       struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */
+
+       /* avoid racing between foreground op and gc */
+       struct rw_semaphore i_gc_rwsem[2];
        struct rw_semaphore i_mmap_sem;
        struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */
 
index 10668720a6612b395a3893dee7cf5aeb8140375f..8af352c3239d9c845c4f19d5cf5110e670db9a43 100644 (file)
@@ -1187,7 +1187,7 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
        pg_end = (offset + len) >> PAGE_SHIFT;
 
        /* avoid gc operation during block exchange */
-       down_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
 
        down_write(&F2FS_I(inode)->i_mmap_sem);
        /* write out all dirty pages from offset */
@@ -1213,7 +1213,7 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
                f2fs_i_size_write(inode, new_size);
 out_unlock:
        up_write(&F2FS_I(inode)->i_mmap_sem);
-       up_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
        return ret;
 }
 
@@ -1389,7 +1389,7 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
        f2fs_balance_fs(sbi, true);
 
        /* avoid gc operation during block exchange */
-       down_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
 
        down_write(&F2FS_I(inode)->i_mmap_sem);
        ret = truncate_blocks(inode, i_size_read(inode), true);
@@ -1430,7 +1430,7 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
                f2fs_i_size_write(inode, new_size);
 out:
        up_write(&F2FS_I(inode)->i_mmap_sem);
-       up_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
        return ret;
 }
 
@@ -1677,7 +1677,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
 
        inode_lock(inode);
 
-       down_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
 
        if (f2fs_is_atomic_file(inode))
                goto out;
@@ -1704,7 +1704,7 @@ skip_flush:
        stat_inc_atomic_write(inode);
        stat_update_max_atomic_write(inode);
 out:
-       up_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
        inode_unlock(inode);
        mnt_drop_write_file(filp);
        return ret;
@@ -1724,7 +1724,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
 
        inode_lock(inode);
 
-       down_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
 
        if (f2fs_is_volatile_file(inode)) {
                ret = -EINVAL;
@@ -1746,7 +1746,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
                ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false);
        }
 err_out:
-       up_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+       up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
        inode_unlock(inode);
        mnt_drop_write_file(filp);
        return ret;
@@ -2333,12 +2333,12 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
        }
 
        inode_lock(src);
-       down_write(&F2FS_I(src)->dio_rwsem[WRITE]);
+       down_write(&F2FS_I(src)->i_gc_rwsem[WRITE]);
        if (src != dst) {
                ret = -EBUSY;
                if (!inode_trylock(dst))
                        goto out;
-               if (!down_write_trylock(&F2FS_I(dst)->dio_rwsem[WRITE])) {
+               if (!down_write_trylock(&F2FS_I(dst)->i_gc_rwsem[WRITE])) {
                        inode_unlock(dst);
                        goto out;
                }
@@ -2400,11 +2400,11 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
        f2fs_unlock_op(sbi);
 out_unlock:
        if (src != dst) {
-               up_write(&F2FS_I(dst)->dio_rwsem[WRITE]);
+               up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]);
                inode_unlock(dst);
        }
 out:
-       up_write(&F2FS_I(src)->dio_rwsem[WRITE]);
+       up_write(&F2FS_I(src)->i_gc_rwsem[WRITE]);
        inode_unlock(src);
        return ret;
 }
@@ -2814,9 +2814,9 @@ int f2fs_precache_extents(struct inode *inode)
        while (map.m_lblk < end) {
                map.m_len = end - map.m_lblk;
 
-               down_write(&fi->dio_rwsem[WRITE]);
+               down_write(&fi->i_gc_rwsem[WRITE]);
                err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_PRECACHE);
-               up_write(&fi->dio_rwsem[WRITE]);
+               up_write(&fi->i_gc_rwsem[WRITE]);
                if (err)
                        return err;
 
index a7de8b3431a9aad44a6caefac6173fb33ef15378..94746d5ac141055505b3e45241556173b669ace6 100644 (file)
@@ -858,7 +858,7 @@ next_step:
                        }
 
                        if (!down_write_trylock(
-                               &F2FS_I(inode)->dio_rwsem[WRITE])) {
+                               &F2FS_I(inode)->i_gc_rwsem[WRITE])) {
                                iput(inode);
                                continue;
                        }
@@ -867,7 +867,7 @@ next_step:
                        data_page = get_read_data_page(inode,
                                        start_bidx + ofs_in_node, REQ_RAHEAD,
                                        true);
-                       up_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
+                       up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
                        if (IS_ERR(data_page)) {
                                iput(inode);
                                continue;
@@ -885,11 +885,11 @@ next_step:
                        bool locked = false;
 
                        if (S_ISREG(inode->i_mode)) {
-                               if (!down_write_trylock(&fi->dio_rwsem[READ]))
+                               if (!down_write_trylock(&fi->i_gc_rwsem[READ]))
                                        continue;
                                if (!down_write_trylock(
-                                               &fi->dio_rwsem[WRITE])) {
-                                       up_write(&fi->dio_rwsem[READ]);
+                                               &fi->i_gc_rwsem[WRITE])) {
+                                       up_write(&fi->i_gc_rwsem[READ]);
                                        continue;
                                }
                                locked = true;
@@ -907,8 +907,8 @@ next_step:
                                                                segno, off);
 
                        if (locked) {
-                               up_write(&fi->dio_rwsem[WRITE]);
-                               up_write(&fi->dio_rwsem[READ]);
+                               up_write(&fi->i_gc_rwsem[WRITE]);
+                               up_write(&fi->i_gc_rwsem[READ]);
                        }
 
                        stat_inc_data_blk_count(sbi, 1, gc_type);
index 5b03041a88b18efee399f6ab346294b8c65b2a18..baab473d728e6d64ec4b1effbe5a2bc351b548c8 100644 (file)
@@ -837,8 +837,8 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
        INIT_LIST_HEAD(&fi->inmem_ilist);
        INIT_LIST_HEAD(&fi->inmem_pages);
        mutex_init(&fi->inmem_lock);
-       init_rwsem(&fi->dio_rwsem[READ]);
-       init_rwsem(&fi->dio_rwsem[WRITE]);
+       init_rwsem(&fi->i_gc_rwsem[READ]);
+       init_rwsem(&fi->i_gc_rwsem[WRITE]);
        init_rwsem(&fi->i_mmap_sem);
        init_rwsem(&fi->i_xattr_sem);