linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* elementary d_move question
@ 2013-10-23 15:46 J. Bruce Fields
  2013-10-29 16:28 ` Jan Kara
  0 siblings, 1 reply; 3+ messages in thread
From: J. Bruce Fields @ 2013-10-23 15:46 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel

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.

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

* Re: elementary d_move question
@ 2013-10-23 17:27 J. Bruce Fields
  0 siblings, 0 replies; 3+ messages in thread
From: J. Bruce Fields @ 2013-10-23 17:27 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel

(Bah, apologies, I messed up the list cc.  Resending in case it's useful
to have the answer in the archives.)

On Wed, Oct 23, 2013 at 01:23:38PM -0400, J. Bruce Fields wrote:
> On Wed, Oct 23, 2013 at 05:14:02PM +0100, Al Viro wrote:
> > On Wed, Oct 23, 2013 at 11:43:41AM -0400, J. Bruce Fields wrote:
> > 
> > > 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);
> > 
> > Yes
> > 
> > > giving target name "foo"
> > 
> > Not really.  Check what it does when both names are inline ones (i.e.
> > shorter than 32 characters and stored in struct dentry itself)...
> 
> Doh--got it, thanks!
> 
> I have a feeling I've gotten lost here before.
> 
> I assume it's just never seemed worth the trouble to make the readlink
> string more consistent given that its value's not really well-defined
> anyway, OK.
> 
> --b.

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

* Re: elementary d_move question
  2013-10-23 15:46 elementary d_move question J. Bruce Fields
@ 2013-10-29 16:28 ` Jan Kara
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kara @ 2013-10-29 16:28 UTC (permalink / raw)
  To: J. Bruce Fields; +Cc: Al Viro, linux-fsdevel

On Wed 23-10-13 11:46:54, J. Bruce Fields wrote:
> 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....
  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
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

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

end of thread, other threads:[~2013-10-29 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23 15:46 elementary d_move question J. Bruce Fields
2013-10-29 16:28 ` Jan Kara
  -- strict thread matches above, loose matches on Subject: below --
2013-10-23 17:27 J. Bruce Fields

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).