Skip to contentSkip to conversation

elementary d_move question

DISCUSSION J. Bruce Fields 2 participants 2 messages Oct 23, 2013 – Oct 29, 2013 VFS

lore
Share & tools
lore
#0 lore raw

If I rename foo over bar, while holding bar open, then /proc/<pid>/fd/<fd> still shows me bar's old path:

	$ touch foo bar
	$ tail -f bar &
	[1] 23492
	$ mv foo bar
	$ readlink /proc/23492/fd/3
	/home/bfields/bar (deleted)

The rename does a d_move(dentry, target) where I assume dentry is for "foo" and target for "bar", with target the same dentry that the file descriptor holds a reference on.

But d_move() does

	switch_names(dentry, target);

giving target name "foo". So how does readlink still get "bar"?

I've clearly missed something obvious....

--b.

reviewer
#1 lore raw
Quoted 14 lines · J. Bruce Fields

If I rename foo over bar, while holding bar open, then /proc/<pid>/fd/<fd> still shows me bar's old path:

	$ touch foo bar
	$ tail -f bar &
	[1] 23492
	$ mv foo bar
	$ readlink /proc/23492/fd/3
	/home/bfields/bar (deleted)

The rename does a d_move(dentry, target) where I assume dentry is for "foo" and target for "bar", with target the same dentry that the file descriptor holds a reference on.

Quoted 7 lines

But d_move() does

	switch_names(dentry, target);

giving target name "foo". So how does readlink still get "bar"?

I've clearly missed something obvious....

You didn't read switch_names() carefully enough :) (and I didn't either
on the first reading). There is one (the common) case when the switching doesn't happen and the name is only copied from 'target' to 'dentry' so target's name remains intact...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR