"pwd", inodes, and readdir

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

"pwd", inodes, and readdir

David Shaw
Here's a fairly subtle problem, and a possible fix.

The problem is that if you export a Fuse filesystem via NFS, and mount
it on some clients (OSX, Irix, HPUX, *BSD), getcwd() from within the
Fuse filesystem doesn't work (failing with ENOENT).  Since pwd calls
getcwd() this is a very annoying problem as pwd is used frequently in
scripts, etc.

The reason for the problem is in how getcwd() is implemented: it stats
the current directory ("."), notes the inode number, then opens the
directory ".."  and reads each entry looking for that inode.  Repeat
until we reach the root.

Unless use_ino is set, fuse does not fill in the d_ino field of a
struct dirent (it fills in (ino_t)-1 instead).  Since -1 never matches
the inode that getcwd() is looking for, getcwd() fails.

Here's a patch to fill in d_ino in directory listings.  If use_ino is
set, the passed-in inode is used of course.  This only changes the
behavior when use_ino isn't set.  Also, this isn't perfect - if the
cache no longer has the node in question, then -1 is returned for the
inode like it is now.  However, this is unlikely and if it does
happen, we're no worse off than we are now.

David

d_ino_patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: "pwd", inodes, and readdir

Miklos Szeredi
> Here's a fairly subtle problem, and a possible fix.
>
> The problem is that if you export a Fuse filesystem via NFS, and mount
> it on some clients (OSX, Irix, HPUX, *BSD), getcwd() from within the
> Fuse filesystem doesn't work (failing with ENOENT).  Since pwd calls
> getcwd() this is a very annoying problem as pwd is used frequently in
> scripts, etc.
>
> The reason for the problem is in how getcwd() is implemented: it stats
> the current directory ("."), notes the inode number, then opens the
> directory ".."  and reads each entry looking for that inode.  Repeat
> until we reach the root.
>
> Unless use_ino is set, fuse does not fill in the d_ino field of a
> struct dirent (it fills in (ino_t)-1 instead).  Since -1 never matches
> the inode that getcwd() is looking for, getcwd() fails.
>
> Here's a patch to fill in d_ino in directory listings.  If use_ino is
> set, the passed-in inode is used of course.  This only changes the
> behavior when use_ino isn't set.  Also, this isn't perfect - if the
> cache no longer has the node in question, then -1 is returned for the
> inode like it is now.  However, this is unlikely and if it does
> happen, we're no worse off than we are now.

OK.

I'm a little afraid of such a non-deterministic behavior.  How about
making it dependent on a new mount option (readdir_ino)?

Thanks,
Miklos


-------------------------------------------------------
SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
online with coworkers and clients while avoiding the high cost of travel and
communications. There is no equipment to buy and you can meet as often as
you want. Try it free.http://ads.osdn.com/?ad_id=7402&alloc_id=16135&op=click
_______________________________________________
fuse-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/fuse-devel
Reply | Threaded
Open this post in threaded view
|

Re: "pwd", inodes, and readdir

David Shaw
On Thu, May 26, 2005 at 10:20:31AM +0200, Miklos Szeredi wrote:

> > Here's a fairly subtle problem, and a possible fix.
> >
> > The problem is that if you export a Fuse filesystem via NFS, and mount
> > it on some clients (OSX, Irix, HPUX, *BSD), getcwd() from within the
> > Fuse filesystem doesn't work (failing with ENOENT).  Since pwd calls
> > getcwd() this is a very annoying problem as pwd is used frequently in
> > scripts, etc.
> >
> > The reason for the problem is in how getcwd() is implemented: it stats
> > the current directory ("."), notes the inode number, then opens the
> > directory ".."  and reads each entry looking for that inode.  Repeat
> > until we reach the root.
> >
> > Unless use_ino is set, fuse does not fill in the d_ino field of a
> > struct dirent (it fills in (ino_t)-1 instead).  Since -1 never matches
> > the inode that getcwd() is looking for, getcwd() fails.
> >
> > Here's a patch to fill in d_ino in directory listings.  If use_ino is
> > set, the passed-in inode is used of course.  This only changes the
> > behavior when use_ino isn't set.  Also, this isn't perfect - if the
> > cache no longer has the node in question, then -1 is returned for the
> > inode like it is now.  However, this is unlikely and if it does
> > happen, we're no worse off than we are now.
>
> OK.
>
> I'm a little afraid of such a non-deterministic behavior.  How about
> making it dependent on a new mount option (readdir_ino)?
OK.  Here's a new patch.  The default is the current behavior.  Adding
"readdir_ino" does the extra best-effort inode lookup, and adding
"use_ino" overrides everything.

David

readdir_ino.patch (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: "pwd", inodes, and readdir

Miklos Szeredi
> OK.  Here's a new patch.  The default is the current behavior.  Adding
> "readdir_ino" does the extra best-effort inode lookup, and adding
> "use_ino" overrides everything.

Cool. Will apply.

Thanks,
Miklos


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
fuse-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/fuse-devel
Reply | Threaded
Open this post in threaded view
|

Re: "pwd", inodes, and readdir

David Shaw
On Thu, May 26, 2005 at 05:36:57PM +0200, Miklos Szeredi wrote:
> > OK.  Here's a new patch.  The default is the current behavior.  Adding
> > "readdir_ino" does the extra best-effort inode lookup, and adding
> > "use_ino" overrides everything.
>
> Cool. Will apply.

Excellent, thanks!

David


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
fuse-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/fuse-devel