大网数据广告活动
服务器运维问答

Overmount existing directory contents at runtime

· 52CE 我爱测

I have the following scenario: users run software installed in /path/to/software I create a file-backed FS image with exactly the same contents as in /path/to/software I mount the image using loopback in read-only mode at /path/t…

问题原文

原帖链接 · angainor · CC BY-SA 3.0

I have the following scenario:

  1. users run software installed in /path/to/software
  2. I create a file-backed FS image with exactly the same contents as in /path/to/software
  3. I mount the image using loopback in read-only mode at /path/to/software

After step 3 the old contents of the directory are 'shadowed' by the newly mounted image with exactly same contents.

Can this in any way affect the users that have started the original software prior to the mount? I have made a few tests and it seems that the started programs are unaware of any change, i.e., they continue to run without any error. It is a bit surprising since the programs have previously opened some files (libraries) in the old file system, which is gone after step 3. I would expect that the file descriptors would change after the mount.

So how come there is no error? Are the old files visible somehow to the running programs despite the fact that the directory contents have been shadowed?

已采纳解答

原帖链接 · chicks · CC BY-SA 3.0

In POSIX-compliant file systems open files are not removed until no one has them open anymore. This same behavior is used in the standard library tmpfile which opens a temporary file and then deletes it. The open file handle is still usable by the process that has the file handle (or its children) but no other processes can open the file since there is no filename anymore. It seems reasonable to expect this would also work when mounting over some directory.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。