ls: optimize for when getfilecon would often fail (~33% perf. gain)
commit9f237a03c039eb9d71a16e93119dc1fc56152dd6
authorJim Meyering <meyering@redhat.com>
Sat, 11 Feb 2012 11:36:57 +0000 (11 12:36 +0100)
committerJim Meyering <meyering@redhat.com>
Sat, 18 Feb 2012 09:26:10 +0000 (18 10:26 +0100)
tree6b7f2ebf983cbd35781290f222b95b07244eeafd
parentd55d3dd5886c146547482c9f45ac653c1ebe9237
ls: optimize for when getfilecon would often fail (~33% perf. gain)

On systems or file systems without SELinux support, all getfilecon
and lgetfilecon calls would fail due to lack of support.  We can non-
invasively cache such failure (on most recently accessed device) and
avoid the vast majority of the failing underlying getxattr syscalls.
* src/ls.c (errno_unsupported): New function.
(selinux_challenged_device): New file-scoped global.
(getfilecon_cache, lgetfilecon_cache): New error-caching wrapper
functions.
(gobble_file): Use the caching wrappers, for when many *getfilecon
calls would fail with ENOTSUP or EOPNOTSUPP.
Suggested by Sven Breuner in
http://thread.gmane.org/gmane.comp.gnu.coreutils.general/2187
Improved-by: Pádraig Brady.
src/ls.c