aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/delayed-inode.c
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2011-06-23 03:27:13 -0400
committerChris Mason <chris.mason@oracle.com>2011-06-27 11:34:27 -0400
commit2f7e33d432d097a2a7f467b031bf18be91cb3d49 (patch)
treea1729a436b3c9921390e23cae35e5b837653dfe4 /fs/btrfs/delayed-inode.c
parent9b90f5135320bc74dc6c9a8c74d69fd4821d9282 (diff)
btrfs: fix inconsonant inode information
When iputting the inode, We may leave the delayed nodes if they have some delayed items that have not been dealt with. So when the inode is read again, we must look up the relative delayed node, and use the information in it to initialize the inode. Or we will get inconsonant inode information, it may cause that the same directory index number is allocated again, and hit the following oops: [ 5447.554187] err add delayed dir index item(name: pglog_0.965_0) into the insertion tree of the delayed node(root id: 262, inode id: 258, errno: -17) [ 5447.569766] ------------[ cut here ]------------ [ 5447.575361] kernel BUG at fs/btrfs/delayed-inode.c:1301! [SNIP] [ 5447.790721] Call Trace: [ 5447.793191] [<ffffffffa0641c4e>] btrfs_insert_dir_item+0x189/0x1bb [btrfs] [ 5447.800156] [<ffffffffa0651a45>] btrfs_add_link+0x12b/0x191 [btrfs] [ 5447.806517] [<ffffffffa0651adc>] btrfs_add_nondir+0x31/0x58 [btrfs] [ 5447.812876] [<ffffffffa0651d6a>] btrfs_create+0xf9/0x197 [btrfs] [ 5447.818961] [<ffffffff8111f840>] vfs_create+0x72/0x92 [ 5447.824090] [<ffffffff8111fa8c>] do_last+0x22c/0x40b [ 5447.829133] [<ffffffff8112076a>] path_openat+0xc0/0x2ef [ 5447.834438] [<ffffffff810c58e2>] ? __perf_event_task_sched_out+0x24/0x44 [ 5447.841216] [<ffffffff8103ecdd>] ? perf_event_task_sched_out+0x59/0x67 [ 5447.847846] [<ffffffff81121a79>] do_filp_open+0x3d/0x87 [ 5447.853156] [<ffffffff811e126c>] ? strncpy_from_user+0x43/0x4d [ 5447.859072] [<ffffffff8111f1f5>] ? getname_flags+0x2e/0x80 [ 5447.864636] [<ffffffff8111f179>] ? do_getname+0x14b/0x173 [ 5447.870112] [<ffffffff8111f1b7>] ? audit_getname+0x16/0x26 [ 5447.875682] [<ffffffff8112b1ab>] ? spin_lock+0xe/0x10 [ 5447.880882] [<ffffffff81112d39>] do_sys_open+0x69/0xae [ 5447.886153] [<ffffffff81112db1>] sys_open+0x20/0x22 [ 5447.891114] [<ffffffff813b9aab>] system_call_fastpath+0x16/0x1b Fix it by reusing the old delayed node. Reported-by: Jim Schutt <jaschut@sandia.gov> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Tested-by: Jim Schutt <jaschut@sandia.gov> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/delayed-inode.c')
-rw-r--r--fs/btrfs/delayed-inode.c104
1 files changed, 80 insertions, 24 deletions
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index f1cbd028f7b3..98c68e658a9b 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -82,19 +82,16 @@ static inline struct btrfs_delayed_root *btrfs_get_delayed_root(
82 return root->fs_info->delayed_root; 82 return root->fs_info->delayed_root;
83} 83}
84 84
85static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node( 85static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode)
86 struct inode *inode)
87{ 86{
88 struct btrfs_delayed_node *node;
89 struct btrfs_inode *btrfs_inode = BTRFS_I(inode); 87 struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
90 struct btrfs_root *root = btrfs_inode->root; 88 struct btrfs_root *root = btrfs_inode->root;
91 u64 ino = btrfs_ino(inode); 89 u64 ino = btrfs_ino(inode);
92 int ret; 90 struct btrfs_delayed_node *node;
93 91
94again:
95 node = ACCESS_ONCE(btrfs_inode->delayed_node); 92 node = ACCESS_ONCE(btrfs_inode->delayed_node);
96 if (node) { 93 if (node) {
97 atomic_inc(&node->refs); /* can be accessed */ 94 atomic_inc(&node->refs);
98 return node; 95 return node;
99 } 96 }
100 97
@@ -102,8 +99,10 @@ again:
102 node = radix_tree_lookup(&root->delayed_nodes_tree, ino); 99 node = radix_tree_lookup(&root->delayed_nodes_tree, ino);
103 if (node) { 100 if (node) {
104 if (btrfs_inode->delayed_node) { 101 if (btrfs_inode->delayed_node) {
102 atomic_inc(&node->refs); /* can be accessed */
103 BUG_ON(btrfs_inode->delayed_node != node);
105 spin_unlock(&root->inode_lock); 104 spin_unlock(&root->inode_lock);
106 goto again; 105 return node;
107 } 106 }
108 btrfs_inode->delayed_node = node; 107 btrfs_inode->delayed_node = node;
109 atomic_inc(&node->refs); /* can be accessed */ 108 atomic_inc(&node->refs); /* can be accessed */
@@ -113,6 +112,23 @@ again:
113 } 112 }
114 spin_unlock(&root->inode_lock); 113 spin_unlock(&root->inode_lock);
115 114
115 return NULL;
116}
117
118static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node(
119 struct inode *inode)
120{
121 struct btrfs_delayed_node *node;
122 struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
123 struct btrfs_root *root = btrfs_inode->root;
124 u64 ino = btrfs_ino(inode);
125 int ret;
126
127again:
128 node = btrfs_get_delayed_node(inode);
129 if (node)
130 return node;
131
116 node = kmem_cache_alloc(delayed_node_cache, GFP_NOFS); 132 node = kmem_cache_alloc(delayed_node_cache, GFP_NOFS);
117 if (!node) 133 if (!node)
118 return ERR_PTR(-ENOMEM); 134 return ERR_PTR(-ENOMEM);
@@ -548,19 +564,6 @@ struct btrfs_delayed_item *__btrfs_next_delayed_item(
548 return next; 564 return next;
549} 565}
550 566
551static inline struct btrfs_delayed_node *btrfs_get_delayed_node(
552 struct inode *inode)
553{
554 struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
555 struct btrfs_delayed_node *delayed_node;
556
557 delayed_node = btrfs_inode->delayed_node;
558 if (delayed_node)
559 atomic_inc(&delayed_node->refs);
560
561 return delayed_node;
562}
563
564static inline struct btrfs_root *btrfs_get_fs_root(struct btrfs_root *root, 567static inline struct btrfs_root *btrfs_get_fs_root(struct btrfs_root *root,
565 u64 root_id) 568 u64 root_id)
566{ 569{
@@ -1404,8 +1407,7 @@ end:
1404 1407
1405int btrfs_inode_delayed_dir_index_count(struct inode *inode) 1408int btrfs_inode_delayed_dir_index_count(struct inode *inode)
1406{ 1409{
1407 struct btrfs_delayed_node *delayed_node = BTRFS_I(inode)->delayed_node; 1410 struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
1408 int ret = 0;
1409 1411
1410 if (!delayed_node) 1412 if (!delayed_node)
1411 return -ENOENT; 1413 return -ENOENT;
@@ -1415,11 +1417,14 @@ int btrfs_inode_delayed_dir_index_count(struct inode *inode)
1415 * a new directory index is added into the delayed node and index_cnt 1417 * a new directory index is added into the delayed node and index_cnt
1416 * is updated now. So we needn't lock the delayed node. 1418 * is updated now. So we needn't lock the delayed node.
1417 */ 1419 */
1418 if (!delayed_node->index_cnt) 1420 if (!delayed_node->index_cnt) {
1421 btrfs_release_delayed_node(delayed_node);
1419 return -EINVAL; 1422 return -EINVAL;
1423 }
1420 1424
1421 BTRFS_I(inode)->index_cnt = delayed_node->index_cnt; 1425 BTRFS_I(inode)->index_cnt = delayed_node->index_cnt;
1422 return ret; 1426 btrfs_release_delayed_node(delayed_node);
1427 return 0;
1423} 1428}
1424 1429
1425void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list, 1430void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list,
@@ -1613,6 +1618,57 @@ static void fill_stack_inode_item(struct btrfs_trans_handle *trans,
1613 inode->i_ctime.tv_nsec); 1618 inode->i_ctime.tv_nsec);
1614} 1619}
1615 1620
1621int btrfs_fill_inode(struct inode *inode, u32 *rdev)
1622{
1623 struct btrfs_delayed_node *delayed_node;
1624 struct btrfs_inode_item *inode_item;
1625 struct btrfs_timespec *tspec;
1626
1627 delayed_node = btrfs_get_delayed_node(inode);
1628 if (!delayed_node)
1629 return -ENOENT;
1630
1631 mutex_lock(&delayed_node->mutex);
1632 if (!delayed_node->inode_dirty) {
1633 mutex_unlock(&delayed_node->mutex);
1634 btrfs_release_delayed_node(delayed_node);
1635 return -ENOENT;
1636 }
1637
1638 inode_item = &delayed_node->inode_item;
1639
1640 inode->i_uid = btrfs_stack_inode_uid(inode_item);
1641 inode->i_gid = btrfs_stack_inode_gid(inode_item);
1642 btrfs_i_size_write(inode, btrfs_stack_inode_size(inode_item));
1643 inode->i_mode = btrfs_stack_inode_mode(inode_item);
1644 inode->i_nlink = btrfs_stack_inode_nlink(inode_item);
1645 inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item));
1646 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item);
1647 BTRFS_I(inode)->sequence = btrfs_stack_inode_sequence(inode_item);
1648 inode->i_rdev = 0;
1649 *rdev = btrfs_stack_inode_rdev(inode_item);
1650 BTRFS_I(inode)->flags = btrfs_stack_inode_flags(inode_item);
1651
1652 tspec = btrfs_inode_atime(inode_item);
1653 inode->i_atime.tv_sec = btrfs_stack_timespec_sec(tspec);
1654 inode->i_atime.tv_nsec = btrfs_stack_timespec_nsec(tspec);
1655
1656 tspec = btrfs_inode_mtime(inode_item);
1657 inode->i_mtime.tv_sec = btrfs_stack_timespec_sec(tspec);
1658 inode->i_mtime.tv_nsec = btrfs_stack_timespec_nsec(tspec);
1659
1660 tspec = btrfs_inode_ctime(inode_item);
1661 inode->i_ctime.tv_sec = btrfs_stack_timespec_sec(tspec);
1662 inode->i_ctime.tv_nsec = btrfs_stack_timespec_nsec(tspec);
1663
1664 inode->i_generation = BTRFS_I(inode)->generation;
1665 BTRFS_I(inode)->index_cnt = (u64)-1;
1666
1667 mutex_unlock(&delayed_node->mutex);
1668 btrfs_release_delayed_node(delayed_node);
1669 return 0;
1670}
1671
1616int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, 1672int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
1617 struct btrfs_root *root, struct inode *inode) 1673 struct btrfs_root *root, struct inode *inode)
1618{ 1674{