Linux 移动底座';s源目录

Linux 移动底座';s源目录,linux,directory,mount,nfs,Linux,Directory,Mount,Nfs,我在我们的生产环境中遇到了一种奇怪的行为。 我们有一个NFS和一个linux服务器来运行我们的应用程序 在linux服务器上有到NFS的装载, from:/configuration/data(在NFS上) 至:/software(在linux服务器上) 应用程序定期修改其中的文件。 不久前,有人意外地将“数据”文件夹移动到:/configuration/other/data 应用程序保持运行,没有任何副作用,并定期修改文件,,/configuration/other/data中的文件也发生了更

我在我们的生产环境中遇到了一种奇怪的行为。

我们有一个NFS和一个linux服务器来运行我们的应用程序

在linux服务器上有到NFS的装载,
from:/configuration/data(在NFS上)
至:/software(在linux服务器上)
应用程序定期修改其中的文件。

不久前,有人意外地将“数据”文件夹移动到:/configuration/other/data

应用程序保持运行,没有任何副作用,
并定期修改文件,
,/configuration/other/data中的文件也发生了更改,即使挂载(/configuration/data)没有指向任何内容。

我想有一个快捷方式可以找到在文件夹重新定位时修改的装载原点,但这只是一个猜测。

我想知道这种行为为什么可能,如何可能,以及它在内部是如何工作的

以及它如何在内部工作

文件描述符指的是一个文件。您可以移动文件,也可以删除文件-文件描述符引用相同的“实体”。因此,在shell中,您可以例如:

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

当没有指向该文件的链接时(当最后一个文件描述符关闭时),该文件实际上被“删除”。研究posix文件描述符,例如参见
MAN2 unlink
和其他资源,解释什么是文件描述符

很可能您的应用程序已经连续打开了
/configuration/data
中文件的文件描述符,因此在移动文件后,数据在新位置变得可用,但应用程序仍然使用相同的文件描述符

# 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
char *filename = mkstemp(...);
int fd = open(filename);
unlink(filename); 
// use fd