NFS cache-cleaning command?
Depending on what you mean by "false-caching errors", running sync
may get you what you need. This will flush all filesystem buffers.
If needed, you can also clear out the VM caches in the kernel using /proc/sys/vm/drop_caches
.
# To free pagecache
echo 1 > /proc/sys/vm/drop_caches
# To free dentries and inodes
echo 2 > /proc/sys/vm/drop_caches
# To free pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
howto force refresh NFS cache when checking newly created file?
This solution belongs to the Category B : exit_code or return code of writing function
...only
open()
andfopen()
need to guarantee that they get a consistent handle to a particular file for reading and writing.stat
and friends are not required to retrieve fresh attributes. Thus, for the sake of close-to-open cache coherence, onlyopen()
andfopen()
are considered an "open event" where fresh attributes need to be fetched immediately from the server[1].
The following solutions belong to the Category A : NFS clients setting
i.e. if you do NOT expect cached file/dir entries to be served to the client, disable caching.
Setup a shared cache
If the file in the NFS mount (whose existence is being checked) is created by another application on the same client (possibly using another mount point to the same NFS export) the consider using a single shared NFS cache on the client.
Use the sharecache
option to setup the NFS mounts on the client.
This option determines how the client's data-cache and attribute-cache are shared when mounting the same export more than once concurrently. Using the same cache reduces memory requirements on the client and presents identical file contents to applications when the same remote file is accessed via different mount points.
Setting-up a NFS-mount without caching
Disable attribute caching.
Mount the NFS share on the client with the noac
option.
Alternately, disable cached directory attributes from being served.
Use acdirmin=0,acdirmax=0
to set the cache timeouts to 0 (effectively disabling caching).
Setting-up a NFS-mount to ignore lookup caches
Use
lookupcache=positive
ORlookupcache=none
(available options : all
, positive
and none
)
When attempting to access a directory entry over a NFS mount,
if the requested directory entry exists on the server, the result is referred to as positive
.
if the requested directory entry does not exist on the server, the result is referred to as negative
.
If the lookupcache
option is not specified, or if all
is specified, the client assumes both types of directory cache entries are valid until their parent directory's cached attributes expire.
If pos
or positive
is specified, the client assumes positive entries are valid until their parent directory's cached attributes expire, but always revalidates negative entires before an application can use them.
If none
is specified, the client revalidates both types of directory cache entries before an application can use them. This permits quick detection of files that were created or removed by other clients, but can impact application and server performance.
References:
1. Close-To-Open Cache Consistency in the Linux NFS Client
2. NFS - Detecting remotely created files programmatically?
3. NFS cache : file content not updated on client when modified on server
4. NFS man page. Especially the "Data And Metadata Coherence" section.
How to purge disk I/O caches on Linux?
Sounds like you want the sync command, or the sync() function.
If you want disk cache flushing: echo 3 | sudo tee /proc/sys/vm/drop_caches
bitbake clean fails with read-only NFS SSTATE CACHE
If its a read-only sstate archive, use SSTATE_MIRRORS instead.
How do I take an NFS file handle, and derive its fully-qualified path and extract the attributes of the file?
tl; dr: nfs_fhget()
-> d_obtain_alias() -> d_absolute_path()
.
You will need the struct vfsmount
that describes the mounted filesystem.
Disclaimer: The assumption here is that you got the file handle from fs-cache, i.e. it's the raw NFS file handle, not a struct fid
that you got from something like name_to_handle_at(2).
Source of the handle
If you got this handle from the handle fairy, i.e. with no previous context, then the client can't map it to a path. In fact, the server will probably also be unable to map it into a path without a find(1)
.
Just like an inode, it can have multiple paths within the filesystem, and multiple mount points of that filesystem within the mount tree.
But assuming that you got this handle by means of file name lookup, the dcache will contain dentries which point to an inode, which will have an i_private
pointing to that file handle. The inode will also have its list of cached dentries in i_dentry
.
Likewise, the mount tree may have the same NFS mount bind-mounted multiple times.
Finding the VFS inode
Because you have a raw NFS file handle, we start at the NFS layer, mapping a file handle to an inode using nfs_fhget()
.
If the inode isn't already in the cache, nfs_fhget()
will just return a blank NFS inode. This can be detected by putting some interesting value in the contents of the fattr
argument.
There are a couple of requirements on fattr
, see nfs_find_actor().
But once you've succeeded, you're done with the NFS layer and you have a VFS inode.
The returned inode also has all the other information like inode permissions, ownership, dates, etc..
Obtaining the VFS dentry
Once you have an inode, you want a dentry that points to it.
That's done by d_obtain_alias().
Like with nfs_fhget()
, d_obtain_alias()
won't fail if there's no dentry in the cache. Instead, it will create an "anonymous dentry", i.e. a dentry without an actual name. In this case, its name, relative to the mount point, is just /
.
Converting VFS data structures to path
Assuming that you have the struct vfsmount
and now that you have the dentry, you can build a you have a struct path
.
With a struct path
, you can now call d_absolute_path()
, which finally returns an absolute path.
Related Topics
Linux Command or Script Counting Duplicated Lines in a Text File
When to Use Pipes VS When to Use Shared Memory
Unix - Count of Columns in File
Linux Command to Translate Domain Name to Ip
How to Extract Filename.Tar.Gz File
Unzip All Files in a Directory
Eclipse Cdt Indexer Lost After System Update
Need an Overview of Debugging Process from the Hardware Layer
How to Find a List of Ip Addresses in Another File
Automatic Login on Angstrom Linux
Embedding the Password in the Bash Script
Backup a Running Docker Container
PDF Compare on Linux Command Line
Remove File Coding Mark But Preserve Its Coding
How to Configure a Systemd Service to Restart Periodically