Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 139470
b: refs/heads/master
c: 12fcfd2
h: refs/heads/master
v: v3
  • Loading branch information
Chris Mason committed Mar 24, 2009
1 parent 40a2ec2 commit d645dbb
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 99 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a74ac3220774d33db967088906dc3351829e2d3a
refs/heads/master: 12fcfd22fe5bf4fe74710232098bc101af497995
13 changes: 7 additions & 6 deletions trunk/fs/btrfs/btrfs_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ struct btrfs_inode {
*/
u64 logged_trans;

/*
* trans that last made a change that should be fully fsync'd. This
* gets reset to zero each time the inode is logged
*/
u64 log_dirty_trans;

/* total number of bytes pending delalloc, used by stat to calc the
* real block usage of the file
*/
Expand Down Expand Up @@ -121,6 +115,13 @@ struct btrfs_inode {
/* the start of block group preferred for allocations. */
u64 block_group;

/* the fsync log has some corner cases that mean we have to check
* directories to see if any unlinks have been done before
* the directory was logged. See tree-log.c for all the
* details
*/
u64 last_unlink_trans;

struct inode vfs_inode;
};

Expand Down
7 changes: 6 additions & 1 deletion trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,12 @@ struct btrfs_fs_info {

u64 generation;
u64 last_trans_committed;
u64 last_trans_new_blockgroup;

/*
* this is updated to the current trans every time a full commit
* is required instead of the faster short fsync log commits
*/
u64 last_trans_log_full_commit;
u64 open_ioctl_trans;
unsigned long mount_opt;
u64 max_extent;
Expand Down
2 changes: 1 addition & 1 deletion trunk/fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -5897,7 +5897,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,

extent_root = root->fs_info->extent_root;

root->fs_info->last_trans_new_blockgroup = trans->transid;
root->fs_info->last_trans_log_full_commit = trans->transid;

cache = kzalloc(sizeof(*cache), GFP_NOFS);
if (!cache)
Expand Down
14 changes: 10 additions & 4 deletions trunk/fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,11 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
ret = btrfs_log_dentry_safe(trans, root,
file->f_dentry);
if (ret == 0) {
btrfs_sync_log(trans, root);
btrfs_end_transaction(trans, root);
ret = btrfs_sync_log(trans, root);
if (ret == 0)
btrfs_end_transaction(trans, root);
else
btrfs_commit_transaction(trans, root);
} else {
btrfs_commit_transaction(trans, root);
}
Expand Down Expand Up @@ -1266,8 +1269,11 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync)
if (ret > 0) {
ret = btrfs_commit_transaction(trans, root);
} else {
btrfs_sync_log(trans, root);
ret = btrfs_end_transaction(trans, root);
ret = btrfs_sync_log(trans, root);
if (ret == 0)
ret = btrfs_end_transaction(trans, root);
else
ret = btrfs_commit_transaction(trans, root);
}
mutex_lock(&dentry->d_inode->i_mutex);
out:
Expand Down
28 changes: 25 additions & 3 deletions trunk/fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2246,8 +2246,6 @@ int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
ret = btrfs_del_inode_ref_in_log(trans, root, name, name_len,
inode, dir->i_ino);
BUG_ON(ret != 0 && ret != -ENOENT);
if (ret != -ENOENT)
BTRFS_I(dir)->log_dirty_trans = trans->transid;

ret = btrfs_del_dir_entries_in_log(trans, root, name, name_len,
dir, index);
Expand Down Expand Up @@ -2280,6 +2278,9 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
trans = btrfs_start_transaction(root, 1);

btrfs_set_trans_block_group(trans, dir);

btrfs_record_unlink_dir(trans, dir, dentry->d_inode, 0);

ret = btrfs_unlink_inode(trans, root, dir, dentry->d_inode,
dentry->d_name.name, dentry->d_name.len);

Expand Down Expand Up @@ -3042,7 +3043,7 @@ static noinline void init_btrfs_i(struct inode *inode)
bi->disk_i_size = 0;
bi->flags = 0;
bi->index_cnt = (u64)-1;
bi->log_dirty_trans = 0;
bi->last_unlink_trans = 0;
extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_tree,
inode->i_mapping, GFP_NOFS);
Expand Down Expand Up @@ -3786,6 +3787,8 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
drop_inode = 1;

nr = trans->blocks_used;

btrfs_log_new_name(trans, inode, NULL, dentry->d_parent);
btrfs_end_transaction_throttle(trans, root);
fail:
if (drop_inode) {
Expand Down Expand Up @@ -4666,13 +4669,25 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,

trans = btrfs_start_transaction(root, 1);

/*
* this is an ugly little race, but the rename is required to make
* sure that if we crash, the inode is either at the old name
* or the new one. pinning the log transaction lets us make sure
* we don't allow a log commit to come in after we unlink the
* name but before we add the new name back in.
*/
btrfs_pin_log_trans(root);

btrfs_set_trans_block_group(trans, new_dir);

btrfs_inc_nlink(old_dentry->d_inode);
old_dir->i_ctime = old_dir->i_mtime = ctime;
new_dir->i_ctime = new_dir->i_mtime = ctime;
old_inode->i_ctime = ctime;

if (old_dentry->d_parent != new_dentry->d_parent)
btrfs_record_unlink_dir(trans, old_dir, old_inode, 1);

ret = btrfs_unlink_inode(trans, root, old_dir, old_dentry->d_inode,
old_dentry->d_name.name,
old_dentry->d_name.len);
Expand Down Expand Up @@ -4704,7 +4719,14 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (ret)
goto out_fail;

btrfs_log_new_name(trans, old_inode, old_dir,
new_dentry->d_parent);
out_fail:

/* this btrfs_end_log_trans just allows the current
* log-sub transaction to complete
*/
btrfs_end_log_trans(root);
btrfs_end_transaction_throttle(trans, root);
out_unlock:
return ret;
Expand Down
Loading

0 comments on commit d645dbb

Please sign in to comment.