Skip to content

Commit

Permalink
btrfs_dirty_inode
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason authored and David Woodhouse committed Mar 26, 2007
1 parent b52d63f commit 4730a4b
Showing 1 changed file with 57 additions and 5 deletions.
62 changes: 57 additions & 5 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ static void reada_leaves(struct btrfs_root *root, struct btrfs_path *path)
}

}

static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
struct inode *inode = filp->f_path.dentry->d_inode;
Expand Down Expand Up @@ -392,6 +393,51 @@ static void fill_inode_item(struct btrfs_inode_item *item,
btrfs_set_inode_generation(item, inode->i_generation);
}

static int btrfs_update_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct inode *inode)
{
struct btrfs_inode_item *inode_item;
struct btrfs_path path;
int ret;

btrfs_init_path(&path);

ret = btrfs_lookup_inode(trans, root, &path, inode->i_ino, 1);
if (ret) {
if (ret > 0)
ret = -ENOENT;
goto failed;
}

inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]),
path.slots[0],
struct btrfs_inode_item);

fill_inode_item(inode_item, inode);
mark_buffer_dirty(path.nodes[0]);
failed:
btrfs_release_path(root, &path);
return 0;
}

static int btrfs_write_inode(struct inode *inode, int wait)
{
struct btrfs_root *root = btrfs_sb(inode->i_sb);
struct btrfs_trans_handle *trans;
int ret;

mutex_lock(&root->fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 1);
ret = btrfs_update_inode(trans, root, inode);
if (wait)
btrfs_commit_transaction(trans, root);
else
btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex);
return ret;
}

static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
struct inode *dir, int mode)
{
Expand All @@ -415,9 +461,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
inode->i_ino = objectid;
inode->i_blocks = 0;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
/* FIXME do this on link */
if (mode & S_IFDIR)
inode->i_size = 3;
fill_inode_item(&inode_item, inode);

key.objectid = objectid;
Expand All @@ -431,7 +474,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
BUG_ON(ret);

insert_inode_hash(inode);
// FIXME mark_inode_dirty(inode)
return inode;
}

Expand All @@ -443,6 +485,12 @@ static int btrfs_add_link(struct btrfs_trans_handle *trans,
dentry->d_name.name, dentry->d_name.len,
dentry->d_parent->d_inode->i_ino,
inode->i_ino, 0);
if (ret == 0) {
dentry->d_parent->d_inode->i_size += dentry->d_name.len;
ret = btrfs_update_inode(trans, btrfs_sb(inode->i_sb),
dentry->d_parent->d_inode);
}

return ret;
}

Expand Down Expand Up @@ -502,6 +550,10 @@ static int btrfs_make_empty_dir(struct btrfs_trans_handle *trans,
goto error;
ret = btrfs_insert_dir_item(trans, root, buf, 2, inode->i_ino,
dir->i_ino, 1);
if (ret)
goto error;
inode->i_size = 3;
ret = btrfs_update_inode(trans, root, inode);
error:
return ret;
}
Expand Down Expand Up @@ -536,7 +588,6 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
if (err)
goto out_fail;
d_instantiate(dentry, inode);
mark_inode_dirty(inode);
drop_on_err = 0;

out_fail:
Expand Down Expand Up @@ -600,6 +651,7 @@ static struct super_operations btrfs_super_ops = {
.read_inode = btrfs_read_locked_inode,
.write_super = btrfs_write_super,
.sync_fs = btrfs_sync_fs,
.write_inode = btrfs_write_inode,
};

static struct inode_operations btrfs_dir_inode_operations = {
Expand Down

0 comments on commit 4730a4b

Please sign in to comment.