aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2012-05-23 14:13:11 -0400
committerJosef Bacik <josef@redhat.com>2012-05-30 10:23:36 -0400
commit72ac3c0d7921f943d92d1ef42a549fb52e56817d (patch)
treec8825a2b3848f201a2b67b3a2ec0aaf9669f9ed3 /fs/btrfs/inode.c
parentcd023e7b17fe86c530475da210b3348421c40e5f (diff)
Btrfs: convert the inode bit field to use the actual bit operations
Miao pointed this out while I was working on an orphan problem that messing with a bitfield where different ranges are protected by different locks doesn't work out right. Turns out we've been doing this forever where we have different parts of the bit field protected by either no lock at all or different locks which could cause all sorts of weird problems including the issue I was hitting. So instead make a runtime_flags thing that we use the normal bit operations on that are all atomic so we can keep having our no/different locking for the different flags and then make force_compress it's own thing so it can be treated normally. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9a1b96fd672a..91ad63901756 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2182,10 +2182,9 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
2182 insert = 1; 2182 insert = 1;
2183 } 2183 }
2184 2184
2185 if (!BTRFS_I(inode)->orphan_meta_reserved) { 2185 if (!test_and_set_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
2186 BTRFS_I(inode)->orphan_meta_reserved = 1; 2186 &BTRFS_I(inode)->runtime_flags))
2187 reserve = 1; 2187 reserve = 1;
2188 }
2189 spin_unlock(&root->orphan_lock); 2188 spin_unlock(&root->orphan_lock);
2190 2189
2191 /* grab metadata reservation from transaction handle */ 2190 /* grab metadata reservation from transaction handle */
@@ -2233,10 +2232,9 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode)
2233 delete_item = 1; 2232 delete_item = 1;
2234 } 2233 }
2235 2234
2236 if (BTRFS_I(inode)->orphan_meta_reserved) { 2235 if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
2237 BTRFS_I(inode)->orphan_meta_reserved = 0; 2236 &BTRFS_I(inode)->runtime_flags))
2238 release_rsv = 1; 2237 release_rsv = 1;
2239 }
2240 spin_unlock(&root->orphan_lock); 2238 spin_unlock(&root->orphan_lock);
2241 2239
2242 if (trans && delete_item) { 2240 if (trans && delete_item) {
@@ -3642,7 +3640,8 @@ static int btrfs_setsize(struct inode *inode, loff_t newsize)
3642 * any new writes get down to disk quickly. 3640 * any new writes get down to disk quickly.
3643 */ 3641 */
3644 if (newsize == 0) 3642 if (newsize == 0)
3645 BTRFS_I(inode)->ordered_data_close = 1; 3643 set_bit(BTRFS_INODE_ORDERED_DATA_CLOSE,
3644 &BTRFS_I(inode)->runtime_flags);
3646 3645
3647 /* we don't support swapfiles, so vmtruncate shouldn't fail */ 3646 /* we don't support swapfiles, so vmtruncate shouldn't fail */
3648 truncate_setsize(inode, newsize); 3647 truncate_setsize(inode, newsize);
@@ -4102,7 +4101,7 @@ static struct inode *new_simple_dir(struct super_block *s,
4102 4101
4103 BTRFS_I(inode)->root = root; 4102 BTRFS_I(inode)->root = root;
4104 memcpy(&BTRFS_I(inode)->location, key, sizeof(*key)); 4103 memcpy(&BTRFS_I(inode)->location, key, sizeof(*key));
4105 BTRFS_I(inode)->dummy_inode = 1; 4104 set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
4106 4105
4107 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID; 4106 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID;
4108 inode->i_op = &btrfs_dir_ro_inode_operations; 4107 inode->i_op = &btrfs_dir_ro_inode_operations;
@@ -4406,7 +4405,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
4406 int ret = 0; 4405 int ret = 0;
4407 bool nolock = false; 4406 bool nolock = false;
4408 4407
4409 if (BTRFS_I(inode)->dummy_inode) 4408 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
4410 return 0; 4409 return 0;
4411 4410
4412 if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode)) 4411 if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode))
@@ -4439,7 +4438,7 @@ int btrfs_dirty_inode(struct inode *inode)
4439 struct btrfs_trans_handle *trans; 4438 struct btrfs_trans_handle *trans;
4440 int ret; 4439 int ret;
4441 4440
4442 if (BTRFS_I(inode)->dummy_inode) 4441 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
4443 return 0; 4442 return 0;
4444 4443
4445 trans = btrfs_join_transaction(root); 4444 trans = btrfs_join_transaction(root);
@@ -6752,7 +6751,8 @@ static int btrfs_truncate(struct inode *inode)
6752 * using truncate to replace the contents of the file will 6751 * using truncate to replace the contents of the file will
6753 * end up with a zero length file after a crash. 6752 * end up with a zero length file after a crash.
6754 */ 6753 */
6755 if (inode->i_size == 0 && BTRFS_I(inode)->ordered_data_close) 6754 if (inode->i_size == 0 && test_bit(BTRFS_INODE_ORDERED_DATA_CLOSE,
6755 &BTRFS_I(inode)->runtime_flags))
6756 btrfs_add_ordered_operation(trans, root, inode); 6756 btrfs_add_ordered_operation(trans, root, inode);
6757 6757
6758 while (1) { 6758 while (1) {
@@ -6889,11 +6889,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
6889 ei->outstanding_extents = 0; 6889 ei->outstanding_extents = 0;
6890 ei->reserved_extents = 0; 6890 ei->reserved_extents = 0;
6891 6891
6892 ei->ordered_data_close = 0; 6892 ei->runtime_flags = 0;
6893 ei->orphan_meta_reserved = 0;
6894 ei->dummy_inode = 0;
6895 ei->in_defrag = 0;
6896 ei->delalloc_meta_reserved = 0;
6897 ei->force_compress = BTRFS_COMPRESS_NONE; 6893 ei->force_compress = BTRFS_COMPRESS_NONE;
6898 6894
6899 ei->delayed_node = NULL; 6895 ei->delayed_node = NULL;