Invalidating NFS attribute cache
Subsystems (2)
Hi,
For some silly reason I have an application that needs to poll for the existence of a certain file on a NFS share.
(This is done from Sybase ASE ;-)
Now I run into the issue of attribute caching. Turning of the attribute cache with the mount option of -o noac easily solves all the issues.
However, it would be nice if we could still use attribute caching and force to invalidate on-demand the attribute cache.
After a lot of trying, the following solution seems to work for me now:
(pathname is the test file)
#define _GNU_SOURCE
char *copy = strdup(pathname);
char *path = dirname(copy);
int fd = open(path, O_DIRECTORY);
if (fd >= 0)
close(fd);
free(copy);
return access(pathname, F_OK);Just opening the parent directory with O_DIRECTORY seems to do the trick.
My questions: Is this hack going to work under every circumstance or could it fail in the future with some update. Is there a ioctl call that could the the same thing? That is invalidate the parent directory cache. Or do I miss something completely ?-)
Thanks in advance
Hans
A message that is not in the archive (sent off-list or not yet received): 1247142894.7427.43.camel-6FgEqA8bTCrD1MxPaE+0Y3nhMCiq3JZZ@public.gmane.org
Quoted 11 lines · Hans Kramer
Hi,
For some silly reason I have an application that needs to poll for the existence of a certain file on a NFS share.
(This is done from Sybase ASE ;-)Now I run into the issue of attribute caching. Turning of the attribute cache with the mount option of -o noac easily solves all the issues.
However, it would be nice if we could still use attribute caching and force to invalidate on-demand the attribute cache.
Since you are only concerned with the existence of a file (and not its mtime, say). have you considered the new directory cache mount option: lookupcache=?
I see it's not mentioned in nfs(8) so you should probably look in recent archives of this mailing list for information.
Quoted 32 lines
After a lot of trying, the following solution seems to work for me now:
(pathname is the test file)#define
_GNU_SOURCEchar *copy = strdup(pathname); char *path = dirname(copy); int fd = open(path, O_DIRECTORY); if (fd >= 0) close(fd); free(copy); return access(pathname, F_OK);Just opening the parent directory with
O_DIRECTORYseems to do the trick.My questions: Is this hack going to work under every circumstance or could it fail in the future with some update. Is there a ioctl call that could the the same thing? That is invalidate the parent directory cache. Or do I miss something completely ?-)
Thanks in advance
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Thanks Chuck,
I was not aware of this mount option.
I will try it.
Thanks!
Quoted 58 lines · Chuck Lever
Quoted 6 lines · Hans Kramer
Hi,
For some silly reason I have an application that needs to poll for the existence of a certain file on a NFS share.
(This is done from Sybase ASE ;-)Quoted 6 lines
Now I run into the issue of attribute caching. Turning of the attribute
cache with the mount option of -o noac easily solves all the issues.However, it would be nice if we could still use attribute caching and force to invalidate on-demand the attribute cache.
Since you are only concerned with the existence of a file (and not its mtime, say). have you considered the new directory cache mount option:
lookupcache=?I see it's not mentioned in nfs(8) so you should probably look in recent archives of this mailing list for information.
Quoted 36 lines
After a lot of trying, the following solution seems to work for me now:
(pathname is the test file)#define
_GNU_SOURCEchar *copy = strdup(pathname); char *path = dirname(copy); int fd = open(path, O_DIRECTORY); if (fd >= 0) close(fd); free(copy); return access(pathname, F_OK);Just opening the parent directory with
O_DIRECTORYseems to do the trick.My questions: Is this hack going to work under every circumstance or could it fail in the future with some update. Is there a ioctl call that
could the the same thing? That is invalidate the parent directory cache.
Or do I miss something completely ?-)Thanks in advance
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html