python / python/cpython

os.path.ismounts: further situations it doesn't detect correctly

オープン
#96,328 コメント 18 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

docs type-bug
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

Bug report

I had a look at os.path.ismount():
https://github.com/python/cpython/blob/43a6deadbb40bc93e0eaebb3c56c34f8a3502132/Lib/posixpath.py#L186-L216

And it may have some issues:

  1. The documentation already says, that it isn't capable of detecting bind-mounts of some filesystem on the very same filesystem. While it's good that it mentions this, the results of ismount() is IMO still simply wrong in these cases, cause it is a mountpoint.
  2. The same problem in the detection algorithm is not only limited to bind-mounts, but also to any other mount points, where the path’s st_dev equals that of its parent. For example, btrfs subvolumes. This is however not documented.

Looking a the code, it effectively does: lstat(), check whether it’s a symlink, lstat() the parent, check whether the device numbers are different (then it's a mountpoint), check whether the inodes are the same.

Now I thought about the latter, and what it is meant for.

The only case I could think of at first is /, where /.. is the same inode. [Is there any other?]

  1. This however already requires, that not only the inodes are the same, but also the device numbers. which is given because of the order of these checks, however, I'd suggest to comment that accordingly.
  2. If the above were the only case, wouldn't it be faster to simply check the pathname for being "/" or b"/". Would perhaps require some realpath() though, to also catch things like "/../.." and so on.
  3. However, I found that / is not the only case: Within a chroot, the chroot's / may (or may not) be a mountpoint - the problem is just, the current algorithm doesn't detect this either. Instead, it wrongly claims that a chroot’s "/" would be a mountpoint, even when it isn't.

Not sure what one could do about all that… /etc/mtab is dead... /proc/mounts may not be available on all POSIX systems and even on Linux it's nowadays rather superseded by /proc/self/mountinfo.

Your environment

  • CPython versions tested on: 3.10.6
  • Operating system and architecture: Debian sid

Cheers,
Chris.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/posixpath.py の os.path.ismount() から始め、特にリンク先の実装を確認し、そのドキュメントを見直してください。指定された Debian 環境で、報告された bind-mount、btrfs サブボリューム、chroot のケースを再現してください。検出方法について合意され、動作が修正され、残るプラットフォーム上の制限がドキュメント化されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。