• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Linux does not see existing file on mounted drive

Hi I have linked a linux directory to my Windows 2000
machine using samba. I have a cgi-script that calls
a program on my windows 2000 machine which in turn creates
a file in the linked directory. My CGI script loops after
calling the windows program checking if the file exists
in the directory using
if (-e $filename1){....}
but it seems to the Linux system that even when the file is created by the Win2000 program  it does not exist.

ie using ls $dir.$filename returns
"This file or directory does not exist" (My system is Japanese so I am translating roughly)

But if I manually list the directory contents using the
"ls" command, the Linux server seems to update it's directory listing and lists my created file and at the exact same time my still running CGI program "sees" the file.

ie
If I call from the Command Line
>ls /myprog/3ddone.txt
the message is returned
"Cannot Find this file or directory"
But if I type
>ls /myprog/
it shows
>3ddone.txt
and if I again call
>ls /myprog/3ddone.txt
its shows
>3ddone.txt

Just calling a "ls" on the directory seems to force
the Linux System to update it's File Tree Listing.

Is there a way via perl to cause the Linux system to
refresh it listing of the shared directory so that
my cgi can "see" the newly craeted file?

sync;sync doesn't work
 





 
0
brian_sweeney
Asked:
brian_sweeney
  • 3
  • 2
1 Solution
 
brian_sweeneyAuthor Commented:
Sorry I was trying to keep the problem simple by not mentioning the fact that the CGIs are actually on a different server to the Server where the outputted file is
physically stored. But the problem could be NFS related rather than Samba related so I reveal all (~_~;

Windows Server = Windows2000 (Linked via Samba to DataDirectory )
WWW Server = Unix   (Linked via NFS to Data Directory)
DataServer = Linux ( Contains Data Directory)

The WWW Server CGI calls an application on the Windows  Server and loops checking the NFS mounted Data Directory for the existence of 3ddone.txt.
The Windows Server writes the file 3ddone.txt to the Samba Linked Data Directory.

The WWW Server cannot see the created file ie
WWW Server CGI :
function -e "/myprog/3ddone.txt" is always false

WWW Server Command Prompt :
>ls /myprog/3ddone.txt
Cannot see file  

but
ls /myprog/
ls /myprog/3ddone.txt
file has magically appeared
CGI function -e "/myprog/3ddone.txt" returns true






 
0
 
bryanhCommented:
It's a good thing you added that information, because this is a classic NFS weakness.  I believe if you wait 30 seconds, the file will show up.  Or, you can do the same thing as the 'ls' in the perl program with opendir() and readdir().
0
 
brian_sweeneyAuthor Commented:
Thnks for your reply.
Could you give me any reference where this weakness is
documented/highlighted/discussed?
0
 
bryanhCommented:
I don't know of one, but any detailed description of NFS should mention that clients typically cache metadata for up to 30 seconds because going to the server every time metadata is needed would make the client too slow.  Hence, the client's view of e.g. the contents of a directory could be out of date.

Another thing to watch out for is that an NFS client caches file data and assumes the file does not change while a user has the file open.  So if Client 1 and Client 2 both have file abc open and Client 1 reads the first block abc, then Client 2 updates the first block of abc, then Client 1 reads the first block again, Client 1 sees the original contents of the block, not what Client 2 wrote.

CIFS (Windows/Samba file sharing), AFS, and NFS 4 (Not to be confused with regular NFS) are some responses to this inadequacy of NFS.
0
 
brian_sweeneyAuthor Commented:
Thanks for the information. Sorry for choosing average but
although the information was good it did not help me
fix the problem. It seemed to be specific to the environment setup I used and did not occur on the customers
system.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now