Q. hlist_bl_add_head_rcu() in d_alloc_parallel()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am afraid there may exist another violation of "no lookups on the same
name in parallel" rule, but I am not sure.

Roughly d_alloc_parallel() behaves like this.

struct dentry *d_alloc_parallel()
{
	new = d_alloc(parent, name);

	rcu_read_lock();
	hlist_bl_lock(b);
	rcu_read_unlock();
	hlist_bl_for_each_entry(dentry, node, b, d_u.d_in_lookup_hash) {
		if (!matched_dentry_found)
			continue;
		dget(dentry);
		hlist_bl_unlock(b);
		return dentry;
	}
	hlist_bl_add_head_rcu(&new->d_u.d_in_lookup_hash, b);
	hlist_bl_unlock(b);
	return new;
}

When two processes try opening a single existing file and enters
d_alloc_parallel() at the same time, only one process wins and should
succeeds hlist_bl_add_head_rcu(). The other process should find the
dentry in d_u.d_in_lookup_hash and return 'dentry' (instead of
'new'). Am I right?

My question is when will 'new' be added into d_u.d_in_lookup_hash?
It should be between these two lines, I guess.
	rcu_read_unlock();
	hlist_bl_for_each_entry(dentry, node, b, d_u.d_in_lookup_hash) {
But can it surely happen?
If 'new' is not added here because someone else is in rcu_read_lock
region or other reason, then both processes will add the same named but
different dentry?

Is it better to change the lock/unlock-order like this?

	rcu_read_unlock();
	rcu_barrier();
	hlist_bl_lock(b);
	hlist_bl_for_each_entry(dentry, node, b, d_u.d_in_lookup_hash) {


J. R. Okajima
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux