summaryrefslogtreecommitdiff
path: root/fs/nilfs2/inode.c
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-08-25 17:45:44 +0900
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-10-23 09:24:34 +0900
commit4d8d9293dce503eb0e083e17a02a328d397e7f00 (patch)
treeffa2dce7f100b1346131adc01cf93e280b225509 /fs/nilfs2/inode.c
parentba65ae4729bf81c58d9fc847f67d57eec525b042 (diff)
downloadlwn-4d8d9293dce503eb0e083e17a02a328d397e7f00.tar.gz
lwn-4d8d9293dce503eb0e083e17a02a328d397e7f00.zip
nilfs2: set pointer to root object in inodes
This puts a pointer to nilfs_root object in the private part of on-memory inode, and makes nilfs_iget function pick up the inode with the same root object. Non-root inodes inherit its nilfs_root object from parent inode. That of the root inode is allocated through nilfs_attach_checkpoint() function. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs/nilfs2/inode.c')
-rw-r--r--fs/nilfs2/inode.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 82cfdbc43e1c..7306fc7c4962 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -37,6 +37,7 @@
struct nilfs_iget_args {
u64 ino;
__u64 cno;
+ struct nilfs_root *root;
int for_gc;
};
@@ -284,6 +285,7 @@ struct inode *nilfs_new_inode(struct inode *dir, int mode)
struct nilfs_sb_info *sbi = NILFS_SB(sb);
struct inode *inode;
struct nilfs_inode_info *ii;
+ struct nilfs_root *root;
int err = -ENOMEM;
ino_t ino;
@@ -294,8 +296,10 @@ struct inode *nilfs_new_inode(struct inode *dir, int mode)
mapping_set_gfp_mask(inode->i_mapping,
mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
+ root = NILFS_I(dir)->i_root;
ii = NILFS_I(inode);
ii->i_state = 1 << NILFS_I_NEW;
+ ii->i_root = root;
err = nilfs_ifile_create_inode(sbi->s_ifile, &ino, &ii->i_bh);
if (unlikely(err))
@@ -484,7 +488,7 @@ static int nilfs_iget_test(struct inode *inode, void *opaque)
struct nilfs_iget_args *args = opaque;
struct nilfs_inode_info *ii;
- if (args->ino != inode->i_ino)
+ if (args->ino != inode->i_ino || args->root != NILFS_I(inode)->i_root)
return 0;
ii = NILFS_I(inode);
@@ -502,13 +506,21 @@ static int nilfs_iget_set(struct inode *inode, void *opaque)
if (args->for_gc) {
NILFS_I(inode)->i_state = 1 << NILFS_I_GCINODE;
NILFS_I(inode)->i_cno = args->cno;
+ NILFS_I(inode)->i_root = NULL;
+ } else {
+ if (args->root && args->ino == NILFS_ROOT_INO)
+ nilfs_get_root(args->root);
+ NILFS_I(inode)->i_root = args->root;
}
return 0;
}
-struct inode *nilfs_iget(struct super_block *sb, unsigned long ino)
+struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
+ unsigned long ino)
{
- struct nilfs_iget_args args = { .ino = ino, .cno = 0, .for_gc = 0 };
+ struct nilfs_iget_args args = {
+ .ino = ino, .root = root, .cno = 0, .for_gc = 0
+ };
struct inode *inode;
int err;
@@ -530,7 +542,9 @@ struct inode *nilfs_iget(struct super_block *sb, unsigned long ino)
struct inode *nilfs_iget_for_gc(struct super_block *sb, unsigned long ino,
__u64 cno)
{
- struct nilfs_iget_args args = { .ino = ino, .cno = cno, .for_gc = 1 };
+ struct nilfs_iget_args args = {
+ .ino = ino, .root = NULL, .cno = cno, .for_gc = 1
+ };
struct inode *inode;
int err;
@@ -682,6 +696,9 @@ static void nilfs_clear_inode(struct inode *inode)
nilfs_bmap_clear(ii->i_bmap);
nilfs_btnode_cache_clear(&ii->i_btnode_cache);
+
+ if (ii->i_root && inode->i_ino == NILFS_ROOT_INO)
+ nilfs_put_root(ii->i_root);
}
void nilfs_evict_inode(struct inode *inode)
@@ -690,7 +707,7 @@ void nilfs_evict_inode(struct inode *inode)
struct super_block *sb = inode->i_sb;
struct nilfs_inode_info *ii = NILFS_I(inode);
- if (inode->i_nlink || unlikely(is_bad_inode(inode))) {
+ if (inode->i_nlink || !ii->i_root || unlikely(is_bad_inode(inode))) {
if (inode->i_data.nrpages)
truncate_inode_pages(&inode->i_data, 0);
end_writeback(inode);