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

Re: [OT] deleting dot files on remote server with ftp



Alan Shutko wrote:
> Tim writes:
> > I'm using ftp or lftp, and find a file called (eg) .nfs80301.
> 
> Some process has an open handle to the file over NFS.
> 
> When you have a program with a file open over NFS, but delete the
> file (over nfs) the file is renamed as you see it.  When the process
> closes, the file gets removed completely.

Yes.  This is known as the "last close" problem and has been around as
long as NFS has been around.  It is a fundamental issue with NFS being
a "stateless", networked filesystem.

Normal unix semantics say you can open a file in a program and then
remove it from the directory and the file still exists until the last
reference to it is closed.  The program can continue to access the
file by the previously opened file handle regardless of it being
removed from all filesystem directories.  In effect the filesystem is
a reference counting, garbage collecting system.  As long as at least
one process has a pointer to the file it must remain around.

The NFS server does not know anything about processes which exist on
other machines.  If you remove the file from the server then it is
gone.  The other process can get an error in this case when using NFS
that could not occur if run on the local disk.

However, the NFS client does know about other processes on the same
machine.  It will try to work like the local filesystem.  When the
file is removed with an open process to it the NFS client will not
actually remove the file.  Instead it will rename it into a .nfsABCD
named file.  Removing that file just renames it again.  It will try to
do the reference counting itself and only remove the file when it
thinks it can.

In the event of a client crash those .nfs* files might be left hanging
around.  In that case nothing would ever remove them.  On Sun systems
a cron job is usually included which scans the disk with 'find'
looking for .nfs* files which are more than a week old and removing
them.

Even though you cannot remove the file it is possible to move the file
around.  You can 'mv .nfs* ../' for example to get the files up a
level.  That empties the directory and would allow you to remove a
directory for example.  Sometimes that can be useful when you don't
want to kill the process that has the file open.

Bob

Attachment: pgpAyucq7kTWn.pgp
Description: PGP signature


Reply to: