2012-11-29 12:28:09 +08:00
|
|
|
/*
|
2012-11-02 16:11:10 +08:00
|
|
|
* fs/f2fs/namei.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
|
|
|
|
* http://www.samsung.com/
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/f2fs_fs.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
|
|
|
|
#include "f2fs.h"
|
2013-03-21 14:21:57 +08:00
|
|
|
#include "node.h"
|
2012-11-02 16:11:10 +08:00
|
|
|
#include "xattr.h"
|
|
|
|
#include "acl.h"
|
2013-04-20 00:28:40 +08:00
|
|
|
#include <trace/events/f2fs.h>
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
|
|
|
nid_t ino;
|
|
|
|
struct inode *inode;
|
|
|
|
bool nid_free = false;
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
int err;
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
inode = new_inode(sb);
|
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (!alloc_nid(sbi, &ino)) {
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
err = -ENOSPC;
|
|
|
|
goto fail;
|
|
|
|
}
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
2014-05-08 17:09:30 +08:00
|
|
|
inode_init_owner(inode, dir, mode);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
inode->i_ino = ino;
|
|
|
|
inode->i_blocks = 0;
|
|
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
|
|
|
|
inode->i_generation = sbi->s_next_generation++;
|
|
|
|
|
|
|
|
err = insert_inode_locked(inode);
|
|
|
|
if (err) {
|
|
|
|
err = -EINVAL;
|
|
|
|
nid_free = true;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-04-25 12:24:33 +08:00
|
|
|
trace_f2fs_new_inode(inode, 0);
|
2012-11-02 16:11:10 +08:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return inode;
|
|
|
|
|
|
|
|
out:
|
|
|
|
clear_nlink(inode);
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
fail:
|
2013-04-25 12:24:33 +08:00
|
|
|
trace_f2fs_new_inode(inode, err);
|
2013-04-30 10:33:27 +08:00
|
|
|
make_bad_inode(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
iput(inode);
|
|
|
|
if (nid_free)
|
|
|
|
alloc_nid_failed(sbi, ino);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_multimedia_file(const unsigned char *s, const char *sub)
|
|
|
|
{
|
2012-12-28 01:55:46 +08:00
|
|
|
size_t slen = strlen(s);
|
|
|
|
size_t sublen = strlen(sub);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
if (sublen > slen)
|
2013-04-20 00:27:21 +08:00
|
|
|
return 0;
|
2012-11-02 16:11:10 +08:00
|
|
|
|
2013-08-22 18:11:25 +08:00
|
|
|
return !strncasecmp(s + slen - sublen, sub, sublen);
|
2012-11-02 16:11:10 +08:00
|
|
|
}
|
|
|
|
|
2012-11-29 12:28:09 +08:00
|
|
|
/*
|
2012-11-02 16:11:10 +08:00
|
|
|
* Set multimedia files as cold files for hot/cold data separation
|
|
|
|
*/
|
2013-03-21 14:21:57 +08:00
|
|
|
static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
|
2012-11-02 16:11:10 +08:00
|
|
|
const unsigned char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
__u8 (*extlist)[8] = sbi->raw_super->extension_list;
|
|
|
|
|
|
|
|
int count = le32_to_cpu(sbi->raw_super->extension_count);
|
|
|
|
for (i = 0; i < count; i++) {
|
2013-04-20 00:27:21 +08:00
|
|
|
if (is_multimedia_file(name, extlist[i])) {
|
2013-06-14 07:52:35 +08:00
|
|
|
file_set_cold(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
|
|
|
bool excl)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
|
|
|
struct inode *inode;
|
|
|
|
nid_t ino = 0;
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
int err;
|
2012-11-02 16:11:10 +08:00
|
|
|
|
2012-12-19 15:25:21 +08:00
|
|
|
f2fs_balance_fs(sbi);
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
inode = f2fs_new_inode(dir, mode);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
|
|
|
|
|
|
|
if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
|
2013-03-21 14:21:57 +08:00
|
|
|
set_cold_files(sbi, inode, dentry->d_name.name);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
inode->i_op = &f2fs_file_inode_operations;
|
|
|
|
inode->i_fop = &f2fs_file_operations;
|
|
|
|
inode->i_mapping->a_ops = &f2fs_dblock_aops;
|
|
|
|
ino = inode->i_ino;
|
|
|
|
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
err = f2fs_add_link(dentry, inode);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
alloc_nid_done(sbi, ino);
|
|
|
|
|
2013-05-16 07:57:43 +08:00
|
|
|
d_instantiate(dentry, inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
unlock_new_inode(inode);
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
clear_nlink(inode);
|
|
|
|
unlock_new_inode(inode);
|
2013-04-30 10:33:27 +08:00
|
|
|
make_bad_inode(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
iput(inode);
|
|
|
|
alloc_nid_failed(sbi, ino);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct inode *inode = old_dentry->d_inode;
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
int err;
|
2012-11-02 16:11:10 +08:00
|
|
|
|
2012-12-19 15:25:21 +08:00
|
|
|
f2fs_balance_fs(sbi);
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
inode->i_ctime = CURRENT_TIME;
|
2013-05-22 11:06:26 +08:00
|
|
|
ihold(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
set_inode_flag(F2FS_I(inode), FI_INC_LINK);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
err = f2fs_add_link(dentry, inode);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
|
|
|
|
iput(inode);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *f2fs_get_parent(struct dentry *child)
|
|
|
|
{
|
|
|
|
struct qstr dotdot = QSTR_INIT("..", 2);
|
|
|
|
unsigned long ino = f2fs_inode_by_name(child->d_inode, &dotdot);
|
|
|
|
if (!ino)
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
return d_obtain_alias(f2fs_iget(child->d_inode->i_sb, ino));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
struct inode *inode = NULL;
|
|
|
|
struct f2fs_dir_entry *de;
|
|
|
|
struct page *page;
|
|
|
|
|
2013-03-03 12:58:05 +08:00
|
|
|
if (dentry->d_name.len > F2FS_NAME_LEN)
|
2012-11-02 16:11:10 +08:00
|
|
|
return ERR_PTR(-ENAMETOOLONG);
|
|
|
|
|
|
|
|
de = f2fs_find_entry(dir, &dentry->d_name, &page);
|
|
|
|
if (de) {
|
|
|
|
nid_t ino = le32_to_cpu(de->ino);
|
|
|
|
kunmap(page);
|
|
|
|
f2fs_put_page(page, 0);
|
|
|
|
|
|
|
|
inode = f2fs_iget(dir->i_sb, ino);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return ERR_CAST(inode);
|
2014-04-07 11:18:34 +08:00
|
|
|
|
|
|
|
stat_inc_inline_inode(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return d_splice_alias(inode, dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
|
|
|
struct inode *inode = dentry->d_inode;
|
|
|
|
struct f2fs_dir_entry *de;
|
|
|
|
struct page *page;
|
|
|
|
int err = -ENOENT;
|
|
|
|
|
2013-04-20 00:28:40 +08:00
|
|
|
trace_f2fs_unlink_enter(dir, dentry);
|
2012-12-19 15:25:21 +08:00
|
|
|
f2fs_balance_fs(sbi);
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
de = f2fs_find_entry(dir, &dentry->d_name, &page);
|
|
|
|
if (!de)
|
|
|
|
goto fail;
|
|
|
|
|
2013-10-08 09:19:28 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2013-07-30 10:36:53 +08:00
|
|
|
err = acquire_orphan_inode(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (err) {
|
2013-10-08 09:19:28 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
kunmap(page);
|
|
|
|
f2fs_put_page(page, 0);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
f2fs_delete_entry(de, page, inode);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
/* In order to evict this inode, we set it dirty */
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
fail:
|
2013-04-20 00:28:40 +08:00
|
|
|
trace_f2fs_unlink_exit(inode, err);
|
2012-11-02 16:11:10 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
|
|
|
const char *symname)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
|
|
|
struct inode *inode;
|
2012-12-28 01:55:46 +08:00
|
|
|
size_t symlen = strlen(symname) + 1;
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
int err;
|
2012-11-02 16:11:10 +08:00
|
|
|
|
2012-12-19 15:25:21 +08:00
|
|
|
f2fs_balance_fs(sbi);
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
|
|
|
|
|
|
|
inode->i_op = &f2fs_symlink_inode_operations;
|
|
|
|
inode->i_mapping->a_ops = &f2fs_dblock_aops;
|
|
|
|
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
err = f2fs_add_link(dentry, inode);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = page_symlink(inode, symname, symlen);
|
|
|
|
alloc_nid_done(sbi, inode->i_ino);
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
return err;
|
|
|
|
out:
|
|
|
|
clear_nlink(inode);
|
|
|
|
unlock_new_inode(inode);
|
2013-04-30 10:33:27 +08:00
|
|
|
make_bad_inode(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
iput(inode);
|
|
|
|
alloc_nid_failed(sbi, inode->i_ino);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
|
|
|
{
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
|
|
|
|
struct inode *inode;
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
int err;
|
2012-11-02 16:11:10 +08:00
|
|
|
|
2012-12-19 15:25:21 +08:00
|
|
|
f2fs_balance_fs(sbi);
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
inode = f2fs_new_inode(dir, S_IFDIR | mode);
|
|
|
|
if (IS_ERR(inode))
|
2012-12-01 09:56:25 +08:00
|
|
|
return PTR_ERR(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
inode->i_op = &f2fs_dir_inode_operations;
|
|
|
|
inode->i_fop = &f2fs_dir_operations;
|
|
|
|
inode->i_mapping->a_ops = &f2fs_dblock_aops;
|
2012-12-08 13:54:18 +08:00
|
|
|
mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
set_inode_flag(F2FS_I(inode), FI_INC_LINK);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
err = f2fs_add_link(dentry, inode);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (err)
|
|
|
|
goto out_fail;
|
|
|
|
|
|
|
|
alloc_nid_done(sbi, inode->i_ino);
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_fail:
|
|
|
|
clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
|
|
|
|
clear_nlink(inode);
|
|
|
|
unlock_new_inode(inode);
|
2013-04-30 10:33:27 +08:00
|
|
|
make_bad_inode(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
iput(inode);
|
|
|
|
alloc_nid_failed(sbi, inode->i_ino);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct inode *inode = dentry->d_inode;
|
|
|
|
if (f2fs_empty_dir(inode))
|
|
|
|
return f2fs_unlink(dir, dentry);
|
|
|
|
return -ENOTEMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
|
|
|
|
umode_t mode, dev_t rdev)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dir->i_sb;
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
|
|
|
struct inode *inode;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (!new_valid_dev(rdev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-12-19 15:25:21 +08:00
|
|
|
f2fs_balance_fs(sbi);
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
inode = f2fs_new_inode(dir, mode);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
|
|
|
|
|
|
|
init_special_inode(inode, inode->i_mode, rdev);
|
|
|
|
inode->i_op = &f2fs_special_inode_operations;
|
|
|
|
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
err = f2fs_add_link(dentry, inode);
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
alloc_nid_done(sbi, inode->i_ino);
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
clear_nlink(inode);
|
|
|
|
unlock_new_inode(inode);
|
2013-04-30 10:33:27 +08:00
|
|
|
make_bad_inode(inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
iput(inode);
|
|
|
|
alloc_nid_failed(sbi, inode->i_ino);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
|
|
{
|
|
|
|
struct super_block *sb = old_dir->i_sb;
|
|
|
|
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
|
|
|
struct inode *old_inode = old_dentry->d_inode;
|
|
|
|
struct inode *new_inode = new_dentry->d_inode;
|
|
|
|
struct page *old_dir_page;
|
2013-07-30 10:36:53 +08:00
|
|
|
struct page *old_page, *new_page;
|
2012-11-02 16:11:10 +08:00
|
|
|
struct f2fs_dir_entry *old_dir_entry = NULL;
|
|
|
|
struct f2fs_dir_entry *old_entry;
|
|
|
|
struct f2fs_dir_entry *new_entry;
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
int err = -ENOENT;
|
2012-11-02 16:11:10 +08:00
|
|
|
|
2012-12-19 15:25:21 +08:00
|
|
|
f2fs_balance_fs(sbi);
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
|
|
|
|
if (!old_entry)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (S_ISDIR(old_inode->i_mode)) {
|
|
|
|
err = -EIO;
|
|
|
|
old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
|
|
|
|
if (!old_dir_entry)
|
|
|
|
goto out_old;
|
|
|
|
}
|
|
|
|
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_lock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
if (new_inode) {
|
|
|
|
|
|
|
|
err = -ENOTEMPTY;
|
|
|
|
if (old_dir_entry && !f2fs_empty_dir(new_inode))
|
|
|
|
goto out_dir;
|
|
|
|
|
|
|
|
err = -ENOENT;
|
|
|
|
new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
|
|
|
|
&new_page);
|
|
|
|
if (!new_entry)
|
|
|
|
goto out_dir;
|
|
|
|
|
2013-07-30 10:36:53 +08:00
|
|
|
err = acquire_orphan_inode(sbi);
|
|
|
|
if (err)
|
|
|
|
goto put_out_dir;
|
|
|
|
|
2013-07-18 17:02:31 +08:00
|
|
|
if (update_dent_inode(old_inode, &new_dentry->d_name)) {
|
2013-07-30 10:36:53 +08:00
|
|
|
release_orphan_inode(sbi);
|
|
|
|
goto put_out_dir;
|
2013-07-18 17:02:31 +08:00
|
|
|
}
|
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
f2fs_set_link(new_dir, new_entry, new_page, old_inode);
|
2014-03-20 18:10:08 +08:00
|
|
|
down_write(&F2FS_I(old_inode)->i_sem);
|
2013-12-21 18:03:28 +08:00
|
|
|
F2FS_I(old_inode)->i_pino = new_dir->i_ino;
|
2014-03-20 18:10:08 +08:00
|
|
|
up_write(&F2FS_I(old_inode)->i_sem);
|
2012-11-02 16:11:10 +08:00
|
|
|
|
|
|
|
new_inode->i_ctime = CURRENT_TIME;
|
2014-03-20 18:10:08 +08:00
|
|
|
down_write(&F2FS_I(new_inode)->i_sem);
|
2012-11-02 16:11:10 +08:00
|
|
|
if (old_dir_entry)
|
|
|
|
drop_nlink(new_inode);
|
|
|
|
drop_nlink(new_inode);
|
2014-03-20 18:10:08 +08:00
|
|
|
up_write(&F2FS_I(new_inode)->i_sem);
|
|
|
|
|
2014-01-21 12:32:12 +08:00
|
|
|
mark_inode_dirty(new_inode);
|
2013-07-30 10:36:53 +08:00
|
|
|
|
2012-11-02 16:11:10 +08:00
|
|
|
if (!new_inode->i_nlink)
|
|
|
|
add_orphan_inode(sbi, new_inode->i_ino);
|
2013-07-30 10:36:53 +08:00
|
|
|
else
|
|
|
|
release_orphan_inode(sbi);
|
|
|
|
|
2013-08-26 20:25:31 +08:00
|
|
|
update_inode_page(old_inode);
|
f2fs: introduce a new global lock scheme
In the previous version, f2fs uses global locks according to the usage types,
such as directory operations, block allocation, block write, and so on.
Reference the following lock types in f2fs.h.
enum lock_type {
RENAME, /* for renaming operations */
DENTRY_OPS, /* for directory operations */
DATA_WRITE, /* for data write */
DATA_NEW, /* for data allocation */
DATA_TRUNC, /* for data truncate */
NODE_NEW, /* for node allocation */
NODE_TRUNC, /* for node truncate */
NODE_WRITE, /* for node write */
NR_LOCK_TYPE,
};
In that case, we lose the performance under the multi-threading environment,
since every types of operations must be conducted one at a time.
In order to address the problem, let's share the locks globally with a mutex
array regardless of any types.
So, let users grab a mutex and perform their jobs in parallel as much as
possbile.
For this, I propose a new global lock scheme as follows.
0. Data structure
- f2fs_sb_info -> mutex_lock[NR_GLOBAL_LOCKS]
- f2fs_sb_info -> node_write
1. mutex_lock_op(sbi)
- try to get an avaiable lock from the array.
- returns the index of the gottern lock variable.
2. mutex_unlock_op(sbi, index of the lock)
- unlock the given index of the lock.
3. mutex_lock_all(sbi)
- grab all the locks in the array before the checkpoint.
4. mutex_unlock_all(sbi)
- release all the locks in the array after checkpoint.
5. block_operations()
- call mutex_lock_all()
- sync_dirty_dir_inodes()
- grab node_write
- sync_node_pages()
Note that,
the pairs of mutex_lock_op()/mutex_unlock_op() and
mutex_lock_all()/mutex_unlock_all() should be used together.
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2012-11-22 15:21:29 +08:00
|
|
|
update_inode_page(new_inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
} else {
|
|
|
|
err = f2fs_add_link(new_dentry, old_inode);
|
|
|
|
if (err)
|
|
|
|
goto out_dir;
|
|
|
|
|
|
|
|
if (old_dir_entry) {
|
|
|
|
inc_nlink(new_dir);
|
f2fs: introduce a new global lock scheme
In the previous version, f2fs uses global locks according to the usage types,
such as directory operations, block allocation, block write, and so on.
Reference the following lock types in f2fs.h.
enum lock_type {
RENAME, /* for renaming operations */
DENTRY_OPS, /* for directory operations */
DATA_WRITE, /* for data write */
DATA_NEW, /* for data allocation */
DATA_TRUNC, /* for data truncate */
NODE_NEW, /* for node allocation */
NODE_TRUNC, /* for node truncate */
NODE_WRITE, /* for node write */
NR_LOCK_TYPE,
};
In that case, we lose the performance under the multi-threading environment,
since every types of operations must be conducted one at a time.
In order to address the problem, let's share the locks globally with a mutex
array regardless of any types.
So, let users grab a mutex and perform their jobs in parallel as much as
possbile.
For this, I propose a new global lock scheme as follows.
0. Data structure
- f2fs_sb_info -> mutex_lock[NR_GLOBAL_LOCKS]
- f2fs_sb_info -> node_write
1. mutex_lock_op(sbi)
- try to get an avaiable lock from the array.
- returns the index of the gottern lock variable.
2. mutex_unlock_op(sbi, index of the lock)
- unlock the given index of the lock.
3. mutex_lock_all(sbi)
- grab all the locks in the array before the checkpoint.
4. mutex_unlock_all(sbi)
- release all the locks in the array after checkpoint.
5. block_operations()
- call mutex_lock_all()
- sync_dirty_dir_inodes()
- grab node_write
- sync_node_pages()
Note that,
the pairs of mutex_lock_op()/mutex_unlock_op() and
mutex_lock_all()/mutex_unlock_all() should be used together.
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2012-11-22 15:21:29 +08:00
|
|
|
update_inode_page(new_dir);
|
2012-11-02 16:11:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
old_inode->i_ctime = CURRENT_TIME;
|
|
|
|
mark_inode_dirty(old_inode);
|
|
|
|
|
|
|
|
f2fs_delete_entry(old_entry, old_page, NULL);
|
|
|
|
|
|
|
|
if (old_dir_entry) {
|
|
|
|
if (old_dir != new_dir) {
|
|
|
|
f2fs_set_link(old_inode, old_dir_entry,
|
|
|
|
old_dir_page, new_dir);
|
2014-03-20 18:10:08 +08:00
|
|
|
down_write(&F2FS_I(old_inode)->i_sem);
|
2013-12-21 18:03:28 +08:00
|
|
|
F2FS_I(old_inode)->i_pino = new_dir->i_ino;
|
2014-03-20 18:10:08 +08:00
|
|
|
up_write(&F2FS_I(old_inode)->i_sem);
|
2014-01-21 12:32:12 +08:00
|
|
|
update_inode_page(old_inode);
|
2012-11-02 16:11:10 +08:00
|
|
|
} else {
|
|
|
|
kunmap(old_dir_page);
|
|
|
|
f2fs_put_page(old_dir_page, 0);
|
|
|
|
}
|
|
|
|
drop_nlink(old_dir);
|
2014-01-21 12:32:12 +08:00
|
|
|
mark_inode_dirty(old_dir);
|
f2fs: introduce a new global lock scheme
In the previous version, f2fs uses global locks according to the usage types,
such as directory operations, block allocation, block write, and so on.
Reference the following lock types in f2fs.h.
enum lock_type {
RENAME, /* for renaming operations */
DENTRY_OPS, /* for directory operations */
DATA_WRITE, /* for data write */
DATA_NEW, /* for data allocation */
DATA_TRUNC, /* for data truncate */
NODE_NEW, /* for node allocation */
NODE_TRUNC, /* for node truncate */
NODE_WRITE, /* for node write */
NR_LOCK_TYPE,
};
In that case, we lose the performance under the multi-threading environment,
since every types of operations must be conducted one at a time.
In order to address the problem, let's share the locks globally with a mutex
array regardless of any types.
So, let users grab a mutex and perform their jobs in parallel as much as
possbile.
For this, I propose a new global lock scheme as follows.
0. Data structure
- f2fs_sb_info -> mutex_lock[NR_GLOBAL_LOCKS]
- f2fs_sb_info -> node_write
1. mutex_lock_op(sbi)
- try to get an avaiable lock from the array.
- returns the index of the gottern lock variable.
2. mutex_unlock_op(sbi, index of the lock)
- unlock the given index of the lock.
3. mutex_lock_all(sbi)
- grab all the locks in the array before the checkpoint.
4. mutex_unlock_all(sbi)
- release all the locks in the array after checkpoint.
5. block_operations()
- call mutex_lock_all()
- sync_dirty_dir_inodes()
- grab node_write
- sync_node_pages()
Note that,
the pairs of mutex_lock_op()/mutex_unlock_op() and
mutex_lock_all()/mutex_unlock_all() should be used together.
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2012-11-22 15:21:29 +08:00
|
|
|
update_inode_page(old_dir);
|
2012-11-02 16:11:10 +08:00
|
|
|
}
|
|
|
|
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-07-30 10:36:53 +08:00
|
|
|
put_out_dir:
|
|
|
|
f2fs_put_page(new_page, 1);
|
2012-11-02 16:11:10 +08:00
|
|
|
out_dir:
|
|
|
|
if (old_dir_entry) {
|
|
|
|
kunmap(old_dir_page);
|
|
|
|
f2fs_put_page(old_dir_page, 0);
|
|
|
|
}
|
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint.
And each other operate routine(besides checkpoint) needs to acquire a fs_lock,
there is a terrible problem here, if these are too many concurrency threads acquiring
fs_lock, so that they will block each other and may lead to some performance problem,
but this is not the phenomenon we want to see.
Though there are some optimization patches introduced to enhance the usage of fs_lock,
but the thorough solution is using a *rw_sem* to replace the fs_lock.
Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block
other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other,
this can avoid the problem described above completely.
Because of the weakness of rw_sem, the above change may introduce a potential problem
that the checkpoint thread might get starved if other threads are intensively locking
the read semaphore for I/O.(Pointed out by Xu Jin)
In order to avoid this, a wait_list is introduced, the appending read semaphore ops
will be dropped into the wait_list if checkpoint thread is waiting for write semaphore,
and will be waked up when checkpoint thread gives up write semaphore.
Thanks to Kim's previous review and test, and will be very glad to see other guys'
performance tests about this patch.
V2:
-fix the potential starvation problem.
-use more suitable func name suggested by Xu Jin.
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: adjust minor coding standard]
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-09-27 18:08:30 +08:00
|
|
|
f2fs_unlock_op(sbi);
|
2012-11-02 16:11:10 +08:00
|
|
|
out_old:
|
|
|
|
kunmap(old_page);
|
|
|
|
f2fs_put_page(old_page, 0);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct inode_operations f2fs_dir_inode_operations = {
|
|
|
|
.create = f2fs_create,
|
|
|
|
.lookup = f2fs_lookup,
|
|
|
|
.link = f2fs_link,
|
|
|
|
.unlink = f2fs_unlink,
|
|
|
|
.symlink = f2fs_symlink,
|
|
|
|
.mkdir = f2fs_mkdir,
|
|
|
|
.rmdir = f2fs_rmdir,
|
|
|
|
.mknod = f2fs_mknod,
|
|
|
|
.rename = f2fs_rename,
|
2013-06-07 15:33:07 +08:00
|
|
|
.getattr = f2fs_getattr,
|
2012-11-02 16:11:10 +08:00
|
|
|
.setattr = f2fs_setattr,
|
|
|
|
.get_acl = f2fs_get_acl,
|
2013-12-20 21:16:45 +08:00
|
|
|
.set_acl = f2fs_set_acl,
|
2012-11-02 16:11:10 +08:00
|
|
|
#ifdef CONFIG_F2FS_FS_XATTR
|
|
|
|
.setxattr = generic_setxattr,
|
|
|
|
.getxattr = generic_getxattr,
|
|
|
|
.listxattr = f2fs_listxattr,
|
|
|
|
.removexattr = generic_removexattr,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct inode_operations f2fs_symlink_inode_operations = {
|
|
|
|
.readlink = generic_readlink,
|
|
|
|
.follow_link = page_follow_link_light,
|
|
|
|
.put_link = page_put_link,
|
2013-06-07 15:33:07 +08:00
|
|
|
.getattr = f2fs_getattr,
|
2012-11-02 16:11:10 +08:00
|
|
|
.setattr = f2fs_setattr,
|
|
|
|
#ifdef CONFIG_F2FS_FS_XATTR
|
|
|
|
.setxattr = generic_setxattr,
|
|
|
|
.getxattr = generic_getxattr,
|
|
|
|
.listxattr = f2fs_listxattr,
|
|
|
|
.removexattr = generic_removexattr,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct inode_operations f2fs_special_inode_operations = {
|
2013-06-07 15:33:07 +08:00
|
|
|
.getattr = f2fs_getattr,
|
2012-11-02 16:11:10 +08:00
|
|
|
.setattr = f2fs_setattr,
|
|
|
|
.get_acl = f2fs_get_acl,
|
2013-12-20 21:16:45 +08:00
|
|
|
.set_acl = f2fs_set_acl,
|
2012-11-02 16:11:10 +08:00
|
|
|
#ifdef CONFIG_F2FS_FS_XATTR
|
|
|
|
.setxattr = generic_setxattr,
|
|
|
|
.getxattr = generic_getxattr,
|
|
|
|
.listxattr = f2fs_listxattr,
|
|
|
|
.removexattr = generic_removexattr,
|
|
|
|
#endif
|
|
|
|
};
|