linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Q. hlist_bl_add_head_rcu() in d_alloc_parallel()
@ 2016-06-17 20:50 J. R. Okajima
  2016-06-17 22:16 ` Al Viro
  0 siblings, 1 reply; 16+ messages in thread
From: J. R. Okajima @ 2016-06-17 20:50 UTC (permalink / raw)
  To: viro, linux-fsdevel


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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-06-29  9:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-17 20:50 Q. hlist_bl_add_head_rcu() in d_alloc_parallel() J. R. Okajima
2016-06-17 22:16 ` Al Viro
2016-06-17 22:56   ` Al Viro
2016-06-19  5:24   ` J. R. Okajima
2016-06-19 16:55     ` Al Viro
2016-06-20  4:34       ` J. R. Okajima
2016-06-20  5:35         ` Al Viro
2016-06-20 14:51           ` Al Viro
2016-06-20 17:14             ` [git pull] vfs fixes Al Viro
2016-06-23  1:19           ` Q. hlist_bl_add_head_rcu() in d_alloc_parallel() J. R. Okajima
2016-06-23  2:58             ` Al Viro
2016-06-24  5:57               ` Linus Torvalds
2016-06-25 22:54                 ` Al Viro
2016-06-26  1:25                   ` Linus Torvalds
2016-06-29  8:17                     ` Al Viro
2016-06-29  9:22                       ` Hekuang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).