- 论坛徽章:
- 9
|
问题是我在创建一个 struct dentry 的过程中,一个 bit 设置不对引起的.
源码如下: /fs/dcache.c
static void __d_rehash(struct dentry * entry, struct dcache_hash_bucket *b)
{
BUG_ON(!d_unhashed(entry));
spin_lock_bucket(b);
entry->d_flags &= ~DCACHE_UNHASHED;
hlist_bl_add_head_rcu(&entry->d_hash, &b->head);
spin_unlock_bucket(b);
}
static void _d_rehash(struct dentry * entry)
{
__d_rehash(entry, d_hash(entry->d_parent, entry->d_name.hash));
}
1. 如上面的源码所示,调用 _d_rehash() 时候,使用 d_hash() 函数获得了 dcache_hashtable 的入口,
此时,入口类型为 struct dcache_hash_bucket,此时其成员 head.first 的值为 NULL.
2. 接着调用 __d_rehash() 经常 spin_lock_bucket(b) 处理之后, head.first 的值的最低位被值位,为 0x00000001.
问题来了,由于这样的操作,导致 head.first 的不为 NULL,在接下来的处理过程中
hlist_bl_add_head_rcu(&entry->d_hash, &b->head);
其源码如下:
static inline void hlist_bl_add_head_rcu(struct hlist_bl_node *n,
struct hlist_bl_head *h)
{
struct hlist_bl_node *first;
/* don't need hlist_bl_first_rcu because we're under lock */
first = hlist_bl_first(h);
n->next = first;
if (first)
first->pprev = &n->next;
n->pprev = &h->first;
/* need _rcu because we can have concurrent lock free readers */
hlist_bl_set_first_rcu(h, n);
}
如上诉,first 的值为 1,但此时判断 first 不为 NULL 之后就对该指针进行操作,就导致系统崩溃.
这个问题该如何解释,请大神给建议. |
|