$ unshare -rm
# mount --bind /tmp /
# awk '{ if ($2 == "/") print $0; }' < /proc/mounts
/dev/mapper/alan_dell_2016-fedora / ext4 rw,seclabel,relatime 0 0
tmpfs / tmpfs rw,seclabel,nosuid,nodev 0 0
/
この新しいマウントは参照されている物理ディレクトリを変更しません。また、見ることができます/proc/self/root
。各プロセスのルートディレクトリを変更するだけですchroot
。アクセスすると、/
tmpfs ではなく ext4 ルートファイルシステムの内容が引き続き表示されます。
# stat -f /tmp --format %T
tmpfs
# stat -f / --format %T
ext2/ext3
# ls -l -d -i /tmp
22161 drwxrwxrwt. 44 nfsnobody nfsnobody 1000 Jul 19 09:49 /tmp
# ls -l -d -i /
2 dr-xr-xr-x. 19 nfsnobody nfsnobody 4096 Jul 7 09:21 /
umount
tmpfsマウントで実行されることを除いて。どのように動作しますか?これら2つのタスクタイプの違いは何ですか?
# umount /
# awk '{ if ($2 == "/") print $0; }' < /proc/mounts
/dev/mapper/alan_dell_2016-fedora / ext4 rw,seclabel,relatime 0 0
環境
$ uname -r # Kernel version
4.17.3-200.fc28.x86_64
システムコールの追跡
私はumount /
run underを使ってこれを繰り返そうとしましたが、それ以上のstrace -f
実現を示していませんでした。 umount
呼び出しだけumount2()
でフラグを渡しません(2番目の引数は0です)。
# strace -f umount /
...
statfs("/", {f_type=EXT2_SUPER_MAGIC, f_bsize=4096, f_blocks=10288440, f_bfree=2384614, f_bavail=1856230, f_files=2621440, f_ffree=2253065, f_fsid={val=[1557883181, 1665775425]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_RELATIME}) = 0
stat("/sbin/umount.ext4", 0x7ffd79ccbb40) = -1 ENOENT (No such file or directory)
stat("/sbin/fs.d/umount.ext4", 0x7ffd79ccbb40) = -1 ENOENT (No such file or directory)
stat("/sbin/fs/umount.ext4", 0x7ffd79ccbb40) = -1 ENOENT (No such file or directory)
umount2("/", 0) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
ベストアンサー1
Linux v4.17を見ると、umount
onがon/
と同じであると言えるでしょう。 「マウントポイントヒープの上」にアクセスします。umount
/..
/..
# stat -f / --format %T
ext2/ext3
# stat -f /.. --format %T
tmpfs
このあいまいな動作は..
POSIXで許可されているようです。 「特別な場合でルートディレクトリに点(.)」とだけ出ています。可能ルートディレクトリ自体を表します。 (POSIX.1-2017、セクション4.13「パス名の確認」)。
これを一般化し、umount
on実装の動作を定義したい場合その他マウントポイントとの比較は..
あまり良くありません。非常に正式な定義のようには聞こえませんが、「ヒープのマウントポイントの上部」という用語はまだ適用されます。
カーネルソースコード
https://elixir.bootlin.com/linux/v4.17/source/fs/namei.c
path_mountpoint()
電話をかける場所を確認してくださいfollow_mount()
。
/**
* path_mountpoint - look up a path to be umounted
* @nd: lookup context
* @flags: lookup flags
* @path: pointer to container for result
*
* Look up the given name, but don't attempt to revalidate the last component.
* Returns 0 and "path" will be valid on success; Returns error otherwise.
*/
static int
path_mountpoint(struct nameidata *nd, unsigned flags, struct path *path)
{
const char *s = path_init(nd, flags);
int err;
if (IS_ERR(s))
return PTR_ERR(s);
while (!(err = link_path_walk(s, nd)) &&
(err = mountpoint_last(nd)) > 0) {
s = trailing_symlink(nd);
if (IS_ERR(s)) {
err = PTR_ERR(s);
break;
}
}
if (!err) {
*path = nd->path;
nd->path.mnt = NULL;
nd->path.dentry = NULL;
follow_mount(path);
}
terminate_walk(nd);
return err;
}
さんのコメントがfollow_mount()
質問に関連しているようです。follow_dotdot()
アンケートのこのポイントを表す主要ユーザーに言及します。
/*
* Skip to top of mountpoint pile in refwalk mode for follow_dotdot()
*/
static void follow_mount(struct path *path)
{
while (d_mountpoint(path->dentry)) {
struct vfsmount *mounted = lookup_mnt(path);
if (!mounted)
break;
dput(path->dentry);
mntput(path->mnt);
path->mnt = mounted;
path->dentry = dget(mounted->mnt_root);
}
}
static int follow_dotdot(struct nameidata *nd)
..
私はマウントポイントからその親ポイントに移動する方法(「ポイント」)について考えてきました/tmp/..
。たとえば。しかし、そうすれば、「マウントポイントスタックの一番上に移動する」ことができることは考慮しませんでした。/tmp
これは、最上位インストールが元のディレクトリを含むインストールではない場合にも発生します。