-1

I have experienced a weird behaivour on our production environment.

We have a NFS and a linux server which runs our application.

On the linux server there is a mount to the NFS,
from: /configuration/data (on the NFS)
To: /software (on the linux server).
Which the application modifies the files there periodically.

Some time ago someone accidentally moved to "data" folder to: /configuration/other/data

The application kept running without any side effect,
and modified the files periodically,
and the files inside /configuration/other/data also changed even though the mount (/configuration/data) point to nothing.

I guess there is a shortcut to the origin of the mount which being modified on the folder relocation, but that just a guess.

I would like to know why and how this behaivour is possible, and how it works internally.

1 Answers1

2

and how it works internally.

File descriptor refers to a file. You can move the file, you can remove the file - the file descriptor refers to the same "entity". So in shell you can for example:

# open fd 10 to refer to /tmp/10
$ exec 10>/tmp/10

# Just write something so that it works
$ echo abc >&10
$ cat /tmp/10
abc

# Move the file to some dir
$ mkdir /tmp/dir
$ mv /tmp/10 /tmp/dir/10
# now it still writes to the same "file", even when moved
$ echo def >&10
$ cat /tmp/dir/10 
abc
def

# You can remove the file and still access it
# The file still "exists"
$ exec 11</tmp/dir/10
$ rm /tmp/dir/10
$ echo 123 >&10
$ cat <&11
abc
def
123

Creating a file descriptor to a file and then removing the file is typically in C programs:

char *filename = mkstemp(...);
int fd = open(filename);
unlink(filename); 
// use fd

The file is really "removed" when there are no links to it - when the last file descriptor is closed. Research posix file descriptors and see for example man 2 unlink and other resources explaining what is a file descriptor.

Most probably you application has continously opened file descriptors to files inside /configuration/data, so after the file is moved, the data become available at the new location but application still uses same file descriptors.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111