Env: Linux Kernel 5.3; FS: ext4
When requesting stat(const char *pathname, struct stat *statbuf)
how is the const char *pathname
is checked for existence?
It is necessary since in case there is no such path stat
returns -1 (ENOENT)
. Here is the program I was testing:
static const char *pathname = "/some/fancy/path/name";
int main(void){
struct stat statbuf;
unsigned long i = 0;
int fd = -1;
while(1){
if((++i) % 2){
fd = open(pathname, O_CREAT, 0644);
}
stat(pathname, &statbuf);
if(i % 2){
close(fd);
unlink(pathname);
}
}
}
Every 2 iterations the file was deleted and re-created again on the next one. To inspect kernel call stack I used perf report
:
The call stack does not meet my expectation. I expected ext4
calls under the vfs_statx
in order to traverse ext4
internal data structures which would probably require disk I/O.
If it was cached in the inode or dentry cache how to flush it in order to inspect what ext4
calls would require stat(const char *pathname, struct stat *statbuf);
?
UPD: Taking closer look at the implementation I found that it seems to be taken from dentry cache as specified in the link_path_walk