Hello,
I encounter some difficulties when testing file existence over NFS. I use
access("filename", F_OK) in a while-loop to test for the existence of
"filename", and there are two cases, but quit different results:
1. If the file is created on another node before the testing begins, then
the access() would success in a very short time (less than 0.001 sec), and
quit the while-loop. Otherwise,
1. If the file is created on another node after the test begins, the
while-loop would last for quite a long time (about 20~30 sec) until the
access() returns ok.
I think this is not so related to 'noac', and I can not figure out what
makes them different. The NFS server/client are configured with default
options. Is there a safety method to test the existence of a newly created
file?
BTW, I am not in the list, please cc to me if you reply. Thanks!
Best
Andrew
Below is my testing code:
/****************************************************
* fexist.c
* gcc -o fexit fexit.c
*
* test cases: (before the test, make sure no file 'test' exist)
* 1. on one node create a file `test', then run `fexit' on another node
(returns in l sec)
* 2. run `fexit' in one node at first, and then creat file 'test' on
another (returns in 20~30 sec)
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
static double gettime()
{
struct timeval tp;
gettimeofday(&tp, NULL);
return ((double)tp.tv_sec + tp.tv_usec * 1e-6);
}
static int file_exist(const char* path)
{
struct stat sbuf;
return access(path, F_OK);
}
int main()
{
double s, e;
s = gettime();
while (file_exist("./test") != 0);
e = gettime();
printf("Wait: %f\n", e - s);
return 0;
}