[PATCH 4 of 5 V2] util: add a getfstype method

Jun Wu quark at fb.com
Sat Mar 11 20:13:57 EST 2017


Per discussion with Augie, we have to be more conservative and couldn't
trust /proc (not to mention /etc).

Fortunately, it seems modern Linux has a syscall to get the filesystem
information. I'm investigating the details.

Excerpts from Yuya Nishihara's message of 2017-03-11 16:48:54 -0800:
> On Thu, 2 Mar 2017 22:13:30 -0800, Jun Wu wrote:
> > # HG changeset patch
> > # User Jun Wu <quark at fb.com>
> > # Date 1488521308 28800
> > #      Thu Mar 02 22:08:28 2017 -0800
> > # Node ID d79c818940ff7e29c76ff5e985b920885aa4e7c1
> > # Parent  1cf153ec3faaef92c9ad3515372a6d8591195d6e
> > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r d79c818940ff
> > util: add a getfstype method
> 
> Can you update debugfsinfo to include this information?

Good advice. Will do.

> > +if pycompat.sysplatform.startswith('linux'):
> > +    # for Linux, reading /etc/mtab (symlink to /proc/self/mounts) is a sane way
> > +    # to get the current filesystem mount information
> > +    def _getfstypetable():
> > +        result = {}
> > +        try:
> > +            with open('/etc/mtab', 'r') as f:
> > +                for line in f.read().splitlines():
> > +                    name, path, fs, ops, freq, passno = line.split(' ', 5)
> > +                    result[path] = fs
> > +        except OSError:
> 
> For reminder, it should be IOError.
> 
> Shouldn't we take care of mtab corruption as well? IIRC, it was a plain file
> on old Linux.
> 
> > +# cache _getfstypetable() to avoid repetitive expensive queries, it assumes
> > +# mount table does not change during the lifetime of the process, which is
> > +# reasonable for short-lived process
> > +_fstypetable = None
> 
> This can be problem on chg or hgweb. Short-lived cache in vfs would help.

Good idea.


More information about the Mercurial-devel mailing list